diff --git a/src/app/cms/cms.component.ts b/src/app/cms/cms.component.ts index 519db24..fb61208 100644 --- a/src/app/cms/cms.component.ts +++ b/src/app/cms/cms.component.ts @@ -1,24 +1,30 @@ import {StateConfig, Component, Inject, provide} from 'ng-forward'; import {Profile} from "./../models/interfaces"; import {ArticleService} from "../../lib/ng-noosfero-api/http/article.service"; +import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; @Component({ selector: 'cms', templateUrl: "app/cms/cms.html", - providers: [provide('articleService', { useClass: ArticleService })] + providers: [ + provide('articleService', { useClass: ArticleService }), + provide('profileService', { useClass: ProfileService }) + ] }) -@Inject(ArticleService, "noosfero", "$stateParams", "$httpParamSerializer", "$state", "SweetAlert") +@Inject(ArticleService, ProfileService, "$stateParams", "$httpParamSerializer", "$state", "SweetAlert") export class Cms { article: any = {}; profile: 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) { - - } + constructor(private articleService: ArticleService, + private profileService: ProfileService, + private $stateParams: ng.ui.IStateParamsService, + private $httpParamSerializer: any, + private $state: ng.ui.IStateService, private SweetAlert: any) { } save() { - this.noosfero.currentProfile.then((profile: Profile) => { + this.profileService.getCurrentProfile().then((profile: Profile) => { 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 }); diff --git a/src/app/components/noosfero/noosfero.service.js b/src/app/components/noosfero/noosfero.service.js deleted file mode 100644 index 3592ea3..0000000 --- a/src/app/components/noosfero/noosfero.service.js +++ /dev/null @@ -1,12 +0,0 @@ -(function() { - 'use strict'; - - angular.module('noosferoApp').factory('noosfero', function(Restangular, $q) { - var currentProfile = $q.defer(); - - return { - currentProfile: currentProfile.promise, - setCurrentProfile: function(profile) { currentProfile.resolve(profile) } - } - }); -})(); diff --git a/src/app/content-viewer/content-viewer-actions.component.ts b/src/app/content-viewer/content-viewer-actions.component.ts index cc0c675..e846658 100644 --- a/src/app/content-viewer/content-viewer-actions.component.ts +++ b/src/app/content-viewer/content-viewer-actions.component.ts @@ -1,18 +1,21 @@ -import {Component, Inject} from "ng-forward"; +import {Component, Inject, provide} from "ng-forward"; +import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; import {Profile} from "./../models/interfaces"; + @Component({ selector: "content-viewer-actions", templateUrl: "app/content-viewer/navbar-actions.html", + providers: [provide('profileService', { useClass: ProfileService })] }) -@Inject("noosfero") +@Inject(ProfileService) export class ContentViewerActions { article: any; profile: any; - constructor(noosfero: any) { - noosfero.currentProfile.then((profile: Profile) => { + constructor(profileService: ProfileService) { + profileService.getCurrentProfile().then((profile: Profile) => { this.profile = profile; }); } diff --git a/src/app/content-viewer/content-viewer.component.ts b/src/app/content-viewer/content-viewer.component.ts index d8007bc..4e855d9 100644 --- a/src/app/content-viewer/content-viewer.component.ts +++ b/src/app/content-viewer/content-viewer.component.ts @@ -6,14 +6,18 @@ import {Input, Component, StateConfig, Inject, provide} from "ng-forward"; import {ArticleBlog} from "./../components/noosfero-articles/blog/blog.component"; import {ArticleService} from "../../lib/ng-noosfero-api/http/article.service"; +import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; @Component({ selector: "content-viewer", templateUrl: "app/content-viewer/page.html", directives: [ArticleBlog, ArticleView], - providers: [provide('articleService', { useClass: ArticleService })] + providers: [ + provide('articleService', { useClass: ArticleService }), + provide('profileService', { useClass: ProfileService }) + ] }) -@Inject(ArticleService, "noosfero", "$log", "$stateParams") +@Inject(ArticleService, ProfileService, "$log", "$stateParams") export class ContentViewer { @Input() @@ -22,12 +26,12 @@ export class ContentViewer { @Input() profile: noosfero.Profile = null; - constructor(private articleService: ArticleService, private noosfero: any, private $log: ng.ILogService, private $stateParams: angular.ui.IStateParamsService) { + constructor(private articleService: ArticleService, private profileService: ProfileService, private $log: ng.ILogService, private $stateParams: angular.ui.IStateParamsService) { this.activate(); } activate() { - this.noosfero.currentProfile.then((profile: noosfero.Profile) => { + this.profileService.getCurrentProfile().then((profile: noosfero.Profile) => { this.profile = profile; return this.articleService.getByProfile(this.profile.id, { path: this.$stateParams["page"] }); }).then((response: restangular.IResponse) => { diff --git a/src/app/index.ts b/src/app/index.ts index 97ddf95..e920bb7 100644 --- a/src/app/index.ts +++ b/src/app/index.ts @@ -28,7 +28,6 @@ NoosferoApp.addConstants("AUTH_EVENTS", AUTH_EVENTS); NoosferoApp.addConfig(noosferoModuleConfig); NoosferoApp.run(noosferoAngularRunBlock); -require("./components/noosfero/noosfero.service.js"); require("./components/noosfero/profile-image/profile-image.component.js"); NoosferoApp.addConfig(routeConfig); diff --git a/src/app/profile-info/profile-info.component.ts b/src/app/profile-info/profile-info.component.ts index 5f7a967..2b1687c 100644 --- a/src/app/profile-info/profile-info.component.ts +++ b/src/app/profile-info/profile-info.component.ts @@ -8,18 +8,18 @@ import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; templateUrl: "app/profile-info/profile-info.html", providers: [provide('profileService', { useClass: ProfileService })] }) -@Inject(ProfileService, "noosfero") +@Inject(ProfileService) export class ProfileInfo { activities: any profile: any - constructor(private profileService: ProfileService, private noosfero: any) { + constructor(private profileService: ProfileService) { this.activate(); } activate() { - this.noosfero.currentProfile.then((profile: Profile) => { + this.profileService.getCurrentProfile().then((profile: Profile) => { this.profile = profile; return this.profileService.getActivities(this.profile.id); }).then((response: restangular.IResponse) => { diff --git a/src/app/profile/profile-home.component.ts b/src/app/profile/profile-home.component.ts index c7364bc..b5119da 100644 --- a/src/app/profile/profile-home.component.ts +++ b/src/app/profile/profile-home.component.ts @@ -8,13 +8,13 @@ import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; template: "
", providers: [provide('profileService', { useClass: ProfileService })] }) -@Inject(ProfileService, "noosfero", "$log", "$stateParams", "$scope", "$state") +@Inject(ProfileService, "$log", "$stateParams", "$scope", "$state") export class ProfileHome { profile: Profile; - constructor(profileService: ProfileService, noosfero: any, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService, $scope: ng.IScope, $state: ng.ui.IStateService) { - noosfero.currentProfile.then((profile: Profile) => { + constructor(profileService: ProfileService, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService, $scope: ng.IScope, $state: ng.ui.IStateService) { + profileService.getCurrentProfile().then((profile: Profile) => { this.profile = profile; return profileService.get(this.profile.id).customGET('home_page', { fields: 'path' }); }).then((response: restangular.IResponse) => { diff --git a/src/app/profile/profile.component.ts b/src/app/profile/profile.component.ts index 5395ba3..04fcbb0 100644 --- a/src/app/profile/profile.component.ts +++ b/src/app/profile/profile.component.ts @@ -6,6 +6,7 @@ import {ContentViewer} from "../content-viewer/content-viewer.component"; import {ContentViewerActions} from "../content-viewer/content-viewer-actions.component"; import {NoosferoActivities} from "../components/noosfero-activities/activities.component"; import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; +import {NoosferoService} from "../components/noosfero/noosfero.service"; import * as noosferoModels from "./../models/interfaces"; @@ -69,16 +70,16 @@ import * as noosferoModels from "./../models/interfaces"; } } ]) -@Inject(ProfileService, "noosfero", "$log", "$stateParams") +@Inject(ProfileService, "$log", "$stateParams") export class Profile { boxes: noosferoModels.Box[]; profile: noosferoModels.Profile; - constructor(profileService: ProfileService, noosfero: any, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService) { + constructor(profileService: ProfileService, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService) { profileService.getByIdentifier($stateParams["profile"]).then((response: restangular.IResponse) => { this.profile = response.data[0]; - noosfero.setCurrentProfile(this.profile); + profileService.setCurrentProfile(this.profile); return profileService.getBoxes(this.profile.id); }).then((response: restangular.IResponse) => { this.boxes = response.data.boxes; diff --git a/src/lib/ng-noosfero-api/http/profile.service.ts b/src/lib/ng-noosfero-api/http/profile.service.ts index e49c6b9..17cc742 100644 --- a/src/lib/ng-noosfero-api/http/profile.service.ts +++ b/src/lib/ng-noosfero-api/http/profile.service.ts @@ -1,10 +1,23 @@ import { Injectable, Inject } from "ng-forward"; +import {Profile} from "../../../app/models/interfaces"; @Injectable() -@Inject("Restangular") +@Inject("Restangular", "$q") export class ProfileService { - constructor(private restangular: restangular.IService) { } + private _currentProfilePromise: ng.IDeferred