boxes.component.ts
2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import {Input, Inject, Component} from 'ng-forward';
import {SessionService, AuthService, AuthEvents} from "../../login";
import {DisplayBlocks} from "./display-blocks.filter";
@Component({
selector: "noosfero-boxes",
templateUrl: "app/layout/boxes/boxes.html",
directives: [DisplayBlocks]
})
@Inject("SessionService", 'AuthService', "$state", "$rootScope")
export class BoxesComponent {
@Input() boxes: noosfero.Box[];
@Input() owner: noosfero.Profile | noosfero.Environment;
currentUser: noosfero.User;
isHomepage = true;
constructor(private session: SessionService,
private authService: AuthService,
private $state: ng.ui.IStateService,
private $rootScope: ng.IRootScopeService) {
this.currentUser = this.session.currentUser();
this.authService.subscribe(AuthEvents[AuthEvents.loginSuccess], () => {
this.currentUser = this.session.currentUser();
this.verifyHomepage();
});
this.authService.subscribe(AuthEvents[AuthEvents.logoutSuccess], () => {
this.currentUser = this.session.currentUser();
this.verifyHomepage();
});
this.$rootScope.$on("$stateChangeSuccess", (event: ng.IAngularEvent, toState: ng.ui.IState) => {
this.verifyHomepage();
});
}
ngOnInit() {
this.verifyHomepage();
}
boxesOrder(box: noosfero.Box) {
if (box.position === 2) return 0;
return box.position;
}
private verifyHomepage() {
if (this.owner && ["Profile", "Community", "Person"].indexOf((<any>this.owner)['type']) >= 0) {
let profile = <noosfero.Profile>this.owner;
this.isHomepage = this.$state.current.name === "main.profile.home";
if (profile.homepage) {
this.isHomepage = this.isHomepage ||
(this.$state.current.name === "main.profile.page" && profile.homepage === this.$state.params['page']);
} else {
this.isHomepage = this.isHomepage || this.$state.current.name === "main.profile.info";
}
} else {
this.isHomepage = this.$state.current.name === "main.environment.home";
}
}
}