Commit 7557eb0debd6d118cf96e3d86bee598d1dc8f4d8

Authored by Victor Costa
1 parent c55481d4

Hold the current profile in profile service so we can use it in the api calls that depends on the id

src/app/cms/cms.component.ts
1 1 import {StateConfig, Component, Inject, provide} from 'ng-forward';
2 2 import {Profile} from "./../models/interfaces";
3 3 import {ArticleService} from "../../lib/ng-noosfero-api/http/article.service";
  4 +import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service";
4 5  
5 6 @Component({
6 7 selector: 'cms',
7 8 templateUrl: "app/cms/cms.html",
8   - providers: [provide('articleService', { useClass: ArticleService })]
  9 + providers: [
  10 + provide('articleService', { useClass: ArticleService }),
  11 + provide('profileService', { useClass: ProfileService })
  12 + ]
9 13 })
10   -@Inject(ArticleService, "noosfero", "$stateParams", "$httpParamSerializer", "$state", "SweetAlert")
  14 +@Inject(ArticleService, ProfileService, "$stateParams", "$httpParamSerializer", "$state", "SweetAlert")
11 15 export class Cms {
12 16  
13 17 article: any = {};
14 18 profile: any;
15 19  
16   - 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) {
17   -
18   - }
  20 + constructor(private articleService: ArticleService,
  21 + private profileService: ProfileService,
  22 + private $stateParams: ng.ui.IStateParamsService,
  23 + private $httpParamSerializer: any,
  24 + private $state: ng.ui.IStateService, private SweetAlert: any) { }
19 25  
20 26 save() {
21   - this.noosfero.currentProfile.then((profile: Profile) => {
  27 + this.profileService.getCurrentProfile().then((profile: Profile) => {
22 28 return this.articleService.create(profile.id, this.article);
23 29 }).then((response: restangular.IResponse) => {
24 30 this.$state.transitionTo('main.profile.page', { page: response.data.article.path, profile: response.data.article.profile.identifier });
... ...
src/app/components/noosfero/noosfero.service.js
... ... @@ -1,12 +0,0 @@
1   -(function() {
2   - 'use strict';
3   -
4   - angular.module('noosferoApp').factory('noosfero', function(Restangular, $q) {
5   - var currentProfile = $q.defer();
6   -
7   - return {
8   - currentProfile: currentProfile.promise,
9   - setCurrentProfile: function(profile) { currentProfile.resolve(profile) }
10   - }
11   - });
12   -})();
src/app/content-viewer/content-viewer-actions.component.ts
1   -import {Component, Inject} from "ng-forward";
  1 +import {Component, Inject, provide} from "ng-forward";
  2 +import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service";
2 3  
3 4 import {Profile} from "./../models/interfaces";
  5 +
4 6 @Component({
5 7 selector: "content-viewer-actions",
6 8 templateUrl: "app/content-viewer/navbar-actions.html",
  9 + providers: [provide('profileService', { useClass: ProfileService })]
7 10 })
8   -@Inject("noosfero")
  11 +@Inject(ProfileService)
9 12 export class ContentViewerActions {
10 13  
11 14 article: any;
12 15 profile: any;
13 16  
14   - constructor(noosfero: any) {
15   - noosfero.currentProfile.then((profile: Profile) => {
  17 + constructor(profileService: ProfileService) {
  18 + profileService.getCurrentProfile().then((profile: Profile) => {
16 19 this.profile = profile;
17 20 });
18 21 }
... ...
src/app/content-viewer/content-viewer.component.ts
... ... @@ -6,14 +6,18 @@ import {Input, Component, StateConfig, Inject, provide} from "ng-forward";
6 6  
7 7 import {ArticleBlog} from "./../components/noosfero-articles/blog/blog.component";
8 8 import {ArticleService} from "../../lib/ng-noosfero-api/http/article.service";
  9 +import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service";
9 10  
10 11 @Component({
11 12 selector: "content-viewer",
12 13 templateUrl: "app/content-viewer/page.html",
13 14 directives: [ArticleBlog, ArticleView],
14   - providers: [provide('articleService', { useClass: ArticleService })]
  15 + providers: [
  16 + provide('articleService', { useClass: ArticleService }),
  17 + provide('profileService', { useClass: ProfileService })
  18 + ]
15 19 })
16   -@Inject(ArticleService, "noosfero", "$log", "$stateParams")
  20 +@Inject(ArticleService, ProfileService, "$log", "$stateParams")
17 21 export class ContentViewer {
18 22  
19 23 @Input()
... ... @@ -22,12 +26,12 @@ export class ContentViewer {
22 26 @Input()
23 27 profile: noosfero.Profile = null;
24 28  
25   - constructor(private articleService: ArticleService, private noosfero: any, private $log: ng.ILogService, private $stateParams: angular.ui.IStateParamsService) {
  29 + constructor(private articleService: ArticleService, private profileService: ProfileService, private $log: ng.ILogService, private $stateParams: angular.ui.IStateParamsService) {
26 30 this.activate();
27 31 }
28 32  
29 33 activate() {
30   - this.noosfero.currentProfile.then((profile: noosfero.Profile) => {
  34 + this.profileService.getCurrentProfile().then((profile: noosfero.Profile) => {
31 35 this.profile = profile;
32 36 return this.articleService.getByProfile(this.profile.id, { path: this.$stateParams["page"] });
33 37 }).then((response: restangular.IResponse) => {
... ...
src/app/index.ts
... ... @@ -28,7 +28,6 @@ NoosferoApp.addConstants("AUTH_EVENTS", AUTH_EVENTS);
28 28 NoosferoApp.addConfig(noosferoModuleConfig);
29 29 NoosferoApp.run(noosferoAngularRunBlock);
30 30  
31   -require("./components/noosfero/noosfero.service.js");
32 31 require("./components/noosfero/profile-image/profile-image.component.js");
33 32  
34 33 NoosferoApp.addConfig(routeConfig);
... ...
src/app/profile-info/profile-info.component.ts
... ... @@ -8,18 +8,18 @@ import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service";
8 8 templateUrl: "app/profile-info/profile-info.html",
9 9 providers: [provide('profileService', { useClass: ProfileService })]
10 10 })
11   -@Inject(ProfileService, "noosfero")
  11 +@Inject(ProfileService)
12 12 export class ProfileInfo {
13 13  
14 14 activities: any
15 15 profile: any
16 16  
17   - constructor(private profileService: ProfileService, private noosfero: any) {
  17 + constructor(private profileService: ProfileService) {
18 18 this.activate();
19 19 }
20 20  
21 21 activate() {
22   - this.noosfero.currentProfile.then((profile: Profile) => {
  22 + this.profileService.getCurrentProfile().then((profile: Profile) => {
23 23 this.profile = profile;
24 24 return this.profileService.getActivities(this.profile.id);
25 25 }).then((response: restangular.IResponse) => {
... ...
src/app/profile/profile-home.component.ts
... ... @@ -8,13 +8,13 @@ import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service";
8 8 template: "<div></div>",
9 9 providers: [provide('profileService', { useClass: ProfileService })]
10 10 })
11   -@Inject(ProfileService, "noosfero", "$log", "$stateParams", "$scope", "$state")
  11 +@Inject(ProfileService, "$log", "$stateParams", "$scope", "$state")
12 12 export class ProfileHome {
13 13  
14 14 profile: Profile;
15 15  
16   - constructor(profileService: ProfileService, noosfero: any, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService, $scope: ng.IScope, $state: ng.ui.IStateService) {
17   - noosfero.currentProfile.then((profile: Profile) => {
  16 + constructor(profileService: ProfileService, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService, $scope: ng.IScope, $state: ng.ui.IStateService) {
  17 + profileService.getCurrentProfile().then((profile: Profile) => {
18 18 this.profile = profile;
19 19 return profileService.get(this.profile.id).customGET('home_page', { fields: 'path' });
20 20 }).then((response: restangular.IResponse) => {
... ...
src/app/profile/profile.component.ts
... ... @@ -6,6 +6,7 @@ import {ContentViewer} from &quot;../content-viewer/content-viewer.component&quot;;
6 6 import {ContentViewerActions} from "../content-viewer/content-viewer-actions.component";
7 7 import {NoosferoActivities} from "../components/noosfero-activities/activities.component";
8 8 import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service";
  9 +import {NoosferoService} from "../components/noosfero/noosfero.service";
9 10  
10 11 import * as noosferoModels from "./../models/interfaces";
11 12  
... ... @@ -69,16 +70,16 @@ import * as noosferoModels from &quot;./../models/interfaces&quot;;
69 70 }
70 71 }
71 72 ])
72   -@Inject(ProfileService, "noosfero", "$log", "$stateParams")
  73 +@Inject(ProfileService, "$log", "$stateParams")
73 74 export class Profile {
74 75  
75 76 boxes: noosferoModels.Box[];
76 77 profile: noosferoModels.Profile;
77 78  
78   - constructor(profileService: ProfileService, noosfero: any, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService) {
  79 + constructor(profileService: ProfileService, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService) {
79 80 profileService.getByIdentifier($stateParams["profile"]).then((response: restangular.IResponse) => {
80 81 this.profile = response.data[0];
81   - noosfero.setCurrentProfile(this.profile);
  82 + profileService.setCurrentProfile(this.profile);
82 83 return profileService.getBoxes(this.profile.id);
83 84 }).then((response: restangular.IResponse) => {
84 85 this.boxes = response.data.boxes;
... ...
src/lib/ng-noosfero-api/http/profile.service.ts
1 1 import { Injectable, Inject } from "ng-forward";
  2 +import {Profile} from "../../../app/models/interfaces";
2 3  
3 4 @Injectable()
4   -@Inject("Restangular")
  5 +@Inject("Restangular", "$q")
5 6 export class ProfileService {
6 7  
7   - constructor(private restangular: restangular.IService) { }
  8 + private _currentProfilePromise: ng.IDeferred<Profile>;
  9 +
  10 + constructor(private restangular: restangular.IService, $q: ng.IQService) {
  11 + this._currentProfilePromise = $q.defer();
  12 + }
  13 +
  14 + getCurrentProfile(): ng.IPromise<Profile> {
  15 + return this._currentProfilePromise.promise;
  16 + }
  17 +
  18 + setCurrentProfile(profile: Profile) {
  19 + this._currentProfilePromise.resolve(profile);
  20 + }
8 21  
9 22 getByIdentifier(identifier: string): restangular.IPromise<any> {
10 23 return this.restangular.one('profiles').get({ identifier: identifier });
... ...