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 1c48c6a8414c97bd375439f5a471729f3061a8d7..ca5de2c037f05ce8911e8d3ed94f4843aa6598e1 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 @@ -128,7 +128,6 @@ export class DepositDetailEditRoutable extends SharedAbstractDetailEditRoutable< canDoAlterationActions: boolean = false; canSubmitAction: boolean = false; canReserveDoiAction: boolean = false; - afterChangeInFiles: boolean = false; canDoAlterationActionsBS: BehaviorSubject<boolean | undefined> = new BehaviorSubject(undefined); readonly canDoAlterationActionsObs: Observable<boolean | undefined> = ObservableUtil.asObservable(this.canDoAlterationActionsBS); @@ -234,6 +233,37 @@ export class DepositDetailEditRoutable extends SharedAbstractDetailEditRoutable< } this.listTabs = [...this.listTabs]; }); + + this._createPollingListenerForFileReady(); + } + + private _createPollingListenerForFileReady(): void { + this.subscribe(PollingHelper.startPollingObs({ + intervalRefreshInSecond: environment.refreshDepositSubmittedIntervalInSecond, + doBeforeFilter: () => { + const shouldContinuePollingBefore = this.shouldContinuePolling; + this.computedShouldContinuePolling(); + if (shouldContinuePollingBefore && !this.shouldContinuePolling) { + this._store.dispatch(new DepositDataFileAction.Refresh(this._resId)); + } + }, + filter: () => this.shouldContinuePolling, + actionToDo: () => { + this._store.dispatch(new DepositDataFileAction.GetNumberFilesInError(this._resId)); + this._store.dispatch(new DepositDataFileAction.GetNumberFilesIgnored(this._resId)); + this._store.dispatch(new DepositDataFileAction.GetNumberFilesExcluded(this._resId)); + this._store.dispatch(new DepositDataFileAction.GetNumberFilesNotReady(this._resId)); + }, + })); + } + + private shouldContinuePolling: boolean = false; + + private computedShouldContinuePolling(): void { + this.shouldContinuePolling = MemoizedUtil.selectSnapshot(this._store, DepositDataFileState, state => state.numberFilesInError === 0) + && MemoizedUtil.selectSnapshot(this._store, DepositDataFileState, state => state.numberFilesIgnored === 0) + && MemoizedUtil.selectSnapshot(this._store, DepositDataFileState, state => state.numberFilesExcluded === 0) + && MemoizedUtil.selectSnapshot(this._store, DepositDataFileState, state => state.numberFilesNotReady > 0); } ngOnDestroy(): void { @@ -270,7 +300,7 @@ export class DepositDetailEditRoutable extends SharedAbstractDetailEditRoutable< const canDoValidatorActions = this._securityService.depositInValidationStep(deposit); const canDoAlterationActions = this._securityService.depositInEditionStep(deposit); - this.subscribe(combineLatest(this.numberCollectionObs, this.numberFilesObs, this.numberFilesNotReady) + this.subscribe(combineLatest([this.numberCollectionObs, this.numberFilesObs, this.numberFilesNotReady]) .pipe( distinctUntilChanged(), filter(([numberCollections, numberFiles, numberFilesNotReady]) => @@ -278,7 +308,6 @@ export class DepositDetailEditRoutable extends SharedAbstractDetailEditRoutable< !isNullOrUndefined(numberFiles) && !isNullOrUndefined(numberFilesNotReady)), tap(([numberCollections, numberFiles, numberFilesNotReady]) => { - this.afterChangeInFiles = true; let canSubmitAction = deposit.status === Deposit.StatusEnum.INPROGRESS; this.messageReasonUnableSubmit = undefined; if (numberFiles === 0 && numberCollections === 0) { @@ -289,33 +318,11 @@ export class DepositDetailEditRoutable extends SharedAbstractDetailEditRoutable< this.messageReasonUnableSubmit = TRANSLATE("deposit.error.fileNotReady"); canSubmitAction = false; } + console.error("CAN SUBMIT ACTION", canSubmitAction); this.canSubmitAction = canSubmitAction; }), )); - if (this.afterChangeInFiles) { - this.subscribe(PollingHelper.startPollingObs({ - intervalRefreshInSecond: environment.refreshDepositSubmittedIntervalInSecond, - actionToDo: () => { - this._store.dispatch(new DepositDataFileAction.GetNumberFilesInError(this._resId)); - this._store.dispatch(new DepositDataFileAction.GetNumberFilesExcluded(this._resId)); - this._store.dispatch(new DepositDataFileAction.GetNumberFilesIgnored(this._resId)); - this._store.dispatch(new DepositDataFileAction.GetNumberFilesNotReady(this._resId)); - }, - continueUntil: () => MemoizedUtil.selectSnapshot(this._store, DepositDataFileState, state => state.numberFilesInError === 0) - && MemoizedUtil.selectSnapshot(this._store, DepositDataFileState, state => state.numberFilesIgnored === 0) - && MemoizedUtil.selectSnapshot(this._store, DepositDataFileState, state => state.numberFilesExcluded === 0) - && MemoizedUtil.selectSnapshot(this._store, DepositDataFileState, state => state.numberFilesNotReady > 0), - })).add(() => { - this.canSubmitAction = - (MemoizedUtil.selectSnapshot(this._store, DepositDataFileState, state => state.numberFilesInError === 0) - && MemoizedUtil.selectSnapshot(this._store, DepositDataFileState, state => state.numberFiles > 0) - && MemoizedUtil.selectSnapshot(this._store, DepositDataFileState, state => state.numberFilesExcluded === 0) - && MemoizedUtil.selectSnapshot(this._store, DepositDataFileState, state => state.numberFilesIgnored === 0)) - || MemoizedUtil.selectSnapshot(this._store, DepositCollectionState, state => state.numberCollections > 0); - this.afterChangeInFiles = false; - }); - } if (this._securityService.isRootOrAdmin()) { this.canDoValidatorActions = canDoValidatorActions; this.canDoAlterationActions = canDoAlterationActions; diff --git a/src/app/shared/helpers/polling.helper.ts b/src/app/shared/helpers/polling.helper.ts index d95409405ea9db6350edf966f37d5c1a64d9e441..5df323345f1d07df83ee81365569632dd8a97c42 100644 --- a/src/app/shared/helpers/polling.helper.ts +++ b/src/app/shared/helpers/polling.helper.ts @@ -6,6 +6,7 @@ import { filter, map, takeWhile, + tap, } from "rxjs/operators"; import {isUndefined} from "solidify-frontend"; @@ -14,6 +15,7 @@ export class PollingHelper<Type> { const intervalInMillisecond = config.intervalRefreshInSecond * 1000; return timer(intervalInMillisecond, intervalInMillisecond).pipe( takeWhile(() => isUndefined(config.continueUntil) || config.continueUntil()), + tap(() => isUndefined(config.doBeforeFilter) || config.doBeforeFilter()), filter(() => isUndefined(config.filter) || config.filter()), map(() => config.actionToDo()), ); @@ -22,6 +24,7 @@ export class PollingHelper<Type> { export interface PollingConfigInfo<Type> { intervalRefreshInSecond: number; + doBeforeFilter?: () => void | undefined; continueUntil?: () => boolean | undefined; filter?: () => boolean | undefined; actionToDo: () => Type;