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

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

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

    
111

    
112
  }
113
}
(4-4/10)