2 |
2 |
* Created by stefania on 3/21/16.
|
3 |
3 |
*/
|
4 |
4 |
|
5 |
|
import { Component } from '@angular/core';
|
6 |
|
import{MenuItem, RootMenuItem} from './openaireLibrary/sharedComponents/menu';
|
|
5 |
import {Component, ViewChild} from '@angular/core';
|
|
6 |
import {MenuItem, RootMenuItem, SideMenuItem} from './openaireLibrary/sharedComponents/menu';
|
7 |
7 |
import {ActivatedRoute} from '@angular/router';
|
8 |
|
import { EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';
|
|
8 |
import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';
|
9 |
9 |
import {CommunitiesService} from "./openaireLibrary/connect/communities/communities.service";
|
10 |
|
import { EnvProperties} from './openaireLibrary/utils/properties/env-properties';
|
|
10 |
import {EnvProperties} from './openaireLibrary/utils/properties/env-properties';
|
11 |
11 |
import {Session} from './openaireLibrary/login/utils/helper.class';
|
|
12 |
import {root} from "rxjs/util/root";
|
|
13 |
import {SideBarComponent} from "./openaireLibrary/sharedComponents/sidebar/sideBar.component";
|
12 |
14 |
|
13 |
15 |
declare var UIkit: any;
|
14 |
16 |
|
... | ... | |
19 |
21 |
|
20 |
22 |
export class AppComponent {
|
21 |
23 |
title = 'Metadata Registry Service';
|
22 |
|
//isClient:boolean = false;
|
|
24 |
userMenuItems: MenuItem[] = [];
|
23 |
25 |
|
|
26 |
menuItems: RootMenuItem [] = [];
|
|
27 |
sideMenuItems: SideMenuItem[] = [];
|
|
28 |
logInUrl = null;
|
|
29 |
logOutUrl = null;
|
|
30 |
community: { id: string, name: string, logoUrl: string } = null;
|
|
31 |
communityId = "";
|
|
32 |
communityType = null;
|
|
33 |
properties: EnvProperties = null;
|
|
34 |
isPortalAdministrator: boolean = false;
|
|
35 |
showSidebar: boolean;
|
24 |
36 |
|
25 |
|
userMenuItems:MenuItem[] = [];
|
|
37 |
constructor(private route: ActivatedRoute, private propertiesService: EnvironmentSpecificService, private _communitiesService: CommunitiesService) {
|
26 |
38 |
|
27 |
|
menuItems:RootMenuItem [] = [];
|
|
39 |
}
|
28 |
40 |
|
29 |
|
logInUrl = null;
|
30 |
|
logOutUrl = null;
|
31 |
|
community: {id:string, name:string, logoUrl:string} = null;
|
32 |
|
communityId="";
|
33 |
|
communityType=null;
|
34 |
|
properties:EnvProperties = null;
|
35 |
|
isPortalAdministrator:boolean = false;
|
36 |
|
constructor( private route: ActivatedRoute, private propertiesService:EnvironmentSpecificService, private _communitiesService:CommunitiesService) {
|
|
41 |
ngOnInit() {
|
|
42 |
this.propertiesService.loadEnvironment()
|
|
43 |
.then(es => {
|
|
44 |
this.propertiesService.setEnvProperties(es);
|
|
45 |
this.properties = this.propertiesService.envSpecific;
|
|
46 |
this.logInUrl = this.properties.loginUrl;
|
|
47 |
this.logOutUrl = this.properties.logoutUrl;
|
|
48 |
this.showSidebar = false;
|
|
49 |
if (Session.getUser()) {
|
|
50 |
localStorage.setItem('user_id', Session.getUser().id);
|
|
51 |
localStorage.setItem('mining_backend_address', this.properties.miningBackendURL);
|
|
52 |
localStorage.setItem('isCommunityManager', Session.isCommunityCurator() + "");
|
37 |
53 |
|
38 |
|
}
|
|
54 |
this.isPortalAdministrator = Session.isPortalAdministrator();
|
|
55 |
/*this.isPortalAdministrator = true;*/
|
|
56 |
}
|
|
57 |
this.route.queryParams.subscribe(data => {
|
|
58 |
this.communityId = ((data['communityId']) ? data['communityId'] : "");
|
|
59 |
this.communityType = null;
|
|
60 |
this.menuItems = [];
|
|
61 |
this.userMenuItems = [];
|
|
62 |
this._communitiesService.getCommunities(this.properties, this.properties.communityAPI + "communities").subscribe(
|
|
63 |
communities => {
|
|
64 |
// this.community = community;
|
|
65 |
this.userMenuItems = [];
|
|
66 |
let countCommunities = 0;
|
|
67 |
let index_managerOfCommunity = null;
|
|
68 |
for (let i = 0; i < communities.length; i++) {
|
|
69 |
let com = communities[i];
|
|
70 |
if (Session.isPortalAdministrator() || Session.isCommunityCurator()) {
|
|
71 |
this.userMenuItems.push(new MenuItem("manage" + com.communityId, "Manage " + ((com.shortTitle) ? com.shortTitle : com.title), "", "/dashboard", false, [], [], {communityId: com.communityId}));
|
|
72 |
} else {
|
|
73 |
for (var manager of com.managers) {
|
|
74 |
if (manager == Session.getUserEmail()) {
|
|
75 |
countCommunities++;
|
|
76 |
index_managerOfCommunity = i;
|
|
77 |
this.userMenuItems.push(new MenuItem("manage" + com.communityId, "Manage " + ((com.shortTitle) ? com.shortTitle : com.title), "", "/dashboard", false, [], [], {communityId: com.communityId}));
|
|
78 |
break;
|
|
79 |
}
|
|
80 |
}
|
|
81 |
}
|
|
82 |
if (com.communityId == this.communityId) {
|
|
83 |
this.community = {
|
|
84 |
id: com.communityId,
|
|
85 |
name: (com.shortTitle) ? com.shortTitle : com.title,
|
|
86 |
logoUrl: com.logoUrl
|
|
87 |
};
|
|
88 |
this.communityType = com.type;
|
|
89 |
this.menuItems = [
|
|
90 |
{
|
|
91 |
rootItem: new MenuItem("dashboard", "Overview", "/dashboard", "/dashboard", false, [], null, {communityId: com.communityId}),
|
|
92 |
items: []
|
|
93 |
}
|
|
94 |
];
|
|
95 |
} else if (countCommunities == 1 && index_managerOfCommunity != null) {
|
|
96 |
this.community = {
|
|
97 |
id: communities[index_managerOfCommunity].communityId,
|
|
98 |
name: (communities[index_managerOfCommunity].shortTitle) ? communities[index_managerOfCommunity].shortTitle : com.title,
|
|
99 |
logoUrl: communities[index_managerOfCommunity].logoUrl
|
|
100 |
};
|
|
101 |
this.menuItems = [
|
|
102 |
{
|
|
103 |
rootItem: new MenuItem("dashboard", "Overview", "/dashboard", "/dashboard", false, [], null, {communityId: communities[index_managerOfCommunity].communityId}),
|
|
104 |
items: []
|
|
105 |
}
|
|
106 |
];
|
|
107 |
}
|
|
108 |
}
|
|
109 |
if (!this.communityId || this.communityId == '') {
|
|
110 |
this.community = null;
|
|
111 |
}
|
|
112 |
if (this.communityId) {
|
|
113 |
this.userMenuItems.push(new MenuItem("manage-user-notifications", "Manage notification settings", "", "/manage-user-notifications", false, [], [], {communityId: this.communityId}));
|
|
114 |
}
|
|
115 |
this.buildSideBar();
|
|
116 |
},
|
|
117 |
error => {
|
|
118 |
if ((this.communityId && this.communityId != "") || window.location.pathname == "/") {
|
|
119 |
UIkit.notification({
|
|
120 |
message: '<strong>System error retrieving communities.<strong>',
|
|
121 |
status: 'warning',
|
|
122 |
timeout: 3000,
|
|
123 |
pos: 'top-center'
|
|
124 |
})
|
|
125 |
}
|
|
126 |
}
|
|
127 |
);
|
|
128 |
});
|
|
129 |
});
|
39 |
130 |
|
40 |
|
ngOnInit() {
|
41 |
|
this.propertiesService.loadEnvironment()
|
42 |
|
.then(es => {
|
43 |
|
this.propertiesService.setEnvProperties(es);
|
44 |
|
this.properties = this.propertiesService.envSpecific;
|
45 |
|
this.logInUrl = this.properties.loginUrl;
|
46 |
|
this.logOutUrl = this.properties.logoutUrl;
|
47 |
|
if( Session.getUser()){
|
48 |
|
localStorage.setItem('user_id', Session.getUser().id);
|
49 |
|
localStorage.setItem('mining_backend_address', this.properties.miningBackendURL);
|
50 |
|
localStorage.setItem('isCommunityManager', Session.isCommunityCurator()+"");
|
51 |
131 |
|
52 |
|
this.isPortalAdministrator = Session.isPortalAdministrator();
|
53 |
|
}
|
54 |
|
this.route.queryParams.subscribe(data => {
|
55 |
|
this.communityId = ((data['communityId'])?data['communityId']:"");
|
56 |
|
this.communityType = null;
|
57 |
|
this.menuItems = [];
|
58 |
|
this.userMenuItems = [];
|
59 |
|
this._communitiesService.getCommunities(this.properties, this.properties.communityAPI+"communities").subscribe (
|
60 |
|
communities => {
|
61 |
|
// this.community = community;
|
62 |
|
this.userMenuItems =[];
|
63 |
|
var countCommunities = 0;
|
64 |
|
var index_managerOfCommunity = null;
|
65 |
|
for(var i = 0;i <communities.length; i++){
|
66 |
|
var com = communities[i];
|
67 |
|
if(Session.isPortalAdministrator() || Session.isCommunityCurator()){
|
68 |
|
this.userMenuItems.push(new MenuItem("manage"+com.communityId,"Manage "+((com.shortTitle)?com.shortTitle:com.title),"","/dashboard",false,[],[],{communityId: com.communityId}));
|
69 |
|
}else{
|
70 |
|
for(var manager of com.managers){
|
71 |
|
if(manager== Session.getUserEmail()){
|
72 |
|
countCommunities++;
|
73 |
|
index_managerOfCommunity = i;
|
74 |
|
this.userMenuItems.push(new MenuItem("manage"+com.communityId,"Manage "+((com.shortTitle)?com.shortTitle:com.title),"","/dashboard",false,[],[],{communityId: com.communityId}));
|
75 |
|
break;
|
76 |
|
}
|
77 |
|
}
|
78 |
|
}
|
79 |
|
if(com.communityId == this.communityId){
|
80 |
|
this.community = {id: com.communityId, name: (com.shortTitle)?com.shortTitle:com.title, logoUrl:com.logoUrl};
|
81 |
|
this.communityType = com.type;
|
82 |
|
this.menuItems= [
|
83 |
|
{rootItem: new MenuItem("dashboard","Overview","/dashboard","/dashboard",false,[],null,{communityId:com.communityId}),
|
84 |
|
items: []
|
85 |
|
}
|
86 |
|
];
|
87 |
|
}else if(countCommunities == 1 &&index_managerOfCommunity!=null ){
|
88 |
|
this.community = {id: communities[index_managerOfCommunity].communityId, name: (communities[index_managerOfCommunity].shortTitle)?communities[index_managerOfCommunity].shortTitle:com.title, logoUrl:communities[index_managerOfCommunity].logoUrl};
|
89 |
|
this.menuItems= [
|
90 |
|
{rootItem: new MenuItem("dashboard","Overview","/dashboard","/dashboard",false,[],null,{communityId:communities[index_managerOfCommunity].communityId}),
|
91 |
|
items: []
|
92 |
|
}
|
93 |
|
];
|
94 |
|
}
|
95 |
|
}
|
96 |
|
if(this.communityId){
|
97 |
|
this.userMenuItems.push(new MenuItem("manage-user-notifications","Manage notification settings","","/manage-user-notifications",false,[],[],{communityId: this.communityId}));
|
98 |
|
}
|
|
132 |
}
|
99 |
133 |
|
100 |
|
|
101 |
|
},
|
102 |
|
error => {
|
103 |
|
if( ( this.communityId && this.communityId != "") || window.location.pathname == "/"){
|
104 |
|
UIkit.notification({
|
105 |
|
message : '<strong>System error retrieving communities.<strong>',
|
106 |
|
status : 'warning',
|
107 |
|
timeout : 3000,
|
108 |
|
pos : 'top-center'
|
109 |
|
})
|
110 |
|
}
|
111 |
|
}
|
112 |
|
);
|
113 |
|
});
|
114 |
|
});
|
115 |
|
|
116 |
|
|
|
134 |
private buildSideBar() {
|
|
135 |
this.sideMenuItems = [];
|
|
136 |
if ((!this.communityId || this.communityId == '') && this.isPortalAdministrator) {
|
|
137 |
let adminTools: SideMenuItem = {
|
|
138 |
rootItem: new MenuItem('adminTools', 'Admin Tools', '',
|
|
139 |
'', false, [], [], null),
|
|
140 |
items: [],
|
|
141 |
ukIcon: 'desktop'
|
|
142 |
};
|
|
143 |
adminTools.items.push({
|
|
144 |
rootItem: new MenuItem('communities', 'Communities', '/communities',
|
|
145 |
'/communities', false, [], [], null),
|
|
146 |
items: []
|
|
147 |
}
|
|
148 |
);
|
|
149 |
adminTools.items.push({
|
|
150 |
rootItem: new MenuItem('classes', 'Classes', '/classes',
|
|
151 |
'/classes', false, [], [], null),
|
|
152 |
items: []
|
|
153 |
}
|
|
154 |
);
|
|
155 |
this.sideMenuItems.push(adminTools);
|
|
156 |
} else if (this.communityId && this.communityId != '') {
|
|
157 |
this.sideMenuItems.push({
|
|
158 |
rootItem: new MenuItem('overview', 'Overview', '/dashboard',
|
|
159 |
'/dashboard', false, [], [], {communityId: this.communityId}),
|
|
160 |
items: [],
|
|
161 |
ukIcon: 'home'
|
|
162 |
});
|
|
163 |
if (this.isPortalAdministrator) {
|
|
164 |
let adminTools: SideMenuItem = {
|
|
165 |
rootItem: new MenuItem('adminTools', 'Admin Tools', '/communities',
|
|
166 |
'/communities', false, [], [], null),
|
|
167 |
items: [],
|
|
168 |
ukIcon: 'desktop'
|
|
169 |
};
|
|
170 |
this.sideMenuItems.push(adminTools);
|
|
171 |
}
|
|
172 |
if (this.communityId != 'openaire') {
|
|
173 |
let community: SideMenuItem = {
|
|
174 |
rootItem: new MenuItem('community', 'Community', '',
|
|
175 |
'', false, [], [], null),
|
|
176 |
items: [],
|
|
177 |
ukIcon: 'album'
|
|
178 |
}
|
|
179 |
community.items.push({
|
|
180 |
rootItem: new MenuItem('communityProfile', 'Community Profile', '/community-edit-form',
|
|
181 |
'/community-edit-form', false, [], [], {communityId: this.communityId}),
|
|
182 |
items: []
|
|
183 |
})
|
|
184 |
/*community.items.push({
|
|
185 |
rootItem: new MenuItem('communityLayout', 'Community Layout', '/community-layout',
|
|
186 |
'/community-layout', false, [], [], {communityId: this.communityId}),
|
|
187 |
items: []
|
|
188 |
})*/
|
|
189 |
this.sideMenuItems.push(community);
|
|
190 |
let communityContent: SideMenuItem = {
|
|
191 |
rootItem: new MenuItem('communityContent', 'Community Content', '',
|
|
192 |
'', false, [], [], null),
|
|
193 |
items: [],
|
|
194 |
ukIcon: 'list'
|
|
195 |
}
|
|
196 |
communityContent.items.push({
|
|
197 |
rootItem: new MenuItem('projects', 'Projects', '/manage-projects',
|
|
198 |
'/manage-projects', false, [], [], {communityId: this.communityId}),
|
|
199 |
items: []
|
|
200 |
}
|
|
201 |
)
|
|
202 |
communityContent.items.push({
|
|
203 |
rootItem: new MenuItem('contentProviders', 'Content providers', '/manage-content-providers',
|
|
204 |
'/manage-content-providers', false, [], [], {communityId: this.communityId}),
|
|
205 |
items: []
|
|
206 |
})
|
|
207 |
if (this.communityType && this.communityType != 'ri') {
|
|
208 |
communityContent.items.push({
|
|
209 |
rootItem: new MenuItem('subjects', 'Subjects', '/manage-subjects',
|
|
210 |
'/manage-subjects', false, [], [], {communityId: this.communityId}),
|
|
211 |
items: []
|
|
212 |
})
|
|
213 |
}
|
|
214 |
communityContent.items.push({
|
|
215 |
rootItem: new MenuItem('zenodoCommunities', 'Zenodo communities', '/manage-zenodo-communities',
|
|
216 |
'/manage-zenodo-communities', false, [], [], {communityId: this.communityId}),
|
|
217 |
items: []
|
|
218 |
})
|
|
219 |
this.sideMenuItems.push(communityContent);
|
|
220 |
}
|
|
221 |
let entities: SideMenuItem = {
|
|
222 |
rootItem: new MenuItem('entitiesPages', 'Entities & pages', '',
|
|
223 |
'', false, [], [], null),
|
|
224 |
items: [],
|
|
225 |
ukIcon: 'world'
|
|
226 |
}
|
|
227 |
entities.items.push({
|
|
228 |
rootItem: new MenuItem('entities', 'Activate Entities', '/entities',
|
|
229 |
'/entities', false, [], [], {communityId: this.communityId}),
|
|
230 |
items: []
|
|
231 |
})
|
|
232 |
let pages: MenuItem[] = [];
|
|
233 |
pages.push(new MenuItem('search', 'Search', '/pages',
|
|
234 |
'/pages', false, [], [], {communityId: this.communityId, type: 'search'}));
|
|
235 |
pages.push(new MenuItem('link', 'Link', '/pages',
|
|
236 |
'/pages', false, [], [], {communityId: this.communityId, type: 'link'}));
|
|
237 |
pages.push(new MenuItem('share', 'Share', '/pages',
|
|
238 |
'/pages', false, [], [], {communityId: this.communityId, type: 'share'}));
|
|
239 |
pages.push(new MenuItem('landing', 'Landing', '/pages',
|
|
240 |
'/pages', false, [], [], {communityId: this.communityId, type: 'landing'}));
|
|
241 |
pages.push(new MenuItem('html', 'HTML', '/pages',
|
|
242 |
'/pages', false, [], [], {communityId: this.communityId, type: 'html'}));
|
|
243 |
pages.push(new MenuItem('other', 'Other', '/pages',
|
|
244 |
'/pages', false, [], [], {communityId: this.communityId, type: 'other'}));
|
|
245 |
entities.items.push({
|
|
246 |
rootItem: new MenuItem('pages', 'Pages', '/pages',
|
|
247 |
'/pages', false, [], [], {communityId: this.communityId}),
|
|
248 |
items: pages
|
|
249 |
})
|
|
250 |
this.sideMenuItems.push(entities);
|
|
251 |
let help: SideMenuItem = {
|
|
252 |
rootItem: new MenuItem('help', 'Help Texts', '',
|
|
253 |
'', false, [], [], null),
|
|
254 |
items: [],
|
|
255 |
ukIcon: 'file-edit'
|
|
256 |
}
|
|
257 |
help.items.push({
|
|
258 |
rootItem: new MenuItem('pages', 'Page Help Texts', '/pageContents',
|
|
259 |
'/pageContents', false, [], [], {communityId: this.communityId}),
|
|
260 |
items: []
|
|
261 |
})
|
|
262 |
help.items.push({
|
|
263 |
rootItem: new MenuItem('classes', 'Class Help Texts', '/classContents',
|
|
264 |
'/classContents', false, [], [], {communityId: this.communityId}),
|
|
265 |
items: []
|
|
266 |
})
|
|
267 |
this.sideMenuItems.push(help);
|
|
268 |
if (this.communityId != 'openaire') {
|
|
269 |
let stats: SideMenuItem = {
|
|
270 |
rootItem: new MenuItem('stats', 'Statistics & Charts', '/stats',
|
|
271 |
'/stats', false, [], [], {communityId: this.communityId}),
|
|
272 |
items: [],
|
|
273 |
ukIcon: 'image'
|
|
274 |
}
|
|
275 |
this.sideMenuItems.push(stats);
|
|
276 |
let claims: SideMenuItem = {
|
|
277 |
rootItem: new MenuItem('claims', 'Links', '/claims',
|
|
278 |
'/claims', false, [], [], {communityId: this.communityId}),
|
|
279 |
items: [],
|
|
280 |
ukIcon: 'link'
|
|
281 |
}
|
|
282 |
this.sideMenuItems.push(claims);
|
|
283 |
if (this.communityType && this.communityType == 'ri') {
|
|
284 |
let mining: SideMenuItem = {
|
|
285 |
rootItem: new MenuItem('mining', 'Text Mining Rules', '/mining/manage-profiles',
|
|
286 |
'/mining/manage-profiles', false, [], [], {communityId: this.communityId}),
|
|
287 |
items: [],
|
|
288 |
ukIcon: 'settings'
|
|
289 |
}
|
|
290 |
this.sideMenuItems.push(mining);
|
|
291 |
}
|
|
292 |
let users: SideMenuItem = {
|
|
293 |
rootItem: new MenuItem('users', 'Users', '',
|
|
294 |
'', false, [], [], null),
|
|
295 |
items: [],
|
|
296 |
ukIcon: 'user'
|
|
297 |
}
|
|
298 |
users.items.push({
|
|
299 |
rootItem: new MenuItem('subscribers', 'Subscribers', '/manage-subscribers',
|
|
300 |
'/manage-subscribers', false, [], [], {communityId: this.communityId}),
|
|
301 |
items: []
|
|
302 |
})
|
|
303 |
users.items.push({
|
|
304 |
rootItem: new MenuItem('invite', 'Invite to Subscribe', 'https://beta.' + this.communityId + '.openaire.eu/invite',
|
|
305 |
'', false, [], [], null),
|
|
306 |
items: []
|
|
307 |
})
|
|
308 |
users.items.push({
|
|
309 |
rootItem: new MenuItem('notifications', 'Notification settings', '/manage-user-notifications',
|
|
310 |
'/manage-user-notifications', false, [], [], {communityId: this.communityId}),
|
|
311 |
items: []
|
|
312 |
})
|
|
313 |
this.sideMenuItems.push(users);
|
|
314 |
}
|
|
315 |
}
|
|
316 |
if (this.sideMenuItems.length > 0) {
|
|
317 |
this.showSidebar = true;
|
|
318 |
}
|
117 |
319 |
}
|
118 |
320 |
}
|
[Trunk|Admin]: 1. Build sideBar menu in app.component. 2. Add AdminLoginGuard to /classes route