Commit 1c46de0e authored by Florent POITTEVIN's avatar Florent POITTEVIN
Browse files

fix: unable to save deposit after edition due to javascript error

parent 8eb97960
......@@ -27,6 +27,7 @@ import {AppBannerState} from "@app/stores/banner/app-banner.state";
import {AppOrgUnitPersonRoleAction} from "@app/stores/organizational-unit-person-role/app-organizational-unit-person-role.action";
import {DepositRejectDialog} from "@deposit/components/dialogs/deposit-reject/deposit-reject.dialog";
import {ModeDepositTabEnum} from "@deposit/enums/mode-deposit-tab.enum";
import {DataFileUploadHelper} from "@deposit/helpers/data-file-upload.helper";
import {
DepositHelper,
DepositMode,
......@@ -331,7 +332,7 @@ export class DepositDetailEditRoutable extends SharedAbstractDetailEditRoutable<
}
private computedShouldContinuePolling(): void {
this.shouldContinuePolling = DepositDataFileState.numberFilesPending(this._store) > 0
this.shouldContinuePolling = DataFileUploadHelper.numberFilesPending(this._store) > 0
&& MemoizedUtil.selectSnapshot(this._store, DepositState, state => state?.current?.status !== Enums.Deposit.StatusEnum.CLEANED);
}
......@@ -385,14 +386,14 @@ export class DepositDetailEditRoutable extends SharedAbstractDetailEditRoutable<
let canSubmitAction = deposit.status === Enums.Deposit.StatusEnum.INPROGRESS;
this.messageReasonUnableSubmit = undefined;
this.messageParametersUnableSubmit = undefined;
if (DepositDataFileState.numberFiles(this._store) === 0 && numberCollections === 0) {
if (DataFileUploadHelper.numberFiles(this._store) === 0 && numberCollections === 0) {
this.messageReasonUnableSubmit = MARK_AS_TRANSLATABLE("deposit.error.noFileOrCollection");
canSubmitAction = false;
}
const numberFilesPending = DepositDataFileState.numberFilesPending(this._store);
const numberFilesIgnored = DepositDataFileState.numberFilesIgnored(this._store);
const numberFilesInError = DepositDataFileState.numberFilesInError(this._store);
const numberFilesExcluded = DepositDataFileState.numberFilesExcluded(this._store);
const numberFilesPending = DataFileUploadHelper.numberFilesPending(this._store);
const numberFilesIgnored = DataFileUploadHelper.numberFilesIgnored(this._store);
const numberFilesInError = DataFileUploadHelper.numberFilesInError(this._store);
const numberFilesExcluded = DataFileUploadHelper.numberFilesExcluded(this._store);
if (numberFilesPending > 0) {
this.messageReasonUnableSubmit = MARK_AS_TRANSLATABLE("deposit.error.fileNotReady");
......
......@@ -5,9 +5,29 @@ import {UploadEventModel} from "@app/features/deposit/models/upload-event.model"
import {UploadFileStatus} from "@app/features/deposit/models/upload-file-status.model";
import {DepositStateModel} from "@app/features/deposit/stores/deposit.state";
import {Guid} from "@app/shared/models/guid.model";
import {StateContext} from "@ngxs/store";
import {DepositDataFileState} from "@deposit/stores/data-file/deposit-data-file.state";
import {Enums} from "@enums";
import {
StateContext,
Store,
} from "@ngxs/store";
import {
MappingObjectUtil,
MemoizedUtil,
} from "solidify-frontend";
export class DataFileUploadHelper {
private static readonly LIST_PENDING_STATUS: Enums.DataFile.StatusEnum[] = [
Enums.DataFile.StatusEnum.RECEIVED,
Enums.DataFile.StatusEnum.CHANGE_RELATIVE_LOCATION,
Enums.DataFile.StatusEnum.TO_PROCESS,
Enums.DataFile.StatusEnum.PROCESSED,
Enums.DataFile.StatusEnum.FILE_FORMAT_IDENTIFIED,
Enums.DataFile.StatusEnum.FILE_FORMAT_UNKNOWN,
Enums.DataFile.StatusEnum.VIRUS_CHECKED,
Enums.DataFile.StatusEnum.CLEANING,
];
static addToUploadStatus(ctx: StateContext<DepositStateModel>, fileUploadWrapper: FileUploadWrapper, isArchive: boolean): UploadFileStatus {
const uploadFileStatus = this.createNewUploadFileStatus(fileUploadWrapper, isArchive);
ctx.patchState({
......@@ -94,4 +114,39 @@ export class DataFileUploadHelper {
const uploadStatus = ctx.getState().uploadStatus;
return uploadStatus.findIndex(u => u.guid === guid);
}
static numberFiles(store: Store): number {
const listCurrentStatus = MemoizedUtil.selectSnapshot(store, DepositDataFileState, state => state.listCurrentStatus);
let pendingCounter = 0;
MappingObjectUtil.forEach(listCurrentStatus, (value, key: Enums.DataFile.StatusEnum) => {
pendingCounter += value;
});
return pendingCounter;
}
static numberFilesInError(store: Store): number {
const listCurrentStatus = MemoizedUtil.selectSnapshot(store, DepositDataFileState, state => state.listCurrentStatus);
return MappingObjectUtil.get(listCurrentStatus, Enums.DataFile.StatusEnum.IN_ERROR) ?? 0;
}
static numberFilesIgnored(store: Store): number {
const listCurrentStatus = MemoizedUtil.selectSnapshot(store, DepositDataFileState, state => state.listCurrentStatus);
return MappingObjectUtil.get(listCurrentStatus, Enums.DataFile.StatusEnum.IGNORED_FILE) ?? 0;
}
static numberFilesExcluded(store: Store): number {
const listCurrentStatus = MemoizedUtil.selectSnapshot(store, DepositDataFileState, state => state.listCurrentStatus);
return MappingObjectUtil.get(listCurrentStatus, Enums.DataFile.StatusEnum.EXCLUDED_FILE) ?? 0;
}
static numberFilesPending(store: Store): number {
const listCurrentStatus = MemoizedUtil.selectSnapshot(store, DepositDataFileState, state => state.listCurrentStatus);
let pendingCounter = 0;
MappingObjectUtil.forEach(listCurrentStatus, (value, key: Enums.DataFile.StatusEnum) => {
if (this.LIST_PENDING_STATUS.indexOf(key) !== -1) {
pendingCounter += value;
}
});
return pendingCounter;
}
}
......@@ -100,16 +100,6 @@ export interface DepositDataFileStateModel extends CompositionStateModel<Deposit
export class DepositDataFileState extends CompositionState<DepositDataFileStateModel, DepositDataFile> {
private readonly KEY_STATUS: keyof DepositDataFile = "status";
private readonly KEY_RELATIVE_LOCATION: keyof DepositDataFile = "relativeLocation";
private static readonly LIST_PENDING_STATUS: Enums.DataFile.StatusEnum[] = [
Enums.DataFile.StatusEnum.RECEIVED,
Enums.DataFile.StatusEnum.CHANGE_RELATIVE_LOCATION,
Enums.DataFile.StatusEnum.TO_PROCESS,
Enums.DataFile.StatusEnum.PROCESSED,
Enums.DataFile.StatusEnum.FILE_FORMAT_IDENTIFIED,
Enums.DataFile.StatusEnum.FILE_FORMAT_UNKNOWN,
Enums.DataFile.StatusEnum.VIRUS_CHECKED,
Enums.DataFile.StatusEnum.CLEANING,
];
constructor(protected apiService: ApiService,
protected store: Store,
......@@ -124,41 +114,6 @@ export class DepositDataFileState extends CompositionState<DepositDataFileStateM
});
}
static numberFiles(store: Store): number {
const listCurrentStatus = MemoizedUtil.selectSnapshot(store, DepositDataFileState, state => state.listCurrentStatus);
let pendingCounter = 0;
MappingObjectUtil.forEach(listCurrentStatus, (value, key: Enums.DataFile.StatusEnum) => {
pendingCounter += value;
});
return pendingCounter;
}
static numberFilesInError(store: Store): number {
const listCurrentStatus = MemoizedUtil.selectSnapshot(store, DepositDataFileState, state => state.listCurrentStatus);
return MappingObjectUtil.get(listCurrentStatus, Enums.DataFile.StatusEnum.IN_ERROR) ?? 0;
}
static numberFilesIgnored(store: Store): number {
const listCurrentStatus = MemoizedUtil.selectSnapshot(store, DepositDataFileState, state => state.listCurrentStatus);
return MappingObjectUtil.get(listCurrentStatus, Enums.DataFile.StatusEnum.IGNORED_FILE) ?? 0;
}
static numberFilesExcluded(store: Store): number {
const listCurrentStatus = MemoizedUtil.selectSnapshot(store, DepositDataFileState, state => state.listCurrentStatus);
return MappingObjectUtil.get(listCurrentStatus, Enums.DataFile.StatusEnum.EXCLUDED_FILE) ?? 0;
}
static numberFilesPending(store: Store): number {
const listCurrentStatus = MemoizedUtil.selectSnapshot(store, DepositDataFileState, state => state.listCurrentStatus);
let pendingCounter = 0;
MappingObjectUtil.forEach(listCurrentStatus, (value, key: Enums.DataFile.StatusEnum) => {
if (this.LIST_PENDING_STATUS.indexOf(key) !== -1) {
pendingCounter += value;
}
});
return pendingCounter;
}
protected get _urlResource(): string {
return PreIngestResourceApiEnum.deposits;
}
......
......@@ -922,7 +922,7 @@ export class DepositState extends ResourceLogoState<DepositStateModel, Deposit>
const currentDisplay = url.substring(url.lastIndexOf(urlSeparator) + 1, url.length);
const baseUrl = url.substring(0, url.lastIndexOf(urlSeparator));
const numberCollection = ctx.getState()?.deposit_collection?.numberCollections;
const numberFiles = DepositDataFileState.numberFiles(this.store);
const numberFiles = DataFileUploadHelper.numberFiles(this.store);
let redirectionRouteSuffix = undefined;
if (numberCollection > 0) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment