update folder devices array for the "shared with" section in the folder list #CTR-2

This commit is contained in:
Jesse Lucas 2020-04-12 21:56:01 -04:00
parent 7a9f317ee1
commit 8b4a1f52d0

View File

@ -6,6 +6,7 @@ import { DbStatusService } from './db-status.service';
import { ProgressService } from './progress.service'; import { ProgressService } from './progress.service';
import { DbCompletionService } from './db-completion.service'; import { DbCompletionService } from './db-completion.service';
import { StType } from '../type'; import { StType } from '../type';
import { DeviceService } from './device.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -19,6 +20,7 @@ export class FolderService {
constructor( constructor(
private systemConfigService: SystemConfigService, private systemConfigService: SystemConfigService,
private deviceService: DeviceService,
private dbStatusService: DbStatusService, private dbStatusService: DbStatusService,
private dbCompletionService: DbCompletionService, private dbCompletionService: DbCompletionService,
private progressService: ProgressService, private progressService: ProgressService,
@ -33,24 +35,48 @@ export class FolderService {
} }
const folder: Folder = this.folders[startIndex]; const folder: Folder = this.folders[startIndex];
startIndex = startIndex + 1; startIndex = startIndex + 1;
this.dbStatusService.getFolderStatus(folder.id).subscribe(
status => {
folder.status = status;
this.dbCompletionService.getCompletion(StType.Folder, folder.id).subscribe( // Folder devices array only has deviceID
c => { // and we want all the device info
folder.completion = c; this.systemConfigService.getDevices().subscribe(
folder.stateType = Folder.getStateType(folder); devices => {
folder.state = Folder.stateTypeToString(folder.stateType); devices.forEach(device => {
// Update any device this folder
// has reference to
folder.devices.forEach((folderDevice, index) => {
if (folderDevice.deviceID === device.deviceID) {
console.log("find device match?", device.name)
folder.devices[index] = device;
this.folderAddedSource.next(folder); console.log("update?", folder.devices);
this.progressService.addToProgress(1); }
// recursively get the status of the next folder
this.getFolderStatusInOrder(startIndex);
}); });
});
// Gather the folder information from the status and
// completion services
this.dbStatusService.getFolderStatus(folder.id).subscribe(
status => {
folder.status = status;
this.dbCompletionService.getCompletion(StType.Folder, folder.id).subscribe(
c => {
folder.completion = c;
folder.stateType = Folder.getStateType(folder);
folder.state = Folder.stateTypeToString(folder.stateType);
this.folderAddedSource.next(folder);
this.progressService.addToProgress(1);
// Now that we have all the folder information
// recursively get the status of the next folder
this.getFolderStatusInOrder(startIndex);
});
}
);
} }
); )
} }
/** /**