Project

General

Profile

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

    
5
import { Component } from '@angular/core';
6
import{MenuItem, RootMenuItem} from './openaireLibrary/sharedComponents/menu';
7
import {ActivatedRoute} 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

    
13
@Component({
14
  selector: 'app',
15
  templateUrl: './app.component.html',
16
})
17

    
18
export class AppComponent {
19
  title = 'Metadata Registry Service';
20
  isClient:boolean = false;
21

    
22

    
23
   userMenuItems:MenuItem[] =  [];
24

    
25
   menuItems:RootMenuItem [] = [];
26

    
27
logInUrl = null;
28
logOutUrl = null;
29
community: {id:string, name:string, logoUrl:string} = null;
30
communityId="";
31
properties:EnvProperties = null;
32
isPortalAdministrator:boolean = false;
33
constructor(  private  route: ActivatedRoute, private propertiesService:EnvironmentSpecificService, private _communitiesService:CommunitiesService) {
34

    
35
}
36

    
37
   ngOnInit() {
38
     this.propertiesService.loadEnvironment()
39
             .then(es => {
40
                 this.propertiesService.setEnvProperties(es);
41
                 this.properties = this.propertiesService.envSpecific;
42
                 this.logInUrl = this.properties.loginUrl;
43
                 this.logOutUrl = this.properties.logoutUrl;
44
                 if( Session.getUser()){
45
                   localStorage.setItem('user_id', Session.getUser().id);
46
                   localStorage.setItem('mining_backend_address', this.properties.miningBackendURL);
47
                   this.isPortalAdministrator = Session.isPortalAdministrator();
48
                 }
49
                 this.route.queryParams.subscribe(data => {
50
                   this.communityId = ((data['communityId'])?data['communityId']:"");
51
                   this.menuItems = [];
52
                   this.userMenuItems = [];
53
                   this._communitiesService.getCommunities(this.properties.communityAPI+"communities").subscribe (
54
                     communities => {
55
                          //  this.community = community;
56

    
57
                           this.userMenuItems =[];
58
                            for(var com of communities){
59
                              if(Session.isPortalAdministrator()){
60
                                this.userMenuItems.push(new MenuItem("manage"+com.communityId,"Manage "+((com.shortTitle)?com.shortTitle:com.title),"","dashboard",false,[],[],{communityId: com.communityId}));
61
                              }else{
62
                                for(var manager of com.managers){
63
                                    if(manager== Session.getUserEmail()){
64
                                       this.userMenuItems.push(new MenuItem("manage"+com.communityId,"Manage "+((com.shortTitle)?com.shortTitle:com.title),"","dashboard",false,[],[],{communityId: com.communityId}));
65
                                    }
66
                                }
67
                              }
68
                              if(com.communityId == this.communityId){
69
                                this.community = {id: com.communityId, name: (com.shortTitle)?com.shortTitle:com.title, logoUrl:com.logoUrl};
70
                                this.menuItems= [
71
                                  {rootItem: new MenuItem("dashboard","Administration Dashboard","/dashboard","/dashboard",false,[],[],{communityId:com.communityId}),
72
                                  items: []
73
                                  }
74
                              ];
75
                               }
76
                            }
77
                     });
78
                  });
79
              });
80

    
81

    
82
  }
83
}
(4-4/10)