import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { ActivatedRouteSnapshot } from '@angular/router'; import { Observable } from 'rxjs/Observable'; import { environment } from '../../../environments/environment'; import { KanbanBoard } from './kanban-board.model'; @Injectable() export class KanbanService { private url = environment.apiUrl + '/api/kanban'; private cachedKanbanBoard: KanbanBoard = new KanbanBoard(); constructor(private httpService: HttpClient) { } /** * Returns an observable instance to the kanban board api * * @returns {Observable} */ public getList(): Observable { return this.httpService.get(this.url); } /** * Route preload resolver * * @param {ActivatedRouteSnapshot} route * @returns {Promise} */ public resolve(route: ActivatedRouteSnapshot): Promise { return this.getList().toPromise().then(result => result ? result : false); } /** * Reload the board */ public reload() { this.getList().subscribe(result => this.cachedKanbanBoard = result); } get kanbanBoard(): KanbanBoard { return this.cachedKanbanBoard; } set kanbanBoard(kanbanBoard: KanbanBoard) { this.cachedKanbanBoard = kanbanBoard; } }