2021-03-04 12:35:10 +01:00
|
|
|
import {Component, Input, OnDestroy, ViewChild} from "@angular/core";
|
2020-10-19 11:07:43 +02:00
|
|
|
import {Stakeholder} from "../../openaireLibrary/monitor/entities/stakeholder";
|
|
|
|
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
|
|
|
|
import {StakeholderUtils} from "../../utils/indicator-utils";
|
2020-11-12 18:57:57 +01:00
|
|
|
import {Option} from "../../openaireLibrary/sharedComponents/input/input.component";
|
2020-11-13 17:42:12 +01:00
|
|
|
import {Subscriber, Subscription} from "rxjs";
|
2020-10-19 11:07:43 +02:00
|
|
|
import {EnvProperties} from "../../openaireLibrary/utils/properties/env-properties";
|
|
|
|
import {properties} from "../../../environments/environment";
|
|
|
|
import {StakeholderService} from "../../openaireLibrary/monitor/services/stakeholder.service";
|
|
|
|
import {UtilitiesService} from "../../openaireLibrary/services/utilities.service";
|
2021-03-04 12:35:10 +01:00
|
|
|
import {Role, Session, User} from "../../openaireLibrary/login/utils/helper.class";
|
2020-11-03 10:42:47 +01:00
|
|
|
import {UserManagementService} from "../../openaireLibrary/services/user-management.service";
|
2020-12-17 16:39:31 +01:00
|
|
|
import {StringUtils} from "../../openaireLibrary/utils/string-utils.class";
|
2021-03-04 12:35:10 +01:00
|
|
|
import {NotifyFormComponent} from "../../openaireLibrary/notifications/notify-form/notify-form.component";
|
|
|
|
import {NotificationUtils} from "../../openaireLibrary/notifications/notification-utils";
|
|
|
|
import {Notification} from "../../openaireLibrary/notifications/notifications";
|
2020-10-19 11:07:43 +02:00
|
|
|
|
2020-11-03 11:04:45 +01:00
|
|
|
declare var UIkit;
|
|
|
|
|
2020-10-19 11:07:43 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'edit-stakeholder',
|
|
|
|
template: `
|
2021-03-04 12:35:10 +01:00
|
|
|
<div [ngStyle]="{'max-height': maxHeight}"
|
2020-10-19 23:18:09 +02:00
|
|
|
[class.uk-padding-small]="!paddingLarge" [class.uk-padding-large]="paddingLarge"
|
2021-03-04 12:35:10 +01:00
|
|
|
class="uk-overflow-auto uk-padding-remove-bottom">
|
|
|
|
<form *ngIf="stakeholderFb" [formGroup]="stakeholderFb">
|
|
|
|
<div class="uk-grid" [class.uk-margin-small-bottom]="!paddingLarge"
|
|
|
|
[class.uk-margin-large-bottom]="paddingLarge" uk-grid uk-height-match=".uk-form-hint">
|
2021-07-14 18:02:04 +02:00
|
|
|
<div dashboard-input id="name" class="uk-width-1-2@m" [formInput]="stakeholderFb.get('name')" label="Name"
|
2021-03-04 12:35:10 +01:00
|
|
|
placeholder="Write a name..."
|
|
|
|
hint="Set a name for your profile."></div>
|
|
|
|
<div dashboard-input class="uk-width-1-2@m" [formInput]="stakeholderFb.get('alias')"
|
|
|
|
hint="Set an URL alias for your profile."
|
|
|
|
label="URL Alias" placeholder="Write an alias..."></div>
|
|
|
|
<div dashboard-input class="uk-width-1-3@m" [formInput]="stakeholderFb.get('index_id')"
|
|
|
|
label="Index ID" placeholder="Write index ID.">
|
|
|
|
</div>
|
|
|
|
<div dashboard-input class="uk-width-1-3@m" [formInput]="stakeholderFb.get('index_name')"
|
|
|
|
label="Index Name" placeholder="Write index name.">
|
|
|
|
</div>
|
|
|
|
<div dashboard-input class="uk-width-1-3@m" [formInput]="stakeholderFb.get('index_shortName')"
|
|
|
|
label="Index Short Name" placeholder="Write index short name.">
|
|
|
|
</div>
|
|
|
|
<div dashboard-input class="uk-width-1-1" [type]="'textarea'" placeholder="Write a description..."
|
|
|
|
hint="Write a description for your profile"
|
|
|
|
[rows]="4" [formInput]="stakeholderFb.get('description')" label="Description"></div>
|
|
|
|
<input #file id="photo" type="file" class="uk-hidden" (change)="fileChangeEvent($event)"/>
|
|
|
|
<div dashboard-input class="uk-width-1-1" type="logoURL" flex="top" [hideControl]="stakeholderFb.get('isUpload').value"
|
|
|
|
hint="Upload or link the logo of your profile" [placeholder]="'Write link to the logo'"
|
|
|
|
[formInput]="stakeholderFb.get('logoUrl')" label="Logo">
|
|
|
|
<div *ngIf="!stakeholderFb.get('isUpload').value" style="margin-top: 7px;" class="uk-width-2-5@l uk-width-1-1">
|
|
|
|
<div class="uk-grid uk-flex uk-flex-middle" uk-grid>
|
|
|
|
<div class="uk-width-3-4@l uk-width-1-1 uk-flex uk-flex-center">
|
|
|
|
<button class="uk-button uk-button-secondary uk-flex uk-flex-middle uk-flex-wrap"
|
|
|
|
(click)="file.click()">
|
|
|
|
<icon name="cloud_upload" [flex]="true"></icon>
|
|
|
|
<span class="uk-margin-small-left">Upload a file</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div class="uk-text-center uk-text-bold uk-width-expand">
|
|
|
|
OR
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div *ngIf="stakeholderFb.get('isUpload').value" class="uk-width-1-1 uk-flex uk-flex-middle">
|
|
|
|
<div class="uk-card uk-card-default uk-text-center uk-border-circle">
|
|
|
|
<img class="uk-position-center" [src]="photo">
|
|
|
|
</div>
|
|
|
|
<div class="uk-margin-left">
|
|
|
|
<button (click)="remove()" class="uk-button-secondary outlined uk-icon-button">
|
|
|
|
<icon name="remove"></icon>
|
2020-10-29 15:20:13 +01:00
|
|
|
</button>
|
2020-10-19 17:06:06 +02:00
|
|
|
</div>
|
2021-03-04 12:35:10 +01:00
|
|
|
<div class="uk-margin-small-left">
|
|
|
|
<button class="uk-button-secondary uk-icon-button" (click)="file.click()">
|
|
|
|
<icon name="edit"></icon>
|
|
|
|
</button>
|
2020-10-19 17:06:06 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-03-04 12:35:10 +01:00
|
|
|
<div *ngIf="uploadError" class="uk-text-danger uk-width-1-1">{{uploadError}}</div>
|
|
|
|
<div class="uk-width-1-1 uk-grid uk-child-width-1-1" [class.uk-child-width-1-2@m]="!canChooseType"
|
|
|
|
[class.uk-child-width-1-3@m]="canChooseType" uk-grid>
|
|
|
|
<div dashboard-input [formInput]="stakeholderFb.get('visibility')"
|
|
|
|
[placeholder]="'Select a status'"
|
|
|
|
label="Status" hint="Select the visibility status of your profile"
|
|
|
|
[options]="stakeholderUtils.statuses" type="select">
|
2020-10-19 17:06:06 +02:00
|
|
|
</div>
|
2021-03-04 12:35:10 +01:00
|
|
|
<div dashboard-input [formInput]="stakeholderFb.get('type')"
|
|
|
|
[placeholder]="'Select a type'" hint="Select the type of your profile"
|
|
|
|
label="Type" [options]="types" type="select">
|
2020-12-17 16:39:31 +01:00
|
|
|
</div>
|
2021-03-04 12:35:10 +01:00
|
|
|
<ng-container *ngIf="canChooseType">
|
|
|
|
<div [placeholder]="'Select a template'"
|
|
|
|
hint="Select a template for your profile"
|
|
|
|
dashboard-input class="uk-width-1-3@m" [formInput]="stakeholderFb.get('defaultId')"
|
|
|
|
label="Template" [options]="defaultStakeholdersOptions" type="select"></div>
|
|
|
|
</ng-container>
|
2020-12-17 16:39:31 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-03-04 12:35:10 +01:00
|
|
|
</form>
|
2021-08-02 17:46:21 +02:00
|
|
|
<div #notify notify-form class="uk-width-1-1 uk-margin-medium-top uk-margin-medium-bottom"></div>
|
2020-10-19 17:06:06 +02:00
|
|
|
</div>`,
|
|
|
|
styleUrls: ['edit-stakeholder.component.css']
|
2020-10-19 11:07:43 +02:00
|
|
|
})
|
2020-10-19 17:06:06 +02:00
|
|
|
export class EditStakeholderComponent implements OnDestroy {
|
2020-10-19 11:07:43 +02:00
|
|
|
@Input()
|
|
|
|
public maxHeight = 'none';
|
2020-10-19 23:18:09 +02:00
|
|
|
@Input()
|
|
|
|
public paddingLarge: boolean = false;
|
|
|
|
@Input()
|
|
|
|
public disableAlias: boolean = false;
|
2020-10-19 11:07:43 +02:00
|
|
|
public stakeholderFb: FormGroup;
|
2020-12-18 12:01:58 +01:00
|
|
|
public secure: boolean = false;
|
2020-10-19 11:07:43 +02:00
|
|
|
public stakeholderUtils: StakeholderUtils = new StakeholderUtils();
|
|
|
|
public defaultStakeholdersOptions: Option[];
|
|
|
|
public defaultStakeholders: Stakeholder[];
|
2020-12-08 17:40:11 +01:00
|
|
|
public alias: string[];
|
2020-10-19 11:07:43 +02:00
|
|
|
public stakeholder: Stakeholder;
|
|
|
|
public isDefault: boolean;
|
|
|
|
public isNew: boolean;
|
2020-11-03 13:06:47 +01:00
|
|
|
public types: Option[];
|
2020-10-19 11:07:43 +02:00
|
|
|
public properties: EnvProperties = properties;
|
|
|
|
private subscriptions: any[] = [];
|
|
|
|
/**
|
|
|
|
* Photo upload
|
|
|
|
* */
|
|
|
|
public file: File;
|
|
|
|
public photo: string | ArrayBuffer;
|
|
|
|
public uploadError: string;
|
|
|
|
public deleteCurrentPhoto: boolean = false;
|
|
|
|
private maxsize: number = 200 * 1024;
|
2020-11-03 10:42:47 +01:00
|
|
|
user: User;
|
2021-07-14 18:02:04 +02:00
|
|
|
@ViewChild('notify', { static: true }) notify: NotifyFormComponent;
|
2021-03-04 12:35:10 +01:00
|
|
|
private notification: Notification;
|
2020-11-03 13:06:47 +01:00
|
|
|
|
2020-10-19 11:07:43 +02:00
|
|
|
constructor(private fb: FormBuilder,
|
|
|
|
private stakeholderService: StakeholderService,
|
2020-11-03 10:42:47 +01:00
|
|
|
private utilsService: UtilitiesService, private userManagementService: UserManagementService,) {
|
2020-10-19 11:07:43 +02:00
|
|
|
}
|
|
|
|
|
2020-10-19 17:06:06 +02:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.reset();
|
|
|
|
}
|
|
|
|
|
2020-12-08 17:40:11 +01:00
|
|
|
public init(stakeholder: Stakeholder, alias: string[], defaultStakeholders: Stakeholder[], isDefault: boolean, isNew: boolean) {
|
2020-10-19 17:06:06 +02:00
|
|
|
this.reset();
|
2020-10-19 11:07:43 +02:00
|
|
|
this.deleteCurrentPhoto = false;
|
|
|
|
this.stakeholder = stakeholder;
|
2020-12-08 17:40:11 +01:00
|
|
|
this.alias = alias;
|
2020-10-19 11:07:43 +02:00
|
|
|
this.defaultStakeholders = defaultStakeholders;
|
|
|
|
this.isDefault = isDefault;
|
|
|
|
this.isNew = isNew;
|
2020-11-03 10:42:47 +01:00
|
|
|
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
|
2020-11-03 13:06:47 +01:00
|
|
|
this.user = user;
|
|
|
|
this.types = this.stakeholderUtils.getTypesByUserRoles(this.user, this.stakeholder.alias);
|
|
|
|
this.stakeholderFb = this.fb.group({
|
|
|
|
_id: this.fb.control(this.stakeholder._id),
|
|
|
|
defaultId: this.fb.control(this.stakeholder.defaultId),
|
|
|
|
name: this.fb.control(this.stakeholder.name, Validators.required),
|
|
|
|
description: this.fb.control(this.stakeholder.description),
|
|
|
|
index_name: this.fb.control(this.stakeholder.index_name, Validators.required),
|
|
|
|
index_id: this.fb.control(this.stakeholder.index_id, Validators.required),
|
|
|
|
index_shortName: this.fb.control(this.stakeholder.index_shortName, Validators.required),
|
|
|
|
creationDate: this.fb.control(this.stakeholder.creationDate),
|
|
|
|
alias: this.fb.control(this.stakeholder.alias,
|
|
|
|
[
|
|
|
|
Validators.required,
|
2020-12-08 17:40:11 +01:00
|
|
|
this.stakeholderUtils.aliasValidatorString(
|
2020-12-17 16:39:31 +01:00
|
|
|
this.alias.filter(alias => alias !== this.stakeholder.alias)
|
2020-11-03 13:06:47 +01:00
|
|
|
)]
|
|
|
|
),
|
|
|
|
isDefault: this.fb.control((this.isDefault)),
|
|
|
|
visibility: this.fb.control(this.stakeholder.visibility, Validators.required),
|
|
|
|
type: this.fb.control(this.stakeholder.type, Validators.required),
|
|
|
|
topics: this.fb.control(this.stakeholder.topics),
|
|
|
|
isUpload: this.fb.control(this.stakeholder.isUpload),
|
2020-12-18 12:01:58 +01:00
|
|
|
logoUrl: this.fb.control(this.stakeholder.logoUrl),
|
2020-11-03 13:06:47 +01:00
|
|
|
});
|
2020-12-18 12:01:58 +01:00
|
|
|
if (this.stakeholder.isUpload) {
|
|
|
|
this.stakeholderFb.get('logoUrl').clearValidators();
|
|
|
|
this.stakeholderFb.get('logoUrl').updateValueAndValidity();
|
|
|
|
} else {
|
|
|
|
this.stakeholderFb.get('logoUrl').setValidators([StringUtils.urlValidator()]);
|
|
|
|
this.stakeholderFb.get('logoUrl').updateValueAndValidity();
|
|
|
|
}
|
|
|
|
this.subscriptions.push(this.stakeholderFb.get('isUpload').valueChanges.subscribe(value => {
|
|
|
|
if (value == true) {
|
|
|
|
this.stakeholderFb.get('logoUrl').clearValidators();
|
|
|
|
this.stakeholderFb.updateValueAndValidity();
|
|
|
|
} else {
|
|
|
|
this.stakeholderFb.get('logoUrl').setValidators([StringUtils.urlValidator()]);
|
|
|
|
this.stakeholderFb.updateValueAndValidity();
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
this.secure = (!this.stakeholderFb.get('logoUrl').value || this.stakeholderFb.get('logoUrl').value.includes('https://'));
|
|
|
|
this.subscriptions.push(this.stakeholderFb.get('logoUrl').valueChanges.subscribe(value => {
|
|
|
|
this.secure = (!value || value.includes('https://'));
|
|
|
|
}));
|
2020-11-03 13:06:47 +01:00
|
|
|
this.initPhoto();
|
|
|
|
if (!isDefault) {
|
|
|
|
this.subscriptions.push(this.stakeholderFb.get('type').valueChanges.subscribe(value => {
|
|
|
|
this.onTypeChange(value, defaultStakeholders);
|
|
|
|
}));
|
|
|
|
this.stakeholderFb.setControl('defaultId', this.fb.control(stakeholder.defaultId, Validators.required));
|
|
|
|
}
|
2020-11-11 10:20:54 +01:00
|
|
|
if (!isNew) {
|
2021-03-04 12:35:10 +01:00
|
|
|
this.notification = NotificationUtils.editStakeholder(this.user.firstname + ' ' + this.user.lastname, this.stakeholder.name);
|
|
|
|
this.notify.reset(this.notification.message);
|
2020-11-11 10:20:54 +01:00
|
|
|
if (this.isAdmin) {
|
|
|
|
if (this.disableAlias) {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.stakeholderFb.get('alias').disable();
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
} else {
|
2020-11-03 13:06:47 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
this.stakeholderFb.get('alias').disable();
|
2020-11-11 10:20:54 +01:00
|
|
|
this.stakeholderFb.get('index_id').disable();
|
|
|
|
this.stakeholderFb.get('index_name').disable();
|
|
|
|
this.stakeholderFb.get('index_shortName').disable();
|
2020-11-03 13:06:47 +01:00
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
setTimeout(() => {
|
2020-11-11 10:20:54 +01:00
|
|
|
this.stakeholderFb.get('type').disable();
|
2020-11-03 13:06:47 +01:00
|
|
|
}, 0);
|
|
|
|
} else {
|
2021-03-04 12:35:10 +01:00
|
|
|
this.notification = NotificationUtils.createStakeholder(this.user.firstname + ' ' + this.user.lastname);
|
|
|
|
this.notify.reset(this.notification.message);
|
2020-11-03 13:06:47 +01:00
|
|
|
setTimeout(() => {
|
2020-11-11 10:20:54 +01:00
|
|
|
this.stakeholderFb.get('type').enable();
|
2020-11-03 13:06:47 +01:00
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
));
|
2020-10-19 11:07:43 +02:00
|
|
|
}
|
|
|
|
|
2020-11-11 10:20:54 +01:00
|
|
|
public get isAdmin() {
|
|
|
|
return Session.isPortalAdministrator(this.user);
|
|
|
|
}
|
|
|
|
|
2020-10-19 11:07:43 +02:00
|
|
|
public get disabled(): boolean {
|
2020-10-19 17:06:06 +02:00
|
|
|
return (this.stakeholderFb && this.stakeholderFb.invalid) ||
|
|
|
|
(this.stakeholderFb && this.stakeholderFb.pristine && !this.isNew && !this.file) ||
|
|
|
|
(this.uploadError && this.uploadError.length > 0);
|
2020-10-19 11:07:43 +02:00
|
|
|
}
|
|
|
|
|
2020-10-19 23:18:09 +02:00
|
|
|
public get dirty(): boolean {
|
|
|
|
return this.stakeholderFb && this.stakeholderFb.dirty;
|
|
|
|
}
|
|
|
|
|
2021-03-04 12:35:10 +01:00
|
|
|
public get canChooseType(): boolean {
|
|
|
|
return !this.stakeholderFb.get('isDefault').value && this.isNew && this.stakeholderFb.get('type').valid && !!this.defaultStakeholdersOptions;
|
|
|
|
}
|
|
|
|
|
2020-10-19 11:07:43 +02:00
|
|
|
reset() {
|
2020-10-19 17:06:06 +02:00
|
|
|
this.uploadError = null;
|
2020-10-19 11:07:43 +02:00
|
|
|
this.stakeholderFb = null;
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscription) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onTypeChange(value, defaultStakeholders: Stakeholder[]) {
|
|
|
|
this.stakeholderFb.setControl('defaultId', this.fb.control(this.stakeholder.defaultId, Validators.required));
|
|
|
|
this.defaultStakeholdersOptions = [{
|
|
|
|
label: 'New blank profile',
|
|
|
|
value: '-1'
|
|
|
|
}];
|
|
|
|
defaultStakeholders.filter(stakeholder => stakeholder.type === value).forEach(stakeholder => {
|
|
|
|
this.defaultStakeholdersOptions.push({
|
|
|
|
label: 'Use ' + stakeholder.name + ' profile',
|
|
|
|
value: stakeholder._id
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-03 11:04:45 +01:00
|
|
|
public save(callback: Function, errorCallback: Function = null) {
|
2020-10-19 11:07:43 +02:00
|
|
|
if (this.file) {
|
2020-12-03 16:00:31 +01:00
|
|
|
this.stakeholderFb.get('alias').enable();
|
2022-02-10 09:15:32 +01:00
|
|
|
this.stakeholderFb.get('type').enable();
|
|
|
|
this.subscriptions.push(this.utilsService.uploadPhoto(this.properties.utilsService + "/upload/" + encodeURIComponent(this.stakeholderFb.value.type) + "/" + encodeURIComponent(this.stakeholderFb.value.alias), this.file).subscribe(res => {
|
2020-10-19 11:07:43 +02:00
|
|
|
this.deletePhoto();
|
|
|
|
this.stakeholderFb.get('logoUrl').setValue(res.filename);
|
2021-11-12 13:16:51 +01:00
|
|
|
this.removePhoto();
|
2020-11-03 11:04:45 +01:00
|
|
|
this.saveStakeholder(callback, errorCallback);
|
2020-10-19 11:07:43 +02:00
|
|
|
}, error => {
|
|
|
|
this.uploadError = "An error has been occurred during upload your image. Try again later";
|
2020-11-03 11:04:45 +01:00
|
|
|
this.saveStakeholder(callback, errorCallback);
|
2020-11-13 17:42:12 +01:00
|
|
|
}));
|
2020-10-19 11:07:43 +02:00
|
|
|
} else if (this.deleteCurrentPhoto) {
|
|
|
|
this.deletePhoto();
|
2020-11-03 11:04:45 +01:00
|
|
|
this.saveStakeholder(callback, errorCallback);
|
2020-10-19 11:07:43 +02:00
|
|
|
} else {
|
2020-11-03 11:04:45 +01:00
|
|
|
this.saveStakeholder(callback, errorCallback);
|
2020-10-19 11:07:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 13:06:47 +01:00
|
|
|
public saveStakeholder(callback: Function, errorCallback: Function = null) {
|
2020-10-19 11:07:43 +02:00
|
|
|
if (this.isNew) {
|
|
|
|
if (!this.stakeholderFb.value.isDefault) {
|
|
|
|
let stakeholder = this.defaultStakeholders.find(value => value._id === this.stakeholderFb.value.defaultId);
|
|
|
|
this.stakeholderFb.setValue(this.stakeholderUtils.createFunderFromDefaultProfile(this.stakeholderFb.value,
|
|
|
|
(stakeholder ? stakeholder.topics : [])));
|
|
|
|
}
|
|
|
|
this.removePhoto();
|
2020-11-13 17:42:12 +01:00
|
|
|
this.subscriptions.push(this.stakeholderService.buildStakeholder(this.properties.monitorServiceAPIURL,
|
2020-10-19 11:07:43 +02:00
|
|
|
this.stakeholderFb.value).subscribe(stakeholder => {
|
2021-03-04 12:35:10 +01:00
|
|
|
this.notification.entity = stakeholder._id;
|
|
|
|
this.notification.stakeholder = stakeholder.alias;
|
|
|
|
this.notification.stakeholderType = stakeholder.type;
|
|
|
|
this.notification.groups = [Role.curator(stakeholder.type)];
|
|
|
|
this.notify.sendNotification(this.notification);
|
2020-12-03 16:00:31 +01:00
|
|
|
UIkit.notification(stakeholder.name + ' has been <b>successfully created</b>', {
|
2020-11-03 11:04:45 +01:00
|
|
|
status: 'success',
|
2020-12-01 16:43:43 +01:00
|
|
|
timeout: 6000,
|
2020-12-08 12:41:49 +01:00
|
|
|
pos: 'bottom-right'
|
2020-11-03 11:04:45 +01:00
|
|
|
});
|
2020-10-19 11:07:43 +02:00
|
|
|
callback(stakeholder);
|
2020-11-03 11:04:45 +01:00
|
|
|
}, error => {
|
|
|
|
UIkit.notification('An error has occurred. Please try again later', {
|
|
|
|
status: 'danger',
|
2020-12-01 16:43:43 +01:00
|
|
|
timeout: 6000,
|
2020-12-08 12:41:49 +01:00
|
|
|
pos: 'bottom-right'
|
2020-11-03 11:04:45 +01:00
|
|
|
});
|
2020-11-03 13:06:47 +01:00
|
|
|
if (errorCallback) {
|
2020-11-03 11:04:45 +01:00
|
|
|
errorCallback(error)
|
|
|
|
}
|
2020-11-13 17:42:12 +01:00
|
|
|
}));
|
2020-10-19 11:07:43 +02:00
|
|
|
} else {
|
2020-12-08 10:09:07 +01:00
|
|
|
this.stakeholderFb.get('alias').enable();
|
2020-10-19 11:07:43 +02:00
|
|
|
this.stakeholderFb.get('type').enable();
|
2020-11-03 13:06:47 +01:00
|
|
|
this.stakeholderFb.get('index_id').enable();
|
|
|
|
this.stakeholderFb.get('index_name').enable();
|
|
|
|
this.stakeholderFb.get('index_shortName').enable();
|
2020-11-13 17:42:12 +01:00
|
|
|
this.subscriptions.push(this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, this.stakeholderFb.value).subscribe(stakeholder => {
|
2021-03-04 12:35:10 +01:00
|
|
|
this.notification.entity = stakeholder._id;
|
|
|
|
this.notification.stakeholder = stakeholder.alias;
|
|
|
|
this.notification.stakeholderType = stakeholder.type;
|
|
|
|
this.notification.groups = [Role.curator(stakeholder.type), Role.manager(stakeholder.type, stakeholder.alias)];
|
|
|
|
this.notify.sendNotification(this.notification);
|
2020-12-03 16:00:31 +01:00
|
|
|
UIkit.notification(stakeholder.name + ' has been <b>successfully saved</b>', {
|
2020-11-03 11:04:45 +01:00
|
|
|
status: 'success',
|
2020-12-01 16:43:43 +01:00
|
|
|
timeout: 6000,
|
2020-12-08 12:41:49 +01:00
|
|
|
pos: 'bottom-right'
|
2020-11-03 11:04:45 +01:00
|
|
|
});
|
2020-10-19 11:07:43 +02:00
|
|
|
callback(stakeholder);
|
2020-11-03 11:04:45 +01:00
|
|
|
}, error => {
|
|
|
|
UIkit.notification('An error has occurred. Please try again later', {
|
|
|
|
status: 'danger',
|
2020-12-01 16:43:43 +01:00
|
|
|
timeout: 6000,
|
2020-12-08 12:41:49 +01:00
|
|
|
pos: 'bottom-right'
|
2020-11-03 11:04:45 +01:00
|
|
|
});
|
2020-11-13 17:42:12 +01:00
|
|
|
}));
|
2020-10-19 11:07:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fileChangeEvent(event) {
|
|
|
|
if (event.target.files && event.target.files[0]) {
|
|
|
|
this.file = event.target.files[0];
|
|
|
|
if (this.file.type !== 'image/png' && this.file.type !== 'image/jpeg') {
|
|
|
|
this.uploadError = 'You must choose a file with type: image/png or image/jpeg!';
|
2020-10-19 23:18:09 +02:00
|
|
|
this.stakeholderFb.get('isUpload').setValue(false);
|
|
|
|
this.stakeholderFb.get('isUpload').markAsDirty();
|
2020-10-19 11:07:43 +02:00
|
|
|
this.removePhoto();
|
|
|
|
} else if (this.file.size > this.maxsize) {
|
|
|
|
this.uploadError = 'File exceeds size\'s limit! Maximum resolution is 256x256 pixels.';
|
2020-10-19 23:18:09 +02:00
|
|
|
this.stakeholderFb.get('isUpload').setValue(false);
|
|
|
|
this.stakeholderFb.get('isUpload').markAsDirty();
|
2020-10-19 17:06:06 +02:00
|
|
|
this.removePhoto();
|
2020-10-19 11:07:43 +02:00
|
|
|
} else {
|
|
|
|
this.uploadError = null;
|
|
|
|
const reader = new FileReader();
|
|
|
|
reader.readAsDataURL(this.file);
|
|
|
|
reader.onload = () => {
|
|
|
|
this.photo = reader.result;
|
|
|
|
this.stakeholderFb.get('isUpload').setValue(true);
|
2020-10-19 17:06:06 +02:00
|
|
|
this.stakeholderFb.get('isUpload').markAsDirty();
|
2020-10-19 11:07:43 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
initPhoto() {
|
2020-10-19 17:06:06 +02:00
|
|
|
if (this.stakeholderFb.value.isUpload) {
|
|
|
|
this.photo = this.properties.utilsService + "/download/" + this.stakeholderFb.get('logoUrl').value;
|
2020-10-19 11:07:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
removePhoto() {
|
2020-10-19 17:06:06 +02:00
|
|
|
if (this.file) {
|
|
|
|
if (typeof document != 'undefined') {
|
|
|
|
(<HTMLInputElement>document.getElementById("photo")).value = "";
|
|
|
|
}
|
|
|
|
this.initPhoto();
|
|
|
|
this.file = null;
|
2020-10-19 11:07:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
remove() {
|
2020-10-19 23:18:09 +02:00
|
|
|
this.stakeholderFb.get('isUpload').setValue(false);
|
|
|
|
this.stakeholderFb.get('isUpload').markAsDirty();
|
2020-10-19 17:06:06 +02:00
|
|
|
this.removePhoto();
|
2020-12-18 12:01:58 +01:00
|
|
|
this.stakeholderFb.get('logoUrl').setValue(null);
|
2020-10-19 11:07:43 +02:00
|
|
|
if (this.stakeholder.isUpload) {
|
|
|
|
this.deleteCurrentPhoto = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public deletePhoto() {
|
2021-11-12 13:16:51 +01:00
|
|
|
if (this.stakeholder.logoUrl && this.stakeholder.isUpload) {
|
2021-11-26 10:52:26 +01:00
|
|
|
this.subscriptions.push(this.utilsService.deletePhoto(this.properties.utilsService + '/delete/' +
|
|
|
|
encodeURIComponent(this.stakeholder.type) + "/" + encodeURIComponent(this.stakeholder.alias) + "/" + this.stakeholder.logoUrl).subscribe());
|
2020-10-19 11:07:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|