Commit 28d86107d90afd1485f9c24198da801f5d829f95
1 parent
ed34cf65
Exists in
master
and in
27 other branches
Support storage of current object in generic restangular service
Showing
1 changed file
with
15 additions
and
0 deletions
Show diff stats
src/lib/ng-noosfero-api/http/restangular_service.ts
... | ... | @@ -11,6 +11,8 @@ |
11 | 11 | export abstract class RestangularService<T extends noosfero.RestModel> { |
12 | 12 | |
13 | 13 | private baseResource: restangular.IElement; |
14 | + private currentPromise: ng.IDeferred<T>; | |
15 | + | |
14 | 16 | /** |
15 | 17 | * Creates an instance of RestangularService. |
16 | 18 | * |
... | ... | @@ -20,6 +22,7 @@ export abstract class RestangularService<T extends noosfero.RestModel> { |
20 | 22 | */ |
21 | 23 | constructor(protected restangularService: restangular.IService, protected $q: ng.IQService, protected $log: ng.ILogService) { |
22 | 24 | this.baseResource = restangularService.all(this.getResourcePath()); |
25 | + this.resetCurrent(); | |
23 | 26 | // TODO |
24 | 27 | // this.restangularService.setResponseInterceptor((data, operation, what, url, response, deferred) => { |
25 | 28 | // let transformedData: any = data; |
... | ... | @@ -32,6 +35,18 @@ export abstract class RestangularService<T extends noosfero.RestModel> { |
32 | 35 | // }); |
33 | 36 | } |
34 | 37 | |
38 | + public resetCurrent() { | |
39 | + this.currentPromise = this.$q.defer(); | |
40 | + } | |
41 | + | |
42 | + public getCurrent(): ng.IPromise<T> { | |
43 | + return this.currentPromise.promise; | |
44 | + } | |
45 | + | |
46 | + public setCurrent(object: T) { | |
47 | + this.currentPromise.resolve(object); | |
48 | + } | |
49 | + | |
35 | 50 | protected extractData(response: restangular.IResponse): noosfero.RestResult<T> { |
36 | 51 | let dataKey: string; |
37 | 52 | if (response.data && this.getDataKeys()) { | ... | ... |