116 lines
5.6 KiB
TypeScript
116 lines
5.6 KiB
TypeScript
/**
|
|
* Created by stefania on 3/21/16.
|
|
*/
|
|
|
|
import { Component } from '@angular/core';
|
|
import{MenuItem, RootMenuItem} from './openaireLibrary/sharedComponents/menu';
|
|
import {ActivatedRoute} from '@angular/router';
|
|
import { EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';
|
|
import {CommunitiesService} from "./openaireLibrary/connect/communities/communities.service";
|
|
import { EnvProperties} from './openaireLibrary/utils/properties/env-properties';
|
|
import {Session} from './openaireLibrary/login/utils/helper.class';
|
|
|
|
declare var UIkit: any;
|
|
|
|
@Component({
|
|
selector: 'app',
|
|
templateUrl: './app.component.html',
|
|
})
|
|
|
|
export class AppComponent {
|
|
title = 'Metadata Registry Service';
|
|
isClient:boolean = false;
|
|
|
|
|
|
userMenuItems:MenuItem[] = [];
|
|
|
|
menuItems:RootMenuItem [] = [];
|
|
|
|
logInUrl = null;
|
|
logOutUrl = null;
|
|
community: {id:string, name:string, logoUrl:string} = null;
|
|
communityId="";
|
|
communityType=null;
|
|
properties:EnvProperties = null;
|
|
isPortalAdministrator:boolean = false;
|
|
constructor( private route: ActivatedRoute, private propertiesService:EnvironmentSpecificService, private _communitiesService:CommunitiesService) {
|
|
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.propertiesService.loadEnvironment()
|
|
.then(es => {
|
|
this.propertiesService.setEnvProperties(es);
|
|
this.properties = this.propertiesService.envSpecific;
|
|
this.logInUrl = this.properties.loginUrl;
|
|
this.logOutUrl = this.properties.logoutUrl;
|
|
if( Session.getUser()){
|
|
localStorage.setItem('user_id', Session.getUser().id);
|
|
localStorage.setItem('mining_backend_address', this.properties.miningBackendURL);
|
|
localStorage.setItem('isCommunityManager', Session.isCommunityCurator()+"");
|
|
|
|
this.isPortalAdministrator = Session.isPortalAdministrator();
|
|
}
|
|
this.route.queryParams.subscribe(data => {
|
|
this.communityId = ((data['communityId'])?data['communityId']:"");
|
|
this.communityType = null;
|
|
this.menuItems = [];
|
|
this.userMenuItems = [];
|
|
this._communitiesService.getCommunities(this.properties, this.properties.communityAPI+"communities").subscribe (
|
|
communities => {
|
|
// this.community = community;
|
|
|
|
this.userMenuItems =[];
|
|
var countCommunities = 0;
|
|
var index_managerOfCommunity = null;
|
|
for(var i = 0;i <communities.length; i++){
|
|
var com = communities[i];
|
|
if(Session.isPortalAdministrator()){
|
|
this.userMenuItems.push(new MenuItem("manage"+com.communityId,"Manage "+((com.shortTitle)?com.shortTitle:com.title),"","/dashboard",false,[],[],{communityId: com.communityId}));
|
|
}else{
|
|
for(var manager of com.managers){
|
|
if(manager== Session.getUserEmail()){
|
|
countCommunities++;
|
|
index_managerOfCommunity = i;
|
|
this.userMenuItems.push(new MenuItem("manage"+com.communityId,"Manage "+((com.shortTitle)?com.shortTitle:com.title),"","/dashboard",false,[],[],{communityId: com.communityId}));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if(com.communityId == this.communityId){
|
|
this.community = {id: com.communityId, name: (com.shortTitle)?com.shortTitle:com.title, logoUrl:com.logoUrl};
|
|
this.communityType = com.type;
|
|
this.menuItems= [
|
|
{rootItem: new MenuItem("dashboard","Administration Dashboard","/dashboard","/dashboard",false,[],[],{communityId:com.communityId}),
|
|
items: []
|
|
}
|
|
];
|
|
}else if(countCommunities == 1 &&index_managerOfCommunity!=null ){
|
|
this.community = {id: communities[index_managerOfCommunity].communityId, name: (communities[index_managerOfCommunity].shortTitle)?communities[index_managerOfCommunity].shortTitle:com.title, logoUrl:communities[index_managerOfCommunity].logoUrl};
|
|
this.menuItems= [
|
|
{rootItem: new MenuItem("dashboard","Administration Dashboard","/dashboard","/dashboard",false,[],[],{communityId:communities[index_managerOfCommunity].communityId}),
|
|
items: []
|
|
}
|
|
];
|
|
}
|
|
}
|
|
|
|
},
|
|
error => {
|
|
if( ( this.communityId && this.communityId != "") || window.location.pathname == "/"){
|
|
UIkit.notification({
|
|
message : '<strong>System error retrieving communities.<strong>',
|
|
status : 'warning',
|
|
timeout : 3000,
|
|
pos : 'top-center'
|
|
})
|
|
}
|
|
}
|
|
);
|
|
});
|
|
});
|
|
|
|
|
|
}
|
|
}
|