2021-05-19 13:40:29 +02:00
|
|
|
import {ChangeDetectorRef, Component, HostListener, OnInit} from '@angular/core';
|
|
|
|
import {MenuItem, RootMenuItem} from './openaireLibrary/sharedComponents/menu';
|
2021-07-14 14:04:42 +02:00
|
|
|
import {ActivatedRoute, Data, NavigationEnd, Params, Router} from '@angular/router';
|
2019-04-22 12:43:22 +02:00
|
|
|
import {EnvProperties} from './openaireLibrary/utils/properties/env-properties';
|
2019-09-13 11:39:18 +02:00
|
|
|
import {Session, User} from './openaireLibrary/login/utils/helper.class';
|
|
|
|
import {UserManagementService} from './openaireLibrary/services/user-management.service';
|
2020-10-14 11:54:49 +02:00
|
|
|
import {Header} from './openaireLibrary/sharedComponents/navigationBar.component';
|
2021-05-19 13:40:29 +02:00
|
|
|
import {LayoutService} from "./openaireLibrary/dashboard/sharedComponents/sidebar/layout.service";
|
|
|
|
import {properties} from "../environments/environment";
|
|
|
|
import {BehaviorSubject, Subscriber} from "rxjs";
|
|
|
|
import {CommunityInfo} from "./openaireLibrary/connect/community/communityInfo";
|
|
|
|
import {CommunityService} from "./openaireLibrary/connect/community/community.service";
|
|
|
|
import {arrow_left} from "./openaireLibrary/utils/icons/icons";
|
|
|
|
import {SmoothScroll} from "./openaireLibrary/utils/smooth-scroll";
|
2021-07-14 14:04:42 +02:00
|
|
|
import {ConnectHelper} from './openaireLibrary/connect/connectHelper';
|
|
|
|
import {ConfigurationService} from './openaireLibrary/utils/configuration/configuration.service';
|
2021-11-12 13:22:44 +01:00
|
|
|
import {StringUtils} from "./openaireLibrary/utils/string-utils.class";
|
2018-10-30 16:31:16 +01:00
|
|
|
|
|
|
|
@Component({
|
2021-05-19 13:40:29 +02:00
|
|
|
selector: 'app-root',
|
2018-10-30 16:31:16 +01:00
|
|
|
templateUrl: './app.component.html',
|
|
|
|
})
|
2019-09-13 11:39:18 +02:00
|
|
|
export class AppComponent implements OnInit {
|
2021-05-19 13:40:29 +02:00
|
|
|
title = 'Research Community Dashboard | Administrator';
|
|
|
|
properties: EnvProperties = properties;
|
2019-09-13 11:39:18 +02:00
|
|
|
user: User;
|
2021-05-19 13:40:29 +02:00
|
|
|
params: BehaviorSubject<Params> = new BehaviorSubject<Params>(null);
|
2021-07-14 14:04:42 +02:00
|
|
|
data: BehaviorSubject<Data> = new BehaviorSubject<Data>(null);
|
2021-05-19 13:40:29 +02:00
|
|
|
hasSidebar: boolean = false;
|
|
|
|
hasHeader: boolean = false;
|
|
|
|
hasAdminMenu: boolean = false;
|
|
|
|
isFrontPage: boolean = false;
|
|
|
|
isDashboard: boolean = false;
|
|
|
|
sideBarItems: MenuItem[] = [];
|
|
|
|
specialSideBarMenuItem: MenuItem = null;
|
|
|
|
menuItems: RootMenuItem[] = [];
|
|
|
|
menuHeader: Header = {
|
|
|
|
route: "/",
|
|
|
|
url: null,
|
|
|
|
title: "Default menu header",
|
|
|
|
logoUrl: null,
|
|
|
|
logoSmallUrl: null,
|
|
|
|
position: 'center',
|
|
|
|
badge: false,
|
|
|
|
stickyAnimation: false
|
|
|
|
};
|
|
|
|
userMenuItems: MenuItem[] = [];
|
|
|
|
loading: boolean = true;
|
|
|
|
paramsResolved: boolean = false;
|
|
|
|
innerWidth;
|
|
|
|
public community: CommunityInfo = null;
|
|
|
|
private subscriptions: any[] = [];
|
|
|
|
headerLogoUrl: string;
|
|
|
|
headerUrl: string;
|
|
|
|
|
2019-07-12 11:11:38 +02:00
|
|
|
constructor(private route: ActivatedRoute,
|
2021-05-19 13:40:29 +02:00
|
|
|
private communityService: CommunityService,
|
|
|
|
private router: Router,
|
|
|
|
private cdr: ChangeDetectorRef,
|
|
|
|
private smoothScroll: SmoothScroll,
|
|
|
|
private layoutService: LayoutService,
|
2021-07-14 14:04:42 +02:00
|
|
|
private userManagementService: UserManagementService,
|
|
|
|
private configurationService: ConfigurationService) {
|
2021-05-19 13:40:29 +02:00
|
|
|
this.subscriptions.push(this.router.events.subscribe(event => {
|
|
|
|
if (event instanceof NavigationEnd) {
|
|
|
|
let r = this.route;
|
2021-07-14 14:04:42 +02:00
|
|
|
while (r.firstChild) {
|
2021-05-19 13:40:29 +02:00
|
|
|
r = r.firstChild;
|
|
|
|
}
|
|
|
|
this.paramsResolved = true;
|
2021-07-14 14:04:42 +02:00
|
|
|
this.params.next(r.snapshot.params);
|
|
|
|
this.data.next(r.snapshot.data);
|
2019-07-15 14:32:41 +02:00
|
|
|
}
|
2021-05-19 13:40:29 +02:00
|
|
|
}));
|
2019-04-22 12:43:22 +02:00
|
|
|
}
|
2021-05-19 13:40:29 +02:00
|
|
|
|
2019-04-22 12:43:22 +02:00
|
|
|
ngOnInit() {
|
2021-05-19 13:40:29 +02:00
|
|
|
if (typeof document !== 'undefined' && window) {
|
|
|
|
this.innerWidth = window.innerWidth;
|
|
|
|
}
|
|
|
|
this.subscriptions.push(this.layoutService.hasSidebar.subscribe(hasSidebar => {
|
|
|
|
this.hasSidebar = hasSidebar;
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
}));
|
|
|
|
this.subscriptions.push(this.layoutService.hasHeader.subscribe(hasHeader => {
|
|
|
|
this.hasHeader = hasHeader;
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
}));
|
|
|
|
this.subscriptions.push(this.layoutService.hasAdminMenu.subscribe(hasAdminMenu => {
|
|
|
|
this.hasAdminMenu = hasAdminMenu;
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
}));
|
|
|
|
this.subscriptions.push(this.layoutService.isFrontPage.subscribe(isFrontPage => {
|
|
|
|
this.isFrontPage = isFrontPage;
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
}));
|
|
|
|
this.subscriptions.push(this.layoutService.isDashboard.subscribe(isDashboard => {
|
|
|
|
this.isDashboard = isDashboard;
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
}));
|
|
|
|
this.layoutService.setSmallScreen((this.innerWidth && this.innerWidth < 1219));
|
|
|
|
this.layoutService.setOpen(!(this.innerWidth && this.innerWidth < 1219));
|
|
|
|
this.subscriptions.push(this.params.subscribe(params => {
|
|
|
|
if (this.paramsResolved) {
|
|
|
|
this.loading = true;
|
|
|
|
if (params && params['community']) {
|
|
|
|
if (!this.community || this.community.communityId !== params['community']) {
|
|
|
|
this.subscriptions.push(this.communityService.getCommunity(params['community']).subscribe(community => {
|
|
|
|
if (community) {
|
|
|
|
this.community = community;
|
2021-07-14 14:04:42 +02:00
|
|
|
this.setProperties(community.communityId);
|
2021-05-19 13:40:29 +02:00
|
|
|
this.buildMenu();
|
|
|
|
this.loading = false;
|
|
|
|
} else {
|
|
|
|
this.community = null;
|
|
|
|
this.buildMenu();
|
|
|
|
this.loading = false;
|
2019-04-22 12:43:22 +02:00
|
|
|
}
|
2021-05-19 13:40:29 +02:00
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
this.buildMenu();
|
|
|
|
this.loading = false;
|
2019-04-22 12:43:22 +02:00
|
|
|
}
|
2021-05-19 13:40:29 +02:00
|
|
|
} else {
|
|
|
|
this.communityService.setCommunity(null);
|
|
|
|
this.layoutService.setOpen(!(this.innerWidth && this.innerWidth < 1219));
|
|
|
|
this.community = null;
|
|
|
|
this.buildMenu();
|
|
|
|
this.loading = false;
|
2019-04-22 12:43:22 +02:00
|
|
|
}
|
|
|
|
}
|
2021-05-19 13:40:29 +02:00
|
|
|
}));
|
2021-07-14 14:04:42 +02:00
|
|
|
this.subscriptions.push(this.data.subscribe(data => {
|
|
|
|
if(data && data.portal) {
|
|
|
|
this.setProperties(data.portal);
|
|
|
|
this.configurationService.initCommunityInformation(this.properties, this.properties.adminToolsCommunity);
|
|
|
|
}
|
|
|
|
}));
|
2021-05-19 13:40:29 +02:00
|
|
|
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
|
|
|
|
this.user = user;
|
|
|
|
if (this.user) {
|
|
|
|
localStorage.setItem('user_id', this.user.id);
|
|
|
|
localStorage.setItem('mining_backend_address', this.properties.miningBackendURL);
|
|
|
|
localStorage.setItem('isCommunityManager', Session.isCommunityCurator(this.user) + '');
|
|
|
|
this.buildMenu();
|
[Trunk | Admin]:
1. pages.component: Show link to add pageHelpContents only when at least one posiiton is enabled.
2. help-content.service:
Add 'pid' parameter in 'getDivIdsFull()' method to be able to get divIds that are enabled in a community.
Add 'with_positions' parameter in 'getPages()' method to be able to get pages that have at least one position or no positions enabled.
3. app.component: Hide '/classContents' route for communities (currently no divIds for communities).
4. div-help-content-form.component: Get divIds that are enabled for the community.
5. div-help-contents.component: When a page is pre-selected ('pageId' url param exists), check if page is enabled in the community, otherwise redirect.
6. edit-div-help-content.component & new-div-help-content.component:
Add 'getPage()' method, to get page (if disabled in community, redirect - if pageId is pre-selected) and show it in the page title.
7. edit-div-help-content.component: If there is no 'divContentId' url param, redirect
8. edit-page-help-content.component:
If there is no 'pageContentId' url param, redirect
Add 'getPage()' method, to get page (if disabled in community, redirect - if pageId is pre-selected or use pageHelpContent.page - if pageId != pageHelpContent.page, redirect) and show it in the p$
9. new-page-help-content.component: Add 'getPage()' method, to get page (if disabled in community, redirect - if pageId is pre-selected) and show it in the page title.
10. page-help-content-form.component: Do not perform a query to get page when it is pre-selected (new & edit do the query now) | Get pages with at least one posiiton enabled.
11. page-help-contents.component: When a page is pre-selected ('pageId' url param exists), check if page is enabled in the community, otherwise redirect | Get pages with at least one posiiton enabled.
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-admin-portal/trunk@56740 d315682c-612b-4755-9ff5-7f18f6832af3
2019-07-24 11:16:42 +02:00
|
|
|
}
|
2021-05-19 13:40:29 +02:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
@HostListener('window:resize', ['$event'])
|
|
|
|
onResize(event) {
|
|
|
|
if (this.layoutService.isSmallScreen && event.target.innerWidth > 1219) {
|
|
|
|
this.layoutService.setSmallScreen(false);
|
|
|
|
} else if (!this.layoutService.isSmallScreen && event.target.innerWidth < 1219) {
|
|
|
|
this.layoutService.setSmallScreen(true);
|
|
|
|
this.layoutService.setOpen(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
this.subscriptions.forEach(value => {
|
|
|
|
if (value instanceof Subscriber) {
|
|
|
|
value.unsubscribe();
|
2019-04-22 12:43:22 +02:00
|
|
|
}
|
2021-05-19 13:40:29 +02:00
|
|
|
});
|
|
|
|
this.communityService.clearSubscriptions();
|
|
|
|
this.userManagementService.clearSubscriptions();
|
|
|
|
this.layoutService.clearSubscriptions();
|
|
|
|
this.smoothScroll.clearSubscriptions();
|
|
|
|
}
|
|
|
|
|
2021-07-14 14:04:42 +02:00
|
|
|
setProperties(id, type = null){
|
|
|
|
this.properties.adminToolsCommunity = id;
|
|
|
|
if(type) {
|
|
|
|
this.properties.adminToolsPortalType = type;
|
|
|
|
} else {
|
|
|
|
ConnectHelper.setPortalTypeFromPid(id);
|
|
|
|
}
|
|
|
|
this.configurationService.initCommunityInformation(this.properties, this.properties.adminToolsCommunity);
|
|
|
|
}
|
|
|
|
|
2021-05-19 13:40:29 +02:00
|
|
|
public get open() {
|
|
|
|
return this.layoutService.open;
|
|
|
|
}
|
|
|
|
|
|
|
|
private buildMenu() {
|
|
|
|
this.menuItems = [];
|
|
|
|
this.userMenuItems = [];
|
|
|
|
this.sideBarItems = [];
|
|
|
|
if (this.user) {
|
|
|
|
if (this.isCurator()) {
|
|
|
|
this.userMenuItems.push(new MenuItem("", "Manage communities",
|
|
|
|
"", "/", false, [], [], {}));
|
|
|
|
}
|
|
|
|
if (Session.isPortalAdministrator(this.user)) {
|
|
|
|
this.userMenuItems.push(new MenuItem("adminOptions", "Super Admin options", "", "/admin-tools/portals", false, [], [], {}));
|
|
|
|
this.userMenuItems.push(new MenuItem("connectOptions", "Connect portal options", "", "/connect/admin-tools/pages", false, [], [], {}));
|
|
|
|
this.userMenuItems.push(new MenuItem("exploreOptions", "Explore portal options", "", "/openaire/admin-tools/pages", false, [], [], {}));
|
|
|
|
|
|
|
|
}
|
|
|
|
this.userMenuItems.push(new MenuItem("", "User information", "", "/user-info", false, [], [], {}));
|
2019-04-22 12:43:22 +02:00
|
|
|
}
|
2021-05-19 13:40:29 +02:00
|
|
|
if (this.community) {
|
2021-11-12 13:22:44 +01:00
|
|
|
this.headerLogoUrl = StringUtils.getLogoUrl(this.community);
|
2021-05-19 13:40:29 +02:00
|
|
|
this.headerUrl = 'https://' + ((properties.environment !== 'production')?'beta.':'') + this.community.communityId + '.openaire.eu';
|
|
|
|
this.menuHeader = {
|
|
|
|
route: "/" + this.community.communityId,
|
|
|
|
url: null,
|
|
|
|
title: 'Admin - ' + this.community.shortTitle,
|
|
|
|
logoUrl: null,
|
|
|
|
logoSmallUrl: null,
|
|
|
|
position: 'center',
|
|
|
|
badge: false,
|
|
|
|
stickyAnimation: false
|
|
|
|
};
|
|
|
|
this.sideBarItems.push(new MenuItem("community", "Community Info", "", "/" + this.community.communityId, false, [], [], {}, null, null, null, "/" + this.community.communityId + "/info"));
|
|
|
|
this.sideBarItems.push(new MenuItem("users", "Users", "", "/" + this.community.communityId + "/users", false, [], [], {}, null, null, null, "/" + this.community.communityId + "/users"));
|
|
|
|
this.sideBarItems.push(new MenuItem("admin-tools", "Pages & Entities", "", "/" + this.community.communityId + "/admin-tools/pages", false, [], [], {}, null, null, null, "/" + this.community.communityId + "/admin-tools"));
|
|
|
|
this.sideBarItems.push(new MenuItem("customization", "Customization", "", "/" + this.community.communityId + "/customize-layout", false, [], [], {}));
|
|
|
|
if (this.community.type === 'ri') {
|
|
|
|
this.sideBarItems.push(new MenuItem("mining", "Mining", "", "/" + this.community.communityId + "/mining/manage-profiles", false, [], [], {}, null, null, null, "/" + this.community.communityId + "/mining"));
|
|
|
|
}
|
|
|
|
this.specialSideBarMenuItem = new MenuItem("back", "Manage communities", "", "/", false, [], null, {});
|
|
|
|
this.specialSideBarMenuItem.icon = '<span class="uk-icon-button small uk-icon uk-button-secondary">' + arrow_left.data + '</span>';
|
|
|
|
this.specialSideBarMenuItem.customClass = 'uk-text-uppercase uk-text-bold uk-text-secondary';
|
|
|
|
} else {
|
|
|
|
this.headerLogoUrl = null;
|
|
|
|
this.headerUrl = 'https://' + ((properties.environment !== 'production')?'beta.':'') + 'connect.openaire.eu';
|
|
|
|
this.menuHeader = {
|
|
|
|
route: null,
|
|
|
|
url: null,
|
|
|
|
title: 'Admin - Research Community Dashboard',
|
|
|
|
logoUrl: null,
|
|
|
|
logoSmallUrl: null,
|
|
|
|
position: 'center',
|
|
|
|
badge: false,
|
|
|
|
stickyAnimation: false
|
|
|
|
};
|
|
|
|
this.sideBarItems.push(new MenuItem("communities", "Manage Communities", "", "/", false, [], [], {}));
|
|
|
|
this.specialSideBarMenuItem = null;
|
2019-04-22 12:43:22 +02:00
|
|
|
}
|
2018-10-30 16:31:16 +01:00
|
|
|
}
|
2021-05-19 13:40:29 +02:00
|
|
|
|
|
|
|
private isCurator() {
|
|
|
|
return this.user && (Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || Session.isKindOfCommunityManager(this.user));
|
|
|
|
}
|
2018-10-30 16:31:16 +01:00
|
|
|
}
|