Recalculate completion for devices and update total properties
This commit is contained in:
@@ -5,6 +5,7 @@ import { apiURL, apiRetry } from '../api-utils';
|
||||
import { Completion } from '../completion';
|
||||
import { retry, map } from 'rxjs/operators';
|
||||
import { Observable } from 'rxjs';
|
||||
import { StType } from '../type';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -14,12 +15,21 @@ export class DbCompletionService {
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
getDeviceCompletion(id: string): Observable<Completion> {
|
||||
getCompletion(type: StType, id: string): Observable<Completion> {
|
||||
let httpOptions: { params: HttpParams };
|
||||
if (id) {
|
||||
httpOptions = {
|
||||
params: new HttpParams().set('device', id)
|
||||
};
|
||||
switch (type) {
|
||||
case StType.Device:
|
||||
httpOptions = {
|
||||
params: new HttpParams().set('device', id)
|
||||
};
|
||||
break;
|
||||
case StType.Folder:
|
||||
httpOptions = {
|
||||
params: new HttpParams().set('folder', id)
|
||||
};
|
||||
break;
|
||||
}
|
||||
} else { }
|
||||
|
||||
return this.http
|
||||
@@ -38,6 +48,5 @@ export class DbCompletionService {
|
||||
return res;
|
||||
})
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import { DbCompletionService } from './db-completion.service';
|
||||
import { SystemConnections } from '../connections';
|
||||
import { SystemStatusService } from './system-status.service';
|
||||
import { ProgressService } from './progress.service';
|
||||
import { StType } from '../type';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -48,16 +49,17 @@ export class DeviceService {
|
||||
}
|
||||
}
|
||||
|
||||
this.dbCompletionService.getDeviceCompletion(device.deviceID).subscribe(
|
||||
this.dbCompletionService.getCompletion(StType.Device, device.deviceID).subscribe(
|
||||
c => {
|
||||
device.completion = c.completion;
|
||||
device.completion = c;
|
||||
Device.recalcCompletion(device);
|
||||
device.stateType = Device.getStateType(device);
|
||||
device.state = Device.stateTypeToString(device.stateType);
|
||||
observer.next(device);
|
||||
|
||||
this.progressService.addToProgress(1);
|
||||
|
||||
// recursively get the status of the next folder
|
||||
// recursively get the status of the next device
|
||||
this.getDeviceStatusInOrder(observer, startIndex);
|
||||
});
|
||||
}
|
||||
@@ -75,22 +77,29 @@ export class DeviceService {
|
||||
status => {
|
||||
this.devices.forEach(device => {
|
||||
if (device.deviceID === status.myID) {
|
||||
console.log("found thisDevice!", device);
|
||||
// TODO Determine if it should ignore thisDevice
|
||||
this.thisDevice = device;
|
||||
}
|
||||
});
|
||||
|
||||
// TODO Determine if it should ignore thisDevice
|
||||
|
||||
// Check folder devices to see if the device is used
|
||||
this.systemConfigService.getFolders().subscribe(
|
||||
folders => {
|
||||
// Loop through all folder devices to see if the device is used
|
||||
this.devices.forEach(device => {
|
||||
// Alloc array if needed
|
||||
if (!device.folders) {
|
||||
device.folders = [];
|
||||
}
|
||||
|
||||
folders.forEach(folder => {
|
||||
folder.devices.forEach(fdevice => {
|
||||
if (device.deviceID === fdevice.deviceID) {
|
||||
// The device is used by a folder
|
||||
device.used = true;
|
||||
|
||||
// Add a reference to the folder to the device
|
||||
device.folders.push(folder);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,8 @@ import { Observable, Subscriber } from 'rxjs';
|
||||
import Folder from '../folder';
|
||||
import { DbStatusService } from './db-status.service';
|
||||
import { ProgressService } from './progress.service';
|
||||
import { DbCompletionService } from './db-completion.service';
|
||||
import { StType } from '../type';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -14,6 +16,7 @@ export class FolderService {
|
||||
constructor(
|
||||
private systemConfigService: SystemConfigService,
|
||||
private dbStatusService: DbStatusService,
|
||||
private dbCompletionService: DbCompletionService,
|
||||
private progressService: ProgressService,
|
||||
) { }
|
||||
|
||||
@@ -28,15 +31,19 @@ export class FolderService {
|
||||
this.dbStatusService.getFolderStatus(folder.id).subscribe(
|
||||
status => {
|
||||
folder.status = status;
|
||||
folder.stateType = Folder.getStateType(folder);
|
||||
folder.state = Folder.stateTypeToString(folder.stateType);
|
||||
observer.next(folder);
|
||||
|
||||
// Add one to the progress service
|
||||
this.progressService.addToProgress(1);
|
||||
this.dbCompletionService.getCompletion(StType.Folder, folder.id).subscribe(
|
||||
c => {
|
||||
folder.completion = c;
|
||||
folder.stateType = Folder.getStateType(folder);
|
||||
folder.state = Folder.stateTypeToString(folder.stateType);
|
||||
observer.next(folder);
|
||||
|
||||
// recursively get the status of the next folder
|
||||
this.getFolderStatusInOrder(observer, startIndex);
|
||||
this.progressService.addToProgress(1);
|
||||
|
||||
// recursively get the status of the next folder
|
||||
this.getFolderStatusInOrder(observer, startIndex);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user