import {Component, OnInit, QueryList, ViewChildren} from "@angular/core"; import {ManageStakeholders, StakeholderType} from "../../monitor/entities/stakeholder"; import {Session} from "../../login/utils/helper.class"; import {StakeholderBaseComponent} from "../utils/stakeholder-base.component"; import {StakeholderService} from "../../monitor/services/stakeholder.service"; import {UserManagementService} from "../../services/user-management.service"; import {ActivatedRoute} from "@angular/router"; import {Title} from "@angular/platform-browser"; import {Option} from "../../sharedComponents/input/input.component"; import {zip} from "rxjs"; import {StringUtils} from "../../utils/string-utils.class"; import {StakeholderCategory} from "../utils/indicator-utils"; import {ManageStakeholdersComponent} from "./manageStakeholders.component"; @Component({ selector: `manage-all`, template: `

No profiles to manage yet

` }) export class ManageAllComponent extends StakeholderBaseComponent implements OnInit { public loading: boolean = true; public stakeholderCategories: StakeholderCategory[] = this.stakeholderUtils.stakeholderCategories; public active: 'all' | 'templates' | 'standalone' | 'umbrella' | 'dependent' = 'all'; public aliases: string[]; public manageStakeholders: ManageStakeholders; public user = null; /** * Filters */ public keyword: string; public type: StakeholderType | 'all' = 'all'; public types: Option[] = [{value: 'all', label: 'All'}].concat(this.stakeholderUtils.types); @ViewChildren(ManageStakeholdersComponent) manageStakeholdersList: QueryList; public readonly StringUtils = StringUtils; constructor(private stakeholderService: StakeholderService, private userManagementService: UserManagementService, protected _route: ActivatedRoute, protected _title: Title) { super(); } ngOnInit(): void { this.title = 'Manage Profiles'; this.setMetadata(); this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => { this.user = user; if(!this.isManager()) { this.stakeholderCategories = []; } else if(!this.isCurator()) { this.stakeholderCategories = this.stakeholderCategories.filter(category => category.value !== 'templates'); } this.active = this.stakeholderCategories[0].value; })); let data = zip( this.stakeholderService.getMyStakeholders(), this.stakeholderService.getAlias() ); this.subscriptions.push(data.subscribe(res => { this.manageStakeholders = res[0]; this.aliases = res[1]; this.loading = false; }, error => { this.loading = false; })); } public isManager(): boolean { return this.isCurator() || (Session.isKindOfMonitorManager(this.user)); } public isCurator(): boolean { return this.isAdmin() || Session.isMonitorCurator(this.user); } public isAdmin(): boolean { return Session.isPortalAdministrator(this.user); } get categories(): StakeholderCategory[] { return this.stakeholderCategories.filter(category => category.value !== 'all' && (this.active === 'all' || category.value === this.active)); } }