[Trunk|Admin]: Use RoutesRecognized event to read query params.

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-admin-portal/trunk@56396 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2019-07-08 12:20:39 +00:00
parent 63a8efe503
commit 2621817e70
2 changed files with 84 additions and 80 deletions

View File

@ -1,4 +1,4 @@
<navbar *ngIf= "properties" portal="connect-admin" logoPath="assets/imgs/" [onlyTop]=false [userMenu]=true
<navbar *ngIf= "properties && showMenu" portal="connect-admin" logoPath="assets/imgs/" [onlyTop]=false [userMenu]=true
[homeurl] = false [userMenuItems]=userMenuItems [menuItems]=menuItems [properties]=properties
[community]=community class="adminMenu"></navbar>

View File

@ -4,7 +4,7 @@
import {Component, OnInit} from '@angular/core';
import {MenuItem, RootMenuItem, SideMenuItem} from './openaireLibrary/sharedComponents/menu';
import {ActivatedRoute, NavigationStart, Router} from '@angular/router';
import {ActivatedRoute, NavigationStart, Router, RoutesRecognized} 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';
@ -33,21 +33,12 @@ export class AppComponent implements OnInit{
isPortalAdministrator = false;
showSidebar: boolean;
wellcome = false;
showMenu:boolean = false;
constructor(private route: ActivatedRoute,
private propertiesService: EnvironmentSpecificService,
private _communitiesService: CommunitiesService,
private router: Router) {
router.events.forEach((event) => {
if (event instanceof NavigationStart) {
HelperFunctions.scroll();
if(event.url === '/') {
this.wellcome = true;
} else {
this.wellcome = false;
}
}
});
}
ngOnInit() {
@ -58,6 +49,7 @@ export class AppComponent implements OnInit{
this.logInUrl = this.properties.loginUrl;
this.logOutUrl = this.properties.logoutUrl;
this.showSidebar = false;
this.showMenu = false;
if (Session.getUser()) {
localStorage.setItem('user_id', Session.getUser().id);
localStorage.setItem('mining_backend_address', this.properties.miningBackendURL);
@ -66,80 +58,92 @@ export class AppComponent implements OnInit{
this.isPortalAdministrator = Session.isPortalAdministrator();
}
this._communitiesService.updateCommunities(this.properties, this.properties.communityAPI + 'communities');
this.router.events.forEach((event) => {
if(event instanceof RoutesRecognized) {
HelperFunctions.scroll();
if(event.url === '/') {
this.wellcome = true;
} else {
this.wellcome = false;
}
this.communityId = (event.state.root.firstChild.queryParams['communityId']) ? event.state.root.firstChild.queryParams['communityId'] : '';
this.route.queryParams.subscribe(data => {
this.communityId = ((data['communityId']) ? data['communityId'] : '');
this.communityType = null;
this.menuItems = [];
this.userMenuItems = [];
this._communitiesService.getCommunitiesState().subscribe(
communities => {
// this.community = community;
this.userMenuItems = [];
let countCommunities = 0;
let index_managerOfCommunity = null;
for (let i = 0; i < communities.length; i++) {
const com = communities[i];
if (Session.isPortalAdministrator() || Session.isCommunityCurator()) {
this.userMenuItems.push(new MenuItem('manage' + com.communityId, 'Manage ' + ((com.shortTitle) ? com.shortTitle : com.title), '', '/dashboard', false, [], [], {communityId: com.communityId}));
} else {
for (const 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;
this.communityType = null;
this.menuItems = [];
this.userMenuItems = [];
this._communitiesService.getCommunitiesState().subscribe(
communities => {
// this.community = community;
if(!communities || communities.length === 0) {
return;
}
this.userMenuItems = [];
let countCommunities = 0;
let index_managerOfCommunity = null;
for (let i = 0; i < communities.length; i++) {
const com = communities[i];
if (Session.isPortalAdministrator() || Session.isCommunityCurator()) {
this.userMenuItems.push(new MenuItem('manage' + com.communityId, 'Manage ' + ((com.shortTitle) ? com.shortTitle : com.title), '', '/dashboard', false, [], [], {communityId: com.communityId}));
} else {
for (const 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', 'Overview', '/dashboard', '/dashboard', false, [], null, {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', 'Overview', '/dashboard', '/dashboard', false, [], null, {communityId: communities[index_managerOfCommunity].communityId}),
items: []
}
];
}
}
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', 'Overview', '/dashboard', '/dashboard', false, [], null, {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', 'Overview', '/dashboard', '/dashboard', false, [], null, {communityId: communities[index_managerOfCommunity].communityId}),
items: []
}
];
if (!this.communityId || this.communityId === '') {
this.community = null;
}
if (this.communityId) {
this.userMenuItems.push(new MenuItem('manage-user-notifications', 'Manage notification settings', '', '/manage-user-notifications', false, [], [], {communityId: this.communityId}));
this.userMenuItems.push(new MenuItem('personal', 'Manage Personal Info', '', '/personal', false, [], [], {communityId: this.communityId}));
this.userMenuItems.push(new MenuItem("","Support","https://openaire-connect.d4science.org/group/openaire-connect-gateway/explore?siteId=172366611","",false,[],[],{}))
}
this.showMenu = true;
this.buildSideBar();
},
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'
});
}
}
if (!this.communityId || this.communityId === '') {
this.community = null;
}
if (this.communityId) {
this.userMenuItems.push(new MenuItem('manage-user-notifications', 'Manage notification settings', '', '/manage-user-notifications', false, [], [], {communityId: this.communityId}));
this.userMenuItems.push(new MenuItem('personal', 'Manage Personal Info', '', '/personal', false, [], [], {communityId: this.communityId}));
this.userMenuItems.push(new MenuItem("","Support","https://openaire-connect.d4science.org/group/openaire-connect-gateway/explore?siteId=172366611","",false,[],[],{}))
}
this.buildSideBar();
},
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'
});
}
}
);
);
}
});
});
}