openaire-library/dashboard/sharedComponents/admin-tabs/admin-tabs.component.ts

62 lines
2.3 KiB
TypeScript
Raw Normal View History

import {Component, Input, OnInit} from '@angular/core';
import {Session, User} from "../../../login/utils/helper.class";
import {UserManagementService} from "../../../services/user-management.service";
import {Subscriber} from "rxjs";
import {ActivatedRoute} from "@angular/router";
import {HelperFunctions} from "../../../utils/HelperFunctions.class";
@Component({
selector: 'admin-tabs',
template: `
<ul class="uk-tab customTabs admin uk-flex uk-flex-center uk-flex-left@m">
<li *ngIf="isPortalAdmin && (!portal )" class="uk-disabled" > <span class = "uk-margin-small-right" uk-icon="cog"></span></li>
<li *ngIf="isPortalAdmin && !portal" [class.uk-active]="tab === 'portal'"><a routerLink="../../portals"><span class="title">Portals</span></a></li>
<li [class.uk-active]="tab === 'page'"><a routerLink="../../pages" [queryParams]="(portal? {communityId:portal}:{})" ><span class="title">Pages</span></a></li>
<li [class.uk-active]="tab === 'entity'"><a routerLink="../../entities" [queryParams]="(portal? {communityId:portal}:{})"><span class="title">Entities</span></a></li>
<li *ngIf="isPortalAdmin && !portal" [class.uk-active]="tab === 'class'"><a routerLink="../../classes"><span class="title">Class Ids</span></a></li>
</ul>
`
})
export class AdminTabsComponent implements OnInit {
@Input()
public type: string;
@Input()
portal = null;
@Input()
public user: User;
@Input()
public tab: "portal"| "page" | "entity" | "class" = 'page';
private subscriptions: any[] = [];
constructor(private route: ActivatedRoute, private userManagementService: UserManagementService) {
}
ngOnInit() {
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
this.user = user;
}));
this.subscriptions.push(this.route.queryParams.subscribe(params => {
HelperFunctions.scroll();
this.portal = params['communityId'];
}));
}
ngOnDestroy(): void {
this.subscriptions.forEach(value => {
if (value instanceof Subscriber) {
value.unsubscribe();
} else if (value instanceof Function) {
value();
}
});
}
public get isPortalAdmin() {
return Session.isPortalAdministrator(this.user) || Session.isCurator(this.type, this.user);
}
}