Project

General

Profile

1 49060 argiro.kok
/**
2
 * Created by stefania on 3/21/16.
3
 */
4
5
import { Component } from '@angular/core';
6 50764 argiro.kok
import{MenuItem, RootMenuItem} from './openaireLibrary/sharedComponents/menu';
7 50682 argiro.kok
import {ActivatedRoute} from '@angular/router';
8 51223 argiro.kok
import { EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';
9 51305 argiro.kok
import {CommunitiesService} from "./openaireLibrary/connect/communities/communities.service";
10 51223 argiro.kok
import { EnvProperties} from './openaireLibrary/utils/properties/env-properties';
11 51305 argiro.kok
import {Session} from './openaireLibrary/login/utils/helper.class';
12 50682 argiro.kok
13 51853 konstantin
declare var UIkit: any;
14
15 49060 argiro.kok
@Component({
16 51074 argiro.kok
  selector: 'app',
17 49060 argiro.kok
  templateUrl: './app.component.html',
18
})
19
20
export class AppComponent {
21
  title = 'Metadata Registry Service';
22 50287 argiro.kok
  isClient:boolean = false;
23
24
25 51305 argiro.kok
   userMenuItems:MenuItem[] =  [];
26 50608 argiro.kok
27
   menuItems:RootMenuItem [] = [];
28
29
logInUrl = null;
30
logOutUrl = null;
31 51223 argiro.kok
community: {id:string, name:string, logoUrl:string} = null;
32 51305 argiro.kok
communityId="";
33 52015 argiro.kok
communityType=null;
34 51223 argiro.kok
properties:EnvProperties = null;
35 51454 argiro.kok
isPortalAdministrator:boolean = false;
36
constructor(  private  route: ActivatedRoute, private propertiesService:EnvironmentSpecificService, private _communitiesService:CommunitiesService) {
37 50287 argiro.kok
38 51454 argiro.kok
}
39
40 50287 argiro.kok
   ngOnInit() {
41 51223 argiro.kok
     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 51454 argiro.kok
                 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 52070 argiro.kok
                 this.route.queryParams.subscribe(data => {
53 51305 argiro.kok
                   this.communityId = ((data['communityId'])?data['communityId']:"");
54 52015 argiro.kok
                   this.communityType = null;
55 51305 argiro.kok
                   this.menuItems = [];
56
                   this.userMenuItems = [];
57 51669 konstantin
                   this._communitiesService.getCommunities(this.properties, this.properties.communityAPI+"communities").subscribe (
58 51305 argiro.kok
                     communities => {
59
                          //  this.community = community;
60 50682 argiro.kok
61 51454 argiro.kok
                           this.userMenuItems =[];
62 51971 argiro.kok
                           var countCommunities = 0;
63
                           var index_managerOfCommunity = null;
64
                            for(var i = 0;i <communities.length; i++){
65
                              var com = communities[i];
66 51305 argiro.kok
                              if(Session.isPortalAdministrator()){
67 51568 argiro.kok
                                this.userMenuItems.push(new MenuItem("manage"+com.communityId,"Manage "+((com.shortTitle)?com.shortTitle:com.title),"","/dashboard",false,[],[],{communityId: com.communityId}));
68 51305 argiro.kok
                              }else{
69
                                for(var manager of com.managers){
70
                                    if(manager== Session.getUserEmail()){
71 51971 argiro.kok
                                      countCommunities++;
72
                                      index_managerOfCommunity = i;
73 51568 argiro.kok
                                       this.userMenuItems.push(new MenuItem("manage"+com.communityId,"Manage "+((com.shortTitle)?com.shortTitle:com.title),"","/dashboard",false,[],[],{communityId: com.communityId}));
74 52015 argiro.kok
                                       break;
75 51305 argiro.kok
                                    }
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 52015 argiro.kok
                                this.communityType = com.type;
81 51305 argiro.kok
                                this.menuItems= [
82
                                  {rootItem: new MenuItem("dashboard","Administration Dashboard","/dashboard","/dashboard",false,[],[],{communityId:com.communityId}),
83
                                  items: []
84
                                  }
85
                              ];
86 51971 argiro.kok
                            }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 51305 argiro.kok
                            }
94 51971 argiro.kok
                           }
95 52015 argiro.kok
96 51853 konstantin
                     },
97
                     error => {
98 52070 argiro.kok
                       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 51853 konstantin
                     }
107
                   );
108 51305 argiro.kok
                  });
109
              });
110 50682 argiro.kok
111
112 51305 argiro.kok
  }
113 49060 argiro.kok
}