[Trunk|Admin]: AppComponent: constructor: add scroll at top base on router events logic

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-admin-portal/trunk@55661 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2019-05-21 14:14:02 +00:00
parent f196153275
commit c168efa0f8
1 changed files with 66 additions and 60 deletions

View File

@ -2,15 +2,14 @@
* Created by stefania on 3/21/16.
*/
import {Component, ViewChild} from '@angular/core';
import {Component, OnInit} from '@angular/core';
import {MenuItem, RootMenuItem, SideMenuItem} from './openaireLibrary/sharedComponents/menu';
import {ActivatedRoute} from '@angular/router';
import {ActivatedRoute, NavigationStart, Router} from '@angular/router';
import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';
import {CommunitiesService} from "./openaireLibrary/connect/communities/communities.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';
import {root} from "rxjs/util/root";
import {SideBarComponent} from "./openaireLibrary/sharedComponents/sidebar/sideBar.component";
import {HelperFunctions} from './openaireLibrary/utils/HelperFunctions.class';
declare var UIkit: any;
@ -19,7 +18,7 @@ declare var UIkit: any;
templateUrl: './app.component.html',
})
export class AppComponent {
export class AppComponent implements OnInit{
title = 'Metadata Registry Service';
userMenuItems: MenuItem[] = [];
@ -28,14 +27,21 @@ export class AppComponent {
logInUrl = null;
logOutUrl = null;
community: { id: string, name: string, logoUrl: string } = null;
communityId = "";
communityId = '';
communityType = null;
properties: EnvProperties = null;
isPortalAdministrator: boolean = false;
isPortalAdministrator = false;
showSidebar: boolean;
constructor(private route: ActivatedRoute, private propertiesService: EnvironmentSpecificService, private _communitiesService: CommunitiesService) {
constructor(private route: ActivatedRoute,
private propertiesService: EnvironmentSpecificService,
private _communitiesService: CommunitiesService,
private router: Router) {
router.events.forEach((event) => {
if (event instanceof NavigationStart) {
HelperFunctions.scroll();
}
});
}
ngOnInit() {
@ -49,15 +55,15 @@ export class AppComponent {
if (Session.getUser()) {
localStorage.setItem('user_id', Session.getUser().id);
localStorage.setItem('mining_backend_address', this.properties.miningBackendURL);
localStorage.setItem('isCommunityManager', Session.isCommunityCurator() + "");
localStorage.setItem('isCommunityManager', Session.isCommunityCurator() + '');
this.isPortalAdministrator = Session.isPortalAdministrator();
/*this.isPortalAdministrator = true;*/
}
this._communitiesService.updateCommunities(this.properties, this.properties.communityAPI + "communities");
this._communitiesService.updateCommunities(this.properties, this.properties.communityAPI + 'communities');
this.route.queryParams.subscribe(data => {
this.communityId = ((data['communityId']) ? data['communityId'] : "");
this.communityId = ((data['communityId']) ? data['communityId'] : '');
this.communityType = null;
this.menuItems = [];
this.userMenuItems = [];
@ -68,20 +74,20 @@ export class AppComponent {
let countCommunities = 0;
let index_managerOfCommunity = null;
for (let i = 0; i < communities.length; i++) {
let com = communities[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}));
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) {
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}));
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) {
if (com.communityId === this.communityId) {
this.community = {
id: com.communityId,
name: (com.shortTitle) ? com.shortTitle : com.title,
@ -90,11 +96,11 @@ export class AppComponent {
this.communityType = com.type;
this.menuItems = [
{
rootItem: new MenuItem("dashboard", "Overview", "/dashboard", "/dashboard", false, [], null, {communityId: com.communityId}),
rootItem: new MenuItem('dashboard', 'Overview', '/dashboard', '/dashboard', false, [], null, {communityId: com.communityId}),
items: []
}
];
} else if (countCommunities == 1 && index_managerOfCommunity != null) {
} 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,
@ -102,28 +108,28 @@ export class AppComponent {
};
this.menuItems = [
{
rootItem: new MenuItem("dashboard", "Overview", "/dashboard", "/dashboard", false, [], null, {communityId: communities[index_managerOfCommunity].communityId}),
rootItem: new MenuItem('dashboard', 'Overview', '/dashboard', '/dashboard', false, [], null, {communityId: communities[index_managerOfCommunity].communityId}),
items: []
}
];
}
}
if (!this.communityId || this.communityId == '') {
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('manage-user-notifications', 'Manage notification settings', '', '/manage-user-notifications', false, [], [], {communityId: this.communityId}));
}
this.buildSideBar();
},
error => {
if ((this.communityId && this.communityId != "") || window.location.pathname == "/") {
if ((this.communityId && this.communityId !== '') || window.location.pathname === '/') {
UIkit.notification({
message: '<strong>System error retrieving communities.<strong>',
status: 'warning',
timeout: 3000,
pos: 'top-center'
})
});
}
}
);
@ -136,7 +142,7 @@ export class AppComponent {
private buildSideBar() {
this.sideMenuItems = [];
if ((!this.communityId || this.communityId == '') && this.isPortalAdministrator) {
let adminTools: SideMenuItem = {
const adminTools: SideMenuItem = {
rootItem: new MenuItem('adminTools', 'Admin Tools', '',
'', false, [], [], null),
items: [],
@ -155,7 +161,7 @@ export class AppComponent {
}
);
this.sideMenuItems.push(adminTools);
} else if (this.communityId && this.communityId != '') {
} else if (this.communityId && this.communityId !== '') {
this.sideMenuItems.push({
rootItem: new MenuItem('overview', 'Overview', '/dashboard',
'/dashboard', false, [], [], {communityId: this.communityId}),
@ -163,7 +169,7 @@ export class AppComponent {
ukIcon: 'home'
});
if (this.isPortalAdministrator) {
let adminTools: SideMenuItem = {
const adminTools: SideMenuItem = {
rootItem: new MenuItem('adminTools', 'Admin Tools', '/communities',
'/communities', false, [], [], null),
items: [],
@ -171,67 +177,67 @@ export class AppComponent {
};
this.sideMenuItems.push(adminTools);
}
if (this.communityId != 'openaire') {
let community: SideMenuItem = {
if (this.communityId !== 'openaire') {
const community: SideMenuItem = {
rootItem: new MenuItem('community', 'Community', '',
'', false, [], [], null),
items: [],
ukIcon: 'album'
}
};
community.items.push({
rootItem: new MenuItem('communityProfile', 'Community Profile', '/community-edit-form',
'/community-edit-form', false, [], [], {communityId: this.communityId}),
items: []
})
});
/*community.items.push({
rootItem: new MenuItem('communityLayout', 'Community Layout', '/community-layout',
'/community-layout', false, [], [], {communityId: this.communityId}),
items: []
})*/
this.sideMenuItems.push(community);
let communityContent: SideMenuItem = {
const communityContent: SideMenuItem = {
rootItem: new MenuItem('communityContent', 'Community Content', '',
'', false, [], [], null),
items: [],
ukIcon: 'list'
}
};
communityContent.items.push({
rootItem: new MenuItem('projects', 'Projects', '/manage-projects',
'/manage-projects', false, [], [], {communityId: this.communityId}),
items: []
}
)
);
communityContent.items.push({
rootItem: new MenuItem('contentProviders', 'Content providers', '/manage-content-providers',
'/manage-content-providers', false, [], [], {communityId: this.communityId}),
items: []
})
});
if (this.communityType && this.communityType != 'ri') {
communityContent.items.push({
rootItem: new MenuItem('subjects', 'Subjects', '/manage-subjects',
'/manage-subjects', false, [], [], {communityId: this.communityId}),
items: []
})
});
}
communityContent.items.push({
rootItem: new MenuItem('zenodoCommunities', 'Zenodo communities', '/manage-zenodo-communities',
'/manage-zenodo-communities', false, [], [], {communityId: this.communityId}),
items: []
})
});
this.sideMenuItems.push(communityContent);
}
let entities: SideMenuItem = {
const entities: SideMenuItem = {
rootItem: new MenuItem('entitiesPages', 'Entities & pages', '',
'', false, [], [], null),
items: [],
ukIcon: 'world'
}
};
entities.items.push({
rootItem: new MenuItem('entities', 'Activate Entities', '/entities',
'/entities', false, [], [], {communityId: this.communityId}),
items: []
})
let pages: MenuItem[] = [];
});
const pages: MenuItem[] = [];
pages.push(new MenuItem('search', 'Search', '/pages',
'/pages', false, [], [], {communityId: this.communityId, type: 'search'}));
pages.push(new MenuItem('link', 'Link', '/pages',
@ -248,70 +254,70 @@ export class AppComponent {
rootItem: new MenuItem('pages', 'Pages', '/pages',
'/pages', false, [], [], {communityId: this.communityId}),
items: pages
})
});
this.sideMenuItems.push(entities);
let help: SideMenuItem = {
const help: SideMenuItem = {
rootItem: new MenuItem('help', 'Help Texts', '',
'', false, [], [], null),
items: [],
ukIcon: 'file-edit'
}
};
help.items.push({
rootItem: new MenuItem('pages', 'Page Help Texts', '/pageContents',
'/pageContents', false, [], [], {communityId: this.communityId}),
items: []
})
});
help.items.push({
rootItem: new MenuItem('classes', 'Class Help Texts', '/classContents',
'/classContents', false, [], [], {communityId: this.communityId}),
items: []
})
});
this.sideMenuItems.push(help);
if (this.communityId != 'openaire') {
let stats: SideMenuItem = {
if (this.communityId !== 'openaire') {
const stats: SideMenuItem = {
rootItem: new MenuItem('stats', 'Statistics & Charts', '/stats',
'/stats', false, [], [], {communityId: this.communityId}),
items: [],
ukIcon: 'image'
}
};
this.sideMenuItems.push(stats);
let claims: SideMenuItem = {
const claims: SideMenuItem = {
rootItem: new MenuItem('claims', 'Links', '/claims',
'/claims', false, [], [], {communityId: this.communityId}),
items: [],
ukIcon: 'link'
}
};
this.sideMenuItems.push(claims);
if (this.communityType && this.communityType == 'ri') {
let mining: SideMenuItem = {
if (this.communityType && this.communityType === 'ri') {
const mining: SideMenuItem = {
rootItem: new MenuItem('mining', 'Text Mining Rules', '/mining/manage-profiles',
'/mining/manage-profiles', false, [], [], {communityId: this.communityId}),
items: [],
ukIcon: 'settings'
}
};
this.sideMenuItems.push(mining);
}
let users: SideMenuItem = {
const users: SideMenuItem = {
rootItem: new MenuItem('users', 'Users', '',
'', false, [], [], null),
items: [],
ukIcon: 'user'
}
};
users.items.push({
rootItem: new MenuItem('subscribers', 'Subscribers', '/manage-subscribers',
'/manage-subscribers', false, [], [], {communityId: this.communityId}),
items: []
})
});
users.items.push({
rootItem: new MenuItem('invite', 'Invite to Subscribe', 'https://beta.' + this.communityId + '.openaire.eu/invite',
'', false, [], [], null),
items: []
})
});
users.items.push({
rootItem: new MenuItem('notifications', 'Notification settings', '/manage-user-notifications',
'/manage-user-notifications', false, [], [], {communityId: this.communityId}),
items: []
})
});
this.sideMenuItems.push(users);
}
}