From ab52cdb15825478e2c6e495165a8d76cd13aa57d Mon Sep 17 00:00:00 2001 From: Sondissimo Date: Wed, 31 May 2023 17:25:31 +0200 Subject: [PATCH 01/25] DSC-1111 Provided buttons next to the logo upload/delete to save changes in the edit community page --- .../comcol/comcol-forms/comcol-form/comcol-form.component.html | 3 +++ src/app/shared/upload/uploader/uploader.component.html | 3 +++ src/assets/i18n/en.json5 | 2 ++ 3 files changed, 8 insertions(+) diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html index c79dba42b78..293665e5c16 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html @@ -21,6 +21,9 @@ (click)="undoDeleteLogo()"> + diff --git a/src/app/shared/upload/uploader/uploader.component.html b/src/app/shared/upload/uploader/uploader.component.html index b1fd8199d83..53f088e7cb6 100644 --- a/src/app/shared/upload/uploader/uploader.component.html +++ b/src/app/shared/upload/uploader/uploader.component.html @@ -38,6 +38,9 @@ + {{ uploader.progress }}% {{'uploader.processing' | translate}} diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index e20a724158a..156e8b4aac8 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -1226,6 +1226,8 @@ "community.edit.logo.delete.title": "Delete logo", + "community.edit.logo.add.title": "Add logo", + "community.edit.logo.delete-undo.title": "Undo delete", "community.edit.logo.label": "Community logo", From 2ae82fb07a3a57be5274c3c2b7bbb6978fa8c393 Mon Sep 17 00:00:00 2001 From: Sondissimo Date: Mon, 5 Jun 2023 14:17:34 +0200 Subject: [PATCH 02/25] DSC-1111 Provided buttons next to the logo delete to save changes in the edit community page, also now the file upload is started automatically --- src/app/shared/upload/uploader/uploader.component.html | 3 --- src/app/shared/upload/uploader/uploader.component.ts | 3 +++ src/assets/i18n/en.json5 | 2 -- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/app/shared/upload/uploader/uploader.component.html b/src/app/shared/upload/uploader/uploader.component.html index 53f088e7cb6..b1fd8199d83 100644 --- a/src/app/shared/upload/uploader/uploader.component.html +++ b/src/app/shared/upload/uploader/uploader.component.html @@ -38,9 +38,6 @@ - {{ uploader.progress }}% {{'uploader.processing' | translate}} diff --git a/src/app/shared/upload/uploader/uploader.component.ts b/src/app/shared/upload/uploader/uploader.component.ts index 2072cb4c83b..26fd355871e 100644 --- a/src/app/shared/upload/uploader/uploader.component.ts +++ b/src/app/shared/upload/uploader/uploader.component.ts @@ -130,6 +130,9 @@ export class UploaderComponent { ngAfterViewInit() { this.uploader.onAfterAddingAll = ((items) => { this.onFileSelected.emit(items); + if (this.uploader.queue.length > 0) { + this.uploader.uploadAll(); + } }); if (isUndefined(this.onBeforeUpload)) { this.onBeforeUpload = () => {return;}; diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index 156e8b4aac8..e20a724158a 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -1226,8 +1226,6 @@ "community.edit.logo.delete.title": "Delete logo", - "community.edit.logo.add.title": "Add logo", - "community.edit.logo.delete-undo.title": "Undo delete", "community.edit.logo.label": "Community logo", From dd5e4de97a7402c69601ee856dd351bb0295c303 Mon Sep 17 00:00:00 2001 From: Sondissimo Date: Mon, 5 Jun 2023 15:39:47 +0200 Subject: [PATCH 03/25] DSC-1111 Button is now type button, the trailing space has been removed --- .../comcol-forms/comcol-form/comcol-form.component.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html index 293665e5c16..2dd17956376 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html @@ -21,8 +21,8 @@ (click)="undoDeleteLogo()"> - From 0086cf78e9a3fc51157639f344fa3e8fa2b97ebb Mon Sep 17 00:00:00 2001 From: Sondissimo Date: Wed, 14 Jun 2023 10:37:01 +0200 Subject: [PATCH 04/25] DSC-1111 Synced with main --- .../collection-form.component.ts | 8 +-- .../community-form.component.ts | 6 ++- .../community-metadata.component.html | 2 +- .../comcol-form/comcol-form.component.html | 51 ++++++++++++------- .../comcol-form/comcol-form.component.ts | 31 ++++++++++- .../comcol-metadata.component.ts | 11 +++- src/assets/i18n/en.json5 | 2 + 7 files changed, 84 insertions(+), 27 deletions(-) diff --git a/src/app/collection-page/collection-form/collection-form.component.ts b/src/app/collection-page/collection-form/collection-form.component.ts index aae200b4019..7f2fb81ec85 100644 --- a/src/app/collection-page/collection-form/collection-form.component.ts +++ b/src/app/collection-page/collection-form/collection-form.component.ts @@ -23,7 +23,7 @@ import { getFirstSucceededRemoteListPayload } from '../../core/shared/operators' import { collectionFormEntityTypeSelectionConfig, collectionFormModels, } from './collection-form.models'; import { NONE_ENTITY_TYPE } from '../../core/shared/item-relationships/item-type.resource-type'; import { hasNoValue, isNotNull } from 'src/app/shared/empty.util'; - +import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; /** * Form used for creating and editing collections @@ -64,8 +64,10 @@ export class CollectionFormComponent extends ComColFormComponent imp protected requestService: RequestService, protected objectCache: ObjectCacheService, protected entityTypeService: EntityTypeDataService, - protected chd: ChangeDetectorRef) { - super(formService, translate, notificationsService, authService, requestService, objectCache); + protected chd: ChangeDetectorRef, + protected submissionDefinitionService: SubmissionDefinitionsConfigDataService, + protected modalService: NgbModal) { + super(formService, translate, notificationsService, authService, requestService, objectCache, modalService); } ngOnInit(): void { diff --git a/src/app/community-page/community-form/community-form.component.ts b/src/app/community-page/community-form/community-form.component.ts index fa4809738d9..53f36c30cbf 100644 --- a/src/app/community-page/community-form/community-form.component.ts +++ b/src/app/community-page/community-form/community-form.component.ts @@ -14,6 +14,7 @@ import { AuthService } from '../../core/auth/auth.service'; import { RequestService } from '../../core/data/request.service'; import { ObjectCacheService } from '../../core/cache/object-cache.service'; import { environment } from '../../../environments/environment'; +import {NgbModal} from '@ng-bootstrap/ng-bootstrap'; /** * Form used for creating and editing communities @@ -78,8 +79,9 @@ export class CommunityFormComponent extends ComColFormComponent imple protected authService: AuthService, protected dsoService: CommunityDataService, protected requestService: RequestService, - protected objectCache: ObjectCacheService) { - super(formService, translate, notificationsService, authService, requestService, objectCache); + protected objectCache: ObjectCacheService, + protected modalService: NgbModal) { + super(formService, translate, notificationsService, authService, requestService, objectCache, modalService); } ngOnChanges(changes: SimpleChanges) { diff --git a/src/app/community-page/edit-community-page/community-metadata/community-metadata.component.html b/src/app/community-page/edit-community-page/community-metadata/community-metadata.component.html index 2ca5b768e4d..169f79df678 100644 --- a/src/app/community-page/edit-community-page/community-metadata/community-metadata.component.html +++ b/src/app/community-page/edit-community-page/community-metadata/community-metadata.component.html @@ -1,5 +1,5 @@ + (finish)="returnToEdit()"> diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html index 2dd17956376..c6386634ea6 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html @@ -4,25 +4,28 @@ {{type.value + '.edit.logo.label' | translate}} -
+
- - -
@@ -41,12 +44,24 @@
- - + + + + + + diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts index 631a9f0b197..7767da63996 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts @@ -22,7 +22,7 @@ import { UploaderComponent } from '../../../upload/uploader/uploader.component'; import { Operation } from 'fast-json-patch'; import { NoContent } from '../../../../core/shared/NoContent.model'; import { getFirstCompletedRemoteData } from '../../../../core/shared/operators'; - +import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; /** * A form for creating and editing Communities or Collections */ @@ -118,12 +118,15 @@ export class ComColFormComponent implements On */ protected dsoService: ComColDataService; + public uploader = new FileUploader(this.uploadFilesOptions); + public constructor(protected formService: DynamicFormService, protected translate: TranslateService, protected notificationsService: NotificationsService, protected authService: AuthService, protected requestService: RequestService, - protected objectCache: ObjectCacheService) { + protected objectCache: ObjectCacheService, + protected modalService: NgbModal) { } ngOnInit(): void { @@ -265,6 +268,30 @@ export class ComColFormComponent implements On this.markLogoForDeletion = false; } + openModal(content: any) { + this.modalService.open(content); + } + + confirmLogoDelete(removeLogo: any) { + this.modalService.open(removeLogo).result.then( (result) => { + if (result === 'delete') { + this.deleteLogo(); + this.onSubmit(); + } else if (result === 'cancel') { + return; + } + }); + } + + handleLogoReplace(event: Event) { + const fileInput = event.target as HTMLInputElement; + if (fileInput.files && fileInput.files.length > 0) { + this.markLogoForDeletion = true; + this.onSubmit(); + this.uploader.uploadAll(); + } + } + /** * Refresh the object's cache to ensure the latest version */ diff --git a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts index d59030251dc..1547ad739e8 100644 --- a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts +++ b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts @@ -88,6 +88,15 @@ export class ComcolMetadataComponent imp take(1) ).subscribe((dsoRD: RemoteData) => { this.router.navigate([this.frontendURL + dsoRD.payload.id]); - }); + }); + } + + returnToEdit() { + this.dsoRD$.pipe( + getFirstSucceededRemoteData(), + take(1) + ).subscribe((dsoRD: RemoteData) => { + this.router.navigate([this.frontendURL + dsoRD.payload.id + '/edit/metadata']); + }); } } diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index e20a724158a..315fcb66726 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -978,6 +978,8 @@ "collection.edit.item-mapper.tabs.map": "Map new items", + "collection.edit.logo.replace.title": "Replace logo", + "collection.edit.logo.delete.title": "Delete logo", "collection.edit.logo.delete-undo.title": "Undo delete", From b017f9ad163f131a0149a186071eec499ed8efe6 Mon Sep 17 00:00:00 2001 From: Andrea Barbasso <´andrea.barbasso@4science.com´> Date: Mon, 12 Feb 2024 17:39:59 +0100 Subject: [PATCH 05/25] [DSC-1111] fix logo not showing after upload --- .../comcol-forms/comcol-form/comcol-form.component.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts index 7767da63996..14e625979be 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts @@ -23,6 +23,8 @@ import { Operation } from 'fast-json-patch'; import { NoContent } from '../../../../core/shared/NoContent.model'; import { getFirstCompletedRemoteData } from '../../../../core/shared/operators'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; +import { followLink } from '../../../utils/follow-link-config.model'; + /** * A form for creating and editing Communities or Collections */ @@ -298,6 +300,13 @@ export class ComColFormComponent implements On private refreshCache() { this.requestService.removeByHrefSubstring(this.dso._links.self.href); this.objectCache.remove(this.dso._links.self.href); + this.dsoService.findById(this.dso.id, false, true, followLink('logo')).pipe( + getFirstCompletedRemoteData() + ).subscribe((rd: RemoteData) => { + if (rd.hasSucceeded) { + this.dso = rd.payload; + } + }); } /** From 6d98bf9d3afad0e7e1ec0559e90dac178d59cc97 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Tue, 13 Feb 2024 12:05:30 +0100 Subject: [PATCH 06/25] [DSC-1111] Start implementation refactoring --- .../collection-form/collection-form.component.ts | 4 ++-- .../comcol-form/comcol-form.component.html | 10 ++++++---- .../comcol-forms/comcol-form/comcol-form.component.ts | 10 +++++----- src/app/shared/upload/uploader/uploader.component.ts | 3 --- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/app/collection-page/collection-form/collection-form.component.ts b/src/app/collection-page/collection-form/collection-form.component.ts index 7f2fb81ec85..37bdc13d7e4 100644 --- a/src/app/collection-page/collection-form/collection-form.component.ts +++ b/src/app/collection-page/collection-form/collection-form.component.ts @@ -12,7 +12,7 @@ import { import { Collection } from '../../core/shared/collection.model'; import { ComColFormComponent } from '../../shared/comcol/comcol-forms/comcol-form/comcol-form.component'; import { NotificationsService } from '../../shared/notifications/notifications.service'; -import { CommunityDataService } from '../../core/data/community-data.service'; +import { CollectionDataService } from '../../core/data/collection-data.service'; import { AuthService } from '../../core/auth/auth.service'; import { RequestService } from '../../core/data/request.service'; import { ObjectCacheService } from '../../core/cache/object-cache.service'; @@ -60,7 +60,7 @@ export class CollectionFormComponent extends ComColFormComponent imp protected translate: TranslateService, protected notificationsService: NotificationsService, protected authService: AuthService, - protected dsoService: CommunityDataService, + protected dsoService: CollectionDataService, protected requestService: RequestService, protected objectCache: ObjectCacheService, protected entityTypeService: EntityTypeDataService, diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html index c6386634ea6..4ea3d341d7d 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html @@ -4,8 +4,7 @@ {{type.value + '.edit.logo.label' | translate}}
-
+
@@ -44,8 +43,11 @@
- + diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts index 14e625979be..0c667f25987 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts @@ -75,7 +75,7 @@ export class ComColFormComponent implements On * @type {UploaderOptions} */ uploadFilesOptions: UploaderOptions = Object.assign(new UploaderOptions(), { - autoUpload: false + autoUpload: true }); /** @@ -155,9 +155,9 @@ export class ComColFormComponent implements On this.uploadFilesOptions.url = href; this.uploadFilesOptions.authToken = this.authService.buildAuthHeader(); // If the object already contains a logo, send out a PUT request instead of POST for setting a new logo - if (hasValue(logoRD.payload)) { - this.uploadFilesOptions.method = RestRequestMethod.PUT; - } + // if (hasValue(logoRD.payload)) { + // this.uploadFilesOptions.method = RestRequestMethod.PUT; + // } this.initializedUploaderOptions.next(true); }) ); @@ -317,7 +317,7 @@ export class ComColFormComponent implements On this.refreshCache(); } this.notificationsService.success(null, this.translate.get(this.type.value + '.edit.logo.notifications.add.success')); - this.finish.emit(); + // this.finish.emit(); } /** diff --git a/src/app/shared/upload/uploader/uploader.component.ts b/src/app/shared/upload/uploader/uploader.component.ts index 26fd355871e..2072cb4c83b 100644 --- a/src/app/shared/upload/uploader/uploader.component.ts +++ b/src/app/shared/upload/uploader/uploader.component.ts @@ -130,9 +130,6 @@ export class UploaderComponent { ngAfterViewInit() { this.uploader.onAfterAddingAll = ((items) => { this.onFileSelected.emit(items); - if (this.uploader.queue.length > 0) { - this.uploader.uploadAll(); - } }); if (isUndefined(this.onBeforeUpload)) { this.onBeforeUpload = () => {return;}; From 8165b5feee8b4761f2ab007e8eb26a73016e4f31 Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Tue, 13 Feb 2024 15:49:52 +0000 Subject: [PATCH 07/25] DSC-1111 Moved logo update to a specific method instead of the generic onsubmit --- .../comcol-form/comcol-form.component.html | 19 +--- .../comcol-form/comcol-form.component.ts | 94 +++++++------------ 2 files changed, 37 insertions(+), 76 deletions(-) diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html index 4ea3d341d7d..3d2e990fe48 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html @@ -4,28 +4,18 @@ {{type.value + '.edit.logo.label' | translate}}
-
+
-
- -
@@ -65,5 +55,4 @@
- + diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts index 0c667f25987..bb4ba7cef0d 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts @@ -83,8 +83,6 @@ export class ComColFormComponent implements On */ @Output() submitForm: EventEmitter<{ dso: T, - uploader: FileUploader, - deleteLogo: boolean, operations: Operation[], }> = new EventEmitter(); @@ -104,11 +102,6 @@ export class ComColFormComponent implements On */ initializedUploaderOptions = new BehaviorSubject(false); - /** - * Is the logo marked to be deleted? - */ - markLogoForDeletion = false; - /** * Array to track all subscriptions and unsubscribe them onDestroy * @type {Array} @@ -174,27 +167,6 @@ export class ComColFormComponent implements On * Checks which new fields were added and sends the updated version of the DSO to the parent component */ onSubmit() { - if (this.markLogoForDeletion && hasValue(this.dso.id) && hasValue(this.dso._links.logo)) { - this.dsoService.deleteLogo(this.dso).pipe( - getFirstCompletedRemoteData() - ).subscribe((response: RemoteData) => { - 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; this.formModel.forEach((fieldModel: DynamicInputModel) => { const value: MetadataValue = { @@ -232,8 +204,6 @@ export class ComColFormComponent implements On this.submitForm.emit({ dso: updatedDSO, - uploader: hasValue(this.uploaderComponent) ? this.uploaderComponent.uploader : undefined, - deleteLogo: this.markLogoForDeletion, operations: operations, }); } @@ -254,44 +224,46 @@ export class ComColFormComponent implements On } ); } - - /** - * Mark the logo to be deleted - * 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 + * Helper method that provides a modal */ - undoDeleteLogo() { - this.markLogoForDeletion = false; - } - openModal(content: any) { this.modalService.open(content); } - + /** + * Helper method that confirms the deletion of the logo and handles possible errors + */ confirmLogoDelete(removeLogo: any) { - this.modalService.open(removeLogo).result.then( (result) => { - if (result === 'delete') { - this.deleteLogo(); - this.onSubmit(); - } else if (result === 'cancel') { - return; - } - }); - } + //this.refreshCache() + this.modalService.open(removeLogo).result.then((result) => { + if (result === 'delete') { + if (hasValue(this.dso.id) && hasValue(this.dso._links.logo)) { + this.dsoService.deleteLogo(this.dso).pipe( + getFirstCompletedRemoteData() + ).subscribe((response: RemoteData) => { + 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(); + }); + + } else if (result === 'cancel') { + return; + } + } - handleLogoReplace(event: Event) { - const fileInput = event.target as HTMLInputElement; - if (fileInput.files && fileInput.files.length > 0) { - this.markLogoForDeletion = true; - this.onSubmit(); - this.uploader.uploadAll(); - } + } + ); } /** From f48eb5dcb8c4d1b03e52a39070e5169ce5371ca7 Mon Sep 17 00:00:00 2001 From: Andrea Barbasso <´andrea.barbasso@4science.com´> Date: Tue, 13 Feb 2024 17:45:02 +0100 Subject: [PATCH 08/25] [DSC-1111] fix deletion - upload - deletion flow --- src/app/core/data/comcol-data.service.ts | 2 +- .../comcol-form/comcol-form.component.ts | 26 +++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/app/core/data/comcol-data.service.ts b/src/app/core/data/comcol-data.service.ts index abc9046cd0e..6a0cb16c061 100644 --- a/src/app/core/data/comcol-data.service.ts +++ b/src/app/core/data/comcol-data.service.ts @@ -1,4 +1,4 @@ -import { distinctUntilChanged, filter, map, switchMap, take } from 'rxjs/operators'; +import { distinctUntilChanged, filter, map, switchMap, take, tap } from 'rxjs/operators'; import { combineLatest as observableCombineLatest, Observable } from 'rxjs'; import { hasValue, isEmpty, isNotEmpty } from '../../shared/empty.util'; import { ObjectCacheService } from '../cache/object-cache.service'; diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts index bb4ba7cef0d..81990e5c0b5 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts @@ -3,7 +3,7 @@ import { UntypedFormGroup } from '@angular/forms'; import { DynamicFormControlModel, DynamicFormService, DynamicInputModel } from '@ng-dynamic-forms/core'; import { TranslateService } from '@ngx-translate/core'; import { FileUploader } from 'ng2-file-upload'; -import { BehaviorSubject, combineLatest as observableCombineLatest, Subscription } from 'rxjs'; +import { BehaviorSubject, combineLatest as observableCombineLatest, concatMap, Subscription } from 'rxjs'; import { AuthService } from '../../../../core/auth/auth.service'; import { ObjectCacheService } from '../../../../core/cache/object-cache.service'; import { ComColDataService } from '../../../../core/data/comcol-data.service'; @@ -24,6 +24,7 @@ import { NoContent } from '../../../../core/shared/NoContent.model'; import { getFirstCompletedRemoteData } from '../../../../core/shared/operators'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { followLink } from '../../../utils/follow-link-config.model'; +import { map } from 'rxjs/operators'; /** * A form for creating and editing Communities or Collections @@ -234,11 +235,11 @@ export class ComColFormComponent implements On * Helper method that confirms the deletion of the logo and handles possible errors */ confirmLogoDelete(removeLogo: any) { - //this.refreshCache() this.modalService.open(removeLogo).result.then((result) => { if (result === 'delete') { if (hasValue(this.dso.id) && hasValue(this.dso._links.logo)) { - this.dsoService.deleteLogo(this.dso).pipe( + this.refreshCache().pipe( + concatMap(() => this.dsoService.deleteLogo(this.dso)), getFirstCompletedRemoteData() ).subscribe((response: RemoteData) => { if (response.hasSucceeded) { @@ -272,13 +273,16 @@ export class ComColFormComponent implements On private refreshCache() { this.requestService.removeByHrefSubstring(this.dso._links.self.href); this.objectCache.remove(this.dso._links.self.href); - this.dsoService.findById(this.dso.id, false, true, followLink('logo')).pipe( - getFirstCompletedRemoteData() - ).subscribe((rd: RemoteData) => { - if (rd.hasSucceeded) { - this.dso = rd.payload; - } - }); + return this.dsoService.findById(this.dso.id, false, true, followLink('logo')).pipe( + getFirstCompletedRemoteData(), + map((rd: RemoteData) => { + if (rd.hasSucceeded) { + this.dso = rd.payload; + return true; + } + return false; + }) + ); } /** @@ -286,7 +290,7 @@ export class ComColFormComponent implements On */ public onCompleteItem() { if (hasValue(this.dso.id)) { - this.refreshCache(); + this.subs.push(this.refreshCache().subscribe()); } this.notificationsService.success(null, this.translate.get(this.type.value + '.edit.logo.notifications.add.success')); // this.finish.emit(); From 378d0b2a29f2076450d5a10b5e06e29436192c7c Mon Sep 17 00:00:00 2001 From: Andrea Barbasso <´andrea.barbasso@4science.com´> Date: Wed, 14 Feb 2024 11:47:03 +0100 Subject: [PATCH 09/25] Revert "[DSC-1111] fix deletion - upload - deletion flow" This reverts commit 618151faaf88ea8366c4243dab33a628582cc98c. --- src/app/core/data/comcol-data.service.ts | 2 +- .../comcol-form/comcol-form.component.ts | 26 ++++++++----------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/app/core/data/comcol-data.service.ts b/src/app/core/data/comcol-data.service.ts index 6a0cb16c061..abc9046cd0e 100644 --- a/src/app/core/data/comcol-data.service.ts +++ b/src/app/core/data/comcol-data.service.ts @@ -1,4 +1,4 @@ -import { distinctUntilChanged, filter, map, switchMap, take, tap } from 'rxjs/operators'; +import { distinctUntilChanged, filter, map, switchMap, take } from 'rxjs/operators'; import { combineLatest as observableCombineLatest, Observable } from 'rxjs'; import { hasValue, isEmpty, isNotEmpty } from '../../shared/empty.util'; import { ObjectCacheService } from '../cache/object-cache.service'; diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts index 81990e5c0b5..bb4ba7cef0d 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts @@ -3,7 +3,7 @@ import { UntypedFormGroup } from '@angular/forms'; import { DynamicFormControlModel, DynamicFormService, DynamicInputModel } from '@ng-dynamic-forms/core'; import { TranslateService } from '@ngx-translate/core'; import { FileUploader } from 'ng2-file-upload'; -import { BehaviorSubject, combineLatest as observableCombineLatest, concatMap, Subscription } from 'rxjs'; +import { BehaviorSubject, combineLatest as observableCombineLatest, Subscription } from 'rxjs'; import { AuthService } from '../../../../core/auth/auth.service'; import { ObjectCacheService } from '../../../../core/cache/object-cache.service'; import { ComColDataService } from '../../../../core/data/comcol-data.service'; @@ -24,7 +24,6 @@ import { NoContent } from '../../../../core/shared/NoContent.model'; import { getFirstCompletedRemoteData } from '../../../../core/shared/operators'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { followLink } from '../../../utils/follow-link-config.model'; -import { map } from 'rxjs/operators'; /** * A form for creating and editing Communities or Collections @@ -235,11 +234,11 @@ export class ComColFormComponent implements On * Helper method that confirms the deletion of the logo and handles possible errors */ confirmLogoDelete(removeLogo: any) { + //this.refreshCache() this.modalService.open(removeLogo).result.then((result) => { if (result === 'delete') { if (hasValue(this.dso.id) && hasValue(this.dso._links.logo)) { - this.refreshCache().pipe( - concatMap(() => this.dsoService.deleteLogo(this.dso)), + this.dsoService.deleteLogo(this.dso).pipe( getFirstCompletedRemoteData() ).subscribe((response: RemoteData) => { if (response.hasSucceeded) { @@ -273,16 +272,13 @@ export class ComColFormComponent implements On private refreshCache() { this.requestService.removeByHrefSubstring(this.dso._links.self.href); this.objectCache.remove(this.dso._links.self.href); - return this.dsoService.findById(this.dso.id, false, true, followLink('logo')).pipe( - getFirstCompletedRemoteData(), - map((rd: RemoteData) => { - if (rd.hasSucceeded) { - this.dso = rd.payload; - return true; - } - return false; - }) - ); + this.dsoService.findById(this.dso.id, false, true, followLink('logo')).pipe( + getFirstCompletedRemoteData() + ).subscribe((rd: RemoteData) => { + if (rd.hasSucceeded) { + this.dso = rd.payload; + } + }); } /** @@ -290,7 +286,7 @@ export class ComColFormComponent implements On */ public onCompleteItem() { if (hasValue(this.dso.id)) { - this.subs.push(this.refreshCache().subscribe()); + this.refreshCache(); } this.notificationsService.success(null, this.translate.get(this.type.value + '.edit.logo.notifications.add.success')); // this.finish.emit(); From 795b0a37b46c839d98a2bf78e4c5b43183595bbd Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 15 Feb 2024 11:59:23 +0100 Subject: [PATCH 10/25] [DSC-1111] Fix issue with wrong cache reference --- .../comcol/comcol-forms/comcol-form/comcol-form.component.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts index bb4ba7cef0d..d060cb4ad10 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts @@ -242,6 +242,7 @@ export class ComColFormComponent implements On getFirstCompletedRemoteData() ).subscribe((response: RemoteData) => { if (response.hasSucceeded) { + this.refreshCache(); 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') @@ -254,7 +255,7 @@ export class ComColFormComponent implements On } this.dso.logo = undefined; this.uploadFilesOptions.method = RestRequestMethod.POST; - this.finish.emit(); + // this.finish.emit(); }); } else if (result === 'cancel') { @@ -270,7 +271,7 @@ export class ComColFormComponent implements On * Refresh the object's cache to ensure the latest version */ private refreshCache() { - this.requestService.removeByHrefSubstring(this.dso._links.self.href); + this.requestService.setStaleByHrefSubstring(this.dso.id); this.objectCache.remove(this.dso._links.self.href); this.dsoService.findById(this.dso.id, false, true, followLink('logo')).pipe( getFirstCompletedRemoteData() From e6fe9dd3918e0162f2f3a9faf5c8253d610d4a5c Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Mon, 19 Feb 2024 11:49:52 +0100 Subject: [PATCH 11/25] DSC-1111 Working uploader, cache refresh and retrieve for the updated dso containing the logo, new confirmationmodal --- .../comcol-form/comcol-form.component.html | 19 +- .../comcol-form/comcol-form.component.spec.ts | 136 ++++++-------- .../comcol-form/comcol-form.component.ts | 166 +++++++++++------- src/assets/i18n/en.json5 | 6 + 4 files changed, 167 insertions(+), 160 deletions(-) diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html index 3d2e990fe48..815b1b97489 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html @@ -11,11 +11,7 @@
- +
@@ -42,17 +38,4 @@ {{ type.value + '.edit.return' | translate }} - - - - - diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.spec.ts b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.spec.ts index 3f74f051182..868134b34a7 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.spec.ts +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.spec.ts @@ -19,7 +19,7 @@ import { NotificationsServiceStub } from '../../../testing/notifications-service import { VarDirective } from '../../../utils/var.directive'; import { ComColFormComponent } from './comcol-form.component'; import { Operation } from 'fast-json-patch'; -import { createFailedRemoteDataObject$, createSuccessfulRemoteDataObject$ } from '../../../remote-data.utils'; +import { createSuccessfulRemoteDataObject$ } from '../../../remote-data.utils'; describe('ComColFormComponent', () => { let comp: ComColFormComponent; @@ -61,7 +61,8 @@ describe('ComColFormComponent', () => { const logoEndpoint = 'rest/api/logo/endpoint'; const dsoService = Object.assign({ getLogoEndpoint: () => observableOf(logoEndpoint), - deleteLogo: () => createSuccessfulRemoteDataObject$({}) + deleteLogo: () => createSuccessfulRemoteDataObject$({}), + findById: () => createSuccessfulRemoteDataObject$({}) }); const notificationsService = new NotificationsServiceStub(); @@ -70,7 +71,8 @@ describe('ComColFormComponent', () => { /* eslint-enable no-empty, @typescript-eslint/no-empty-function */ const requestServiceStub = jasmine.createSpyObj('requestService', { - removeByHrefSubstring: {} + removeByHrefSubstring: {}, + setStaleByHrefSubstring: {} }); const objectCacheStub = jasmine.createSpyObj('objectCache', { remove: {} @@ -148,8 +150,6 @@ describe('ComColFormComponent', () => { type: Community.type, } ), - uploader: undefined, - deleteLogo: false, operations: operations, } ); @@ -158,32 +158,22 @@ describe('ComColFormComponent', () => { describe('onCompleteItem', () => { beforeEach(() => { - spyOn(comp.finish, 'emit'); comp.onCompleteItem(); }); it('should show a success notification', () => { expect(notificationsService.success).toHaveBeenCalled(); }); - - it('should emit finish', () => { - expect(comp.finish.emit).toHaveBeenCalled(); - }); }); describe('onUploadError', () => { beforeEach(() => { - spyOn(comp.finish, 'emit'); comp.onUploadError(); }); it('should show an error notification', () => { expect(notificationsService.error).toHaveBeenCalled(); }); - - it('should emit finish', () => { - expect(comp.finish.emit).toHaveBeenCalled(); - }); }); }); @@ -204,6 +194,11 @@ describe('ComColFormComponent', () => { it('should initialize the uploadFilesOptions with a POST method', () => { expect(comp.uploadFilesOptions.method).toEqual(RestRequestMethod.POST); }); + + it('should not show the delete logo button', () => { + const button = fixture.debugElement.query(By.css('#logo-section .btn-danger')); + expect(button).toBeFalsy(); + }); }); describe('and the dso contains a logo', () => { @@ -222,96 +217,71 @@ describe('ComColFormComponent', () => { expect(comp.uploadFilesOptions.url).toEqual(logoEndpoint); }); - it('should initialize the uploadFilesOptions with a PUT method', () => { - expect(comp.uploadFilesOptions.method).toEqual(RestRequestMethod.PUT); + it('should show the delete logo button', () => { + const button = fixture.debugElement.query(By.css('#logo-section .btn-danger')); + expect(button).toBeTruthy(); }); - describe('submit with logo marked for deletion', () => { + describe('when the delete logo button is clicked', () => { beforeEach(() => { - spyOn(dsoService, 'deleteLogo').and.callThrough(); - comp.markLogoForDeletion = true; - }); - - it('should call dsoService.deleteLogo on the DSO', () => { - comp.onSubmit(); + spyOn(dsoService, 'deleteLogo').and.returnValue(createSuccessfulRemoteDataObject$({})); + spyOn(comp, 'handleLogoDeletion').and.callThrough(); + spyOn(comp, 'createConfirmationModal').and.callThrough(); + spyOn(comp, 'subscribeToConfirmationResponse').and.callThrough(); + const deleteButton = fixture.debugElement.query(By.css('#logo-section .btn-danger')); + deleteButton.nativeElement.click(); fixture.detectChanges(); - - expect(dsoService.deleteLogo).toHaveBeenCalledWith(comp.dso); }); - describe('when dsoService.deleteLogo returns a successful response', () => { - beforeEach(() => { - dsoService.deleteLogo.and.returnValue(createSuccessfulRemoteDataObject$({})); - comp.onSubmit(); - }); + it('should create a confirmation modal with the correct labels and properties', () => { + const modalServiceSpy = spyOn((comp as any).modalService, 'open').and.callThrough(); - it('should display a success notification', () => { - expect(notificationsService.success).toHaveBeenCalled(); - }); - }); + const modalRef = comp.createConfirmationModal(); - describe('when dsoService.deleteLogo returns an error response', () => { - beforeEach(() => { - dsoService.deleteLogo.and.returnValue(createFailedRemoteDataObject$('Error', 500)); - comp.onSubmit(); - }); + expect(modalServiceSpy).toHaveBeenCalled(); - it('should display an error notification', () => { - expect(notificationsService.error).toHaveBeenCalled(); - }); - }); - }); + expect(modalRef).toBeDefined(); + expect(modalRef.componentInstance).toBeDefined(); - describe('deleteLogo', () => { - beforeEach(() => { - comp.deleteLogo(); - fixture.detectChanges(); + expect(modalRef.componentInstance.headerLabel).toBe('community-collection.edit.logo.delete.title'); + expect(modalRef.componentInstance.infoLabel).toBe('confirmation-modal.delete-community-collection-logo.info'); + expect(modalRef.componentInstance.cancelLabel).toBe('form.cancel'); + expect(modalRef.componentInstance.confirmLabel).toBe('community-collection.edit.logo.delete.title'); + expect(modalRef.componentInstance.confirmIcon).toBe('fas fa-trash'); }); - it('should set markLogoForDeletion to true', () => { - expect(comp.markLogoForDeletion).toEqual(true); + it('should call createConfirmationModal method', () => { + expect(comp.createConfirmationModal).toHaveBeenCalled(); }); - it('should mark the logo section with a danger alert', () => { - const logoSection = fixture.debugElement.query(By.css('#logo-section.alert-danger')); - expect(logoSection).toBeTruthy(); + it('should call subscribeToConfirmationResponse method', () => { + expect(comp.subscribeToConfirmationResponse).toHaveBeenCalled(); }); - it('should hide the delete button', () => { - const button = fixture.debugElement.query(By.css('#logo-section .btn-danger')); - expect(button).not.toBeTruthy(); - }); + describe('when the modal is closed', () => { - it('should show the undo button', () => { - const button = fixture.debugElement.query(By.css('#logo-section .btn-warning')); - expect(button).toBeTruthy(); - }); - }); + let modalRef; - describe('undoDeleteLogo', () => { - beforeEach(() => { - comp.markLogoForDeletion = true; - comp.undoDeleteLogo(); - fixture.detectChanges(); - }); + beforeEach(() => { + modalRef = comp.createConfirmationModal(); + comp.subscribeToConfirmationResponse(modalRef); + }); - it('should set markLogoForDeletion to false', () => { - expect(comp.markLogoForDeletion).toEqual(false); - }); + it('should call handleLogoDeletion and dsoService.deleteLogo methods when deletion is confirmed', waitForAsync(() => { + modalRef.componentInstance.confirmPressed(); - it('should disable the danger alert on the logo section', () => { - const logoSection = fixture.debugElement.query(By.css('#logo-section.alert-danger')); - expect(logoSection).not.toBeTruthy(); - }); + expect(comp.handleLogoDeletion).toHaveBeenCalled(); + expect(dsoService.deleteLogo).toHaveBeenCalled(); - it('should show the delete button', () => { - const button = fixture.debugElement.query(By.css('#logo-section .btn-danger')); - expect(button).toBeTruthy(); - }); + })); + + it('should not call handleLogoDeletion and dsoService.deleteLogo methods when deletion is refused', waitForAsync(() => { + modalRef.componentInstance.cancelPressed(); + + expect(comp.handleLogoDeletion).not.toHaveBeenCalled(); + expect(dsoService.deleteLogo).not.toHaveBeenCalled(); + })); - it('should hide the undo button', () => { - const button = fixture.debugElement.query(By.css('#logo-section .btn-warning')); - expect(button).not.toBeTruthy(); }); }); }); diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts index d060cb4ad10..cc8539e79b7 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts @@ -3,13 +3,12 @@ import { UntypedFormGroup } from '@angular/forms'; import { DynamicFormControlModel, DynamicFormService, DynamicInputModel } from '@ng-dynamic-forms/core'; import { TranslateService } from '@ngx-translate/core'; import { FileUploader } from 'ng2-file-upload'; -import { BehaviorSubject, combineLatest as observableCombineLatest, Subscription } from 'rxjs'; +import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs'; import { AuthService } from '../../../../core/auth/auth.service'; import { ObjectCacheService } from '../../../../core/cache/object-cache.service'; import { ComColDataService } from '../../../../core/data/comcol-data.service'; import { RemoteData } from '../../../../core/data/remote-data'; import { RequestService } from '../../../../core/data/request.service'; -import { RestRequestMethod } from '../../../../core/data/rest-request-method'; import { Bitstream } from '../../../../core/shared/bitstream.model'; import { Collection } from '../../../../core/shared/collection.model'; import { Community } from '../../../../core/shared/community.model'; @@ -22,8 +21,11 @@ import { UploaderComponent } from '../../../upload/uploader/uploader.component'; import { Operation } from 'fast-json-patch'; import { NoContent } from '../../../../core/shared/NoContent.model'; import { getFirstCompletedRemoteData } from '../../../../core/shared/operators'; -import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; +import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; import { followLink } from '../../../utils/follow-link-config.model'; +import { ConfirmationModalComponent } from '../../../confirmation-modal/confirmation-modal.component'; +import { map, take, tap } from 'rxjs/operators'; +import { DSpaceObject } from '../../../../core/shared/dspace-object.model'; /** * A form for creating and editing Communities or Collections @@ -92,12 +94,7 @@ export class ComColFormComponent implements On @Output() back: EventEmitter = new EventEmitter(); /** - * Fires an event when the logo has finished uploading (with or without errors) or was removed - */ - @Output() finish: EventEmitter = new EventEmitter(); - - /** - * Observable keeping track whether or not the uploader has finished initializing + * Observable keeping track whether the uploader has finished initializing * Used to start rendering the uploader component */ initializedUploaderOptions = new BehaviorSubject(false); @@ -121,7 +118,7 @@ export class ComColFormComponent implements On protected authService: AuthService, protected requestService: RequestService, protected objectCache: ObjectCacheService, - protected modalService: NgbModal) { + protected modalService: NgbModal){ } ngOnInit(): void { @@ -147,10 +144,6 @@ export class ComColFormComponent implements On ]).subscribe(([href, logoRD]: [string, RemoteData]) => { this.uploadFilesOptions.url = href; this.uploadFilesOptions.authToken = this.authService.buildAuthHeader(); - // If the object already contains a logo, send out a PUT request instead of POST for setting a new logo - // if (hasValue(logoRD.payload)) { - // this.uploadFilesOptions.method = RestRequestMethod.PUT; - // } this.initializedUploaderOptions.next(true); }) ); @@ -224,73 +217,129 @@ export class ComColFormComponent implements On } ); } + /** - * Helper method that provides a modal + * Helper method that confirms the deletion of the logo opening a confirmation modal */ - openModal(content: any) { - this.modalService.open(content); + confirmLogoDeleteWithModal(): void { + const modalRef = this.createConfirmationModal(); + this.subscribeToConfirmationResponse(modalRef); } + /** - * Helper method that confirms the deletion of the logo and handles possible errors + * Creates and opens the confirmation modal + * @returns Reference to the opened modal */ - confirmLogoDelete(removeLogo: any) { - //this.refreshCache() - this.modalService.open(removeLogo).result.then((result) => { - if (result === 'delete') { - if (hasValue(this.dso.id) && hasValue(this.dso._links.logo)) { - this.dsoService.deleteLogo(this.dso).pipe( - getFirstCompletedRemoteData() - ).subscribe((response: RemoteData) => { - if (response.hasSucceeded) { - this.refreshCache(); - 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(); - }); - - } else if (result === 'cancel') { - return; - } - } + createConfirmationModal(): NgbModalRef { + const modalRef = this.modalService.open(ConfirmationModalComponent); + modalRef.componentInstance.headerLabel = 'community-collection.edit.logo.delete.title'; + modalRef.componentInstance.infoLabel = 'confirmation-modal.delete-community-collection-logo.info'; + modalRef.componentInstance.cancelLabel = 'form.cancel'; + modalRef.componentInstance.confirmLabel = 'community-collection.edit.logo.delete.title'; + modalRef.componentInstance.confirmIcon = 'fas fa-trash'; + return modalRef; + } + /** + * Subscribes to the confirmation modal's response and calls the logo deletion handler if confirmed + * @param modalRef References to the opened confirmation modal + */ + subscribeToConfirmationResponse(modalRef: NgbModalRef): void { + modalRef.componentInstance.response.pipe( + take(1) + ).subscribe((confirmed: boolean) => { + if (confirmed) { + this.handleLogoDeletion(); } + }); + } + + /** + * Method that confirms the deletion of the logo, handling both possible outcomes + */ + handleLogoDeletion(): void { + if (hasValue(this.dso.id) && hasValue(this.dso._links.logo)) { + this.dsoService.deleteLogo(this.dso).pipe( + getFirstCompletedRemoteData() + ).subscribe((response: RemoteData) => { + const successMessageKey = `${this.type.value}.edit.logo.notifications.delete.success`; + const errorMessageKey = `${this.type.value}.edit.logo.notifications.delete.error`; + + if (response.hasSucceeded) { + this.handleSuccessfulDeletion(successMessageKey); + } else { + this.handleFailedDeletion(errorMessageKey, response.errorMessage); + } + + }); + } + } + + + /** + * Handles successful logo deletion + * @param successMessageKey Translation key for success message + */ + private handleSuccessfulDeletion(successMessageKey: string): void { + this.refreshDsoCache(); + this.notificationsService.success( + this.translate.get(`${successMessageKey}.title`), + this.translate.get(`${successMessageKey}.content`) ); } /** - * Refresh the object's cache to ensure the latest version + * Handles failed logo deletion + * @param errorMessageKey Translation key for error message + * @param errorMessage Error message from the response + */ + private handleFailedDeletion(errorMessageKey: string, errorMessage: string): void { + this.notificationsService.error( + this.translate.get(`${errorMessageKey}.title`), + errorMessage + ); + } + + /** + * Refresh the object's cache to obtain the latest version + */ + private refreshDsoCache() { + this.clearDsoCache(); + return this.fetchUpdatedDso(); + } + + /** + * Clears the cache related to the current dso */ - private refreshCache() { + private clearDsoCache() { this.requestService.setStaleByHrefSubstring(this.dso.id); this.objectCache.remove(this.dso._links.self.href); - this.dsoService.findById(this.dso.id, false, true, followLink('logo')).pipe( - getFirstCompletedRemoteData() - ).subscribe((rd: RemoteData) => { - if (rd.hasSucceeded) { - this.dso = rd.payload; - } - }); } /** + * Fetches the latest data for the dso + */ +private fetchUpdatedDso(): Observable { + return this.dsoService.findById(this.dso.id, false, true, followLink('logo')).pipe( + tap((rd: RemoteData) => { + if (rd.hasSucceeded) { + this.dso = rd.payload; + } + }), + map((rd: RemoteData) => rd.hasSucceeded ? rd.payload : null) + ); + } + + + +/** * The request was successful, display a success notification */ public onCompleteItem() { if (hasValue(this.dso.id)) { - this.refreshCache(); + this.refreshDsoCache(); } this.notificationsService.success(null, this.translate.get(this.type.value + '.edit.logo.notifications.add.success')); - // this.finish.emit(); } /** @@ -298,7 +347,6 @@ export class ComColFormComponent implements On */ public onUploadError() { this.notificationsService.error(null, this.translate.get(this.type.value + '.edit.logo.notifications.add.error')); - this.finish.emit(); } /** diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index 315fcb66726..7b7609a22e2 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -1228,8 +1228,12 @@ "community.edit.logo.delete.title": "Delete logo", + "community-collection.edit.logo.delete.title": "Confirm deletion", + "community.edit.logo.delete-undo.title": "Undo delete", + "community-collection.edit.logo.delete-undo.title": "Undo delete", + "community.edit.logo.label": "Community logo", "community.edit.logo.notifications.add.error": "Uploading community logo failed. Please verify the content before retrying.", @@ -1586,6 +1590,8 @@ "confirmation-modal.delete-eperson.confirm": "Delete", + "confirmation-modal.delete-community-collection-logo.info": "Are you sure you want to delete the logo?", + "confirmation-modal.delete-profile.header": "Delete Profile", "confirmation-modal.delete-profile.info": "Are you sure you want to delete your profile", From 0b3536de8c9054d4a6bfda08f6d4e428aec37282 Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Mon, 19 Feb 2024 11:52:09 +0100 Subject: [PATCH 12/25] DSC-1111 Removed left over label --- src/assets/i18n/en.json5 | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index 7b7609a22e2..b3f719717fc 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -978,8 +978,6 @@ "collection.edit.item-mapper.tabs.map": "Map new items", - "collection.edit.logo.replace.title": "Replace logo", - "collection.edit.logo.delete.title": "Delete logo", "collection.edit.logo.delete-undo.title": "Undo delete", From ea1a8db8e9e35fc63311515c857289a4389f5b59 Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Mon, 19 Feb 2024 12:05:05 +0100 Subject: [PATCH 13/25] DSC-1111 These 2 changes with the finish emit is needed, else when changing logo and then editing a field we do not get the notification and the navigateToHomePage --- .../community-metadata/community-metadata.component.html | 2 +- .../comcol-forms/comcol-form/comcol-form.component.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/app/community-page/edit-community-page/community-metadata/community-metadata.component.html b/src/app/community-page/edit-community-page/community-metadata/community-metadata.component.html index 169f79df678..2ca5b768e4d 100644 --- a/src/app/community-page/edit-community-page/community-metadata/community-metadata.component.html +++ b/src/app/community-page/edit-community-page/community-metadata/community-metadata.component.html @@ -1,5 +1,5 @@ + (finish)="navigateToHomePage()"> diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts index cc8539e79b7..6481add5d07 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts @@ -93,6 +93,12 @@ export class ComColFormComponent implements On */ @Output() back: EventEmitter = new EventEmitter(); + /** + * Event emitted on finish + */ + @Output() finish: EventEmitter = new EventEmitter(); + + /** * Observable keeping track whether the uploader has finished initializing * Used to start rendering the uploader component @@ -199,6 +205,8 @@ export class ComColFormComponent implements On dso: updatedDSO, operations: operations, }); + + this.finish.emit(); } /** From 901234777bbdb14cf9b35c407f6c9cc23fb6d3c7 Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Mon, 19 Feb 2024 12:05:19 +0100 Subject: [PATCH 14/25] DSC-1111 Removed unused method --- .../comcol-metadata/comcol-metadata.component.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts index 1547ad739e8..eda4394bade 100644 --- a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts +++ b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts @@ -90,13 +90,4 @@ export class ComcolMetadataComponent imp this.router.navigate([this.frontendURL + dsoRD.payload.id]); }); } - - returnToEdit() { - this.dsoRD$.pipe( - getFirstSucceededRemoteData(), - take(1) - ).subscribe((dsoRD: RemoteData) => { - this.router.navigate([this.frontendURL + dsoRD.payload.id + '/edit/metadata']); - }); - } } From 95a9d2aa476d96bb6d10e3f78b8b201d282c009c Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Mon, 19 Feb 2024 14:34:51 +0100 Subject: [PATCH 15/25] Removed unused parts --- .../collection-form/collection-form.component.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/app/collection-page/collection-form/collection-form.component.ts b/src/app/collection-page/collection-form/collection-form.component.ts index 37bdc13d7e4..9e4bbaab0a1 100644 --- a/src/app/collection-page/collection-form/collection-form.component.ts +++ b/src/app/collection-page/collection-form/collection-form.component.ts @@ -12,7 +12,6 @@ import { import { Collection } from '../../core/shared/collection.model'; import { ComColFormComponent } from '../../shared/comcol/comcol-forms/comcol-form/comcol-form.component'; import { NotificationsService } from '../../shared/notifications/notifications.service'; -import { CollectionDataService } from '../../core/data/collection-data.service'; import { AuthService } from '../../core/auth/auth.service'; import { RequestService } from '../../core/data/request.service'; import { ObjectCacheService } from '../../core/cache/object-cache.service'; @@ -60,12 +59,10 @@ export class CollectionFormComponent extends ComColFormComponent imp protected translate: TranslateService, protected notificationsService: NotificationsService, protected authService: AuthService, - protected dsoService: CollectionDataService, protected requestService: RequestService, protected objectCache: ObjectCacheService, protected entityTypeService: EntityTypeDataService, protected chd: ChangeDetectorRef, - protected submissionDefinitionService: SubmissionDefinitionsConfigDataService, protected modalService: NgbModal) { super(formService, translate, notificationsService, authService, requestService, objectCache, modalService); } From e71b54c79d814f40753d0affe954a803eef00ef5 Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Tue, 20 Feb 2024 17:16:08 +0100 Subject: [PATCH 16/25] DSC-1111 Fixed issue on create comcol --- .../create-collection-page.component.html | 1 + .../collection-metadata.component.html | 1 + .../create-community-page.component.html | 3 +- .../community-metadata.component.html | 2 +- .../comcol-form/comcol-form.component.ts | 38 ++++++++++++++----- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/app/collection-page/create-collection-page/create-collection-page.component.html b/src/app/collection-page/create-collection-page/create-collection-page.component.html index f3f97856927..ddce9dbec42 100644 --- a/src/app/collection-page/create-collection-page/create-collection-page.component.html +++ b/src/app/collection-page/create-collection-page/create-collection-page.component.html @@ -5,6 +5,7 @@

{{'collection.create.sub-head' | diff --git a/src/app/collection-page/edit-collection-page/collection-metadata/collection-metadata.component.html b/src/app/collection-page/edit-collection-page/collection-metadata/collection-metadata.component.html index 1cf40159ec9..845c82458a5 100644 --- a/src/app/collection-page/edit-collection-page/collection-metadata/collection-metadata.component.html +++ b/src/app/collection-page/edit-collection-page/collection-metadata/collection-metadata.component.html @@ -17,6 +17,7 @@ diff --git a/src/app/community-page/create-community-page/create-community-page.component.html b/src/app/community-page/create-community-page/create-community-page.component.html index 57039040c2a..d99069f6c84 100644 --- a/src/app/community-page/create-community-page/create-community-page.component.html +++ b/src/app/community-page/create-community-page/create-community-page.component.html @@ -2,12 +2,13 @@
- +

{{ 'community.create.sub-head' | translate:{ parent: dsoNameService.getName(parent) } }}

diff --git a/src/app/community-page/edit-community-page/community-metadata/community-metadata.component.html b/src/app/community-page/edit-community-page/community-metadata/community-metadata.component.html index 2ca5b768e4d..bf75944242f 100644 --- a/src/app/community-page/edit-community-page/community-metadata/community-metadata.component.html +++ b/src/app/community-page/edit-community-page/community-metadata/community-metadata.component.html @@ -1,5 +1,5 @@ - diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts index 6481add5d07..13a886dc935 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts @@ -47,6 +47,11 @@ export class ComColFormComponent implements On */ @Input() dso: T; + /** + * Boolean that represents if the comcol is being created or already exists + */ + @Input() isCreation!: boolean; + /** * Type of DSpaceObject that the form represents */ @@ -77,7 +82,7 @@ export class ComColFormComponent implements On * @type {UploaderOptions} */ uploadFilesOptions: UploaderOptions = Object.assign(new UploaderOptions(), { - autoUpload: true + autoUpload: false }); /** @@ -86,6 +91,8 @@ export class ComColFormComponent implements On @Output() submitForm: EventEmitter<{ dso: T, operations: Operation[], + uploader?: FileUploader, + deleteLogo?: boolean, }> = new EventEmitter(); /** @@ -128,6 +135,8 @@ export class ComColFormComponent implements On } ngOnInit(): void { + this.uploadFilesOptions.autoUpload = !this.isCreation; + if (hasValue(this.formModel)) { this.formModel.forEach( (fieldModel: DynamicInputModel) => { @@ -201,12 +210,20 @@ export class ComColFormComponent implements On } }); - this.submitForm.emit({ - dso: updatedDSO, - operations: operations, - }); - - this.finish.emit(); + if (!this.isCreation) { + this.submitForm.emit({ + dso: updatedDSO, + operations: operations, + }); + this.finish.emit(); + } else { + this.submitForm.emit({ + dso: updatedDSO, + deleteLogo: false, + uploader: hasValue(this.uploaderComponent) ? this.uploaderComponent.uploader : undefined, + operations: operations, + }); + } } /** @@ -327,7 +344,7 @@ export class ComColFormComponent implements On /** * Fetches the latest data for the dso */ -private fetchUpdatedDso(): Observable { + private fetchUpdatedDso(): Observable { return this.dsoService.findById(this.dso.id, false, true, followLink('logo')).pipe( tap((rd: RemoteData) => { if (rd.hasSucceeded) { @@ -340,13 +357,16 @@ private fetchUpdatedDso(): Observable { -/** + /** * The request was successful, display a success notification */ public onCompleteItem() { if (hasValue(this.dso.id)) { this.refreshDsoCache(); } + if (this.isCreation) { + this.finish.emit(); + } this.notificationsService.success(null, this.translate.get(this.type.value + '.edit.logo.notifications.add.success')); } From e3b19e4e9fe034d36cafbecb2231d8dcf1b60e0a Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Wed, 21 Feb 2024 13:12:58 +0100 Subject: [PATCH 17/25] DURACOM-235 added missing import and service --- .../collection-form/collection-form.component.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app/collection-page/collection-form/collection-form.component.ts b/src/app/collection-page/collection-form/collection-form.component.ts index 9e4bbaab0a1..7a8ccd549d8 100644 --- a/src/app/collection-page/collection-form/collection-form.component.ts +++ b/src/app/collection-page/collection-form/collection-form.component.ts @@ -12,6 +12,7 @@ import { import { Collection } from '../../core/shared/collection.model'; import { ComColFormComponent } from '../../shared/comcol/comcol-forms/comcol-form/comcol-form.component'; import { NotificationsService } from '../../shared/notifications/notifications.service'; +import { CollectionDataService } from '../../core/data/collection-data.service'; import { AuthService } from '../../core/auth/auth.service'; import { RequestService } from '../../core/data/request.service'; import { ObjectCacheService } from '../../core/cache/object-cache.service'; @@ -59,6 +60,7 @@ export class CollectionFormComponent extends ComColFormComponent imp protected translate: TranslateService, protected notificationsService: NotificationsService, protected authService: AuthService, + protected dsoService: CollectionDataService, protected requestService: RequestService, protected objectCache: ObjectCacheService, protected entityTypeService: EntityTypeDataService, From be452316a862d4380ed9a1ac5e798baf1de277db Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Thu, 22 Feb 2024 11:16:36 +0100 Subject: [PATCH 18/25] DURACOM-235 Removed extra navigation that was breaking community edit behaviour --- .../comcol-metadata/comcol-metadata.component.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts index eda4394bade..36dbc529c50 100644 --- a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts +++ b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts @@ -66,9 +66,6 @@ export class ComcolMetadataComponent imp this.dsoDataService.patch(event.dso, event.operations).pipe(getFirstCompletedRemoteData()) .subscribe(async (response: RemoteData) => { if (response.hasSucceeded) { - if (!newLogo && !deleteLogo) { - await this.router.navigate([this.frontendURL + event.dso.uuid]); - } this.notificationsService.success(null, this.translate.get(`${this.type.value}.edit.notifications.success`)); } else if (response.statusCode === 403) { this.notificationsService.error(null, this.translate.get(`${this.type.value}.edit.notifications.unauthorized`)); @@ -80,7 +77,7 @@ export class ComcolMetadataComponent imp } /** - * Navigate to the home page of the object + * Navigate to the relative DSO page */ navigateToHomePage() { this.dsoRD$.pipe( From 9d490451d1fc332db8b4aa2b0d4eb3f2ad2c9caf Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Fri, 23 Feb 2024 12:04:46 +0100 Subject: [PATCH 19/25] [DURACOM-235] improvement of redirects logic --- .../comcol-form/comcol-form.component.ts | 10 ++++------ .../comcol-metadata.component.ts | 17 ++++------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts index 13a886dc935..760891bb4e7 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts @@ -91,8 +91,7 @@ export class ComColFormComponent implements On @Output() submitForm: EventEmitter<{ dso: T, operations: Operation[], - uploader?: FileUploader, - deleteLogo?: boolean, + uploader?: FileUploader }> = new EventEmitter(); /** @@ -210,17 +209,15 @@ export class ComColFormComponent implements On } }); - if (!this.isCreation) { + if (this.isCreation) { this.submitForm.emit({ dso: updatedDSO, + uploader: hasValue(this.uploaderComponent) ? this.uploaderComponent.uploader : undefined, operations: operations, }); - this.finish.emit(); } else { this.submitForm.emit({ dso: updatedDSO, - deleteLogo: false, - uploader: hasValue(this.uploaderComponent) ? this.uploaderComponent.uploader : undefined, operations: operations, }); } @@ -262,6 +259,7 @@ export class ComColFormComponent implements On modalRef.componentInstance.cancelLabel = 'form.cancel'; modalRef.componentInstance.confirmLabel = 'community-collection.edit.logo.delete.title'; modalRef.componentInstance.confirmIcon = 'fas fa-trash'; + modalRef.componentInstance.brandColor = 'danger'; return modalRef; } diff --git a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts index 36dbc529c50..7fb1ad1c2c8 100644 --- a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts +++ b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts @@ -5,7 +5,7 @@ import { RemoteData } from '../../../../../core/data/remote-data'; import { ActivatedRoute, Router } from '@angular/router'; import { map, take } from 'rxjs/operators'; import { getFirstCompletedRemoteData, getFirstSucceededRemoteData } from '../../../../../core/shared/operators'; -import { hasValue, isEmpty } from '../../../../empty.util'; +import { isEmpty } from '../../../../empty.util'; import { ResourceType } from '../../../../../core/shared/resource-type'; import { ComColDataService } from '../../../../../core/data/comcol-data.service'; import { NotificationsService } from '../../../../notifications/notifications.service'; @@ -50,22 +50,11 @@ export class ComcolMetadataComponent imp * @param event The event returned by the community/collection form. Contains the new dso and logo uploader */ onSubmit(event) { - - const uploader = event.uploader; - const deleteLogo = event.deleteLogo; - - const newLogo = hasValue(uploader) && uploader.queue.length > 0; - if (newLogo) { - this.dsoDataService.getLogoEndpoint(event.dso.uuid).pipe(take(1)).subscribe((href: string) => { - uploader.options.url = href; - uploader.uploadAll(); - }); - } - if (!isEmpty(event.operations)) { this.dsoDataService.patch(event.dso, event.operations).pipe(getFirstCompletedRemoteData()) .subscribe(async (response: RemoteData) => { if (response.hasSucceeded) { + await this.router.navigate([this.frontendURL + event.dso.uuid]); this.notificationsService.success(null, this.translate.get(`${this.type.value}.edit.notifications.success`)); } else if (response.statusCode === 403) { this.notificationsService.error(null, this.translate.get(`${this.type.value}.edit.notifications.unauthorized`)); @@ -73,6 +62,8 @@ export class ComcolMetadataComponent imp this.notificationsService.error(null, this.translate.get(`${this.type.value}.edit.notifications.error`)); } }); + } else { + this.router.navigate([this.frontendURL + event.dso.uuid]); } } From a059c31badfd93e397bd4f17e16e9c521afb506a Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Mon, 26 Feb 2024 12:18:35 +0100 Subject: [PATCH 20/25] DURACOM-235 Update comcol-metadata.component.ts and tests --- .../comcol-metadata.component.spec.ts | 90 +++++++++++++------ .../comcol-metadata.component.ts | 13 ++- 2 files changed, 67 insertions(+), 36 deletions(-) diff --git a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.spec.ts b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.spec.ts index ef69e82c8c3..0ed06140d72 100644 --- a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.spec.ts +++ b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.spec.ts @@ -17,7 +17,7 @@ import { } from '../../../../remote-data.utils'; import { ComcolMetadataComponent } from './comcol-metadata.component'; -describe('ComColMetadataComponent', () => { +fdescribe('ComColMetadataComponent', () => { let comp: ComcolMetadataComponent; let fixture: ComponentFixture>; let dsoDataService; @@ -29,8 +29,6 @@ describe('ComColMetadataComponent', () => { let routerStub; let routeStub; - const logoEndpoint = 'rest/api/logo/endpoint'; - function initializeVars() { community = Object.assign(new Community(), { uuid: 'a20da287-e174-466a-9926-f66b9300d347', @@ -51,7 +49,6 @@ describe('ComColMetadataComponent', () => { communityDataServiceStub = { update: (com, uuid?) => createSuccessfulRemoteDataObject$(newCommunity), patch: () => null, - getLogoEndpoint: () => observableOf(logoEndpoint) }; routerStub = { @@ -118,7 +115,6 @@ describe('ComColMetadataComponent', () => { } /* eslint-enable no-empty,@typescript-eslint/no-empty-function */ }, - deleteLogo: false, }; spyOn(router, 'navigate'); }); @@ -150,48 +146,84 @@ describe('ComColMetadataComponent', () => { }); }); - describe('with at least one item in the uploader\'s queue', () => { + describe('with an empty operations array', () => { beforeEach(() => { data = { - dso: Object.assign(new Community(), { - metadata: [{ - key: 'dc.title', - value: 'test' - }] - }), + operations: [], + dso: new Community(), uploader: { options: { url: '' }, - queue: [ - {} - ], + queue: [], /* eslint-disable no-empty,@typescript-eslint/no-empty-function */ uploadAll: () => { } - /* eslint-enable no-empty, @typescript-eslint/no-empty-function */ - } + /* eslint-enable no-empty,@typescript-eslint/no-empty-function */ + }, }; + spyOn(router, 'navigate'); }); - it('should not navigate', () => { - spyOn(router, 'navigate'); + it('should navigate', () => { comp.onSubmit(data); fixture.detectChanges(); - expect(router.navigate).not.toHaveBeenCalled(); + expect(router.navigate).toHaveBeenCalled(); }); + }); - it('should set the uploader\'s url to the logo\'s endpoint', () => { - comp.onSubmit(data); - fixture.detectChanges(); - expect(data.uploader.options.url).toEqual(logoEndpoint); + describe('with a not empty operations array', () => { + beforeEach(() => { + data = { + operations: [ + { + op: 'replace', + path: '/metadata/dc.title', + value: { + value: 'test', + language: null, + }, + }, + ], + dso: new Community(), + uploader: { + options: { + url: '' + }, + queue: [], + /* eslint-disable no-empty,@typescript-eslint/no-empty-function */ + uploadAll: () => { + } + /* eslint-enable no-empty,@typescript-eslint/no-empty-function */ + }, + }; + spyOn(router, 'navigate'); }); - it('should call the uploader\'s uploadAll', () => { - spyOn(data.uploader, 'uploadAll'); - comp.onSubmit(data); - fixture.detectChanges(); - expect(data.uploader.uploadAll).toHaveBeenCalled(); + describe('when successful', () => { + + beforeEach(() => { + spyOn(dsoDataService, 'patch').and.returnValue(createSuccessfulRemoteDataObject$({})); + }); + + it('should navigate', () => { + comp.onSubmit(data); + fixture.detectChanges(); + expect(router.navigate).toHaveBeenCalled(); + }); + }); + + describe('on failure', () => { + + beforeEach(() => { + spyOn(dsoDataService, 'patch').and.returnValue(createFailedRemoteDataObject$('Error', 500)); + }); + + it('should not navigate', () => { + comp.onSubmit(data); + fixture.detectChanges(); + expect(router.navigate).not.toHaveBeenCalled(); + }); }); }); }); diff --git a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts index 7fb1ad1c2c8..8777568f0aa 100644 --- a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts +++ b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts @@ -18,15 +18,14 @@ import { Collection } from '../../../../../core/shared/collection.model'; template: '' }) export class ComcolMetadataComponent implements OnInit { - /** - * Frontend endpoint for this type of DSO - */ - protected frontendURL: string; /** * The initial DSO object */ public dsoRD$: Observable>; - + /** + * Frontend endpoint for this type of DSO + */ + protected frontendURL: string; /** * The type of the dso */ @@ -54,7 +53,7 @@ export class ComcolMetadataComponent imp this.dsoDataService.patch(event.dso, event.operations).pipe(getFirstCompletedRemoteData()) .subscribe(async (response: RemoteData) => { if (response.hasSucceeded) { - await this.router.navigate([this.frontendURL + event.dso.uuid]); + await this.router.navigate([this.frontendURL, event.dso.uuid]); this.notificationsService.success(null, this.translate.get(`${this.type.value}.edit.notifications.success`)); } else if (response.statusCode === 403) { this.notificationsService.error(null, this.translate.get(`${this.type.value}.edit.notifications.unauthorized`)); @@ -63,7 +62,7 @@ export class ComcolMetadataComponent imp } }); } else { - this.router.navigate([this.frontendURL + event.dso.uuid]); + this.router.navigate([this.frontendURL, event.dso.uuid]); } } From 794eb6bc59eb8248f90addb06564bb6620b60662 Mon Sep 17 00:00:00 2001 From: Vincenzo Mecca Date: Fri, 1 Mar 2024 18:49:18 +0100 Subject: [PATCH 21/25] [DSC-1111] [DURACOM-235] Fixes item cache refresh in comcol-form --- .../comcol-form/comcol-form.component.html | 6 +++- .../comcol-form/comcol-form.component.ts | 31 +++++++++++-------- .../comcol-metadata.component.spec.ts | 2 +- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html index 815b1b97489..1d752869e5e 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html @@ -11,7 +11,11 @@
- +
diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts index 760891bb4e7..a62d53368db 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts @@ -3,7 +3,7 @@ import { UntypedFormGroup } from '@angular/forms'; import { DynamicFormControlModel, DynamicFormService, DynamicInputModel } from '@ng-dynamic-forms/core'; import { TranslateService } from '@ngx-translate/core'; import { FileUploader } from 'ng2-file-upload'; -import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs'; +import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, Subscription, switchMap } from 'rxjs'; import { AuthService } from '../../../../core/auth/auth.service'; import { ObjectCacheService } from '../../../../core/cache/object-cache.service'; import { ComColDataService } from '../../../../core/data/comcol-data.service'; @@ -24,8 +24,7 @@ import { getFirstCompletedRemoteData } from '../../../../core/shared/operators'; import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; import { followLink } from '../../../utils/follow-link-config.model'; import { ConfirmationModalComponent } from '../../../confirmation-modal/confirmation-modal.component'; -import { map, take, tap } from 'rxjs/operators'; -import { DSpaceObject } from '../../../../core/shared/dspace-object.model'; +import { filter, take } from 'rxjs/operators'; /** * A form for creating and editing Communities or Collections @@ -124,6 +123,8 @@ export class ComColFormComponent implements On public uploader = new FileUploader(this.uploadFilesOptions); + protected readonly refreshDSO$ = new EventEmitter(); + public constructor(protected formService: DynamicFormService, protected translate: TranslateService, protected notificationsService: NotificationsService, @@ -168,6 +169,14 @@ export class ComColFormComponent implements On this.initializedUploaderOptions.next(true); } } + + this.subs.push( + this.refreshDSO$.pipe( + switchMap(() => this.refreshDsoCache()), + filter(rd => rd.hasSucceeded), + ).subscribe(({ payload }) => this.dso = payload) + ); + } /** @@ -304,7 +313,7 @@ export class ComColFormComponent implements On * @param successMessageKey Translation key for success message */ private handleSuccessfulDeletion(successMessageKey: string): void { - this.refreshDsoCache(); + this.refreshDSO$.next(); this.notificationsService.success( this.translate.get(`${successMessageKey}.title`), this.translate.get(`${successMessageKey}.content`) @@ -342,15 +351,10 @@ export class ComColFormComponent implements On /** * Fetches the latest data for the dso */ - private fetchUpdatedDso(): Observable { + private fetchUpdatedDso(): Observable> { return this.dsoService.findById(this.dso.id, false, true, followLink('logo')).pipe( - tap((rd: RemoteData) => { - if (rd.hasSucceeded) { - this.dso = rd.payload; - } - }), - map((rd: RemoteData) => rd.hasSucceeded ? rd.payload : null) - ); + getFirstCompletedRemoteData() + ) as Observable>; } @@ -360,7 +364,7 @@ export class ComColFormComponent implements On */ public onCompleteItem() { if (hasValue(this.dso.id)) { - this.refreshDsoCache(); + this.refreshDSO$.next(); } if (this.isCreation) { this.finish.emit(); @@ -379,6 +383,7 @@ export class ComColFormComponent implements On * Unsubscribe from open subscriptions */ ngOnDestroy(): void { + this.refreshDSO$.complete(); this.subs .filter((subscription) => hasValue(subscription)) .forEach((subscription) => subscription.unsubscribe()); diff --git a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.spec.ts b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.spec.ts index 0ed06140d72..e0c73eae8ba 100644 --- a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.spec.ts +++ b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.spec.ts @@ -17,7 +17,7 @@ import { } from '../../../../remote-data.utils'; import { ComcolMetadataComponent } from './comcol-metadata.component'; -fdescribe('ComColMetadataComponent', () => { +describe('ComColMetadataComponent', () => { let comp: ComcolMetadataComponent; let fixture: ComponentFixture>; let dsoDataService; From a525b066ceff128d97e3935f3464aebd129e6cee Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Mon, 6 May 2024 16:47:34 +0200 Subject: [PATCH 22/25] DURACOM-235 Lint fix --- .../collection-form.component.ts | 41 ++++++++++++++----- .../community-form.component.ts | 2 +- .../comcol-form/comcol-form.component.spec.ts | 11 ++--- .../comcol-form/comcol-form.component.ts | 29 ++++++++----- .../comcol-metadata.component.spec.ts | 4 +- .../comcol-metadata.component.ts | 13 ++---- 6 files changed, 58 insertions(+), 42 deletions(-) diff --git a/src/app/collection-page/collection-form/collection-form.component.ts b/src/app/collection-page/collection-form/collection-form.component.ts index 2c21d64cd38..0758435db88 100644 --- a/src/app/collection-page/collection-form/collection-form.component.ts +++ b/src/app/collection-page/collection-form/collection-form.component.ts @@ -1,33 +1,54 @@ -import { AsyncPipe, NgClass, NgIf, } from '@angular/common'; -import { ChangeDetectorRef, Component, Input, OnChanges, OnInit, SimpleChange, SimpleChanges, } from '@angular/core'; +import { + AsyncPipe, + NgClass, + NgIf, +} from '@angular/common'; +import { + ChangeDetectorRef, + Component, + Input, + OnChanges, + OnInit, + SimpleChange, + SimpleChanges, +} from '@angular/core'; +import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { DynamicFormControlModel, DynamicFormOptionConfig, DynamicFormService, DynamicSelectModel, } from '@ng-dynamic-forms/core'; -import { TranslateModule, TranslateService, } from '@ngx-translate/core'; +import { + TranslateModule, + TranslateService, +} from '@ngx-translate/core'; import { Observable } from 'rxjs'; -import { hasNoValue, isNotNull, } from 'src/app/shared/empty.util'; +import { + hasNoValue, + isNotNull, +} from 'src/app/shared/empty.util'; -import { Collection } from '../../core/shared/collection.model'; -import { ComColFormComponent } from '../../shared/comcol/comcol-forms/comcol-form/comcol-form.component'; -import { NotificationsService } from '../../shared/notifications/notifications.service'; -import { CollectionDataService } from '../../core/data/collection-data.service'; import { AuthService } from '../../core/auth/auth.service'; import { ObjectCacheService } from '../../core/cache/object-cache.service'; +import { CollectionDataService } from '../../core/data/collection-data.service'; import { EntityTypeDataService } from '../../core/data/entity-type-data.service'; import { RequestService } from '../../core/data/request.service'; +import { Collection } from '../../core/shared/collection.model'; import { ItemType } from '../../core/shared/item-relationships/item-type.model'; import { NONE_ENTITY_TYPE } from '../../core/shared/item-relationships/item-type.resource-type'; import { MetadataValue } from '../../core/shared/metadata.models'; import { getFirstSucceededRemoteListPayload } from '../../core/shared/operators'; -import { collectionFormEntityTypeSelectionConfig, collectionFormModels, } from './collection-form.models'; -import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; +import { ComColFormComponent } from '../../shared/comcol/comcol-forms/comcol-form/comcol-form.component'; import { ComcolPageLogoComponent } from '../../shared/comcol/comcol-page-logo/comcol-page-logo.component'; import { FormComponent } from '../../shared/form/form.component'; +import { NotificationsService } from '../../shared/notifications/notifications.service'; import { UploaderComponent } from '../../shared/upload/uploader/uploader.component'; import { VarDirective } from '../../shared/utils/var.directive'; +import { + collectionFormEntityTypeSelectionConfig, + collectionFormModels, +} from './collection-form.models'; /** * Form used for creating and editing collections diff --git a/src/app/community-page/community-form/community-form.component.ts b/src/app/community-page/community-form/community-form.component.ts index 2afba89d749..d32d9e408f2 100644 --- a/src/app/community-page/community-form/community-form.component.ts +++ b/src/app/community-page/community-form/community-form.component.ts @@ -10,6 +10,7 @@ import { SimpleChange, SimpleChanges, } from '@angular/core'; +import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { DynamicFormControlModel, DynamicFormService, @@ -33,7 +34,6 @@ import { FormComponent } from '../../shared/form/form.component'; import { NotificationsService } from '../../shared/notifications/notifications.service'; import { UploaderComponent } from '../../shared/upload/uploader/uploader.component'; import { VarDirective } from '../../shared/utils/var.directive'; -import {NgbModal} from '@ng-bootstrap/ng-bootstrap'; /** * Form used for creating and editing communities diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.spec.ts b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.spec.ts index c0f3e3c3768..2035c313fe6 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.spec.ts +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.spec.ts @@ -29,17 +29,12 @@ import { hasValue } from '../../../empty.util'; import { FormComponent } from '../../../form/form.component'; import { AuthServiceMock } from '../../../mocks/auth.service.mock'; import { NotificationsService } from '../../../notifications/notifications.service'; -import { - createFailedRemoteDataObject$, - createSuccessfulRemoteDataObject$, -} from '../../../remote-data.utils'; +import { createSuccessfulRemoteDataObject$ } from '../../../remote-data.utils'; import { NotificationsServiceStub } from '../../../testing/notifications-service.stub'; import { UploaderComponent } from '../../../upload/uploader/uploader.component'; import { VarDirective } from '../../../utils/var.directive'; import { ComcolPageLogoComponent } from '../../comcol-page-logo/comcol-page-logo.component'; import { ComColFormComponent } from './comcol-form.component'; -import { Operation } from 'fast-json-patch'; -import { createSuccessfulRemoteDataObject$ } from '../../../remote-data.utils'; describe('ComColFormComponent', () => { let comp: ComColFormComponent; @@ -82,7 +77,7 @@ describe('ComColFormComponent', () => { const dsoService = Object.assign({ getLogoEndpoint: () => observableOf(logoEndpoint), deleteLogo: () => createSuccessfulRemoteDataObject$({}), - findById: () => createSuccessfulRemoteDataObject$({}) + findById: () => createSuccessfulRemoteDataObject$({}), }); const notificationsService = new NotificationsServiceStub(); @@ -92,7 +87,7 @@ describe('ComColFormComponent', () => { const requestServiceStub = jasmine.createSpyObj('requestService', { removeByHrefSubstring: {}, - setStaleByHrefSubstring: {} + setStaleByHrefSubstring: {}, }); const objectCacheStub = jasmine.createSpyObj('objectCache', { remove: {}, diff --git a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts index 77cd8c2c1f4..0c80ce0d1d9 100644 --- a/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts +++ b/src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts @@ -13,6 +13,10 @@ import { ViewChild, } from '@angular/core'; import { UntypedFormGroup } from '@angular/forms'; +import { + NgbModal, + NgbModalRef, +} from '@ng-bootstrap/ng-bootstrap'; import { DynamicFormControlModel, DynamicFormService, @@ -27,10 +31,15 @@ import { FileUploader } from 'ng2-file-upload'; import { BehaviorSubject, combineLatest as observableCombineLatest, + Observable, Subscription, + switchMap, } from 'rxjs'; +import { + filter, + take, +} from 'rxjs/operators'; -import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, Subscription, switchMap } from 'rxjs'; import { AuthService } from '../../../../core/auth/auth.service'; import { ObjectCacheService } from '../../../../core/cache/object-cache.service'; import { ComColDataService } from '../../../../core/data/comcol-data.service'; @@ -46,6 +55,7 @@ import { import { NoContent } from '../../../../core/shared/NoContent.model'; import { getFirstCompletedRemoteData } from '../../../../core/shared/operators'; import { ResourceType } from '../../../../core/shared/resource-type'; +import { ConfirmationModalComponent } from '../../../confirmation-modal/confirmation-modal.component'; import { hasValue, isNotEmpty, @@ -54,12 +64,9 @@ import { FormComponent } from '../../../form/form.component'; import { NotificationsService } from '../../../notifications/notifications.service'; import { UploaderComponent } from '../../../upload/uploader/uploader.component'; import { UploaderOptions } from '../../../upload/uploader/uploader-options.model'; +import { followLink } from '../../../utils/follow-link-config.model'; import { VarDirective } from '../../../utils/var.directive'; import { ComcolPageLogoComponent } from '../../comcol-page-logo/comcol-page-logo.component'; -import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; -import { followLink } from '../../../utils/follow-link-config.model'; -import { ConfirmationModalComponent } from '../../../confirmation-modal/confirmation-modal.component'; -import { filter, take } from 'rxjs/operators'; /** * A form for creating and editing Communities or Collections @@ -220,7 +227,7 @@ export class ComColFormComponent implements On this.refreshDSO$.pipe( switchMap(() => this.refreshDsoCache()), filter(rd => rd.hasSucceeded), - ).subscribe(({ payload }) => this.dso = payload) + ).subscribe(({ payload }) => this.dso = payload), ); } @@ -324,7 +331,7 @@ export class ComColFormComponent implements On */ subscribeToConfirmationResponse(modalRef: NgbModalRef): void { modalRef.componentInstance.response.pipe( - take(1) + take(1), ).subscribe((confirmed: boolean) => { if (confirmed) { this.handleLogoDeletion(); @@ -338,7 +345,7 @@ export class ComColFormComponent implements On handleLogoDeletion(): void { if (hasValue(this.dso.id) && hasValue(this.dso._links.logo)) { this.dsoService.deleteLogo(this.dso).pipe( - getFirstCompletedRemoteData() + getFirstCompletedRemoteData(), ).subscribe((response: RemoteData) => { const successMessageKey = `${this.type.value}.edit.logo.notifications.delete.success`; const errorMessageKey = `${this.type.value}.edit.logo.notifications.delete.error`; @@ -362,7 +369,7 @@ export class ComColFormComponent implements On this.refreshDSO$.next(); this.notificationsService.success( this.translate.get(`${successMessageKey}.title`), - this.translate.get(`${successMessageKey}.content`) + this.translate.get(`${successMessageKey}.content`), ); } @@ -374,7 +381,7 @@ export class ComColFormComponent implements On private handleFailedDeletion(errorMessageKey: string, errorMessage: string): void { this.notificationsService.error( this.translate.get(`${errorMessageKey}.title`), - errorMessage + errorMessage, ); } @@ -399,7 +406,7 @@ export class ComColFormComponent implements On */ private fetchUpdatedDso(): Observable> { return this.dsoService.findById(this.dso.id, false, true, followLink('logo')).pipe( - getFirstCompletedRemoteData() + getFirstCompletedRemoteData(), ) as Observable>; } diff --git a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.spec.ts b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.spec.ts index afa8e7d5f93..e2b71b39414 100644 --- a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.spec.ts +++ b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.spec.ts @@ -195,12 +195,12 @@ describe('ComColMetadataComponent', () => { dso: new Community(), uploader: { options: { - url: '' + url: '', }, queue: [], /* eslint-disable no-empty,@typescript-eslint/no-empty-function */ uploadAll: () => { - } + }, /* eslint-enable no-empty,@typescript-eslint/no-empty-function */ }, }; diff --git a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts index 2f6b70f61fd..b895f6c80d9 100644 --- a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts +++ b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts @@ -15,10 +15,6 @@ import { import { ComColDataService } from '../../../../../core/data/comcol-data.service'; import { RemoteData } from '../../../../../core/data/remote-data'; -import { ActivatedRoute, Router } from '@angular/router'; -import { map, take } from 'rxjs/operators'; -import { getFirstCompletedRemoteData, getFirstSucceededRemoteData } from '../../../../../core/shared/operators'; -import { isEmpty } from '../../../../empty.util'; import { Collection } from '../../../../../core/shared/collection.model'; import { Community } from '../../../../../core/shared/community.model'; import { DSpaceObject } from '../../../../../core/shared/dspace-object.model'; @@ -27,10 +23,7 @@ import { getFirstSucceededRemoteData, } from '../../../../../core/shared/operators'; import { ResourceType } from '../../../../../core/shared/resource-type'; -import { - hasValue, - isEmpty, -} from '../../../../empty.util'; +import { isEmpty } from '../../../../empty.util'; import { NotificationsService } from '../../../../notifications/notifications.service'; @Component({ @@ -72,9 +65,9 @@ export class ComcolMetadataComponent imp onSubmit(event) { if (!isEmpty(event.operations)) { this.dsoDataService.patch(event.dso, event.operations).pipe(getFirstCompletedRemoteData()) - .subscribe(async (response: RemoteData) => { + .subscribe( (response: RemoteData) => { if (response.hasSucceeded) { - await this.router.navigate([this.frontendURL, event.dso.uuid]); // todo: ok not to await this? + this.router.navigate([this.frontendURL, event.dso.uuid]); // todo: ok not to await this? this.notificationsService.success(null, this.translate.get(`${this.type.value}.edit.notifications.success`)); } else if (response.statusCode === 403) { this.notificationsService.error(null, this.translate.get(`${this.type.value}.edit.notifications.unauthorized`)); From b689b9f8a541701dbad69bd51c8cf9e490059522 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Tue, 14 May 2024 18:14:43 +0200 Subject: [PATCH 23/25] [DURACOM-235] Fixed home page path --- src/app/app-routing-paths.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/app-routing-paths.ts b/src/app/app-routing-paths.ts index fe2837c6e3f..19a8b05021c 100644 --- a/src/app/app-routing-paths.ts +++ b/src/app/app-routing-paths.ts @@ -32,7 +32,7 @@ export function getBitstreamRequestACopyRoute(item, bitstream): { routerLink: st }; } -export const HOME_PAGE_PATH = 'admin'; +export const HOME_PAGE_PATH = 'home'; export function getHomePageRoute() { return `/${HOME_PAGE_PATH}`; From dbf9d29980c3d8755ee4c0539bc5acdc97373742 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Tue, 14 May 2024 18:15:47 +0200 Subject: [PATCH 24/25] [DURACOM-235] Refactored creation in order to navigate to created object page --- .../create-collection-page.component.html | 3 +- .../create-community-page.component.html | 3 +- .../create-comcol-page.component.ts | 45 ++++++++++++------- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/app/collection-page/create-collection-page/create-collection-page.component.html b/src/app/collection-page/create-collection-page/create-collection-page.component.html index ddce9dbec42..465042f6e33 100644 --- a/src/app/collection-page/create-collection-page/create-collection-page.component.html +++ b/src/app/collection-page/create-collection-page/create-collection-page.component.html @@ -6,6 +6,5 @@

{{'collection.create.sub-head' | + (back)="navigateToHome()"> diff --git a/src/app/community-page/create-community-page/create-community-page.component.html b/src/app/community-page/create-community-page/create-community-page.component.html index d99069f6c84..666f8e2ce0f 100644 --- a/src/app/community-page/create-community-page/create-community-page.component.html +++ b/src/app/community-page/create-community-page/create-community-page.component.html @@ -9,6 +9,5 @@

{{ 'community.crea + (back)="navigateToHome()"> diff --git a/src/app/shared/comcol/comcol-forms/create-comcol-page/create-comcol-page.component.ts b/src/app/shared/comcol/comcol-forms/create-comcol-page/create-comcol-page.component.ts index 9034bffe8e6..af97b712d70 100644 --- a/src/app/shared/comcol/comcol-forms/create-comcol-page/create-comcol-page.component.ts +++ b/src/app/shared/comcol/comcol-forms/create-comcol-page/create-comcol-page.component.ts @@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { TranslateService } from '@ngx-translate/core'; import { Observable } from 'rxjs'; -import { mergeMap, take } from 'rxjs/operators'; +import { map, mergeMap, take, tap } from 'rxjs/operators'; import { ComColDataService } from '../../../../core/data/comcol-data.service'; import { CommunityDataService } from '../../../../core/data/community-data.service'; import { RemoteData } from '../../../../core/data/remote-data'; @@ -16,6 +16,8 @@ import { RequestParam } from '../../../../core/cache/models/request-param.model' import { RequestService } from '../../../../core/data/request.service'; import { Collection } from '../../../../core/shared/collection.model'; import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service'; +import { of } from 'rxjs/internal/observable/of'; +import { getHomePageRoute } from '../../../../app-routing-paths'; /** * Component representing the create page for communities and collections @@ -83,33 +85,46 @@ export class CreateComColPageComponent i this.parentUUID$.pipe( take(1), mergeMap((uuid: string) => { - const params = uuid ? [new RequestParam('parent', uuid)] : []; - return this.dsoDataService.create(dso, ...params) - .pipe(getFirstSucceededRemoteDataPayload() - ); - })) - .subscribe((dsoRD: TDomain) => { + const params = uuid ? [new RequestParam('parent', uuid)] : []; + return this.dsoDataService.create(dso, ...params) + .pipe(getFirstSucceededRemoteDataPayload() + ); + }), + mergeMap((dsoRD: TDomain) => { if (isNotUndefined(dsoRD)) { this.newUUID = dsoRD.uuid; if (uploader.queue.length > 0) { - this.dsoDataService.getLogoEndpoint(this.newUUID).pipe(take(1)).subscribe((href: string) => { - uploader.options.url = href; - uploader.uploadAll(); - }); + return this.dsoDataService.getLogoEndpoint(this.newUUID).pipe( + take(1), + tap((href: string) => { + uploader.options.url = href; + uploader.onCompleteAll = () => { + this.navigateToNewPage(); + this.notificationsService.success(null, this.translate.get(this.type.value + '.create.notifications.success')); + }; + uploader.uploadAll(); + }), + map(() => false) + ); } else { - this.navigateToNewPage(); + this.dsoDataService.refreshCache(dsoRD); + return of(true); } - this.dsoDataService.refreshCache(dsoRD); } + }) + ).subscribe((notify: boolean) => { + if (notify) { + this.navigateToNewPage(); this.notificationsService.success(null, this.translate.get(this.type.value + '.create.notifications.success')); - }); + } + }); } /** * Navigate to home page */ navigateToHome() { - this.router.navigate(['/home']); + this.router.navigate([getHomePageRoute()]); } /** From b7d454ffc1e2a26fc6c407c1d62011ec34df691c Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Tue, 14 May 2024 18:44:54 +0200 Subject: [PATCH 25/25] [DURACOM-235] fix refactored after merge --- .../create-comcol-page.component.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/app/shared/comcol/comcol-forms/create-comcol-page/create-comcol-page.component.ts b/src/app/shared/comcol/comcol-forms/create-comcol-page/create-comcol-page.component.ts index 65992413746..cb2b5a9f0c5 100644 --- a/src/app/shared/comcol/comcol-forms/create-comcol-page/create-comcol-page.component.ts +++ b/src/app/shared/comcol/comcol-forms/create-comcol-page/create-comcol-page.component.ts @@ -7,16 +7,18 @@ import { TranslateService } from '@ngx-translate/core'; import { BehaviorSubject, Observable, + of, } from 'rxjs'; import { + map, mergeMap, take, + tap, } from 'rxjs/operators'; +import { getHomePageRoute } from '../../../../app-routing-paths'; import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service'; import { RequestParam } from '../../../../core/cache/models/request-param.model'; -import { Observable } from 'rxjs'; -import { map, mergeMap, take, tap } from 'rxjs/operators'; import { ComColDataService } from '../../../../core/data/comcol-data.service'; import { CommunityDataService } from '../../../../core/data/community-data.service'; import { RemoteData } from '../../../../core/data/remote-data'; @@ -32,12 +34,6 @@ import { isNotUndefined, } from '../../../empty.util'; import { NotificationsService } from '../../../notifications/notifications.service'; -import { RequestParam } from '../../../../core/cache/models/request-param.model'; -import { RequestService } from '../../../../core/data/request.service'; -import { Collection } from '../../../../core/shared/collection.model'; -import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service'; -import { of } from 'rxjs/internal/observable/of'; -import { getHomePageRoute } from '../../../../app-routing-paths'; /** * Component representing the create page for communities and collections @@ -118,7 +114,6 @@ export class CreateComColPageComponent i ); }), mergeMap((dsoRD: TDomain) => { - this.isLoading$.next(false); if (isNotUndefined(dsoRD)) { this.newUUID = dsoRD.uuid; if (uploader.queue.length > 0) { @@ -127,21 +122,23 @@ export class CreateComColPageComponent i tap((href: string) => { uploader.options.url = href; uploader.onCompleteAll = () => { + this.isLoading$.next(false); this.navigateToNewPage(); this.notificationsService.success(null, this.translate.get(this.type.value + '.create.notifications.success')); }; uploader.uploadAll(); }), - map(() => false) + map(() => false), ); } else { this.dsoDataService.refreshCache(dsoRD); return of(true); } } - }) + }), ).subscribe((notify: boolean) => { if (notify) { + this.isLoading$.next(false); this.navigateToNewPage(); this.notificationsService.success(null, this.translate.get(this.type.value + '.create.notifications.success')); }