89 lines
2.9 KiB
TypeScript
89 lines
2.9 KiB
TypeScript
|
import {Component, Input, ViewChild} from '@angular/core';
|
||
|
import {ActivatedRoute, Router} from '@angular/router';
|
||
|
import {Location} from '@angular/common';
|
||
|
import {Stakeholder, StakeholderInfo, Visibility} from "../openaireLibrary/monitor/entities/stakeholder";
|
||
|
import {EnvProperties} from "../openaireLibrary/utils/properties/env-properties";
|
||
|
import {properties} from "../../environments/environment"
|
||
|
import {LocalStorageService} from "../openaireLibrary/services/localStorage.service";
|
||
|
import {Subscriber} from "rxjs";
|
||
|
|
||
|
@Component({
|
||
|
selector: 'browse-stakeholder',
|
||
|
templateUrl: 'browse-stakeholder.component.html'
|
||
|
})
|
||
|
export class BrowseStakeholderComponent {
|
||
|
@Input() public stakeholder: StakeholderInfo = null;
|
||
|
@Input() public showDescription: boolean = true;
|
||
|
@Input() public smallTitle: boolean = false;
|
||
|
@ViewChild('AlertModal', { static: true }) modal;
|
||
|
public thresholdTitle: number = 45;
|
||
|
public properties: EnvProperties = properties;
|
||
|
public directLink: boolean = true;
|
||
|
public visibilityIcon: Map<Visibility, string> = new Map<Visibility, string> ([
|
||
|
["PRIVATE", 'incognito'],
|
||
|
["RESTRICTED", 'group']
|
||
|
]);
|
||
|
private subscriptions: any[] = [];
|
||
|
|
||
|
constructor(private route: ActivatedRoute,
|
||
|
private router: Router,
|
||
|
private location: Location,
|
||
|
private localStorageService: LocalStorageService) {
|
||
|
}
|
||
|
|
||
|
|
||
|
public ngOnInit() {
|
||
|
this.properties = properties;
|
||
|
this.subscriptions.push(this.localStorageService.get().subscribe(value => {
|
||
|
this.directLink = value;
|
||
|
}));
|
||
|
|
||
|
}
|
||
|
ngOnDestroy() {
|
||
|
this.subscriptions.forEach(subscription => {
|
||
|
if (subscription instanceof Subscriber) {
|
||
|
subscription.unsubscribe();
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
|
||
|
isProduction(): boolean {
|
||
|
return this.properties.environment != "development";
|
||
|
}
|
||
|
|
||
|
getProductionPrefix(id:string): string {
|
||
|
return (this.properties.environment == "production") ? "" : "beta.";
|
||
|
}
|
||
|
|
||
|
public confirmModalOpen() {
|
||
|
this.modal.cancelButton = true;
|
||
|
this.modal.okButton = true;
|
||
|
this.modal.alertTitle = 'You are going to visit ' + this.stakeholder.name + ' Monitor Dashboard';
|
||
|
this.modal.alertMessage = false;
|
||
|
this.modal.okButtonLeft = false;
|
||
|
this.modal.okButtonText = 'Yes';
|
||
|
this.modal.cancelButtonText = 'No';
|
||
|
this.modal.choice = true;
|
||
|
this.modal.open();
|
||
|
}
|
||
|
|
||
|
public getStakeholderPageUrl() {
|
||
|
return this.properties.domain + this.properties.baseLink + '/dashboard/' + this.stakeholder.alias;
|
||
|
}
|
||
|
|
||
|
hasPermission() {
|
||
|
return this.stakeholder.visibility === "PUBLIC" ||
|
||
|
(this.stakeholder.visibility === "RESTRICTED" && (this.stakeholder.isManager || this.stakeholder.isMember)) ||
|
||
|
(this.stakeholder.visibility === "PRIVATE" && this.stakeholder.isManager);
|
||
|
}
|
||
|
|
||
|
public goToPage(data: any) {
|
||
|
if (data.value == true) {
|
||
|
let url = this.getStakeholderPageUrl();
|
||
|
this.localStorageService.setCommunityDirectLink(data.choice);
|
||
|
window.open(url, '_blank');
|
||
|
}
|
||
|
}
|
||
|
}
|