mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-15 14:03:06 +00:00
[835] Auto-save in new Item Submission form breaks the form
Store additions: 1. Form AdditionalData: contains the list of the touched metadata 2. Submission metadata: contains the list of the metadata ids assignable for each section We keep also track whether a section ha focused fields or not.
This commit is contained in:
@@ -8,7 +8,7 @@ import { ScrollToConfigOptions, ScrollToService } from '@nicky-lenaers/ngx-scrol
|
||||
import { isEqual } from 'lodash';
|
||||
|
||||
import { SubmissionState } from '../submission.reducers';
|
||||
import { hasValue, isEmpty, isNotEmpty, isNotUndefined } from '../../shared/empty.util';
|
||||
import { hasValue, isEmpty, isNotEmpty, isNotNull, isNotUndefined } from '../../shared/empty.util';
|
||||
import {
|
||||
DisableSectionAction,
|
||||
EnableSectionAction,
|
||||
@@ -36,6 +36,8 @@ import { SubmissionService } from '../submission.service';
|
||||
import { WorkspaceitemSectionDataType } from '../../core/submission/models/workspaceitem-sections.model';
|
||||
import { SectionsType } from './sections-type';
|
||||
import { normalizeSectionData } from '../../core/submission/submission-response-parsing.service';
|
||||
import { SubmissionFormsModel } from '../../core/config/models/config-submission-forms.model';
|
||||
import { parseReviver } from '@ng-dynamic-forms/core';
|
||||
|
||||
/**
|
||||
* A service that provides methods used in submission process.
|
||||
@@ -335,8 +337,10 @@ export class SectionsService {
|
||||
* The section data
|
||||
* @param errors
|
||||
* The list of section errors
|
||||
* @param metadata
|
||||
* The section metadata
|
||||
*/
|
||||
public updateSectionData(submissionId: string, sectionId: string, data: WorkspaceitemSectionDataType, errors: SubmissionSectionError[] = []) {
|
||||
public updateSectionData(submissionId: string, sectionId: string, data: WorkspaceitemSectionDataType, errors: SubmissionSectionError[] = [], metadata?: string[]) {
|
||||
if (isNotEmpty(data)) {
|
||||
const isAvailable$ = this.isSectionAvailable(submissionId, sectionId);
|
||||
const isEnabled$ = this.isSectionEnabled(submissionId, sectionId);
|
||||
@@ -345,7 +349,7 @@ export class SectionsService {
|
||||
take(1),
|
||||
filter(([available, enabled]: [boolean, boolean]) => available))
|
||||
.subscribe(([available, enabled]: [boolean, boolean]) => {
|
||||
this.store.dispatch(new UpdateSectionDataAction(submissionId, sectionId, data, errors));
|
||||
this.store.dispatch(new UpdateSectionDataAction(submissionId, sectionId, data, errors, metadata));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -377,4 +381,30 @@ export class SectionsService {
|
||||
public setSectionStatus(submissionId: string, sectionId: string, status: boolean) {
|
||||
this.store.dispatch(new SectionStatusChangeAction(submissionId, sectionId, status));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the list of selectable metadata for the section configuration.
|
||||
* @param formConfig
|
||||
*/
|
||||
public computeSectionConfiguredMetadata(formConfig: string | SubmissionFormsModel): string[] {
|
||||
const metadata = [];
|
||||
const rawData = typeof formConfig === 'string' ? JSON.parse(formConfig, parseReviver) : formConfig;
|
||||
if (rawData.rows && !isEmpty(rawData.rows)) {
|
||||
rawData.rows.forEach((currentRow) => {
|
||||
if (currentRow.fields && !isEmpty(currentRow.fields)) {
|
||||
currentRow.fields.forEach((field) => {
|
||||
if (field.selectableMetadata && !isEmpty(field.selectableMetadata)) {
|
||||
field.selectableMetadata.forEach((selectableMetadata) => {
|
||||
if (!metadata.includes(selectableMetadata.metadata)) {
|
||||
metadata.push(selectableMetadata.metadata);
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
return metadata;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user