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

    
15
declare var UIkit: any;
16

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

    
22
export class AppComponent implements OnInit {
23
  title = 'Metadata Registry Service';
24
  userMenuItems: MenuItem[] = [];
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 = false;
35
  showSidebar: boolean;
36
  wellcome = false;
37
  showMenu: boolean = false;
38
  user: User;
39

    
40
  constructor(private route: ActivatedRoute,
41
              private propertiesService: EnvironmentSpecificService,
42
              private _communitiesService: CommunitiesService,
43
              public router: Router,
44
              private userManagementService: UserManagementService) {
45
    this.router.events.forEach((event) => {
46
      if (event instanceof NavigationStart) {
47
        HelperFunctions.scroll();
48
        if (event.url === '/') {
49
          this.wellcome = true;
50
        } else {
51
          this.wellcome = false;
52
        }
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

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

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