DSC-1111 Moved logo update to a specific method instead of the generic onsubmit

This commit is contained in:
Mattia Vianelli
2024-02-13 15:49:52 +00:00
parent 6d98bf9d3a
commit 8165b5feee
2 changed files with 37 additions and 76 deletions

View File

@@ -4,28 +4,18 @@
<span>{{type.value + '.edit.logo.label' | translate}}</span> <span>{{type.value + '.edit.logo.label' | translate}}</span>
</div> </div>
<ng-container *ngVar="(dso?.logo | async)?.payload as logo"> <ng-container *ngVar="(dso?.logo | async)?.payload as logo">
<div class="col-12 d-inline-block alert" [ngClass]="{'alert-danger': markLogoForDeletion}" id="logo-section" *ngIf="logo"> <div class="col-12 d-inline-block alert" id="logo-section" *ngIf="logo">
<div class="row"> <div class="row">
<div class="col-8 d-inline-block"> <div class="col-8 d-inline-block">
<ds-comcol-page-logo [alternateText]="type.value + '.logo.alt'" [logo]="logo"></ds-comcol-page-logo> <ds-comcol-page-logo [alternateText]="type.value + '.logo.alt'" [logo]="logo"></ds-comcol-page-logo>
</div> </div>
<div class="col-4 d-inline-block"> <div class="col-4 d-inline-block">
<div *ngIf="logo" class="btn-group btn-group-sm float-right" role="group"> <div *ngIf="logo" class="float-right">
<button (click)="confirmLogoDelete(removeLogo)" *ngIf="!markLogoForDeletion" class="btn btn-danger" <button (click)="confirmLogoDelete(removeLogo)" class="btn btn-danger"
title="{{type.value + '.edit.logo.delete.title' | translate}}" type="button"> title="{{type.value + '.edit.logo.delete.title' | translate}}" type="button">
<i aria-hidden="true" class="fas fa-trash"></i> <i aria-hidden="true" class="fas fa-trash"></i>
{{ 'community.edit.logo.delete.title' | translate}} {{ 'community.edit.logo.delete.title' | translate}}
</button> </button>
<button *ngIf="!markLogoForDeletion" class="btn btn-info" type="button">
<span>
<label (keyup.enter)="$event.stopImmediatePropagation(); fileInput.click()" for="inputFileUploader">
<span role="button">
<i aria-hidden="true" class="fas fa-upload"></i>
{{ 'collection.edit.logo.replace.title' | translate}}
</span>
</label>
</span>
</button>
</div> </div>
</div> </div>
</div> </div>
@@ -65,5 +55,4 @@
<button (click)="c('cancel')" class="btn btn-warning" type="button">{{'form.cancel' | translate}}</button> <button (click)="c('cancel')" class="btn btn-warning" type="button">{{'form.cancel' | translate}}</button>
</div> </div>
</ng-template> </ng-template>
<input #fileInput (change)="handleLogoReplace($event)" [uploader]="uploader" class="d-none" id="inputFileUploader" ng2FileSelect
type="file"/>

View File

@@ -83,8 +83,6 @@ export class ComColFormComponent<T extends Collection | Community> implements On
*/ */
@Output() submitForm: EventEmitter<{ @Output() submitForm: EventEmitter<{
dso: T, dso: T,
uploader: FileUploader,
deleteLogo: boolean,
operations: Operation[], operations: Operation[],
}> = new EventEmitter(); }> = new EventEmitter();
@@ -104,11 +102,6 @@ export class ComColFormComponent<T extends Collection | Community> implements On
*/ */
initializedUploaderOptions = new BehaviorSubject(false); initializedUploaderOptions = new BehaviorSubject(false);
/**
* Is the logo marked to be deleted?
*/
markLogoForDeletion = false;
/** /**
* Array to track all subscriptions and unsubscribe them onDestroy * Array to track all subscriptions and unsubscribe them onDestroy
* @type {Array} * @type {Array}
@@ -174,27 +167,6 @@ export class ComColFormComponent<T extends Collection | Community> implements On
* Checks which new fields were added and sends the updated version of the DSO to the parent component * Checks which new fields were added and sends the updated version of the DSO to the parent component
*/ */
onSubmit() { onSubmit() {
if (this.markLogoForDeletion && hasValue(this.dso.id) && hasValue(this.dso._links.logo)) {
this.dsoService.deleteLogo(this.dso).pipe(
getFirstCompletedRemoteData()
).subscribe((response: RemoteData<NoContent>) => {
if (response.hasSucceeded) {
this.notificationsService.success(
this.translate.get(this.type.value + '.edit.logo.notifications.delete.success.title'),
this.translate.get(this.type.value + '.edit.logo.notifications.delete.success.content')
);
} else {
this.notificationsService.error(
this.translate.get(this.type.value + '.edit.logo.notifications.delete.error.title'),
response.errorMessage
);
}
this.dso.logo = undefined;
this.uploadFilesOptions.method = RestRequestMethod.POST;
this.finish.emit();
});
}
const formMetadata = {} as MetadataMap; const formMetadata = {} as MetadataMap;
this.formModel.forEach((fieldModel: DynamicInputModel) => { this.formModel.forEach((fieldModel: DynamicInputModel) => {
const value: MetadataValue = { const value: MetadataValue = {
@@ -232,8 +204,6 @@ export class ComColFormComponent<T extends Collection | Community> implements On
this.submitForm.emit({ this.submitForm.emit({
dso: updatedDSO, dso: updatedDSO,
uploader: hasValue(this.uploaderComponent) ? this.uploaderComponent.uploader : undefined,
deleteLogo: this.markLogoForDeletion,
operations: operations, operations: operations,
}); });
} }
@@ -254,44 +224,46 @@ export class ComColFormComponent<T extends Collection | Community> implements On
} }
); );
} }
/** /**
* Mark the logo to be deleted * Helper method that provides a modal
* Send out a delete request to remove the logo from the community/collection and display notifications
*/ */
deleteLogo() {
this.markLogoForDeletion = true;
}
/**
* Undo marking the logo to be deleted
*/
undoDeleteLogo() {
this.markLogoForDeletion = false;
}
openModal(content: any) { openModal(content: any) {
this.modalService.open(content); this.modalService.open(content);
} }
/**
* Helper method that confirms the deletion of the logo and handles possible errors
*/
confirmLogoDelete(removeLogo: any) { confirmLogoDelete(removeLogo: any) {
this.modalService.open(removeLogo).result.then( (result) => { //this.refreshCache()
if (result === 'delete') { this.modalService.open(removeLogo).result.then((result) => {
this.deleteLogo(); if (result === 'delete') {
this.onSubmit(); if (hasValue(this.dso.id) && hasValue(this.dso._links.logo)) {
} else if (result === 'cancel') { this.dsoService.deleteLogo(this.dso).pipe(
return; getFirstCompletedRemoteData()
} ).subscribe((response: RemoteData<NoContent>) => {
}); if (response.hasSucceeded) {
} this.notificationsService.success(
this.translate.get(this.type.value + '.edit.logo.notifications.delete.success.title'),
this.translate.get(this.type.value + '.edit.logo.notifications.delete.success.content')
);
} else {
this.notificationsService.error(
this.translate.get(this.type.value + '.edit.logo.notifications.delete.error.title'),
response.errorMessage
);
}
this.dso.logo = undefined;
this.uploadFilesOptions.method = RestRequestMethod.POST;
this.finish.emit();
});
handleLogoReplace(event: Event) { } else if (result === 'cancel') {
const fileInput = event.target as HTMLInputElement; return;
if (fileInput.files && fileInput.files.length > 0) { }
this.markLogoForDeletion = true; }
this.onSubmit();
this.uploader.uploadAll(); }
} );
} }
/** /**