From 95e16399772b7cf3db02fa682b53ec066e7d405c Mon Sep 17 00:00:00 2001 From: Florent Poittevin <florent.poittevin@unige.ch> Date: Fri, 15 Nov 2019 09:32:03 +0100 Subject: [PATCH] feat: do not redirect to list of deposit when reserve a doi --- .../deposit-detail-edit.routable.ts | 12 ++++++++---- src/app/features/deposit/stores/deposit.state.ts | 14 +++++++++++++- .../shared-abstract-detail-edit.routable.ts | 2 +- src/assets/i18n/de.json | 4 ++-- src/assets/i18n/en.json | 2 +- src/assets/i18n/fr.json | 5 ++--- 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/app/features/deposit/components/routables/deposit-detail-edit/deposit-detail-edit.routable.ts b/src/app/features/deposit/components/routables/deposit-detail-edit/deposit-detail-edit.routable.ts index caeaa87f1..21b0d2028 100644 --- a/src/app/features/deposit/components/routables/deposit-detail-edit/deposit-detail-edit.routable.ts +++ b/src/app/features/deposit/components/routables/deposit-detail-edit/deposit-detail-edit.routable.ts @@ -60,6 +60,7 @@ import { take, } from "rxjs/operators"; import { + isFalse, isNullOrUndefined, isTrue, TRANSLATE, @@ -148,6 +149,13 @@ export class DepositDetailEditRoutable extends SharedAbstractDetailEditRoutable< } private _computeCurrentUserRight(): void { + this.subscribe(this.currentObs.pipe( + filter(deposit => !isNullOrUndefined(deposit) && deposit.resId === this._resId && isFalse(this.isEdit) && deposit.status === Deposit.StatusEnum.INPROGRESS), + tap(deposit => { + this.canReserveDoiAction = isNullOrUndefined(deposit.doi); + }), + )); + this.subscribe(this.currentObs.pipe( distinctUntilChanged(), filter(deposit => !isNullOrUndefined(deposit) && deposit.resId === this._resId), @@ -157,9 +165,6 @@ export class DepositDetailEditRoutable extends SharedAbstractDetailEditRoutable< const canDoValidatorActions = this._securityService.depositInValidationStep(deposit); const canDoAlterationActions = this._securityService.depositInEditionStep(deposit); - if (deposit.status === Deposit.StatusEnum.INPROGRESS && isNullOrUndefined(deposit.doi)) { - this.canReserveDoiAction = true; - } this.subscribe(combineLatest(this.numberFilesObs, this.numberFilesInErrorObs).pipe( distinctUntilChanged(), filter(([numberFiles, numberFilesInError]) => !isNullOrUndefined(numberFiles) && !isNullOrUndefined(numberFilesInError)), @@ -305,5 +310,4 @@ export class DepositDetailEditRoutable extends SharedAbstractDetailEditRoutable< ).subscribe(); } - } diff --git a/src/app/features/deposit/stores/deposit.state.ts b/src/app/features/deposit/stores/deposit.state.ts index cf1743a89..8fea19f3a 100644 --- a/src/app/features/deposit/stores/deposit.state.ts +++ b/src/app/features/deposit/stores/deposit.state.ts @@ -457,6 +457,9 @@ export class DepositState extends ResourceState<DepositExtended> { @Action(DepositAction.ReserveDOI) reserveDOI(ctx: StateContext<DepositStateModel>, action: DepositAction.ReserveDOI): Observable<DepositExtended> { + ctx.patchState({ + isLoadingCounter: ctx.getState().isLoadingCounter + 1, + }); return this.apiService.patchByIdWithCustomUrl(this._urlResource + urlSeparator + action.deposit.resId + urlSeparator + ApiActionEnum.RESERVE_DOI) .pipe( tap(deposit => ctx.dispatch(new DepositAction.ReserveDOISuccess(deposit))), @@ -469,12 +472,21 @@ export class DepositState extends ResourceState<DepositExtended> { @Action(DepositAction.ReserveDOISuccess) reserveDOISuccess(ctx: StateContext<DepositStateModel>, action: DepositAction.ReserveDOISuccess): void { - ctx.dispatch(new Navigate([RoutesEnum.deposit])); + ctx.patchState({ + current: undefined, + }); + ctx.patchState({ + current: action.deposit, + isLoadingCounter: ctx.getState().isLoadingCounter - 1, + }); this.notificationService.showSuccess(TRANSLATE("deposit.notification.reserveDOI.success"), true); } @Action(DepositAction.ReserveDOIFail) reserveDOIFail(ctx: StateContext<DepositStateModel>, action: DepositAction.ReserveDOIFail): void { + ctx.patchState({ + isLoadingCounter: ctx.getState().isLoadingCounter - 1, + }); this.notificationService.showError(TRANSLATE("deposit.notification.reserveDOI.fail"), true); } } diff --git a/src/app/shared/components/routables/shared-abstract-detail-edit/shared-abstract-detail-edit.routable.ts b/src/app/shared/components/routables/shared-abstract-detail-edit/shared-abstract-detail-edit.routable.ts index fc88c4b91..5b40d95d4 100644 --- a/src/app/shared/components/routables/shared-abstract-detail-edit/shared-abstract-detail-edit.routable.ts +++ b/src/app/shared/components/routables/shared-abstract-detail-edit/shared-abstract-detail-edit.routable.ts @@ -148,7 +148,7 @@ export abstract class SharedAbstractDetailEditRoutable<TResourceModel, UResource const currentUrl = this._store.selectSnapshot((s: LocalStateModel) => s.router.state.url); this._store.dispatch(new Navigate([StoreRouteLocalUtil.getDetailRoute(this.state), this._resId])).subscribe((state: LocalStateModel) => { if (state.router.state.url !== currentUrl) { - this.formPresentational.resetFormToInitialValue(); + // this.formPresentational.resetFormToInitialValue(); // TODO : Fix don't need to get by id model from backend but fix resetFormToInitialValue with component user role org unit // TODO : Problem currently if redirect to detail page via breadcrumb in case of Deposit this.retrieveCurrentModelWithUrl(); diff --git a/src/assets/i18n/de.json b/src/assets/i18n/de.json index 2aa7aa67e..6d0978fa8 100644 --- a/src/assets/i18n/de.json +++ b/src/assets/i18n/de.json @@ -830,7 +830,7 @@ }, "reserveDOI": { "fail": "There was an error when reserving DOI of the deposit", - "success": "DOI reserved" + "success": "DOI reserved with success" } }, "organizationUnit": "Organizational Unit", @@ -863,8 +863,8 @@ "reject": "Reject", "submissionPolicy": "Submission Policy", "submit": "Submit", - "reserveDOI": "Reserve DOI", "doi": "DOI", + "reserveDOI": "Reserve DOI", "tab": { "datafiles": "Files", "details": "Metadata" diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 1d3a73765..6d0978fa8 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -830,7 +830,7 @@ }, "reserveDOI": { "fail": "There was an error when reserving DOI of the deposit", - "success": "DOI reserved" + "success": "DOI reserved with success" } }, "organizationUnit": "Organizational Unit", diff --git a/src/assets/i18n/fr.json b/src/assets/i18n/fr.json index 14fa3b41c..565a68033 100644 --- a/src/assets/i18n/fr.json +++ b/src/assets/i18n/fr.json @@ -829,8 +829,8 @@ "success": "Dépôt soumis" }, "reserveDOI": { - "fail": "Il y a eu une erreur lors de la réservation du DOI du dépôt", - "success": "DOI réserve" + "fail": "Il y a eu une erreur lors de la réservation du DOI", + "success": "DOI réservé avec succès" } }, "organizationUnit": "Unité organisationnelle", @@ -897,7 +897,6 @@ "publicationDate": "Date à partir de laquelle le dataset (dépôt) doit être disponible en ligne de manière publique", "submissionPolicy": "Montre les options qui ont été choisies lors de la création de votre espace de préservation (ou unité organisationnelle).\n\nVoir la documentation pour plus d'informations", "doi": "Si vous souhaitez attribuer un DOI avant la fin du processus d'archivage,\n\nvous pouvez l'attribuer avec le bouton 'Réserver un DOI" - } }, "error": { -- GitLab