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 | 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 | 79 | it("set isHomepage as true when in environment home page", () => { |
66 | 80 | state.current = { name: "main.environment.home" }; |
67 | 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 | templateUrl: "app/layout/boxes/boxes.html", |
8 | 8 | directives: [DisplayBlocks] |
9 | 9 | }) |
10 | -@Inject("SessionService", 'AuthService', "$state") | |
10 | +@Inject("SessionService", 'AuthService', "$state", "$rootScope") | |
11 | 11 | export class BoxesComponent { |
12 | 12 | |
13 | 13 | @Input() boxes: noosfero.Box[]; |
... | ... | @@ -16,13 +16,22 @@ export class BoxesComponent { |
16 | 16 | currentUser: noosfero.User; |
17 | 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 | 24 | this.currentUser = this.session.currentUser(); |
21 | 25 | this.authService.subscribe(AuthEvents[AuthEvents.loginSuccess], () => { |
22 | 26 | this.currentUser = this.session.currentUser(); |
27 | + this.verifyHomepage(); | |
23 | 28 | }); |
24 | 29 | this.authService.subscribe(AuthEvents[AuthEvents.logoutSuccess], () => { |
25 | 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 | 46 | |
38 | 47 | private verifyHomepage() { |
39 | 48 | if (this.owner && ["Profile", "Community", "Person"].indexOf((<any>this.owner)['type']) >= 0) { |
49 | + let profile = <noosfero.Profile>this.owner; | |
40 | 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 | 57 | } else { |
42 | 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 | 18 | return profileService.getHomePage(<number>this.profile.id, { fields: 'path' }); |
19 | 19 | }).then((response: restangular.IResponse) => { |
20 | 20 | if (response.data.article) { |
21 | + this.profile.homepage = response.data.article.path; | |
21 | 22 | $state.transitionTo('main.profile.page', { page: response.data.article.path, profile: this.profile.identifier }, { location: false }); |
22 | 23 | } else { |
24 | + this.profile.homepage = null; | |
23 | 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 | 22 | * @returns {string} The unque identifier for the Profile |
23 | 23 | */ |
24 | 24 | identifier: string; |
25 | - | |
25 | + | |
26 | 26 | /** |
27 | 27 | * @ngdoc property |
28 | 28 | * @name created_at |
29 | 29 | * @propertyOf noofero.Profile |
30 | 30 | * @returns {string} The timestamp this object was created |
31 | - */ | |
31 | + */ | |
32 | 32 | created_at: string; |
33 | 33 | |
34 | 34 | /** |
... | ... | @@ -54,5 +54,13 @@ namespace noosfero { |
54 | 54 | * @returns {string} A key => value custom fields data of Profile (e.g.: "{'Address':'Street A, Number 102...'}") |
55 | 55 | */ |
56 | 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 | } | ... | ... |