diff --git a/src/app/cms/cms.component.ts b/src/app/cms/cms.component.ts index b4ce620..e0e8129 100644 --- a/src/app/cms/cms.component.ts +++ b/src/app/cms/cms.component.ts @@ -1,27 +1,24 @@ import {StateConfig, Component, Inject} from 'ng-forward'; import {Profile} from "./../models/interfaces"; +import {ArticleService} from "../../lib/ng-noosfero-api/http/article.service"; + @Component({ selector: 'cms', templateUrl: "app/cms/cms.html" }) -@Inject("noosfero", "$stateParams", "$httpParamSerializer", "$state", "SweetAlert") +@Inject(ArticleService, "noosfero", "$stateParams", "$httpParamSerializer", "$state", "SweetAlert") export class Cms { article: any = {}; profile: any; - constructor(private noosfero: any/* TODO convert noosferoService */, private $stateParams: ng.ui.IStateParamsService, private $httpParamSerializer: any, private $state: ng.ui.IStateService, private SweetAlert: any) { + constructor(private ArticleService: ArticleService, private noosfero: any/* TODO convert noosferoService */, private $stateParams: ng.ui.IStateParamsService, private $httpParamSerializer: any, private $state: ng.ui.IStateService, private SweetAlert: any) { } save() { this.noosfero.currentProfile.then((profile: Profile) => { - return this.noosfero.profiles.one(profile.id).customPOST( - { article: this.article }, - 'articles', - {}, - { 'Content-Type': 'application/json' } - ) + return this.ArticleService.create(profile.id, this.article); }).then((response: restangular.IResponse) => { this.$state.transitionTo('main.profile.page', { page: response.data.article.path, profile: response.data.article.profile.identifier }); this.SweetAlert.swal({ diff --git a/src/app/components/noosfero-articles/blog/blog.component.ts b/src/app/components/noosfero-articles/blog/blog.component.ts index 0383661..feacb0e 100644 --- a/src/app/components/noosfero-articles/blog/blog.component.ts +++ b/src/app/components/noosfero-articles/blog/blog.component.ts @@ -1,12 +1,13 @@ import {Component, Input, Inject} from "ng-forward"; import {Article, Profile} from "./../../../models/interfaces"; +import {ArticleService} from "../../../../lib/ng-noosfero-api/http/article.service"; @Component({ selector: "noosfero-blog", templateUrl: "app/components/noosfero-articles/blog/blog.html" }) -@Inject("noosfero", "$scope") +@Inject(ArticleService, "$scope") export class NoosferoArticleBlog { @Input() article: Article; @@ -17,7 +18,7 @@ export class NoosferoArticleBlog { private currentPage: number; private totalPosts: number = 0; - constructor(private noosfero: any, private $scope: ng.IScope) { + constructor(private ArticleService: ArticleService, private $scope: ng.IScope) { } ngOnInit() { @@ -25,7 +26,7 @@ export class NoosferoArticleBlog { } loadPage() { - this.noosfero.articles.one(this.article.id).customGET("children", { + this.ArticleService.getChildren(this.article.id, { content_type: "TinyMceArticle", per_page: this.perPage, page: this.currentPage diff --git a/src/app/components/noosfero/noosfero.service.js b/src/app/components/noosfero/noosfero.service.js index bf7cdbe..3592ea3 100644 --- a/src/app/components/noosfero/noosfero.service.js +++ b/src/app/components/noosfero/noosfero.service.js @@ -6,18 +6,7 @@ return { currentProfile: currentProfile.promise, - setCurrentProfile: function(profile) { currentProfile.resolve(profile) }, - profiles: Restangular.service('profiles'), - articles: Restangular.service('articles'), - profile: function(profileId) { - return Restangular.one('profiles', profileId); - }, - members: function(profile) { - return Restangular.service('members', profile); - }, - boxes: function(profileId) { - return Restangular.service('boxes', Restangular.one('profiles', profileId)) - } + setCurrentProfile: function(profile) { currentProfile.resolve(profile) } } }); })(); diff --git a/src/app/content-viewer/content-viewer.component.ts b/src/app/content-viewer/content-viewer.component.ts index c324f75..4332dfd 100644 --- a/src/app/content-viewer/content-viewer.component.ts +++ b/src/app/content-viewer/content-viewer.component.ts @@ -5,13 +5,14 @@ import {ArticleView} from "../components/noosfero-articles/article/article_view" import {Input, Component, StateConfig, Inject} from "ng-forward"; import {NoosferoArticleBlog} from "./../components/noosfero-articles/blog/blog.component"; +import {ArticleService} from "../../lib/ng-noosfero-api/http/article.service"; @Component({ selector: "content-viewer", templateUrl: "app/content-viewer/page.html", directives: [NoosferoArticleBlog, ArticleView] }) -@Inject("noosfero", "$log", "$stateParams") +@Inject(ArticleService, "noosfero", "$log", "$stateParams") export class ContentViewer { @Input() @@ -20,14 +21,14 @@ export class ContentViewer { @Input() profile: noosfero.Profile = null; - constructor(private noosfero: any, private $log: ng.ILogService, private $stateParams: angular.ui.IStateParamsService) { + constructor(private ArticleService: ArticleService, private noosfero: any, private $log: ng.ILogService, private $stateParams: angular.ui.IStateParamsService) { this.activate(); } activate() { this.noosfero.currentProfile.then((profile: noosfero.Profile) => { this.profile = profile; - return this.noosfero.profiles.one(this.profile.id).one("articles").get({ path: this.$stateParams["page"] }); + return this.ArticleService.getByProfile(this.profile.id, { path: this.$stateParams["page"] }); }).then((response: restangular.IResponse) => { this.article = response.data.article; }); diff --git a/src/app/profile-info/profile-info.component.ts b/src/app/profile-info/profile-info.component.ts index e9fae9f..7b3a021 100644 --- a/src/app/profile-info/profile-info.component.ts +++ b/src/app/profile-info/profile-info.component.ts @@ -1,25 +1,26 @@ import {StateConfig, Component, Inject} from 'ng-forward'; import {Profile} from "./../models/interfaces"; +import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; @Component({ selector: 'profile', templateUrl: "app/profile-info/profile-info.html" }) -@Inject("noosfero") +@Inject(ProfileService, "noosfero") export class ProfileInfo { activities: any profile: any - constructor(private noosfero: any) { + constructor(private ProfileService: ProfileService, private noosfero: any) { this.activate(); } activate() { this.noosfero.currentProfile.then((profile: Profile) => { this.profile = profile; - return this.noosfero.profiles.one(this.profile.id).one('activities').get(); + return this.ProfileService.getActivities(this.profile.id); }).then((response: restangular.IResponse) => { this.activities = response.data.activities; }); diff --git a/src/app/profile/profile-home.component.ts b/src/app/profile/profile-home.component.ts index e2d64e9..4aba00a 100644 --- a/src/app/profile/profile-home.component.ts +++ b/src/app/profile/profile-home.component.ts @@ -1,20 +1,21 @@ import {StateConfig, Component, Inject} from 'ng-forward'; import {Profile} from "./../models/interfaces"; +import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; @Component({ selector: 'profile-home', template: "
" }) -@Inject("noosfero", "$log", "$stateParams", "$scope", "$state") +@Inject(ProfileService, "noosfero", "$log", "$stateParams", "$scope", "$state") export class ProfileHome { profile: Profile; - constructor(noosfero: any, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService, $scope: ng.IScope, $state: ng.ui.IStateService) { + constructor(ProfileService: ProfileService, noosfero: any, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService, $scope: ng.IScope, $state: ng.ui.IStateService) { noosfero.currentProfile.then((profile: Profile) => { this.profile = profile; - return noosfero.profile(this.profile.id).customGET('home_page', { fields: 'path' }); + return ProfileService.get(this.profile.id).customGET('home_page', { fields: 'path' }); }).then((response: restangular.IResponse) => { if (response.data.article) { $state.transitionTo('main.profile.page', { page: response.data.article.path, profile: this.profile.identifier }, { location: false }); diff --git a/src/app/profile/profile.component.ts b/src/app/profile/profile.component.ts index c62c2c9..7cb33f4 100644 --- a/src/app/profile/profile.component.ts +++ b/src/app/profile/profile.component.ts @@ -4,6 +4,7 @@ import {ProfileHome} from '../profile/profile-home.component'; import {Cms} from '../cms/cms.component'; import {ContentViewer} from "../content-viewer/content-viewer.component"; import {NoosferoActivities} from "../components/noosfero-activities/activities.component"; +import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; import * as noosferoModels from "./../models/interfaces"; @@ -66,17 +67,17 @@ import * as noosferoModels from "./../models/interfaces"; } } ]) -@Inject("noosfero", "$log", "$stateParams") +@Inject(ProfileService, "noosfero", "$log", "$stateParams") export class Profile { boxes: noosferoModels.Box[]; profile: noosferoModels.Profile; - constructor(noosfero: any, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService) { - noosfero.profiles.one().get({ identifier: $stateParams["profile"] }).then((response: restangular.IResponse) => { + constructor(ProfileService: ProfileService, noosfero: any, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService) { + ProfileService.getByIdentifier($stateParams["profile"]).then((response: restangular.IResponse) => { this.profile = response.data[0]; noosfero.setCurrentProfile(this.profile); - return noosfero.boxes(this.profile.id).one().get(); + return ProfileService.getBoxes(this.profile.id); }).then((response: restangular.IResponse) => { this.boxes = response.data.boxes; }); diff --git a/src/lib/ng-noosfero-api/http/article.service.ts b/src/lib/ng-noosfero-api/http/article.service.ts index fc78dcd..c02fa60 100644 --- a/src/lib/ng-noosfero-api/http/article.service.ts +++ b/src/lib/ng-noosfero-api/http/article.service.ts @@ -1,4 +1,5 @@ import { Injectable, Inject } from "ng-forward"; +import {Article} from "../../../app/models/interfaces"; @Injectable() @Inject("Restangular") @@ -8,8 +9,25 @@ export class ArticleService { } + create(profileId: number, article: Article) { + return this.Restangular.one('profiles', profileId).customPOST( + { article: article }, + 'articles', + {}, + { 'Content-Type': 'application/json' } + ); + } + + get(articleId: number) { + return this.Restangular.one('articles', articleId); + } + getByProfile(profileId: number, filters: any) { return this.Restangular.one('profiles', profileId).customGET('articles', filters); } + getChildren(articleId: number, options: any = {}) { + return this.get(articleId).customGET('children', options); + } + } diff --git a/src/lib/ng-noosfero-api/http/profile.service.ts b/src/lib/ng-noosfero-api/http/profile.service.ts index b47d4fc..133ca98 100644 --- a/src/lib/ng-noosfero-api/http/profile.service.ts +++ b/src/lib/ng-noosfero-api/http/profile.service.ts @@ -8,8 +8,24 @@ export class ProfileService { } + getActivities(profileId: number, options: any = {}) { + return this.get(profileId).customGET("activities", options); + } + + get(profileId: number) { + return this.Restangular.one('profiles', profileId); + } + getProfileMembers(profileId: number, filters: any) { - return this.Restangular.service('profiles').one(profileId).customGET("members", filters); + return this.get(profileId).customGET("members", filters); + } + + getByIdentifier(identifier: string) { + return this.Restangular.one('profiles').get({ identifier: identifier }); + } + + getBoxes(profileId: number) { + return this.get(profileId).customGET('boxes'); } } -- libgit2 0.21.2