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
declare var UIkit: any;
14

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

    
20
export class AppComponent {
21
  title = 'Metadata Registry Service';
22
  //isClient:boolean = false;
23

    
24

    
25
   userMenuItems:MenuItem[] =  [];
26

    
27
   menuItems:RootMenuItem [] = [];
28

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

    
38
}
39

    
40
   ngOnInit() {
41
     this.propertiesService.loadEnvironment()
42
             .then(es => {
43
                 this.propertiesService.setEnvProperties(es);
44
                 this.properties = this.propertiesService.envSpecific;
45
                 this.logInUrl = this.properties.loginUrl;
46
                 this.logOutUrl = this.properties.logoutUrl;
47
                 if( Session.getUser()){
48
                   localStorage.setItem('user_id', Session.getUser().id);
49
                   localStorage.setItem('mining_backend_address', this.properties.miningBackendURL);
50
                   localStorage.setItem('isCommunityManager', Session.isCommunityCurator()+"");
51

    
52
                   this.isPortalAdministrator = Session.isPortalAdministrator();
53
                 }
54
                 this.route.queryParams.subscribe(data => {
55
                   this.communityId = ((data['communityId'])?data['communityId']:"");
56
                   this.communityType = null;
57
                   this.menuItems = [];
58
                   this.userMenuItems = [];
59
                   this._communitiesService.getCommunities(this.properties, this.properties.communityAPI+"communities").subscribe (
60
                     communities => {
61
                          //  this.community = community;
62

    
63
                           this.userMenuItems =[];
64
                           var countCommunities = 0;
65
                           var index_managerOfCommunity = null;
66
                            for(var i = 0;i <communities.length; i++){
67
                              var com = communities[i];
68
                              if(Session.isPortalAdministrator()){
69
                                this.userMenuItems.push(new MenuItem("manage"+com.communityId,"Manage "+((com.shortTitle)?com.shortTitle:com.title),"","/dashboard",false,[],[],{communityId: com.communityId}));
70
                              }else{
71
                                for(var manager of com.managers){
72
                                    if(manager== Session.getUserEmail()){
73
                                      countCommunities++;
74
                                      index_managerOfCommunity = i;
75
                                       this.userMenuItems.push(new MenuItem("manage"+com.communityId,"Manage "+((com.shortTitle)?com.shortTitle:com.title),"","/dashboard",false,[],[],{communityId: com.communityId}));
76
                                       break;
77
                                    }
78
                                }
79
                              }
80
                              if(com.communityId == this.communityId){
81
                                this.community = {id: com.communityId, name: (com.shortTitle)?com.shortTitle:com.title, logoUrl:com.logoUrl};
82
                                this.communityType = com.type;
83
                                this.menuItems= [
84
                                  {rootItem: new MenuItem("dashboard","Overview","/dashboard","/dashboard",false,[],[],{communityId:com.communityId}),
85
                                  items: []
86
                                  }
87
                              ];
88
                            }else if(countCommunities == 1 &&index_managerOfCommunity!=null ){
89
                              this.community = {id: communities[index_managerOfCommunity].communityId, name: (communities[index_managerOfCommunity].shortTitle)?communities[index_managerOfCommunity].shortTitle:com.title, logoUrl:communities[index_managerOfCommunity].logoUrl};
90
                              this.menuItems= [
91
                                {rootItem: new MenuItem("dashboard","Administration Dashboard","/dashboard","/dashboard",false,[],[],{communityId:communities[index_managerOfCommunity].communityId}),
92
                                items: []
93
                                }
94
                              ];
95
                            }
96
                           }
97
                           if(this.communityId){
98
                              this.userMenuItems.push(new MenuItem("manage-user-notifications","Manage notification settings","","/manage-user-notifications",false,[],[],{communityId: this.communityId}));
99
                           }
100

    
101

    
102
                     },
103
                     error => {
104
                       if( ( this.communityId && this.communityId != "") || window.location.pathname == "/"){
105
                         UIkit.notification({
106
                             message : '<strong>System error retrieving communities.<strong>',
107
                             status  : 'warning',
108
                             timeout : 3000,
109
                             pos     : 'top-center'
110
                          })
111
                       }
112
                     }
113
                   );
114
                  });
115
              });
116

    
117

    
118
  }
119
}
(4-4/10)