Revision 60573
Added by Konstantinos Triantafyllou about 3 years ago
edit-stakeholder.component.ts | ||
---|---|---|
1 |
import {Component, Input, OnDestroy} from "@angular/core"; |
|
1 |
import {Component, Input, OnDestroy, ViewChild} from "@angular/core";
|
|
2 | 2 |
import {Stakeholder} from "../../openaireLibrary/monitor/entities/stakeholder"; |
3 | 3 |
import {FormBuilder, FormGroup, Validators} from "@angular/forms"; |
4 | 4 |
import {StakeholderUtils} from "../../utils/indicator-utils"; |
... | ... | |
8 | 8 |
import {properties} from "../../../environments/environment"; |
9 | 9 |
import {StakeholderService} from "../../openaireLibrary/monitor/services/stakeholder.service"; |
10 | 10 |
import {UtilitiesService} from "../../openaireLibrary/services/utilities.service"; |
11 |
import {Session, User} from "../../openaireLibrary/login/utils/helper.class"; |
|
11 |
import {Role, Session, User} from "../../openaireLibrary/login/utils/helper.class";
|
|
12 | 12 |
import {UserManagementService} from "../../openaireLibrary/services/user-management.service"; |
13 | 13 |
import {StringUtils} from "../../openaireLibrary/utils/string-utils.class"; |
14 |
import {NotifyFormComponent} from "../../openaireLibrary/notifications/notify-form/notify-form.component"; |
|
15 |
import {NotificationUtils} from "../../openaireLibrary/notifications/notification-utils"; |
|
16 |
import {Notification} from "../../openaireLibrary/notifications/notifications"; |
|
14 | 17 |
|
15 | 18 |
declare var UIkit; |
16 | 19 |
|
17 | 20 |
@Component({ |
18 | 21 |
selector: 'edit-stakeholder', |
19 | 22 |
template: ` |
20 |
<div *ngIf="stakeholderFb && user" [ngStyle]="{'max-height': maxHeight}"
|
|
23 |
<div [ngStyle]="{'max-height': maxHeight}" |
|
21 | 24 |
[class.uk-padding-small]="!paddingLarge" [class.uk-padding-large]="paddingLarge" |
22 |
class="uk-overflow-auto uk-padding-remove-bottom" |
|
23 |
[formGroup]="stakeholderFb"> |
|
24 |
<div class="uk-grid" [class.uk-margin-small-bottom]="!paddingLarge" [class.uk-margin-large-bottom]="paddingLarge" uk-grid uk-height-match=".uk-form-hint"> |
|
25 |
<div dashboard-input class="uk-width-1-2@m" [formInput]="stakeholderFb.get('name')" label="Name" |
|
26 |
placeholder="Write a name..." |
|
27 |
hint="Set a name for your profile."></div> |
|
28 |
<div dashboard-input class="uk-width-1-2@m" [formInput]="stakeholderFb.get('alias')" |
|
29 |
hint="Set an URL alias for your profile." |
|
30 |
label="URL Alias" placeholder="Write an alias..."></div> |
|
31 |
<div dashboard-input class="uk-width-1-3@m" [formInput]="stakeholderFb.get('index_id')" |
|
32 |
label="Index ID" placeholder="Write index ID."> |
|
33 |
</div> |
|
34 |
<div dashboard-input class="uk-width-1-3@m" [formInput]="stakeholderFb.get('index_name')" |
|
35 |
label="Index Name" placeholder="Write index name."> |
|
36 |
</div> |
|
37 |
<div dashboard-input class="uk-width-1-3@m" [formInput]="stakeholderFb.get('index_shortName')" |
|
38 |
label="Index Short Name" placeholder="Write index short name."> |
|
39 |
</div> |
|
40 |
<div dashboard-input class="uk-width-1-1" [type]="'textarea'" placeholder="Write a description..." |
|
41 |
hint="Write a description for your profile" |
|
42 |
[rows]="4" [formInput]="stakeholderFb.get('description')" label="Description"></div> |
|
43 |
<input #file id="photo" type="file" class="uk-hidden" (change)="fileChangeEvent($event)"/> |
|
44 |
<div dashboard-input class="uk-width-1-1" [hideControl]="stakeholderFb.get('isUpload').value" |
|
45 |
hint="Upload or link the logo of your profile" [placeholder]="'Write link to the logo'" |
|
46 |
[formInput]="stakeholderFb.get('logoUrl')" label="Logo"> |
|
47 |
<div *ngIf="!stakeholderFb.get('isUpload').value" class="uk-width-2-5@l uk-width-1-1"> |
|
48 |
<div class="uk-grid uk-flex uk-flex-middle" uk-grid> |
|
49 |
<div class="uk-width-3-4@l uk-width-1-1 uk-flex uk-flex-center"> |
|
50 |
<button class="uk-button uk-button-secondary uk-flex uk-flex-middle uk-flex-wrap" |
|
51 |
(click)="file.click()"> |
|
52 |
<icon name="cloud_upload" [flex]="true"></icon> |
|
53 |
<span class="uk-margin-small-left">Upload a file</span> |
|
25 |
class="uk-overflow-auto uk-padding-remove-bottom"> |
|
26 |
<form *ngIf="stakeholderFb" [formGroup]="stakeholderFb"> |
|
27 |
<div class="uk-grid" [class.uk-margin-small-bottom]="!paddingLarge" |
|
28 |
[class.uk-margin-large-bottom]="paddingLarge" uk-grid uk-height-match=".uk-form-hint"> |
|
29 |
<div dashboard-input class="uk-width-1-2@m" [formInput]="stakeholderFb.get('name')" label="Name" |
|
30 |
placeholder="Write a name..." |
|
31 |
hint="Set a name for your profile."></div> |
|
32 |
<div dashboard-input class="uk-width-1-2@m" [formInput]="stakeholderFb.get('alias')" |
|
33 |
hint="Set an URL alias for your profile." |
|
34 |
label="URL Alias" placeholder="Write an alias..."></div> |
|
35 |
<div dashboard-input class="uk-width-1-3@m" [formInput]="stakeholderFb.get('index_id')" |
|
36 |
label="Index ID" placeholder="Write index ID."> |
|
37 |
</div> |
|
38 |
<div dashboard-input class="uk-width-1-3@m" [formInput]="stakeholderFb.get('index_name')" |
|
39 |
label="Index Name" placeholder="Write index name."> |
|
40 |
</div> |
|
41 |
<div dashboard-input class="uk-width-1-3@m" [formInput]="stakeholderFb.get('index_shortName')" |
|
42 |
label="Index Short Name" placeholder="Write index short name."> |
|
43 |
</div> |
|
44 |
<div dashboard-input class="uk-width-1-1" [type]="'textarea'" placeholder="Write a description..." |
|
45 |
hint="Write a description for your profile" |
|
46 |
[rows]="4" [formInput]="stakeholderFb.get('description')" label="Description"></div> |
|
47 |
<input #file id="photo" type="file" class="uk-hidden" (change)="fileChangeEvent($event)"/> |
|
48 |
<div dashboard-input class="uk-width-1-1" type="logoURL" flex="top" [hideControl]="stakeholderFb.get('isUpload').value" |
|
49 |
hint="Upload or link the logo of your profile" [placeholder]="'Write link to the logo'" |
|
50 |
[formInput]="stakeholderFb.get('logoUrl')" label="Logo"> |
|
51 |
<div *ngIf="!stakeholderFb.get('isUpload').value" style="margin-top: 7px;" class="uk-width-2-5@l uk-width-1-1"> |
|
52 |
<div class="uk-grid uk-flex uk-flex-middle" uk-grid> |
|
53 |
<div class="uk-width-3-4@l uk-width-1-1 uk-flex uk-flex-center"> |
|
54 |
<button class="uk-button uk-button-secondary uk-flex uk-flex-middle uk-flex-wrap" |
|
55 |
(click)="file.click()"> |
|
56 |
<icon name="cloud_upload" [flex]="true"></icon> |
|
57 |
<span class="uk-margin-small-left">Upload a file</span> |
|
58 |
</button> |
|
59 |
</div> |
|
60 |
<div class="uk-text-center uk-text-bold uk-width-expand"> |
|
61 |
OR |
|
62 |
</div> |
|
63 |
</div> |
|
64 |
</div> |
|
65 |
<div *ngIf="stakeholderFb.get('isUpload').value" class="uk-width-1-1 uk-flex uk-flex-middle"> |
|
66 |
<div class="uk-card uk-card-default uk-text-center uk-border-circle"> |
|
67 |
<img class="uk-position-center" [src]="photo"> |
|
68 |
</div> |
|
69 |
<div class="uk-margin-left"> |
|
70 |
<button (click)="remove()" class="uk-button-secondary outlined uk-icon-button"> |
|
71 |
<icon name="remove"></icon> |
|
54 | 72 |
</button> |
55 | 73 |
</div> |
56 |
<div class="uk-text-center uk-text-bold uk-width-expand"> |
|
57 |
OR |
|
74 |
<div class="uk-margin-small-left"> |
|
75 |
<button class="uk-button-secondary uk-icon-button" (click)="file.click()"> |
|
76 |
<icon name="edit"></icon> |
|
77 |
</button> |
|
58 | 78 |
</div> |
59 | 79 |
</div> |
60 | 80 |
</div> |
61 |
<div *ngIf="stakeholderFb.get('isUpload').value" class="uk-width-1-1 uk-flex uk-flex-middle"> |
|
62 |
<div class="uk-card uk-card-default uk-text-center uk-border-circle"> |
|
63 |
<img class="uk-position-center" [src]="photo"> |
|
81 |
<div *ngIf="uploadError" class="uk-text-danger uk-width-1-1">{{uploadError}}</div> |
|
82 |
<div class="uk-width-1-1 uk-grid uk-child-width-1-1" [class.uk-child-width-1-2@m]="!canChooseType" |
|
83 |
[class.uk-child-width-1-3@m]="canChooseType" uk-grid> |
|
84 |
<div dashboard-input [formInput]="stakeholderFb.get('visibility')" |
|
85 |
[placeholder]="'Select a status'" |
|
86 |
label="Status" hint="Select the visibility status of your profile" |
|
87 |
[options]="stakeholderUtils.statuses" type="select"> |
|
64 | 88 |
</div> |
65 |
<div class="uk-margin-left"> |
|
66 |
<button (click)="remove()" class="uk-button-secondary outlined uk-icon-button"> |
|
67 |
<icon name="remove"></icon> |
|
68 |
</button> |
|
89 |
<div dashboard-input [formInput]="stakeholderFb.get('type')" |
|
90 |
[placeholder]="'Select a type'" hint="Select the type of your profile" |
|
91 |
label="Type" [options]="types" type="select"> |
|
69 | 92 |
</div> |
70 |
<div class="uk-margin-small-left"> |
|
71 |
<button class="uk-button-secondary uk-icon-button" (click)="file.click()"> |
|
72 |
<icon name="edit"></icon> |
|
73 |
</button> |
|
74 |
</div> |
|
93 |
<ng-container *ngIf="canChooseType"> |
|
94 |
<div [placeholder]="'Select a template'" |
|
95 |
hint="Select a template for your profile" |
|
96 |
dashboard-input class="uk-width-1-3@m" [formInput]="stakeholderFb.get('defaultId')" |
|
97 |
label="Template" [options]="defaultStakeholdersOptions" type="select"></div> |
|
98 |
</ng-container> |
|
75 | 99 |
</div> |
76 | 100 |
</div> |
77 |
<div *ngIf="!stakeholderFb.get('isUpload').value && !secure" class="uk-margin-remove-top uk-width-1-1"> |
|
78 |
<div class="uk-flex uk-flex-right" uk-grid> |
|
79 |
<div class="uk-width-3-5@l uk-width-1-1 uk-text-small uk-text-warning"> |
|
80 |
<span class="uk-text-bold">Note:</span> Prefer urls like "<span class="uk-text-bold">https://</span>example.com/my-secure-image.png" |
|
81 |
instead of "<span class="uk-text-bold">http://</span>example.com/my-image.png". |
|
82 |
<span class="uk-text-bold">Browsers may not load non secure content.</span> |
|
83 |
</div> |
|
84 |
</div> |
|
85 |
</div> |
|
86 |
<div *ngIf="uploadError" class="uk-text-danger uk-width-1-1">{{uploadError}}</div> |
|
87 |
<div dashboard-input class="uk-width-1-3@m" [formInput]="stakeholderFb.get('visibility')" |
|
88 |
[placeholder]="'Select a status'" |
|
89 |
label="Status" hint="Select the visibility status of your profile" |
|
90 |
[options]="stakeholderUtils.statuses" type="select"> |
|
91 |
</div> |
|
92 |
<div dashboard-input class="uk-width-1-3@m" [formInput]="stakeholderFb.get('type')" |
|
93 |
[placeholder]="'Select a type'" hint="Select the type of your profile" |
|
94 |
label="Type" [options]="types" type="select"> |
|
95 |
</div> |
|
96 |
<ng-container |
|
97 |
*ngIf="!stakeholderFb.get('isDefault').value && isNew && stakeholderFb.get('type').valid && defaultStakeholdersOptions"> |
|
98 |
<div [placeholder]="'Select a template'" |
|
99 |
hint="Select a template for your profile" |
|
100 |
dashboard-input class="uk-width-1-3@m" [formInput]="stakeholderFb.get('defaultId')" |
|
101 |
label="Template" [options]="defaultStakeholdersOptions" type="select"></div> |
|
102 |
</ng-container> |
|
103 |
</div> |
|
101 |
</form> |
|
102 |
<div #notify notify-form [class.uk-hidden]="properties.environment !== 'development'" class="uk-width-1-1 uk-margin-medium-top uk-margin-medium-bottom"></div> |
|
104 | 103 |
</div>`, |
105 | 104 |
styleUrls: ['edit-stakeholder.component.css'] |
106 | 105 |
}) |
... | ... | |
132 | 131 |
public deleteCurrentPhoto: boolean = false; |
133 | 132 |
private maxsize: number = 200 * 1024; |
134 | 133 |
user: User; |
134 |
@ViewChild('notify') notify: NotifyFormComponent; |
|
135 |
private notification: Notification; |
|
135 | 136 |
|
136 | 137 |
constructor(private fb: FormBuilder, |
137 | 138 |
private stakeholderService: StakeholderService, |
... | ... | |
204 | 205 |
this.stakeholderFb.setControl('defaultId', this.fb.control(stakeholder.defaultId, Validators.required)); |
205 | 206 |
} |
206 | 207 |
if (!isNew) { |
208 |
this.notification = NotificationUtils.editStakeholder(this.user.firstname + ' ' + this.user.lastname, this.stakeholder.name); |
|
209 |
this.notify.reset(this.notification.message); |
|
207 | 210 |
if (this.isAdmin) { |
208 | 211 |
if (this.disableAlias) { |
209 | 212 |
setTimeout(() => { |
... | ... | |
222 | 225 |
this.stakeholderFb.get('type').disable(); |
223 | 226 |
}, 0); |
224 | 227 |
} else { |
228 |
this.notification = NotificationUtils.createStakeholder(this.user.firstname + ' ' + this.user.lastname); |
|
229 |
this.notify.reset(this.notification.message); |
|
225 | 230 |
setTimeout(() => { |
226 | 231 |
this.stakeholderFb.get('type').enable(); |
227 | 232 |
}, 0); |
... | ... | |
244 | 249 |
return this.stakeholderFb && this.stakeholderFb.dirty; |
245 | 250 |
} |
246 | 251 |
|
252 |
public get canChooseType(): boolean { |
|
253 |
return !this.stakeholderFb.get('isDefault').value && this.isNew && this.stakeholderFb.get('type').valid && !!this.defaultStakeholdersOptions; |
|
254 |
} |
|
255 |
|
|
247 | 256 |
reset() { |
248 | 257 |
this.uploadError = null; |
249 | 258 |
this.stakeholderFb = null; |
... | ... | |
298 | 307 |
this.removePhoto(); |
299 | 308 |
this.subscriptions.push(this.stakeholderService.buildStakeholder(this.properties.monitorServiceAPIURL, |
300 | 309 |
this.stakeholderFb.value).subscribe(stakeholder => { |
310 |
this.notification.entity = stakeholder._id; |
|
311 |
this.notification.stakeholder = stakeholder.alias; |
|
312 |
this.notification.stakeholderType = stakeholder.type; |
|
313 |
this.notification.groups = [Role.curator(stakeholder.type)]; |
|
314 |
this.notify.sendNotification(this.notification); |
|
301 | 315 |
UIkit.notification(stakeholder.name + ' has been <b>successfully created</b>', { |
302 | 316 |
status: 'success', |
303 | 317 |
timeout: 6000, |
... | ... | |
321 | 335 |
this.stakeholderFb.get('index_name').enable(); |
322 | 336 |
this.stakeholderFb.get('index_shortName').enable(); |
323 | 337 |
this.subscriptions.push(this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, this.stakeholderFb.value).subscribe(stakeholder => { |
338 |
this.notification.entity = stakeholder._id; |
|
339 |
this.notification.stakeholder = stakeholder.alias; |
|
340 |
this.notification.stakeholderType = stakeholder.type; |
|
341 |
this.notification.groups = [Role.curator(stakeholder.type), Role.manager(stakeholder.type, stakeholder.alias)]; |
|
342 |
this.notify.sendNotification(this.notification); |
|
324 | 343 |
UIkit.notification(stakeholder.name + ' has been <b>successfully saved</b>', { |
325 | 344 |
status: 'success', |
326 | 345 |
timeout: 6000, |
Also available in: Unified diff
[Monitor dashboard | Trunk]: Notifications for development