mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-20 03:51:00 +00:00
Refactor Folder interface to use Folder namespace
This commit is contained in:
parent
c27fe5694d
commit
32c849e18c
@ -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);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -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<FolderStatus> {
|
||||
getFolderStatus(id: string): Observable<Folder.Status> {
|
||||
let httpOptions: { headers: HttpHeaders } |
|
||||
{ headers: HttpHeaders, params: HttpParams };
|
||||
if (id) {
|
||||
@ -34,17 +34,19 @@ export class DbStatusService {
|
||||
}
|
||||
|
||||
return this.http
|
||||
.get<FolderStatus>(this.dbStatusUrl, httpOptions)
|
||||
.get<Folder.Status>(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;
|
||||
})
|
||||
|
@ -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<Folder> {
|
||||
const _this = this;
|
||||
const folderObservable: Observable<Folder> = 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
|
||||
}
|
||||
|
@ -1,10 +1,59 @@
|
||||
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 {
|
||||
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;
|
||||
@ -35,3 +84,12 @@ export interface FolderStatus {
|
||||
stateChanged: string;
|
||||
version: number;
|
||||
}
|
||||
}
|
||||
|
||||
export default Folder;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -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';
|
||||
|
||||
/**
|
||||
|
@ -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';
|
||||
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user