2020-11-19 18:14:12 +01:00
|
|
|
import {Component, Input, OnInit} from "@angular/core";
|
2020-10-05 15:16:15 +02:00
|
|
|
import {StakeholderService} from "../openaireLibrary/monitor/services/stakeholder.service";
|
|
|
|
import {properties} from "../../environments/environment";
|
2020-11-13 17:42:12 +01:00
|
|
|
import {Subscriber} from "rxjs";
|
2020-11-19 18:14:12 +01:00
|
|
|
import {Title} from "@angular/platform-browser";
|
2021-01-15 12:59:28 +01:00
|
|
|
import {Composer} from "../openaireLibrary/utils/email/composer";
|
|
|
|
import {Email} from "../openaireLibrary/utils/email/email";
|
2021-01-18 17:51:07 +01:00
|
|
|
import {ActivatedRoute} from "@angular/router";
|
|
|
|
|
|
|
|
type Tab = 'member' | 'manager';
|
2020-10-01 11:18:13 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'users',
|
|
|
|
templateUrl: 'users.component.html'
|
|
|
|
})
|
2021-01-18 17:51:07 +01:00
|
|
|
export class UsersComponent implements OnInit {
|
2020-10-05 15:16:15 +02:00
|
|
|
|
|
|
|
public alias: string;
|
|
|
|
public name: string;
|
|
|
|
public type: string;
|
|
|
|
public link: string;
|
|
|
|
public loading: boolean;
|
2021-01-18 17:51:07 +01:00
|
|
|
public messages: Map<Tab, string> = new Map<Tab, string>();
|
|
|
|
public tab: Tab = 'manager';
|
|
|
|
private subscriptions = [];
|
|
|
|
public emailComposer: Function = (name, recipient, role): Email => {
|
2021-01-15 12:59:28 +01:00
|
|
|
return Composer.composeEmailForMonitorDashboard(name, recipient, role);
|
|
|
|
}
|
2020-10-05 15:16:15 +02:00
|
|
|
|
2020-11-19 18:14:12 +01:00
|
|
|
constructor(private stakeholderService: StakeholderService,
|
2021-01-18 17:51:07 +01:00
|
|
|
private route: ActivatedRoute,
|
2020-11-19 18:14:12 +01:00
|
|
|
private title: Title) {
|
2020-11-13 17:42:12 +01:00
|
|
|
}
|
2020-11-19 18:14:12 +01:00
|
|
|
|
2020-10-05 15:16:15 +02:00
|
|
|
ngOnInit() {
|
|
|
|
this.loading = true;
|
2021-01-18 17:51:07 +01:00
|
|
|
this.subscriptions.push(this.route.fragment.subscribe((fragment: Tab) => {
|
|
|
|
if (this.isTab(fragment)) {
|
|
|
|
this.tab = fragment;
|
|
|
|
} else {
|
|
|
|
this.tab = 'manager';
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
this.subscriptions.push(this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
|
|
|
|
if (stakeholder) {
|
2020-10-05 15:16:15 +02:00
|
|
|
this.alias = stakeholder.alias;
|
|
|
|
this.name = stakeholder.name;
|
2020-11-19 18:14:12 +01:00
|
|
|
this.title.setTitle(this.name + " | Users");
|
2020-10-05 15:16:15 +02:00
|
|
|
this.type = stakeholder.type;
|
|
|
|
this.link = this.getURL(this.alias);
|
2020-11-19 18:14:12 +01:00
|
|
|
this.messages.set("member", 'A member has the right to view the <b>restricted access</b> areas of this indicator\'s profile. ' +
|
|
|
|
'A member has <b>no access</b> to the administration part of the profile.');
|
|
|
|
this.messages.set("manager", 'A manager has the right to access the administration part of this indicator\'s profile, ' +
|
|
|
|
'where he is able to customize and manage indicators, and invite other users as members.');
|
2020-10-05 15:16:15 +02:00
|
|
|
this.loading = false;
|
|
|
|
}
|
2021-01-18 17:51:07 +01:00
|
|
|
}));
|
2020-10-05 15:16:15 +02:00
|
|
|
}
|
|
|
|
|
2020-11-19 18:14:12 +01:00
|
|
|
ngOnDestroy() {
|
2021-01-18 17:51:07 +01:00
|
|
|
this.subscriptions.forEach(value => {
|
|
|
|
if (value instanceof Subscriber) {
|
|
|
|
value.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
2020-11-19 18:14:12 +01:00
|
|
|
}
|
|
|
|
|
2021-01-18 17:51:07 +01:00
|
|
|
private isTab(tab: Tab): boolean {
|
|
|
|
switch (tab) {
|
|
|
|
case "manager":
|
|
|
|
return true;
|
|
|
|
case "member":
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2021-01-15 11:19:39 +01:00
|
|
|
}
|
|
|
|
|
2020-10-05 15:16:15 +02:00
|
|
|
private getURL(id: string): string {
|
|
|
|
return properties.domain + properties.baseLink + "/" + id + "?verify=";
|
|
|
|
}
|
|
|
|
}
|