|
|
@ -1,4 +1,4 @@
|
|
|
|
import {Component, Input} from "@angular/core";
|
|
|
|
import {Component, Input, OnDestroy} from "@angular/core";
|
|
|
|
import {Stakeholder} from "../../openaireLibrary/monitor/entities/stakeholder";
|
|
|
|
import {Stakeholder} from "../../openaireLibrary/monitor/entities/stakeholder";
|
|
|
|
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
|
|
|
|
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
|
|
|
|
import {StakeholderUtils} from "../../utils/indicator-utils";
|
|
|
|
import {StakeholderUtils} from "../../utils/indicator-utils";
|
|
|
@ -12,9 +12,11 @@ import {UtilitiesService} from "../../openaireLibrary/services/utilities.service
|
|
|
|
@Component({
|
|
|
|
@Component({
|
|
|
|
selector: 'edit-stakeholder',
|
|
|
|
selector: 'edit-stakeholder',
|
|
|
|
template: `
|
|
|
|
template: `
|
|
|
|
<div *ngIf="stakeholderFb" [ngStyle]="{'max-height': maxHeight}" class="uk-padding-small uk-overflow-auto" [formGroup]="stakeholderFb">
|
|
|
|
<div *ngIf="stakeholderFb" [ngStyle]="{'max-height': maxHeight}" class="uk-padding-small uk-overflow-auto"
|
|
|
|
|
|
|
|
[formGroup]="stakeholderFb">
|
|
|
|
<div class="uk-flex uk-flex-bottom" uk-grid>
|
|
|
|
<div class="uk-flex uk-flex-bottom" uk-grid>
|
|
|
|
<div dashboard-input class="uk-width-1-2@m" [formInput]="stakeholderFb.get('name')" label="Name" placeholder="Write a name..."
|
|
|
|
<div dashboard-input class="uk-width-1-2@m" [formInput]="stakeholderFb.get('name')" label="Name"
|
|
|
|
|
|
|
|
placeholder="Write a name..."
|
|
|
|
hint="Set a name for your profile."></div>
|
|
|
|
hint="Set a name for your profile."></div>
|
|
|
|
<div dashboard-input class="uk-width-1-2@m" [formInput]="stakeholderFb.get('alias')"
|
|
|
|
<div dashboard-input class="uk-width-1-2@m" [formInput]="stakeholderFb.get('alias')"
|
|
|
|
hint="Set an URL alias for your profile."
|
|
|
|
hint="Set an URL alias for your profile."
|
|
|
@ -32,56 +34,61 @@ import {UtilitiesService} from "../../openaireLibrary/services/utilities.service
|
|
|
|
<div dashboard-input class="uk-width-1-1" [type]="'textarea'" placeholder="Write a description..."
|
|
|
|
<div dashboard-input class="uk-width-1-1" [type]="'textarea'" placeholder="Write a description..."
|
|
|
|
hint="Write a description for your profile"
|
|
|
|
hint="Write a description for your profile"
|
|
|
|
[rows]="4" [formInput]="stakeholderFb.get('description')" label="Description"></div>
|
|
|
|
[rows]="4" [formInput]="stakeholderFb.get('description')" label="Description"></div>
|
|
|
|
<div dashboard-input class="uk-width-1-2@m" [formInput]="stakeholderFb.get('visibility')"
|
|
|
|
<input #file id="photo" type="file" class="uk-hidden" (change)="fileChangeEvent($event)"/>
|
|
|
|
|
|
|
|
<div dashboard-input class="uk-width-1-1" [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" class="uk-width-2-5@m uk-width-1-1">
|
|
|
|
|
|
|
|
<div class="uk-grid uk-flex uk-flex-middle" uk-grid>
|
|
|
|
|
|
|
|
<div class="uk-width-1-2@m uk-width-1-1 uk-text-center">
|
|
|
|
|
|
|
|
<button class="uk-button uk-button-secondary" (click)="file.click()">Upload a file</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 small">
|
|
|
|
|
|
|
|
<icon name="remove"></icon>
|
|
|
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="uk-margin-small-left">
|
|
|
|
|
|
|
|
<button class="uk-button-secondary uk-icon-button small" (click)="file.click()">
|
|
|
|
|
|
|
|
<icon name="edit"></icon>
|
|
|
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div *ngIf="uploadError" class="uk-text-danger uk-width-1-1">{{uploadError}}</div>
|
|
|
|
|
|
|
|
<div dashboard-input class="uk-width-1-3@m" [formInput]="stakeholderFb.get('visibility')"
|
|
|
|
[placeholder]="'Select a status'"
|
|
|
|
[placeholder]="'Select a status'"
|
|
|
|
label="Status" hint="Select the visibility status of your profile"
|
|
|
|
label="Status" hint="Select the visibility status of your profile"
|
|
|
|
[options]="stakeholderUtils.statuses" type="select">
|
|
|
|
[options]="stakeholderUtils.statuses" type="select">
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div dashboard-input class="uk-width-1-2@m" [formInput]="stakeholderFb.get('type')"
|
|
|
|
<div dashboard-input class="uk-width-1-3@m" [formInput]="stakeholderFb.get('type')"
|
|
|
|
[placeholder]="'Select a type'" hint="Select the type of your profile"
|
|
|
|
[placeholder]="'Select a type'" hint="Select the type of your profile"
|
|
|
|
label="Type" [options]="stakeholderUtils.types" type="select">
|
|
|
|
label="Type" [options]="stakeholderUtils.types" type="select">
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<ng-container *ngIf="!stakeholderFb.get('isDefault').value && isNew && stakeholderFb.get('type').valid">
|
|
|
|
<ng-container *ngIf="!stakeholderFb.get('isDefault').value && isNew && stakeholderFb.get('type').valid">
|
|
|
|
<div *ngIf="defaultStakeholdersOptions.length === 0" class="uk-text-danger uk-width-1-1">No default profiles has been found
|
|
|
|
<div *ngIf="defaultStakeholdersOptions.length === 0" class="uk-text-danger uk-width-1-3@m">No default profiles
|
|
|
|
|
|
|
|
has been found
|
|
|
|
for this type.
|
|
|
|
for this type.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div *ngIf="defaultStakeholdersOptions.length > 0" [placeholder]="'Select a template'"
|
|
|
|
<div *ngIf="defaultStakeholdersOptions.length > 0" [placeholder]="'Select a template'"
|
|
|
|
hint="Select a template for your profile"
|
|
|
|
hint="Select a template for your profile"
|
|
|
|
dashboard-input class="uk-width-1-1" [formInput]="stakeholderFb.get('defaultId')"
|
|
|
|
dashboard-input class="uk-width-1-3@m" [formInput]="stakeholderFb.get('defaultId')"
|
|
|
|
label="Template" [options]="defaultStakeholdersOptions" type="select"></div>
|
|
|
|
label="Template" [options]="defaultStakeholdersOptions" type="select"></div>
|
|
|
|
</ng-container>
|
|
|
|
</ng-container>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="uk-grid uk-flex uk-flex-center uk-flex-middle" uk-grid>
|
|
|
|
</div>`,
|
|
|
|
<!--<div class="uk-width-1-5">
|
|
|
|
styleUrls: ['edit-stakeholder.component.css']
|
|
|
|
<img [src]="photo">
|
|
|
|
|
|
|
|
</div>-->
|
|
|
|
|
|
|
|
<div *ngIf="!stakeholderFb.get('isUpload').value" class="uk-width-expand">
|
|
|
|
|
|
|
|
<div dashboard-input [formInput]="stakeholderFb.get('logoUrl')" label="Logo Path/URL">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!--<ng-template #uploadPhoto>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
|
|
|
<div uk-form-custom class="uk-width-auto">
|
|
|
|
|
|
|
|
<input id="photo" type="file" (change)="fileChangeEvent($event)"/>
|
|
|
|
|
|
|
|
<button class="md-btn md-btn-primary md-btn-small" tabindex="-1">Upload</button>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<button *ngIf="file || (stakeholder.isUpload && !deleteCurrentPhoto)" class="md-btn md-btn-danger md-btn-small uk-margin-small-left" (click)="remove()">Remove</button>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div *ngIf="uploadError" class="uk-text-danger uk-margin-small-top">{{uploadError}}</div>
|
|
|
|
|
|
|
|
</ng-template>
|
|
|
|
|
|
|
|
<div *ngIf="stakeholderFb.get('isUpload').value" class="uk-width-expand uk-text-center">
|
|
|
|
|
|
|
|
<ng-container [ngTemplateOutlet]="uploadPhoto"></ng-container>
|
|
|
|
|
|
|
|
</div>-->
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!--<div *ngIf="!stakeholderFb.get('isUpload').value" class="uk-text-center uk-margin-bottom">
|
|
|
|
|
|
|
|
<div>- OR -</div>
|
|
|
|
|
|
|
|
<div class="uk-margin-small-top">
|
|
|
|
|
|
|
|
<ng-container [ngTemplateOutlet]="uploadPhoto"></ng-container>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>-->
|
|
|
|
|
|
|
|
</div>`
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
export class EditStakeholderComponent {
|
|
|
|
export class EditStakeholderComponent implements OnDestroy {
|
|
|
|
@Input()
|
|
|
|
@Input()
|
|
|
|
public maxHeight = 'none';
|
|
|
|
public maxHeight = 'none';
|
|
|
|
public stakeholderFb: FormGroup;
|
|
|
|
public stakeholderFb: FormGroup;
|
|
|
@ -108,8 +115,12 @@ export class EditStakeholderComponent {
|
|
|
|
private utilsService: UtilitiesService) {
|
|
|
|
private utilsService: UtilitiesService) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
|
|
|
|
this.reset();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public init(stakeholder: Stakeholder, stakeholders: Stakeholder[], defaultStakeholders: Stakeholder[], isDefault: boolean, isNew: boolean) {
|
|
|
|
public init(stakeholder: Stakeholder, stakeholders: Stakeholder[], defaultStakeholders: Stakeholder[], isDefault: boolean, isNew: boolean) {
|
|
|
|
this.uploadError = null;
|
|
|
|
this.reset();
|
|
|
|
this.deleteCurrentPhoto = false;
|
|
|
|
this.deleteCurrentPhoto = false;
|
|
|
|
this.stakeholder = stakeholder;
|
|
|
|
this.stakeholder = stakeholder;
|
|
|
|
this.stakeholders = stakeholders;
|
|
|
|
this.stakeholders = stakeholders;
|
|
|
@ -143,17 +154,10 @@ export class EditStakeholderComponent {
|
|
|
|
logoUrl: this.fb.control(this.stakeholder.logoUrl),
|
|
|
|
logoUrl: this.fb.control(this.stakeholder.logoUrl),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.initPhoto();
|
|
|
|
this.initPhoto();
|
|
|
|
|
|
|
|
if (!isDefault) {
|
|
|
|
this.subscriptions.push(this.stakeholderFb.get('type').valueChanges.subscribe(value => {
|
|
|
|
this.subscriptions.push(this.stakeholderFb.get('type').valueChanges.subscribe(value => {
|
|
|
|
this.onTypeChange(value, defaultStakeholders);
|
|
|
|
this.onTypeChange(value, defaultStakeholders);
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
this.subscriptions.push(this.stakeholderFb.get('logoUrl').valueChanges.subscribe(value => {
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
|
|
|
|
this.photo = value;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.photo = 'assets/common-assets/curator-default.png';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
if (!isDefault) {
|
|
|
|
|
|
|
|
this.stakeholderFb.setControl('defaultId', this.fb.control(stakeholder.defaultId, Validators.required));
|
|
|
|
this.stakeholderFb.setControl('defaultId', this.fb.control(stakeholder.defaultId, Validators.required));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isNew) {
|
|
|
|
if (isNew) {
|
|
|
@ -174,10 +178,13 @@ export class EditStakeholderComponent {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public get disabled(): boolean {
|
|
|
|
public get disabled(): boolean {
|
|
|
|
return this.stakeholderFb && (this.stakeholderFb.invalid || (this.stakeholderFb.pristine && !this.isNew && !this.file));
|
|
|
|
return (this.stakeholderFb && this.stakeholderFb.invalid) ||
|
|
|
|
|
|
|
|
(this.stakeholderFb && this.stakeholderFb.pristine && !this.isNew && !this.file) ||
|
|
|
|
|
|
|
|
(this.uploadError && this.uploadError.length > 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
reset() {
|
|
|
|
reset() {
|
|
|
|
|
|
|
|
this.uploadError = null;
|
|
|
|
this.stakeholderFb = null;
|
|
|
|
this.stakeholderFb = null;
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscription) {
|
|
|
|
if (subscription instanceof Subscription) {
|
|
|
@ -202,7 +209,7 @@ export class EditStakeholderComponent {
|
|
|
|
|
|
|
|
|
|
|
|
public save(callback: Function) {
|
|
|
|
public save(callback: Function) {
|
|
|
|
if (this.file) {
|
|
|
|
if (this.file) {
|
|
|
|
this.utilsService.uploadPhoto(this.properties.utilsService + "/upload/stakeholder/" + encodeURIComponent(this.stakeholder.alias), this.file).subscribe(res => {
|
|
|
|
this.utilsService.uploadPhoto(this.properties.utilsService + "/upload/stakeholder/" + encodeURIComponent(this.stakeholderFb.value.alias), this.file).subscribe(res => {
|
|
|
|
this.deletePhoto();
|
|
|
|
this.deletePhoto();
|
|
|
|
this.removePhoto();
|
|
|
|
this.removePhoto();
|
|
|
|
this.stakeholderFb.get('logoUrl').setValue(res.filename);
|
|
|
|
this.stakeholderFb.get('logoUrl').setValue(res.filename);
|
|
|
@ -244,12 +251,10 @@ export class EditStakeholderComponent {
|
|
|
|
this.file = event.target.files[0];
|
|
|
|
this.file = event.target.files[0];
|
|
|
|
if (this.file.type !== 'image/png' && this.file.type !== 'image/jpeg') {
|
|
|
|
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!';
|
|
|
|
this.uploadError = 'You must choose a file with type: image/png or image/jpeg!';
|
|
|
|
this.stakeholderFb.get('isUpload').setValue(false);
|
|
|
|
|
|
|
|
this.removePhoto();
|
|
|
|
this.removePhoto();
|
|
|
|
} else if (this.file.size > this.maxsize) {
|
|
|
|
} else if (this.file.size > this.maxsize) {
|
|
|
|
this.uploadError = 'File exceeds size\'s limit! Maximum resolution is 256x256 pixels.';
|
|
|
|
this.uploadError = 'File exceeds size\'s limit! Maximum resolution is 256x256 pixels.';
|
|
|
|
this.stakeholderFb.get('isUpload').setValue(false);
|
|
|
|
this.removePhoto();
|
|
|
|
this.removePhoto()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
this.uploadError = null;
|
|
|
|
this.uploadError = null;
|
|
|
|
const reader = new FileReader();
|
|
|
|
const reader = new FileReader();
|
|
|
@ -257,38 +262,34 @@ export class EditStakeholderComponent {
|
|
|
|
reader.onload = () => {
|
|
|
|
reader.onload = () => {
|
|
|
|
this.photo = reader.result;
|
|
|
|
this.photo = reader.result;
|
|
|
|
this.stakeholderFb.get('isUpload').setValue(true);
|
|
|
|
this.stakeholderFb.get('isUpload').setValue(true);
|
|
|
|
|
|
|
|
this.stakeholderFb.get('isUpload').markAsDirty();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
initPhoto() {
|
|
|
|
initPhoto() {
|
|
|
|
if (this.stakeholderFb.get('logoUrl').value) {
|
|
|
|
if (this.stakeholderFb.value.isUpload) {
|
|
|
|
if (!this.stakeholderFb.value.isUpload) {
|
|
|
|
|
|
|
|
this.photo = this.stakeholderFb.get('logoUrl').value;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.photo = this.properties.utilsService + "/download/" + this.stakeholderFb.get('logoUrl').value;
|
|
|
|
this.photo = this.properties.utilsService + "/download/" + this.stakeholderFb.get('logoUrl').value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.photo = 'assets/common-assets/curator-default.png';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
removePhoto() {
|
|
|
|
removePhoto() {
|
|
|
|
|
|
|
|
this.stakeholderFb.get('isUpload').setValue(false);
|
|
|
|
|
|
|
|
this.stakeholderFb.get('isUpload').markAsDirty();
|
|
|
|
|
|
|
|
if (this.file) {
|
|
|
|
if (typeof document != 'undefined') {
|
|
|
|
if (typeof document != 'undefined') {
|
|
|
|
(<HTMLInputElement>document.getElementById("photo")).value = "";
|
|
|
|
(<HTMLInputElement>document.getElementById("photo")).value = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.initPhoto();
|
|
|
|
this.initPhoto();
|
|
|
|
this.file = null;
|
|
|
|
this.file = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
remove() {
|
|
|
|
remove() {
|
|
|
|
this.stakeholderFb.get('isUpload').setValue(false);
|
|
|
|
|
|
|
|
if (this.file) {
|
|
|
|
|
|
|
|
this.removePhoto();
|
|
|
|
this.removePhoto();
|
|
|
|
}
|
|
|
|
this.stakeholderFb.setControl('logoUrl', this.fb.control(null));
|
|
|
|
if (this.stakeholder.isUpload) {
|
|
|
|
if (this.stakeholder.isUpload) {
|
|
|
|
this.stakeholderFb.get('logoUrl').setValue(null);
|
|
|
|
|
|
|
|
this.deleteCurrentPhoto = true;
|
|
|
|
this.deleteCurrentPhoto = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|