52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
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<KanbanBoard>}
|
|
*/
|
|
public getList(): Observable<KanbanBoard> {
|
|
return this.httpService.get<KanbanBoard>(this.url);
|
|
}
|
|
|
|
/**
|
|
* Route preload resolver
|
|
*
|
|
* @param {ActivatedRouteSnapshot} route
|
|
* @returns {Promise<KanbanBoard>}
|
|
*/
|
|
public resolve(route: ActivatedRouteSnapshot): Promise<KanbanBoard | boolean> {
|
|
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;
|
|
}
|
|
}
|