create Device namespace and getStateType function

This commit is contained in:
Jesse Lucas 2020-03-25 16:08:07 -04:00
parent 0361d303f2
commit 78a31449aa
6 changed files with 73 additions and 19 deletions

View File

@ -1,6 +1,67 @@
export interface Device { interface Device {
deviceID: string; deviceID: string;
name: string; name: string;
state: Device.StateType;
// TODO add additional properties paused: boolean;
connected: boolean;
completion: number;
used: boolean; // indicates if a folder is using the device
} }
namespace Device {
export enum StateType {
Insync = 1,
UnusedInsync,
Unknown,
Syncing,
Paused,
UnusedPaused,
Disconnected,
UnusedDisconnected,
}
export function stateTypeToString(s: StateType): string {
switch (s) {
case StateType.Insync:
return 'Up to Date';
case StateType.UnusedInsync:
return 'Connected (Unused)';
case StateType.Unknown:
return 'Unknown';
case StateType.Syncing:
return 'Syncing';
case StateType.Paused:
return 'Paused';
case StateType.UnusedPaused:
return 'Paused (Unused)';
case StateType.Disconnected:
return 'Disconnected';
case StateType.UnusedDisconnected:
return 'Disconnected (Unused)';
}
}
export function getStateType(d: Device): StateType {
// TODO
/*
if (typeof $scope.connections[deviceCfg.deviceID] === 'undefined') {
return 'unknown';
}
*/
if (d.paused) {
return d.used ? StateType.Paused : StateType.UnusedPaused;
}
if (d.connected) {
if (d.completion === 100) {
return d.used ? StateType.Insync : StateType.UnusedInsync;
} else {
return StateType.Syncing;
}
}
return d.used ? StateType.Disconnected : StateType.UnusedDisconnected;
}
}
export default Device;

View File

@ -1,4 +1,4 @@
import { Device } from './device'; import Device from './device';
interface Folder { interface Folder {
id: string; id: string;
@ -6,6 +6,7 @@ interface Folder {
devices: Device[]; devices: Device[];
status: Folder.Status; status: Folder.Status;
paused: boolean; paused: boolean;
completion: number;
} }
namespace Folder { namespace Folder {
@ -158,11 +159,4 @@ namespace Folder {
version: number; version: number;
} }
} }
export default Folder; export default Folder;

View File

@ -4,7 +4,7 @@ import { MatSort } from '@angular/material/sort';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { Observable, of as observableOf, merge, Subject } from 'rxjs'; import { Observable, of as observableOf, merge, Subject } from 'rxjs';
import { Device } from '../../device'; import Device from '../../device';
import { SystemConfigService } from '../../services/system-config.service'; import { SystemConfigService } from '../../services/system-config.service';
/** /**

View File

@ -4,12 +4,11 @@ import { MatSort } from '@angular/material/sort';
import { MatTable } from '@angular/material/table'; import { MatTable } from '@angular/material/table';
import { DeviceListDataSource } from './device-list-datasource'; import { DeviceListDataSource } from './device-list-datasource';
import { Device } from '../../device'; import Device from '../../device';
import { SystemConfigService } from '../../services/system-config.service'; import { SystemConfigService } from '../../services/system-config.service';
import { dataTableElevation } from '../../style'; import { dataTableElevation } from '../../style';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
@Component({ @Component({
selector: 'app-device-list', selector: 'app-device-list',
templateUrl: './device-list.component.html', templateUrl: './device-list.component.html',

View File

@ -1,9 +1,10 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import Device from '../device';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class DeviceService { export class DeviceService {
private devices: Device[];
constructor() { } constructor() { }
} }

View File

@ -5,8 +5,7 @@ import { Observable, Subject } from 'rxjs';
import { map, retry } from 'rxjs/operators'; import { map, retry } from 'rxjs/operators';
import Folder from '../folder'; import Folder from '../folder';
import { Device } from '../device'; import Device from '../device';
import { CookieService } from './cookie.service';
import { environment } from '../../environments/environment' import { environment } from '../../environments/environment'
import { apiURL, apiRetry } from '../api-utils' import { apiURL, apiRetry } from '../api-utils'