profile.component.ts
3.18 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import {StateConfig, Component, Inject, provide} from 'ng-forward';
import {ProfileInfo} from '../profile-info/profile-info.component';
import {ProfileHome} from '../profile/profile-home.component';
import {Cms} from '../cms/cms.component';
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 {Notification} from "../components/notification/notification.component";
import * as noosferoModels from "./../models/interfaces";
/**
* @ngdoc controller
* @name profile.Profile
* @description
* This is the profile controller. It provide routes to supported Noosfero Profiles.
*/
@Component({
selector: 'profile',
templateUrl: "app/profile/profile.html",
directives: [NoosferoActivities],
providers: [
provide('profileService', { useClass: ProfileService }),
provide('notification', { useClass: Notification })
]
})
@StateConfig([
{
name: 'main.profile.info',
url: "^/profile/:profile",
component: ProfileInfo,
views: {
"mainBlockContent": {
templateUrl: "app/profile-info/profile-info.html",
controller: ProfileInfo,
controllerAs: "vm"
}
}
},
{
name: 'main.profile.cms',
url: "^/myprofile/:profile/cms",
component: Cms,
views: {
"mainBlockContent": {
templateUrl: "app/cms/cms.html",
controller: Cms,
controllerAs: "vm"
}
}
},
{
name: 'main.profile.home',
url: "",
component: ProfileHome,
views: {
"mainBlockContent": {
controller: ProfileHome,
controllerAs: "vm"
}
}
},
{
name: 'main.profile.page',
url: "/{page:any}",
component: ContentViewer,
views: {
"mainBlockContent": {
templateUrl: "app/content-viewer/page.html",
controller: ContentViewer,
controllerAs: "vm"
},
"actions@main": {
templateUrl: "app/content-viewer/navbar-actions.html",
controller: ContentViewerActions,
controllerAs: "vm"
}
}
}
])
@Inject(ProfileService, "$stateParams")
export class Profile {
boxes: noosferoModels.Box[];
profile: noosferoModels.Profile;
constructor(profileService: ProfileService, $stateParams: ng.ui.IStateParamsService, notification: Notification) {
profileService.setCurrentProfileByIdentifier($stateParams["profile"]).then((profile: noosferoModels.Profile) => {
this.profile = profile;
return profileService.getBoxes(this.profile.id);
}).then((response: restangular.IResponse) => {
this.boxes = response.data.boxes;
}).catch(() => {
notification.error("notification.profile.not_found");
});
}
}