diff --git a/src/app/content-viewer/content-viewer.component.spec.ts b/src/app/content-viewer/content-viewer.component.spec.ts index 1bf6c7c..175731e 100644 --- a/src/app/content-viewer/content-viewer.component.spec.ts +++ b/src/app/content-viewer/content-viewer.component.spec.ts @@ -69,7 +69,7 @@ describe('Content Viewer Component', () => { return helpers.mocks.promiseResultTemplate(profile); }; - helpers.mocks.articleService.getOneByProfile = (id: number, params: any) => { + helpers.mocks.articleService.getArticleByProfileAndPath = (profile: noosfero.Profile, path: string) => { return helpers.mocks.promiseResultTemplate({ data: article }); diff --git a/src/app/content-viewer/content-viewer.component.ts b/src/app/content-viewer/content-viewer.component.ts index ac90f16..c7ca7fd 100644 --- a/src/app/content-viewer/content-viewer.component.ts +++ b/src/app/content-viewer/content-viewer.component.ts @@ -30,8 +30,8 @@ export class ContentViewer { activate() { this.profileService.getCurrentProfile().then((profile: noosfero.Profile) => { this.profile = profile; - return this.articleService.getOneByProfile(this.profile, { path: this.$stateParams["page"] }); - }).then((result: noosfero.RestResult) => { + return this.articleService.getArticleByProfileAndPath(this.profile, this.$stateParams["page"]); + }).then((result: noosfero.RestResult) => { this.article = result.data; }); } diff --git a/src/lib/ng-noosfero-api/http/article.service.ts b/src/lib/ng-noosfero-api/http/article.service.ts index 47aecd2..63385fe 100644 --- a/src/lib/ng-noosfero-api/http/article.service.ts +++ b/src/lib/ng-noosfero-api/http/article.service.ts @@ -44,9 +44,28 @@ export class ArticleService extends RestangularService { return this.list(profileElement, params); } + getArticleByProfileAndPath(profile: noosfero.Profile, path: string): ng.IPromise> { + let deferred = this.$q.defer>(); + let profileElement = this.profileService.get(profile.id); + + let restRequest: ng.IPromise; + + let params = { path: path }; + + restRequest = profileElement.customGET(this.getResourcePath(), params); + + + restRequest + .then(this.getHandleSuccessFunction(deferred)) + .catch(this.getHandleErrorFunction(deferred)); + + + return deferred.promise; + } + getOneByProfile(profile: noosfero.Profile, params?: any): ng.IPromise> { let profileElement = this.profileService.get(profile.id); - return this.get(profile.id, params); + return this.getSub(profileElement, params);; } getChildren(article: noosfero.Article, params?: any): ng.IPromise> { diff --git a/src/lib/ng-noosfero-api/http/restangular_service.ts b/src/lib/ng-noosfero-api/http/restangular_service.ts index 900939c..41bb66c 100644 --- a/src/lib/ng-noosfero-api/http/restangular_service.ts +++ b/src/lib/ng-noosfero-api/http/restangular_service.ts @@ -125,6 +125,33 @@ export abstract class RestangularService { return deferred.promise; } + + /** + * Do a HTTP GET call to the resource collection represented + * + * @protected + * @param {number} id (description) + * @returns {ng.IPromise} Returns a Promise to the Generic Type + */ + public getSub(rootElement?: restangular.IElement, queryParams?: any, headers?: any): ng.IPromise> { + let deferred = this.$q.defer>(); + + let restRequest: ng.IPromise; + + if (rootElement) { + restRequest = rootElement.customGET(this.getResourcePath(), queryParams, headers); + } else { + restRequest = this.baseResource.customGET("", queryParams, headers); + } + + + restRequest + .then(this.getHandleSuccessFunction(deferred)) + .catch(this.getHandleErrorFunction(deferred)); + + + return deferred.promise; + } public listSubElements(obj: T, subElement: string, queryParams?: any, headers?: any): ng.IPromise> { let deferred = this.$q.defer>(); diff --git a/src/spec/mocks.ts b/src/spec/mocks.ts index b972e60..3359c77 100644 --- a/src/spec/mocks.ts +++ b/src/spec/mocks.ts @@ -48,7 +48,7 @@ export var mocks = { } }; }, - getOneByProfile: (profileId: number, params?: any) => { + getArticleByProfileAndPath: (profile: noosfero.Profile, path: string) => { return { then: (func?: Function) => { if (func) func({ -- libgit2 0.21.2