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

    
36
  constructor(private  route: ActivatedRoute,
37
              private propertiesService: EnvironmentSpecificService,
38
              private _communitiesService: CommunitiesService,
39
              private router: Router) {
40
    router.events.forEach((event) => {
41
      if (event instanceof NavigationStart) {
42
        HelperFunctions.scroll();
43
      }
44
    });
45
  }
46

    
47
  ngOnInit() {
48
    this.propertiesService.loadEnvironment()
49
      .then(es => {
50
        this.propertiesService.setEnvProperties(es);
51
        this.properties = this.propertiesService.envSpecific;
52
        this.logInUrl = this.properties.loginUrl;
53
        this.logOutUrl = this.properties.logoutUrl;
54
        this.showSidebar = false;
55
        if (Session.getUser()) {
56
          localStorage.setItem('user_id', Session.getUser().id);
57
          localStorage.setItem('mining_backend_address', this.properties.miningBackendURL);
58
          localStorage.setItem('isCommunityManager', Session.isCommunityCurator() + '');
59

    
60
          this.isPortalAdministrator = Session.isPortalAdministrator();
61
        }
62
        this._communitiesService.updateCommunities(this.properties, this.properties.communityAPI + 'communities');
63

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

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