Project

General

Profile

1
/**
2
 * Created by stefania on 3/21/16.
3
 */
4

    
5
import {Component, OnInit} from '@angular/core';
6
import {MenuItem, RootMenuItem, SideMenuItem} from './openaireLibrary/sharedComponents/menu';
7
import {ActivatedRoute, NavigationStart, Router} from '@angular/router';
8
import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';
9
import {CommunitiesService} from './openaireLibrary/connect/communities/communities.service';
10
import {EnvProperties} from './openaireLibrary/utils/properties/env-properties';
11
import {Session, User} from './openaireLibrary/login/utils/helper.class';
12
import {HelperFunctions} from './openaireLibrary/utils/HelperFunctions.class';
13
import {UserManagementService} from './openaireLibrary/services/user-management.service';
14
import {ConnectHelper} from "./openaireLibrary/connect/connectHelper";
15
import {Header} from './openaireLibrary/sharedComponents/navigationBar.component';
16

    
17
declare var UIkit: any;
18

    
19
@Component({
20
  selector: 'app',
21
  templateUrl: './app.component.html',
22
})
23

    
24
export class AppComponent implements OnInit {
25
  title = 'Metadata Registry Service';
26
  userMenuItems: MenuItem[] = [];
27

    
28
  menuItems: RootMenuItem [] = [];
29
  sideMenuItems: SideMenuItem[] = [];
30
  logInUrl = null;
31
  logOutUrl = null;
32
  community: { id: string, name: string, logoUrl: string } = null;
33
  communityId = '';
34
  communityType = null;
35
  properties: EnvProperties = null;
36
  isPortalAdministrator = false;
37
  showSidebar: boolean;
38
  wellcome = false;
39
  showMenu: boolean = false;
40
  user: User;
41
  logoPath: string = 'assets/common-assets/';
42
  header: Header;
43

    
44
  constructor(private route: ActivatedRoute,
45
              private propertiesService: EnvironmentSpecificService,
46
              private _communitiesService: CommunitiesService,
47
              public router: Router,
48
              private userManagementService: UserManagementService) {
49
    this.router.events.forEach((event) => {
50
      if (event instanceof NavigationStart) {
51
        HelperFunctions.scroll();
52
        this.wellcome = event.url === '/';
53
      }
54
    });
55
  }
56

    
57
  ngOnInit() {
58
    this.propertiesService.loadEnvironment()
59
      .then(es => {
60
        this.propertiesService.setEnvProperties(es);
61
        this.properties = this.propertiesService.envSpecific;
62
        this.logInUrl = this.properties.loginUrl;
63
        this.logOutUrl = this.properties.logoutUrl;
64
        this.showSidebar = false;
65
        this.showMenu = false;
66
        this.userManagementService.getUserInfo().subscribe(user => {
67
          this.user = user;
68
          if (this.user) {
69
            localStorage.setItem('user_id', this.user.id);
70
            localStorage.setItem('mining_backend_address', this.properties.miningBackendURL);
71
            localStorage.setItem('isCommunityManager', Session.isCommunityCurator(this.user) + '');
72

    
73
            this.isPortalAdministrator = Session.isPortalAdministrator(this.user);
74
          }
75
          this._communitiesService.updateCommunities(this.properties, this.properties.communityAPI + 'communities');
76
          this.route.queryParams.subscribe(params => {
77
            this.communityId = (params['communityId']) ? params['communityId'] : '';
78
            ConnectHelper.setPortalTypeFromPid(this.communityId);
79

    
80
            this.communityType = null;
81
            this.menuItems = [];
82
            this.userMenuItems = [];
83
            this._communitiesService.getCommunitiesState().subscribe(
84
              communities => {
85
                //  this.community = community;
86
                if (!communities || communities.length === 0) {
87
                  return;
88
                }
89
                this.userMenuItems = [];
90
                let countCommunities = 0;
91
                let index_managerOfCommunity = null;
92
                for (let i = 0; i < communities.length; i++) {
93
                  const com = communities[i];
94
                  if (Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user)) {
95
                    this.userMenuItems.push(new MenuItem('manage' + com.communityId, 'Manage ' + ((com.shortTitle) ? com.shortTitle : com.title), '', '/dashboard', false, [], [], {communityId: com.communityId}));
96
                  } else {
97
                    for (const manager of com.managers) {
98
                      if (this.user && manager == this.user.email) {
99
                        countCommunities++;
100
                        index_managerOfCommunity = i;
101
                        this.userMenuItems.push(new MenuItem('manage' + com.communityId, 'Manage ' + ((com.shortTitle) ? com.shortTitle : com.title), '', '/dashboard', false, [], [], {communityId: com.communityId}));
102
                        break;
103
                      }
104
                    }
105
                  }
106
                  if (com.communityId === this.communityId) {
107
                    this.community = {
108
                      id: com.communityId,
109
                      name: (com.shortTitle) ? com.shortTitle : com.title,
110
                      logoUrl: com.logoUrl
111
                    };
112
                    this.header = {
113
                      url: 'https://' + (this.properties.environment == 'beta' ? 'beta.' : '') + this.community.id + '.openaire.eu',
114
                      title: this.community.name,
115
                      logoUrl: this.community.logoUrl,
116
                      logoSmallUrl: this.community.logoUrl,
117
                      position: 'left',
118
                      badge: true
119
                    };
120
                    this.communityType = com.type;
121
                    this.menuItems = [
122
                      {
123
                        rootItem: new MenuItem('dashboard', 'Overview', '/dashboard', '/dashboard', false, [], null, {communityId: com.communityId}),
124
                        items: []
125
                      }
126
                    ];
127
                  } else if (countCommunities === 1 && index_managerOfCommunity != null) {
128
                    this.community = {
129
                      id: communities[index_managerOfCommunity].communityId,
130
                      name: (communities[index_managerOfCommunity].shortTitle) ? communities[index_managerOfCommunity].shortTitle : com.title,
131
                      logoUrl: communities[index_managerOfCommunity].logoUrl
132
                    };
133
                    this.header = {
134
                      url: 'https://' + (this.properties.environment == 'beta' ? 'beta.' : '') + this.community.id + '.openaire.eu',
135
                      title: this.community.name,
136
                      logoUrl: this.community.logoUrl,
137
                      logoSmallUrl: this.community.logoUrl,
138
                      position: 'left',
139
                      badge: true
140
                    };
141
                    this.menuItems = [
142
                      {
143
                        rootItem: new MenuItem('dashboard', 'Overview', '/dashboard', '/dashboard', false, [], null, {communityId: communities[index_managerOfCommunity].communityId}),
144
                        items: []
145
                      }
146
                    ];
147
                  }
148
                }
149
                if (!this.communityId || this.communityId === '') {
150
                  this.header = {
151
                    route: "/",
152
                    url: null,
153
                    title: 'connect-admin',
154
                    logoUrl: this.logoPath + 'logo-large-connect.png',
155
                    logoSmallUrl:this.logoPath + 'logo-small-connect.png',
156
                    position:'left',
157
                    badge:true
158
                  };
159
                  this.community = null;
160
                }
161
                if (this.communityId) {
162
                  this.userMenuItems.push(new MenuItem('manage-user-notifications', 'Manage notification settings', '', '/manage-user-notifications', false, [], [], {communityId: this.communityId}));
163
                  this.userMenuItems.push(new MenuItem('personal', 'Manage Personal Info', '', '/personal', false, [], [], {communityId: this.communityId}));
164
                  this.userMenuItems.push(new MenuItem('', 'Support', 'https://openaire-connect.d4science.org/group/openaire-connect-gateway/explore?siteId=172366611', '', false, [], [], {}));
165
                }
166
                this.showMenu = true;
167
                this.buildSideBar();
168
              },
169
              error => {
170
                if ((this.communityId && this.communityId !== '') || window.location.pathname === '/') {
171
                  UIkit.notification({
172
                    message: '<strong>System error retrieving communities.<strong>',
173
                    status: 'warning',
174
                    timeout: 3000,
175
                    pos: 'top-center'
176
                  });
177
                }
178
              }
179
            );
180
          });
181
        });
182
      });
183
  }
184

    
185
  private buildSideBar() {
186
    this.sideMenuItems = [];
187
    this.showSidebar = false;
188
    if ((!this.communityId || this.communityId == '') && this.isPortalAdministrator) {
189
      const adminTools: SideMenuItem = {
190
        rootItem: new MenuItem('adminTools', 'Admin Tools', '',
191
          '', false, [], [], null),
192
        items: [],
193
        ukIcon: 'desktop'
194
      };
195
      adminTools.items.push({
196
          rootItem: new MenuItem('communities', 'Communities', '/communities',
197
            '/communities', false, [], [], null),
198
          items: []
199
        }
200
      );
201
      adminTools.items.push({
202
          rootItem: new MenuItem('classes', 'Classes', '/classes',
203
            '/classes', false, [], [], null),
204
          items: []
205
        }
206
      );
207
      adminTools.items.push({
208
          rootItem: new MenuItem('pages', 'Pages', '/pages',
209
            '/pages', false, [], [], null),
210
          items: []
211
        }
212
      );
213
      adminTools.items.push({
214
          rootItem: new MenuItem('entities', 'Entities', '/entities',
215
            '/entities', false, [], [], null),
216
          items: []
217
        }
218
      );
219
      this.sideMenuItems.push(adminTools);
220
      this.sideMenuItems.push({
221
        rootItem: new MenuItem('communities', 'Manage Communities', '/',
222
          '/', false, [], [], null),
223
        items: [],
224
        ukIcon: 'cog'
225
      });
226
      this.sideMenuItems.push({
227
        rootItem: new MenuItem('communities', 'Explore', '',
228
          '/dashboard', false, [], [], {communityId: 'openaire'}),
229
        items: [],
230
        ukIcon: 'cog'
231
      });
232
      this.sideMenuItems.push({
233
        rootItem: new MenuItem('communities', 'Connect', '',
234
          '/dashboard', false, [], [], {communityId: 'connect'}),
235
        items: [],
236
        ukIcon: 'cog'
237
      });
238
    } else if (this.communityId && this.communityId !== '') {
239
      this.sideMenuItems.push({
240
        rootItem: new MenuItem('overview', 'Overview', '/dashboard',
241
          '/dashboard', false, [], [], {communityId: this.communityId}),
242
        items: [],
243
        ukIcon: 'home'
244
      });
245
      if (this.isPortalAdministrator) {
246
        const adminTools: SideMenuItem = {
247
          rootItem: new MenuItem('adminTools', 'Admin Tools', '/communities',
248
            '/communities', false, [], [], null),
249
          items: [],
250
          ukIcon: 'desktop'
251
        };
252
        this.sideMenuItems.push(adminTools);
253
      }
254
      if (this.communityId !== 'openaire' && this.communityId !== 'connect') {
255
        const community: SideMenuItem = {
256
          rootItem: new MenuItem('community', 'Community', '',
257
            '', false, [], [], null),
258
          items: [],
259
          ukIcon: 'album'
260
        };
261
        community.items.push({
262
          rootItem: new MenuItem('communityProfile', 'Community Profile', '/community-edit-form',
263
            '/community-edit-form', false, [], [], {communityId: this.communityId}),
264
          items: []
265
        });
266
        community.items.push({
267
          rootItem: new MenuItem('communityAffiliations', 'Organizations', '/organizations',
268
            '/organizations', false, [], [], {communityId: this.communityId}),
269
          items: []
270
        });
271
        /*community.items.push({
272
          rootItem: new MenuItem('layout', 'Customize Layout', '/customize-layout',
273
            '/customize-layout', false, [], [], {communityId: this.communityId}),
274
          items: []
275
        });*/
276
        this.sideMenuItems.push(community);
277
        const communityContent: SideMenuItem = {
278
          rootItem: new MenuItem('communityContent', 'Community Content', '',
279
            '', false, [], [], null),
280
          items: [],
281
          ukIcon: 'list'
282
        };
283
        communityContent.items.push({
284
            rootItem: new MenuItem('projects', 'Projects', '/manage-projects',
285
              '/manage-projects', false, [], [], {communityId: this.communityId}),
286
            items: []
287
          }
288
        );
289
        communityContent.items.push({
290
          rootItem: new MenuItem('contentProviders', 'Content providers', '/manage-content-providers',
291
            '/manage-content-providers', false, [], [], {communityId: this.communityId}),
292
          items: []
293
        });
294
        if (this.communityType && this.communityType != 'ri') {
295
          communityContent.items.push({
296
            rootItem: new MenuItem('subjects', 'Subjects', '/manage-subjects',
297
              '/manage-subjects', false, [], [], {communityId: this.communityId}),
298
            items: []
299
          });
300
        }
301
        communityContent.items.push({
302
          rootItem: new MenuItem('zenodoCommunities', 'Zenodo communities', '/manage-zenodo-communities',
303
            '/manage-zenodo-communities', false, [], [], {communityId: this.communityId}),
304
          items: []
305
        });
306
        this.sideMenuItems.push(communityContent);
307
      }
308
      const entities: SideMenuItem = {
309
        rootItem: new MenuItem('entitiesPages', 'Entities & pages', '',
310
          '', false, [], [], null),
311
        items: [],
312
        ukIcon: 'world'
313
      };
314
      entities.items.push({
315
        rootItem: new MenuItem('entities', 'Activate Entities', '/entities',
316
          '/entities', false, [], [], {communityId: this.communityId}),
317
        items: []
318
      });
319
      const pages: MenuItem[] = [];
320
      pages.push(new MenuItem('search', 'Search', '/pages',
321
        '/pages', false, [], [], {communityId: this.communityId, type: 'search'}));
322
      pages.push(new MenuItem('link', 'Link', '/pages',
323
        '/pages', false, [], [], {communityId: this.communityId, type: 'link'}));
324
      pages.push(new MenuItem('share', 'Share', '/pages',
325
        '/pages', false, [], [], {communityId: this.communityId, type: 'share'}));
326
      pages.push(new MenuItem('landing', 'Landing', '/pages',
327
        '/pages', false, [], [], {communityId: this.communityId, type: 'landing'}));
328
      // pages.push(new MenuItem('html', 'HTML', '/pages',
329
      //   '/pages', false, [], [], {communityId: this.communityId, type: 'html'}));
330
      pages.push(new MenuItem('other', 'Other', '/pages',
331
        '/pages', false, [], [], {communityId: this.communityId, type: 'other'}));
332
      entities.items.push({
333
        rootItem: new MenuItem('pages', 'Pages', '/pages',
334
          '/pages', false, [], [], {communityId: this.communityId}),
335
        items: pages
336
      });
337
      this.sideMenuItems.push(entities);
338
      const help: SideMenuItem = {
339
        rootItem: new MenuItem('help', 'Help Texts', '',
340
          '', false, [], [], null),
341
        items: [],
342
        ukIcon: 'file-edit'
343
      };
344
      help.items.push({
345
        rootItem: new MenuItem('pages', 'Page Help Texts', '/pageContents',
346
          '/pageContents', false, [], [], {communityId: this.communityId}),
347
        items: []
348
      });
349
      if (this.communityId === 'openaire' || this.communityId === 'connect') {
350
        help.items.push({
351
          rootItem: new MenuItem('classes', 'Class Help Texts', '/classContents',
352
            '/classContents', false, [], [], {communityId: this.communityId}),
353
          items: []
354
        });
355
      }
356
      this.sideMenuItems.push(help);
357
      if (this.communityId !== 'openaire' && this.communityId !== 'connect') {
358
        const stats: SideMenuItem = {
359
          rootItem: new MenuItem('stats', 'Statistics & Charts', '/stats',
360
            '/stats', false, [], [], {communityId: this.communityId}),
361
          items: [],
362
          ukIcon: 'image'
363
        };
364
        this.sideMenuItems.push(stats);
365
        const claims: SideMenuItem = {
366
          rootItem: new MenuItem('claims', 'Links', '/claims',
367
            '/claims', false, [], [], {communityId: this.communityId}),
368
          items: [],
369
          ukIcon: 'link'
370
        };
371
        this.sideMenuItems.push(claims);
372
        if (this.communityType && this.communityType === 'ri') {
373
          const mining: SideMenuItem = {
374
            rootItem: new MenuItem('mining', 'Text Mining Rules', '/mining/manage-profiles',
375
              '/mining/manage-profiles', false, [], [], {communityId: this.communityId}),
376
            items: [],
377
            ukIcon: 'settings'
378
          };
379
          this.sideMenuItems.push(mining);
380
        }
381
        const users: SideMenuItem = {
382
          rootItem: new MenuItem('users', 'Users', '',
383
            '', false, [], [], null),
384
          items: [],
385
          ukIcon: 'user'
386
        };
387
        users.items.push({
388
          rootItem: new MenuItem('invite', 'Invite to Subscribe', 'https://beta.' + this.communityId + '.openaire.eu/invite',
389
            '', false, [], [], null),
390
          items: []
391
        });
392
        users.items.push({
393
          rootItem: new MenuItem('subscribers', 'Subscribers', '/manage-subscribers',
394
            '/manage-subscribers', false, [], [], {communityId: this.communityId}),
395
          items: []
396
        });
397
        users.items.push({
398
          rootItem: new MenuItem('personalInfo', 'Personal Info', '/personal',
399
            '/personal', false, [], [], {communityId: this.communityId}),
400
          items: []
401
        });
402
        users.items.push({
403
          rootItem: new MenuItem('notifications', 'Notification settings', '/manage-user-notifications',
404
            '/manage-user-notifications', false, [], [], {communityId: this.communityId}),
405
          items: []
406
        });
407
        this.sideMenuItems.push(users);
408
      }
409
    }
410
    if (this.sideMenuItems.length > 0) {
411
      this.showSidebar = true;
412
    }
413
  }
414
}
(4-4/8)