Commit 57499aeb0498ee86b507bb7db87289d502503791
1 parent
def8ed54
Exists in
master
and in
26 other branches
Listen for state change to change displayed blocks
Showing
4 changed files
with
44 additions
and
4 deletions
Show diff stats
src/app/layout/boxes/boxes.component.spec.ts
@@ -62,6 +62,20 @@ describe("Boxes Component", () => { | @@ -62,6 +62,20 @@ describe("Boxes Component", () => { | ||
62 | expect(helper.component.isHomepage).toBeTruthy(); | 62 | expect(helper.component.isHomepage).toBeTruthy(); |
63 | }); | 63 | }); |
64 | 64 | ||
65 | + it("set isHomepage as true when in profile info page", () => { | ||
66 | + state.current = { name: "main.profile.info" }; | ||
67 | + helper.component.ngOnInit(); | ||
68 | + expect(helper.component.isHomepage).toBeTruthy(); | ||
69 | + }); | ||
70 | + | ||
71 | + it("set isHomepage as true when in profile page", () => { | ||
72 | + state.current = { name: "main.profile.page" }; | ||
73 | + state.params = { page: "/page" }; | ||
74 | + (<noosfero.Profile>helper.component.owner).homepage = '/page'; | ||
75 | + helper.component.ngOnInit(); | ||
76 | + expect(helper.component.isHomepage).toBeTruthy(); | ||
77 | + }); | ||
78 | + | ||
65 | it("set isHomepage as true when in environment home page", () => { | 79 | it("set isHomepage as true when in environment home page", () => { |
66 | state.current = { name: "main.environment.home" }; | 80 | state.current = { name: "main.environment.home" }; |
67 | helper.component.owner = <noosfero.Environment>{}; | 81 | helper.component.owner = <noosfero.Environment>{}; |
src/app/layout/boxes/boxes.component.ts
@@ -7,7 +7,7 @@ import {DisplayBlocks} from "./display-blocks.filter"; | @@ -7,7 +7,7 @@ import {DisplayBlocks} from "./display-blocks.filter"; | ||
7 | templateUrl: "app/layout/boxes/boxes.html", | 7 | templateUrl: "app/layout/boxes/boxes.html", |
8 | directives: [DisplayBlocks] | 8 | directives: [DisplayBlocks] |
9 | }) | 9 | }) |
10 | -@Inject("SessionService", 'AuthService', "$state") | 10 | +@Inject("SessionService", 'AuthService', "$state", "$rootScope") |
11 | export class BoxesComponent { | 11 | export class BoxesComponent { |
12 | 12 | ||
13 | @Input() boxes: noosfero.Box[]; | 13 | @Input() boxes: noosfero.Box[]; |
@@ -16,13 +16,22 @@ export class BoxesComponent { | @@ -16,13 +16,22 @@ export class BoxesComponent { | ||
16 | currentUser: noosfero.User; | 16 | currentUser: noosfero.User; |
17 | isHomepage = true; | 17 | isHomepage = true; |
18 | 18 | ||
19 | - constructor(private session: SessionService, private authService: AuthService, private $state: ng.ui.IStateService) { | 19 | + constructor(private session: SessionService, |
20 | + private authService: AuthService, | ||
21 | + private $state: ng.ui.IStateService, | ||
22 | + private $rootScope: ng.IRootScopeService) { | ||
23 | + | ||
20 | this.currentUser = this.session.currentUser(); | 24 | this.currentUser = this.session.currentUser(); |
21 | this.authService.subscribe(AuthEvents[AuthEvents.loginSuccess], () => { | 25 | this.authService.subscribe(AuthEvents[AuthEvents.loginSuccess], () => { |
22 | this.currentUser = this.session.currentUser(); | 26 | this.currentUser = this.session.currentUser(); |
27 | + this.verifyHomepage(); | ||
23 | }); | 28 | }); |
24 | this.authService.subscribe(AuthEvents[AuthEvents.logoutSuccess], () => { | 29 | this.authService.subscribe(AuthEvents[AuthEvents.logoutSuccess], () => { |
25 | this.currentUser = this.session.currentUser(); | 30 | this.currentUser = this.session.currentUser(); |
31 | + this.verifyHomepage(); | ||
32 | + }); | ||
33 | + this.$rootScope.$on("$stateChangeSuccess", (event: ng.IAngularEvent, toState: ng.ui.IState) => { | ||
34 | + this.verifyHomepage(); | ||
26 | }); | 35 | }); |
27 | } | 36 | } |
28 | 37 | ||
@@ -37,7 +46,14 @@ export class BoxesComponent { | @@ -37,7 +46,14 @@ export class BoxesComponent { | ||
37 | 46 | ||
38 | private verifyHomepage() { | 47 | private verifyHomepage() { |
39 | if (this.owner && ["Profile", "Community", "Person"].indexOf((<any>this.owner)['type']) >= 0) { | 48 | if (this.owner && ["Profile", "Community", "Person"].indexOf((<any>this.owner)['type']) >= 0) { |
49 | + let profile = <noosfero.Profile>this.owner; | ||
40 | this.isHomepage = this.$state.current.name === "main.profile.home"; | 50 | this.isHomepage = this.$state.current.name === "main.profile.home"; |
51 | + if (profile.homepage) { | ||
52 | + this.isHomepage = this.isHomepage || | ||
53 | + (this.$state.current.name === "main.profile.page" && profile.homepage === this.$state.params['page']); | ||
54 | + } else { | ||
55 | + this.isHomepage = this.isHomepage || this.$state.current.name === "main.profile.info"; | ||
56 | + } | ||
41 | } else { | 57 | } else { |
42 | this.isHomepage = this.$state.current.name === "main.environment.home"; | 58 | this.isHomepage = this.$state.current.name === "main.environment.home"; |
43 | } | 59 | } |
src/app/profile/profile-home.component.ts
@@ -18,8 +18,10 @@ export class ProfileHomeComponent { | @@ -18,8 +18,10 @@ export class ProfileHomeComponent { | ||
18 | return profileService.getHomePage(<number>this.profile.id, { fields: 'path' }); | 18 | return profileService.getHomePage(<number>this.profile.id, { fields: 'path' }); |
19 | }).then((response: restangular.IResponse) => { | 19 | }).then((response: restangular.IResponse) => { |
20 | if (response.data.article) { | 20 | if (response.data.article) { |
21 | + this.profile.homepage = response.data.article.path; | ||
21 | $state.transitionTo('main.profile.page', { page: response.data.article.path, profile: this.profile.identifier }, { location: false }); | 22 | $state.transitionTo('main.profile.page', { page: response.data.article.path, profile: this.profile.identifier }, { location: false }); |
22 | } else { | 23 | } else { |
24 | + this.profile.homepage = null; | ||
23 | $state.transitionTo('main.profile.info', { profile: this.profile.identifier }, { location: false }); | 25 | $state.transitionTo('main.profile.info', { profile: this.profile.identifier }, { location: false }); |
24 | } | 26 | } |
25 | }); | 27 | }); |
src/lib/ng-noosfero-api/interfaces/profile.ts
@@ -22,13 +22,13 @@ namespace noosfero { | @@ -22,13 +22,13 @@ namespace noosfero { | ||
22 | * @returns {string} The unque identifier for the Profile | 22 | * @returns {string} The unque identifier for the Profile |
23 | */ | 23 | */ |
24 | identifier: string; | 24 | identifier: string; |
25 | - | 25 | + |
26 | /** | 26 | /** |
27 | * @ngdoc property | 27 | * @ngdoc property |
28 | * @name created_at | 28 | * @name created_at |
29 | * @propertyOf noofero.Profile | 29 | * @propertyOf noofero.Profile |
30 | * @returns {string} The timestamp this object was created | 30 | * @returns {string} The timestamp this object was created |
31 | - */ | 31 | + */ |
32 | created_at: string; | 32 | created_at: string; |
33 | 33 | ||
34 | /** | 34 | /** |
@@ -54,5 +54,13 @@ namespace noosfero { | @@ -54,5 +54,13 @@ namespace noosfero { | ||
54 | * @returns {string} A key => value custom fields data of Profile (e.g.: "{'Address':'Street A, Number 102...'}") | 54 | * @returns {string} A key => value custom fields data of Profile (e.g.: "{'Address':'Street A, Number 102...'}") |
55 | */ | 55 | */ |
56 | additional_data?: any; | 56 | additional_data?: any; |
57 | + | ||
58 | + /** | ||
59 | + * @ngdoc property | ||
60 | + * @name homepage | ||
61 | + * @propertyOf noofero.Profile | ||
62 | + * @returns {string} The Profile homepage | ||
63 | + */ | ||
64 | + homepage: string; | ||
57 | } | 65 | } |
58 | } | 66 | } |