mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-28 21:02:45 +00:00
Add chart item component, StateType and getStateType to determine state from Folder
This commit is contained in:
parent
32c849e18c
commit
02d14c7e9b
@ -1,4 +1,4 @@
|
||||
<div fxLayout="row" fxLayoutAlign="space-between start">
|
||||
<div>color</div>
|
||||
<div></div>
|
||||
<div>{{state}}</div>
|
||||
</div>
|
@ -1,6 +1,13 @@
|
||||
<mat-card class="{{elevation}}">
|
||||
<mat-card-title>Folders</mat-card-title>
|
||||
<mat-card-content>
|
||||
<app-donut-chart [elementID]="chartID"></app-donut-chart>
|
||||
<div fxLayout="row" fxLayoutAlign="space-between start">
|
||||
<app-donut-chart [elementID]="chartID"></app-donut-chart>
|
||||
<div fxLayout="column" fxLayoutAlign="space-evenly end">
|
||||
<app-chart-item></app-chart-item>
|
||||
<app-chart-item></app-chart-item>
|
||||
<app-chart-item></app-chart-item>
|
||||
</div>
|
||||
</div>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
@ -2,8 +2,6 @@ import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import Folder from '../../folder'
|
||||
import { cardElevation } from '../../style'
|
||||
import { FolderService } from 'src/app/folder.service';
|
||||
import { SystemConfigService } from 'src/app/system-config.service';
|
||||
import { DbStatusService } from 'src/app/db-status.service';
|
||||
import { DonutChartComponent } from '../donut-chart/donut-chart.component';
|
||||
|
||||
@Component({
|
||||
@ -15,16 +13,13 @@ export class FolderChartComponent implements OnInit {
|
||||
@ViewChild(DonutChartComponent) donutChart: DonutChartComponent;
|
||||
chartID: string = 'foldersChart';
|
||||
elevation: string = cardElevation;
|
||||
folderStates: Folder.stateType[];
|
||||
|
||||
constructor(
|
||||
private systemConfigService: SystemConfigService,
|
||||
private folderService: FolderService,
|
||||
private dbStatusService: DbStatusService
|
||||
) { }
|
||||
constructor(private folderService: FolderService) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
//
|
||||
for (let state in Folder.StateType) {
|
||||
console.log(state);
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
@ -34,8 +29,9 @@ export class FolderChartComponent implements OnInit {
|
||||
// TODO: Clear existing data
|
||||
this.donutChart.data([40]);
|
||||
|
||||
// state?
|
||||
const state: string = Folder.statusToString(folder);
|
||||
// Get StateType and convert to string
|
||||
const stateType: Folder.StateType = Folder.getStateType(folder);
|
||||
const state: string = Folder.stateTypeToString(stateType);
|
||||
console.log("folder state?", state, folder);
|
||||
}
|
||||
);
|
||||
|
@ -9,27 +9,99 @@ interface Folder {
|
||||
}
|
||||
|
||||
namespace Folder {
|
||||
export enum stateType {
|
||||
export enum StateType {
|
||||
Paused = 1,
|
||||
Unknown,
|
||||
Unshared,
|
||||
WaitingToScan,
|
||||
Stopped,
|
||||
Scanning,
|
||||
Idle,
|
||||
LocalAdditions,
|
||||
WaitingToSync,
|
||||
PreparingToSync,
|
||||
Syncing,
|
||||
OutOfSync,
|
||||
FailedItems,
|
||||
}
|
||||
|
||||
export function statusToString(f: Folder): string {
|
||||
const fs: Folder.Status = f.status;
|
||||
const state: string = fs.state;
|
||||
/**
|
||||
* stateTypeToString returns a string representation of
|
||||
* the StateType enum
|
||||
* @param s StateType
|
||||
*/
|
||||
export function stateTypeToString(s: StateType): string {
|
||||
switch (s) {
|
||||
case StateType.Paused:
|
||||
return 'Paused';
|
||||
case StateType.Unknown:
|
||||
return 'Unknown';
|
||||
case StateType.Unshared:
|
||||
return 'Unshared';
|
||||
case StateType.WaitingToSync:
|
||||
return 'Waiting to Sync';
|
||||
case StateType.Stopped:
|
||||
return 'Stopped';
|
||||
case StateType.Scanning:
|
||||
return 'Scanning';
|
||||
case StateType.Idle:
|
||||
return 'Up to Date';
|
||||
case StateType.LocalAdditions:
|
||||
return 'Local Additions';
|
||||
case StateType.WaitingToScan:
|
||||
return 'Waiting to Scan';
|
||||
case StateType.PreparingToSync:
|
||||
return 'Preparing to Sync';
|
||||
case StateType.Syncing:
|
||||
return 'Syncing';
|
||||
case StateType.OutOfSync:
|
||||
return 'Out of Sync';
|
||||
case StateType.FailedItems:
|
||||
return 'Failed Items';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getStatusType looks at a folder and determines the correct
|
||||
* StateType to return
|
||||
*
|
||||
* Possible state values from API
|
||||
* "idle", "scanning", "scan-waiting", "sync-waiting", "sync-preparing"
|
||||
* "syncing", "error", "unknown"
|
||||
*
|
||||
* @param f Folder
|
||||
*/
|
||||
export function getStateType(f: Folder): StateType {
|
||||
if (f.paused) {
|
||||
return 'paused';
|
||||
return StateType.Paused;
|
||||
}
|
||||
|
||||
if (!f.status || (Object.keys(f.status).length === 0)) {
|
||||
return 'unknown';
|
||||
return StateType.Unknown;
|
||||
}
|
||||
|
||||
if (state === 'error') {
|
||||
return 'stopped'; // legacy, the state is called "stopped" in the GUI
|
||||
}
|
||||
const fs: Folder.Status = f.status;
|
||||
const state: string = fs.state;
|
||||
|
||||
if (state !== 'idle') {
|
||||
return state;
|
||||
// Match API string to StateType
|
||||
switch (state) {
|
||||
case "idle":
|
||||
return StateType.Idle;
|
||||
case "scanning":
|
||||
return StateType.Scanning;
|
||||
case "scan-waiting":
|
||||
return StateType.WaitingToScan;
|
||||
case "sync-waiting":
|
||||
return StateType.WaitingToSync;
|
||||
case "sync-preparing":
|
||||
return StateType.PreparingToSync;
|
||||
case "syncing":
|
||||
return StateType.Syncing;
|
||||
case "error":
|
||||
// legacy, the state is called "stopped" in the gui
|
||||
return StateType.Stopped;
|
||||
case "unknown":
|
||||
return StateType.Unknown;
|
||||
}
|
||||
|
||||
const needTotalItems = fs.needDeletes + fs.needDirectories +
|
||||
@ -38,21 +110,22 @@ namespace Folder {
|
||||
fs.receiveOnlyChangedFiles + fs.receiveOnlyChangedSymlinks;
|
||||
|
||||
if (needTotalItems > 0) {
|
||||
return 'outofsync';
|
||||
return StateType.OutOfSync;
|
||||
}
|
||||
if (f.status.pullErrors > 0) {
|
||||
return 'faileditems';
|
||||
return StateType.FailedItems;
|
||||
}
|
||||
if (receiveOnlyTotalItems > 0) {
|
||||
return 'localadditions';
|
||||
return StateType.LocalAdditions;
|
||||
}
|
||||
if (f.devices.length <= 1) {
|
||||
return 'unshared';
|
||||
return StateType.Unshared;
|
||||
}
|
||||
|
||||
return state;
|
||||
return StateType.Unknown;
|
||||
}
|
||||
|
||||
|
||||
export interface Status {
|
||||
globalBytes: number;
|
||||
globalDeleted: number;
|
||||
|
Loading…
Reference in New Issue
Block a user