From 81c539c516e7ba1f5f5909aa07057b40cf3a6f9d Mon Sep 17 00:00:00 2001 From: Jesse Lucas Date: Tue, 17 Mar 2020 22:37:11 -0400 Subject: [PATCH] new folder service --- src/app/folder.service.spec.ts | 16 ++++++++++++ src/app/folder.service.ts | 45 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/app/folder.service.spec.ts create mode 100644 src/app/folder.service.ts diff --git a/src/app/folder.service.spec.ts b/src/app/folder.service.spec.ts new file mode 100644 index 000000000..591addf71 --- /dev/null +++ b/src/app/folder.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { FolderService } from './folder.service'; + +describe('FolderService', () => { + let service: FolderService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(FolderService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/folder.service.ts b/src/app/folder.service.ts new file mode 100644 index 000000000..da4f5c2c7 --- /dev/null +++ b/src/app/folder.service.ts @@ -0,0 +1,45 @@ +import { Injectable } from '@angular/core'; +import { SystemConfigService } from './system-config.service'; +import { Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; +import { Folder } from './folder'; +import { DbStatusService } from './db-status.service'; + +@Injectable({ + providedIn: 'root' +}) +export class FolderService { + + constructor( + private systemConfigService: SystemConfigService, + private dbStatusService: DbStatusService + ) { } + + /** + * getAll() finds all folders and uses db status service to + * set all their statuses + */ + getAll(): Observable { + const dbs = this.dbStatusService; + const folderObservable: Observable = new Observable((observer) => { + this.systemConfigService.getFolders().subscribe({ + next(folders) { + let folder: Folder; + for (folder of folders) { + // Get the status of each folder + dbs.getFolderStatus(folder.id).subscribe( + status => { + console.log(status) + folder["status"] = status; + + observer.next(folder); + } + ); + } + }, + error(err) { console.log("getAll error!", err) } + }); + }); + return folderObservable + } +}