2022-02-16 17:19:35 +01:00
|
|
|
import {Component, Input, ViewChild} from '@angular/core';
|
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
|
|
import {Location} from '@angular/common';
|
2022-02-17 16:31:58 +01:00
|
|
|
import {StakeholderInfo, Visibility} from "../openaireLibrary/monitor/entities/stakeholder";
|
2022-02-16 17:19:35 +01:00
|
|
|
import {EnvProperties} from "../openaireLibrary/utils/properties/env-properties";
|
|
|
|
import {properties} from "../../environments/environment"
|
|
|
|
import {LocalStorageService} from "../openaireLibrary/services/localStorage.service";
|
|
|
|
import {Subscriber} from "rxjs";
|
2022-06-09 10:21:37 +02:00
|
|
|
import {StringUtils} from "../openaireLibrary/utils/string-utils.class";
|
2023-03-22 16:16:14 +01:00
|
|
|
import {LayoutService} from "../openaireLibrary/dashboard/sharedComponents/sidebar/layout.service";
|
2022-02-16 17:19:35 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'browse-stakeholder',
|
2022-02-21 15:37:12 +01:00
|
|
|
templateUrl: 'browse-stakeholder.component.html',
|
2022-07-17 23:46:13 +02:00
|
|
|
styleUrls: ['browse-stakeholder.component.less']
|
2022-02-16 17:19:35 +01:00
|
|
|
})
|
|
|
|
export class BrowseStakeholderComponent {
|
|
|
|
@Input() public stakeholder: StakeholderInfo = null;
|
|
|
|
@ViewChild('AlertModal', { static: true }) modal;
|
|
|
|
public properties: EnvProperties = properties;
|
|
|
|
public directLink: boolean = true;
|
|
|
|
public visibilityIcon: Map<Visibility, string> = new Map<Visibility, string> ([
|
|
|
|
["PRIVATE", 'incognito'],
|
2022-02-22 23:39:14 +01:00
|
|
|
["RESTRICTED", 'restricted']
|
2022-02-16 17:19:35 +01:00
|
|
|
]);
|
|
|
|
private subscriptions: any[] = [];
|
|
|
|
|
|
|
|
constructor(private route: ActivatedRoute,
|
|
|
|
private router: Router,
|
|
|
|
private location: Location,
|
2023-03-22 16:16:14 +01:00
|
|
|
private localStorageService: LocalStorageService,
|
|
|
|
private layoutService: LayoutService) {
|
2022-02-16 17:19:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ngOnInit() {
|
|
|
|
this.properties = properties;
|
2023-03-22 16:16:14 +01:00
|
|
|
this.subscriptions.push(this.layoutService.isMobile.subscribe(value => {
|
|
|
|
if(value) {
|
|
|
|
this.directLink = true;
|
|
|
|
} else {
|
|
|
|
this.subscriptions.push(this.localStorageService.get().subscribe(value => {
|
|
|
|
this.directLink = value;
|
|
|
|
}));
|
|
|
|
}
|
2022-02-16 17:19:35 +01:00
|
|
|
}));
|
2023-03-22 16:16:14 +01:00
|
|
|
|
2022-02-16 17:19:35 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscriber) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-02-17 16:31:58 +01:00
|
|
|
|
|
|
|
mapType(type: string) {
|
2022-06-09 10:21:37 +02:00
|
|
|
return StringUtils.getStakeholderType(type, false);
|
2022-02-16 17:19:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public confirmModalOpen() {
|
|
|
|
this.modal.cancelButton = true;
|
|
|
|
this.modal.okButton = true;
|
|
|
|
this.modal.alertTitle = 'You are going to visit ' + this.stakeholder.name + ' Monitor Dashboard';
|
2022-06-02 17:15:22 +02:00
|
|
|
this.modal.message = 'You will be navigated to a new tab. Are you sure that you want to proceed?';
|
2022-02-16 17:19:35 +01:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|