new folder service

This commit is contained in:
Jesse Lucas 2020-03-17 22:37:11 -04:00
parent 75b3b31d11
commit 81c539c516
2 changed files with 61 additions and 0 deletions

View File

@ -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();
});
});

45
src/app/folder.service.ts Normal file
View File

@ -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<Folder> {
const dbs = this.dbStatusService;
const folderObservable: Observable<Folder> = 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
}
}