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} from './openaireLibrary/login/utils/helper.class';
12
import {HelperFunctions} from './openaireLibrary/utils/HelperFunctions.class';
13

    
14
declare var UIkit: any;
15

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

    
21
export class AppComponent implements OnInit{
22
  title = 'Metadata Registry Service';
23
  userMenuItems: MenuItem[] = [];
24

    
25
  menuItems: RootMenuItem [] = [];
26
  sideMenuItems: SideMenuItem[] = [];
27
  logInUrl = null;
28
  logOutUrl = null;
29
  community: { id: string, name: string, logoUrl: string } = null;
30
  communityId = '';
31
  communityType = null;
32
  properties: EnvProperties = null;
33
  isPortalAdministrator = false;
34
  showSidebar: boolean;
35
  wellcome = false;
36

    
37
  constructor(private  route: ActivatedRoute,
38
              private propertiesService: EnvironmentSpecificService,
39
              private _communitiesService: CommunitiesService,
40
              private router: Router) {
41
    router.events.forEach((event) => {
42
      if (event instanceof NavigationStart) {
43
        HelperFunctions.scroll();
44
        if(event.url === '/') {
45
          this.wellcome = true;
46
        } else {
47
          this.wellcome = false;
48
        }
49
      }
50
    });
51
  }
52

    
53
  ngOnInit() {
54
    this.propertiesService.loadEnvironment()
55
      .then(es => {
56
        this.propertiesService.setEnvProperties(es);
57
        this.properties = this.propertiesService.envSpecific;
58
        this.logInUrl = this.properties.loginUrl;
59
        this.logOutUrl = this.properties.logoutUrl;
60
        this.showSidebar = false;
61
        if (Session.getUser()) {
62
          localStorage.setItem('user_id', Session.getUser().id);
63
          localStorage.setItem('mining_backend_address', this.properties.miningBackendURL);
64
          localStorage.setItem('isCommunityManager', Session.isCommunityCurator() + '');
65

    
66
          this.isPortalAdministrator = Session.isPortalAdministrator();
67
        }
68
        this._communitiesService.updateCommunities(this.properties, this.properties.communityAPI + 'communities');
69

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

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