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;
name: string;
state: Device.StateType;
paused: boolean;
connected: boolean;
completion: number;
used: boolean; // indicates if a folder is using the device
}
// TODO add additional properties
}
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 {
id: string;
@ -6,6 +6,7 @@ interface Folder {
devices: Device[];
status: Folder.Status;
paused: boolean;
completion: number;
}
namespace Folder {
@ -158,11 +159,4 @@ namespace Folder {
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 { Observable, of as observableOf, merge, Subject } from 'rxjs';
import { Device } from '../../device';
import Device from '../../device';
import { SystemConfigService } from '../../services/system-config.service';
/**
@ -79,4 +79,4 @@ export class DeviceListDataSource extends DataSource<Device> {
function compare(a: string | number, b: string | number, isAsc: boolean) {
return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
}
}

View File

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

View File

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

View File

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