diff --git a/src/app/chart/folder-chart/folder-chart.component.ts b/src/app/chart/folder-chart/folder-chart.component.ts index a0df360c6..e102eab06 100644 --- a/src/app/chart/folder-chart/folder-chart.component.ts +++ b/src/app/chart/folder-chart/folder-chart.component.ts @@ -1,10 +1,9 @@ import { Component, OnInit, ViewChild } from '@angular/core'; -import { Folder } from '../../folder' +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 { flatMap } from 'rxjs/operators'; import { DonutChartComponent } from '../donut-chart/donut-chart.component'; @Component({ @@ -16,6 +15,7 @@ export class FolderChartComponent implements OnInit { @ViewChild(DonutChartComponent) donutChart: DonutChartComponent; chartID: string = 'foldersChart'; elevation: string = cardElevation; + folderStates: Folder.stateType[]; constructor( private systemConfigService: SystemConfigService, @@ -24,6 +24,7 @@ export class FolderChartComponent implements OnInit { ) { } ngOnInit(): void { + // } ngAfterViewInit() { @@ -33,7 +34,9 @@ export class FolderChartComponent implements OnInit { // TODO: Clear existing data this.donutChart.data([40]); - console.log("folder?", folder) + // state? + const state: string = Folder.statusToString(folder); + console.log("folder state?", state, folder); } ); diff --git a/src/app/db-status.service.ts b/src/app/db-status.service.ts index 67481bfe5..11da2e7f6 100644 --- a/src/app/db-status.service.ts +++ b/src/app/db-status.service.ts @@ -7,7 +7,7 @@ import { map, retry, catchError } from 'rxjs/operators'; import { environment } from '../environments/environment' import { apiURL, apiRetry } from './api-utils' -import { FolderStatus, Folder } from './folder' +import Folder from './folder' @Injectable({ providedIn: 'root' @@ -21,7 +21,7 @@ export class DbStatusService { this.headers = new HttpHeaders(this.cookieService.getCSRFHeader()) } - getFolderStatus(id: string): Observable { + getFolderStatus(id: string): Observable { let httpOptions: { headers: HttpHeaders } | { headers: HttpHeaders, params: HttpParams }; if (id) { @@ -34,17 +34,19 @@ export class DbStatusService { } return this.http - .get(this.dbStatusUrl, httpOptions) + .get(this.dbStatusUrl, httpOptions) .pipe( retry(apiRetry), map(res => { // Remove from array in developement // in-memory-web-api returns arrays if (!environment.production) { + console.log("status res!", res); const a: any = res as any; if (a.length > 0) { return res[0]; } + return {}; } return res; }) diff --git a/src/app/folder.service.ts b/src/app/folder.service.ts index f6650e3d2..3c16be317 100644 --- a/src/app/folder.service.ts +++ b/src/app/folder.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { SystemConfigService } from './system-config.service'; import { Observable, Subscriber } from 'rxjs'; import { map } from 'rxjs/operators'; -import { Folder } from './folder'; +import Folder from './folder'; import { DbStatusService } from './db-status.service'; @Injectable({ @@ -40,30 +40,16 @@ export class FolderService { * set all their statuses */ getAll(): Observable { - const _this = this; const folderObservable: Observable = new Observable((observer) => { - this.systemConfigService.getFolders().subscribe({ - next(folders) { - _this.folders = folders; + this.systemConfigService.getFolders().subscribe( + folders => { + this.folders = folders; // Synchronously get the status of each folder - _this.getFolderStatusInOrder(observer, 0); - - /* - for (let folder of folders) { - // Get the status of each folder - dbs.getFolderStatus(folder.id).subscribe( - status => { - folder["status"] = status; - - observer.next(folder); - } - ); - } - */ + this.getFolderStatusInOrder(observer, 0); }, - error(err) { console.log("getAll error!", err) } - }); + err => { console.log("getAll error!", err) } + ); }); return folderObservable } diff --git a/src/app/folder.ts b/src/app/folder.ts index 4d56e7944..150a05e55 100644 --- a/src/app/folder.ts +++ b/src/app/folder.ts @@ -1,37 +1,95 @@ -export interface Folder { +import { Device } from './device'; + +interface Folder { id: string; label: string; - status: FolderStatus; + devices: Device[]; + status: Folder.Status; + paused: boolean; } -export interface FolderStatus { - globalBytes: number; - globalDeleted: number; - globalDirectories: number; - globalFiles: number; - globalSymlinks: number; - ignorePatterns: boolean; - inSyncBytes: number; - inSyncFiles: number; - invalid: string; - localBytes: number; - localDeleted: number; - localDirectories: number; - localFiles: number; - localSymlinks: number; - needBytes: number; - needDeletes: number; - needDirectories: number; - needFiles: number; - needSymlinks: number; - pullErrors: number; - receiveOnlyChangedBytes: number; - receiveOnlyChangedDeletes: number; - receiveOnlyChangedDirectories: number; - receiveOnlyChangedFiles: number; - receiveOnlyChangedSymlinks: number; - sequence: number; - state: string; - stateChanged: string; - version: number; -} \ No newline at end of file +namespace Folder { + export enum stateType { + } + + export function statusToString(f: Folder): string { + const fs: Folder.Status = f.status; + const state: string = fs.state; + + if (f.paused) { + return 'paused'; + } + + if (!f.status || (Object.keys(f.status).length === 0)) { + return 'unknown'; + } + + if (state === 'error') { + return 'stopped'; // legacy, the state is called "stopped" in the GUI + } + + if (state !== 'idle') { + return state; + } + + const needTotalItems = fs.needDeletes + fs.needDirectories + + fs.needFiles + fs.needSymlinks; + const receiveOnlyTotalItems = fs.receiveOnlyChangedDeletes + fs.receiveOnlyChangedDirectories + + fs.receiveOnlyChangedFiles + fs.receiveOnlyChangedSymlinks; + + if (needTotalItems > 0) { + return 'outofsync'; + } + if (f.status.pullErrors > 0) { + return 'faileditems'; + } + if (receiveOnlyTotalItems > 0) { + return 'localadditions'; + } + if (f.devices.length <= 1) { + return 'unshared'; + } + + return state; + } + + export interface Status { + globalBytes: number; + globalDeleted: number; + globalDirectories: number; + globalFiles: number; + globalSymlinks: number; + ignorePatterns: boolean; + inSyncBytes: number; + inSyncFiles: number; + invalid: string; + localBytes: number; + localDeleted: number; + localDirectories: number; + localFiles: number; + localSymlinks: number; + needBytes: number; + needDeletes: number; + needDirectories: number; + needFiles: number; + needSymlinks: number; + pullErrors: number; + receiveOnlyChangedBytes: number; + receiveOnlyChangedDeletes: number; + receiveOnlyChangedDirectories: number; + receiveOnlyChangedFiles: number; + receiveOnlyChangedSymlinks: number; + sequence: number; + state: string; + stateChanged: string; + version: number; + } +} + +export default Folder; + + + + + + diff --git a/src/app/list/folder-list/folder-list-datasource.ts b/src/app/list/folder-list/folder-list-datasource.ts index 1ffd7e043..1a3da4be4 100644 --- a/src/app/list/folder-list/folder-list-datasource.ts +++ b/src/app/list/folder-list/folder-list-datasource.ts @@ -4,7 +4,7 @@ import { MatSort } from '@angular/material/sort'; import { map } from 'rxjs/operators'; import { Observable, of as observableOf, merge, Subject } from 'rxjs'; -import { Folder } from '../../folder'; +import Folder from '../../folder'; import { SystemConfigService } from '../../system-config.service'; /** diff --git a/src/app/list/folder-list/folder-list.component.ts b/src/app/list/folder-list/folder-list.component.ts index 1a360d03c..7e0c344e5 100644 --- a/src/app/list/folder-list/folder-list.component.ts +++ b/src/app/list/folder-list/folder-list.component.ts @@ -4,7 +4,7 @@ import { MatSort } from '@angular/material/sort'; import { MatTable } from '@angular/material/table'; import { FolderListDataSource } from './folder-list-datasource'; -import { Folder } from '../../folder'; +import Folder from '../../folder'; import { SystemConfigService } from '../../system-config.service'; import { dataTableElevation } from '../../style'; import { Subject } from 'rxjs'; diff --git a/src/app/system-config.service.ts b/src/app/system-config.service.ts index 0cc98d80f..bf6305fd8 100644 --- a/src/app/system-config.service.ts +++ b/src/app/system-config.service.ts @@ -4,7 +4,7 @@ import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable, Subject } from 'rxjs'; import { map, retry } from 'rxjs/operators'; -import { Folder } from './folder'; +import Folder from './folder'; import { Device } from './device'; import { CookieService } from './cookie.service'; import { environment } from '../environments/environment'