profile.component.ts
5.35 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import {StateConfig, Component, Inject, provide} from 'ng-forward';
import {ProfileInfoComponent} from './info/profile-info.component';
import {ProfileHomeComponent} from './profile-home.component';
import {BasicEditorComponent} from '../article/cms/basic-editor/basic-editor.component';
import {CmsComponent} from '../article/cms/cms.component';
import {ContentViewerComponent} from "../article/content-viewer/content-viewer.component";
import {ContentViewerActionsComponent} from "../article/content-viewer/content-viewer-actions.component";
import {ActivitiesComponent} from "./activities/activities.component";
import {ActivityComponent} from "./activities/activity/activity.component";
import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service";
import {NotificationService} from "../shared/services/notification.service";
import {MyProfileComponent} from "./myprofile.component";
import {ProfileActionsComponent} from "./profile-actions.component";
import {ProfileToolbarComponent} from "./profile-toolbar.component";
/**
* @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: [ActivityComponent],
providers: [
provide('profileService', { useClass: ProfileService }),
provide('notificationService', { useClass: NotificationService })
]
})
@StateConfig([
{
name: 'main.profile.info',
url: "^/profile/:profile",
component: ProfileInfoComponent,
views: {
"profile-info": {
templateUrl: "app/profile/info/profile-info.html",
controller: ProfileInfoComponent,
controllerAs: "vm"
},
"actions@main": {
templateUrl: "app/profile/navbar-actions.html",
controller: ProfileActionsComponent,
controllerAs: "vm"
},
"toolbar@main": {
templateUrl: "app/profile/toolbar.html",
controller: ProfileToolbarComponent,
controllerAs: "vm"
},
"mainBlockContent": {
templateUrl: "app/profile/activities/activities.html",
controller: ProfileInfoComponent,
controllerAs: "vm"
}
}
},
{
name: 'main.profile.settings',
url: "^/myprofile/:profile",
component: MyProfileComponent,
views: {
"actions@main": {
templateUrl: "app/profile/navbar-actions.html",
controller: ProfileActionsComponent,
controllerAs: "vm"
},
"toolbar@main": {
templateUrl: "app/profile/toolbar.html",
controller: ProfileToolbarComponent,
controllerAs: "vm"
}
}
},
{
name: 'main.cms',
url: "^/myprofile/:profile/cms?parent_id&type",
component: CmsComponent,
views: {
"content": {
templateUrl: "app/article/cms/cms.html",
controller: CmsComponent,
controllerAs: "vm"
}
}
},
{
name: 'main.cmsEdit',
url: "^/myprofile/:profile/cms/edit/:id",
component: CmsComponent,
views: {
"content": {
templateUrl: "app/article/cms/cms.html",
controller: CmsComponent,
controllerAs: "vm"
}
}
},
{
name: 'main.profile.home',
url: "",
component: ProfileHomeComponent,
views: {
"mainBlockContent": {
controller: ProfileHomeComponent,
controllerAs: "vm"
}
}
},
{
name: 'main.profile.page',
url: "/{page:any}",
component: ContentViewerComponent,
views: {
"mainBlockContent": {
templateUrl: "app/article/content-viewer/page.html",
controller: ContentViewerComponent,
controllerAs: "vm"
},
"actions@main": {
templateUrl: "app/article/content-viewer/navbar-actions.html",
controller: ContentViewerActionsComponent,
controllerAs: "vm"
},
"toolbar@main": {
templateUrl: "app/profile/toolbar.html",
controller: ProfileToolbarComponent,
controllerAs: "vm"
}
}
}
])
@Inject(ProfileService, "$stateParams", "$state")
export class ProfileComponent {
boxes: noosfero.Box[];
profile: noosfero.Profile;
constructor(profileService: ProfileService, $stateParams: ng.ui.IStateParamsService, $state: ng.ui.IStateService, notificationService: NotificationService) {
profileService.setCurrentProfileByIdentifier($stateParams["profile"]).then((profile: noosfero.Profile) => {
this.profile = profile;
return profileService.getBoxes(<number>this.profile.id);
}).then((response: restangular.IResponse) => {
this.boxes = response.data.boxes;
}).catch(() => {
$state.transitionTo('main.environment.home');
notificationService.error({ message: "notification.profile.not_found" });
});
}
}