mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-13 13:03:04 +00:00
populate submission sections with metadata from single effect
This commit is contained in:
@@ -16,10 +16,6 @@ import { FormFieldMetadataValueObject } from '../../shared/form/builder/models/f
|
|||||||
import { SubmissionObject } from './models/submission-object.model';
|
import { SubmissionObject } from './models/submission-object.model';
|
||||||
import { WorkflowItem } from './models/workflowitem.model';
|
import { WorkflowItem } from './models/workflowitem.model';
|
||||||
import { WorkspaceItem } from './models/workspaceitem.model';
|
import { WorkspaceItem } from './models/workspaceitem.model';
|
||||||
import { SubmissionDefinitionsModel } from '../config/models/config-submission-definitions.model';
|
|
||||||
import { SubmissionSectionModel } from '../config/models/config-submission-section.model';
|
|
||||||
import { SectionsType } from '../../submission/sections/sections-type';
|
|
||||||
import { SectionDataModel } from '../../submission/sections/models/section.model';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Export a function to check if object has same properties of FormFieldMetadataValueObject
|
* Export a function to check if object has same properties of FormFieldMetadataValueObject
|
||||||
@@ -140,29 +136,24 @@ export class SubmissionResponseParsingService extends BaseResponseParsingService
|
|||||||
|
|
||||||
processedList.forEach((item) => {
|
processedList.forEach((item) => {
|
||||||
|
|
||||||
|
item = Object.assign({}, item);
|
||||||
// In case data is an Instance of WorkspaceItem normalize field value of all the section of type form
|
// In case data is an Instance of WorkspaceItem normalize field value of all the section of type form
|
||||||
if (item instanceof WorkspaceItem
|
if (item instanceof WorkspaceItem
|
||||||
|| item instanceof WorkflowItem) {
|
|| item instanceof WorkflowItem) {
|
||||||
if (item.sections) {
|
if (item.sections) {
|
||||||
const sectionConfigs = item.sections.page ? (item.submissionDefinition as SubmissionDefinitionsModel).sections.page : [];
|
|
||||||
const precessedSection = Object.create({});
|
const precessedSection = Object.create({});
|
||||||
// Iterate over all workspaceitem's sections
|
// Iterate over all workspaceitem's sections
|
||||||
Object.keys(item.sections)
|
Object.keys(item.sections)
|
||||||
.forEach((sectionId) => {
|
.forEach((sectionId) => {
|
||||||
const sectionConfig: SubmissionSectionModel = sectionConfigs.find((config) => config.id === sectionId);
|
if (typeof item.sections[sectionId] === 'object' && (isNotEmpty(item.sections[sectionId]) &&
|
||||||
let sectionData = item.sections[sectionId];
|
|
||||||
if (sectionConfig && sectionConfig.sectionType === SectionsType.SubmissionForm) {
|
|
||||||
sectionData = item.item.metadata;
|
|
||||||
}
|
|
||||||
if (typeof sectionData === 'object' && (isNotEmpty(sectionData) &&
|
|
||||||
// When Upload section is disabled, add to submission only if there are files
|
// When Upload section is disabled, add to submission only if there are files
|
||||||
(!sectionData.hasOwnProperty('files') || isNotEmpty((sectionData as any).files)))) {
|
(!item.sections[sectionId].hasOwnProperty('files') || isNotEmpty((item.sections[sectionId] as any).files)))) {
|
||||||
|
|
||||||
const sectiondata = Object.create({});
|
const sectiondata = Object.create({});
|
||||||
// Iterate over all sections property
|
// Iterate over all sections property
|
||||||
Object.keys(sectionData)
|
Object.keys(item.sections[sectionId])
|
||||||
.forEach((metdadataId) => {
|
.forEach((metdadataId) => {
|
||||||
const entry = sectionData[metdadataId];
|
const entry = item.sections[sectionId][metdadataId];
|
||||||
// If entry is not an array, for sure is not a section of type form
|
// If entry is not an array, for sure is not a section of type form
|
||||||
if (Array.isArray(entry)) {
|
if (Array.isArray(entry)) {
|
||||||
sectiondata[metdadataId] = [];
|
sectiondata[metdadataId] = [];
|
||||||
|
@@ -25,6 +25,7 @@ import { RelationshipOptions } from '../../models/relationship-options.model';
|
|||||||
import { DynamicConcatModel } from '../models/ds-dynamic-concat.model';
|
import { DynamicConcatModel } from '../models/ds-dynamic-concat.model';
|
||||||
import { RemoveRelationshipAction, UpdateRelationshipAction } from '../relation-lookup-modal/relationship.actions';
|
import { RemoveRelationshipAction, UpdateRelationshipAction } from '../relation-lookup-modal/relationship.actions';
|
||||||
import { SubmissionObject } from '../../../../../core/submission/models/submission-object.model';
|
import { SubmissionObject } from '../../../../../core/submission/models/submission-object.model';
|
||||||
|
import { SaveSubmissionFormAction } from '../../../../../submission/objects/submission-objects.actions';
|
||||||
|
|
||||||
// tslint:disable:max-classes-per-file
|
// tslint:disable:max-classes-per-file
|
||||||
/**
|
/**
|
||||||
|
@@ -16,6 +16,9 @@ import { DynamicConcatModel } from '../models/ds-dynamic-concat.model';
|
|||||||
import { RemoveRelationshipAction } from '../relation-lookup-modal/relationship.actions';
|
import { RemoveRelationshipAction } from '../relation-lookup-modal/relationship.actions';
|
||||||
import { ViewMode } from '../../../../../core/shared/view-mode.model';
|
import { ViewMode } from '../../../../../core/shared/view-mode.model';
|
||||||
import { ReorderableRelationship } from '../existing-metadata-list-element/existing-metadata-list-element.component';
|
import { ReorderableRelationship } from '../existing-metadata-list-element/existing-metadata-list-element.component';
|
||||||
|
import {
|
||||||
|
SaveSubmissionFormAction
|
||||||
|
} from '../../../../../submission/objects/submission-objects.actions';
|
||||||
|
|
||||||
// tslint:disable:max-classes-per-file
|
// tslint:disable:max-classes-per-file
|
||||||
/**
|
/**
|
||||||
|
@@ -4,7 +4,7 @@ import { Store } from '@ngrx/store';
|
|||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { union } from 'lodash';
|
import { union } from 'lodash';
|
||||||
|
|
||||||
import { from as observableFrom, Observable, of as observableOf } from 'rxjs';
|
import { from as observableFrom, Observable, of as observableOf, EMPTY as observableEmpty } from 'rxjs';
|
||||||
import { catchError, map, mergeMap, switchMap, take, tap, withLatestFrom } from 'rxjs/operators';
|
import { catchError, map, mergeMap, switchMap, take, tap, withLatestFrom } from 'rxjs/operators';
|
||||||
import { SubmissionObject } from '../../core/submission/models/submission-object.model';
|
import { SubmissionObject } from '../../core/submission/models/submission-object.model';
|
||||||
import { WorkflowItem } from '../../core/submission/models/workflowitem.model';
|
import { WorkflowItem } from '../../core/submission/models/workflowitem.model';
|
||||||
@@ -46,7 +46,15 @@ import {
|
|||||||
import { SubmissionObjectEntry } from './submission-objects.reducer';
|
import { SubmissionObjectEntry } from './submission-objects.reducer';
|
||||||
import { Item } from '../../core/shared/item.model';
|
import { Item } from '../../core/shared/item.model';
|
||||||
import { RemoteData } from '../../core/data/remote-data';
|
import { RemoteData } from '../../core/data/remote-data';
|
||||||
import { getRemoteDataPayload, getSucceededRemoteData } from '../../core/shared/operators';
|
import {
|
||||||
|
getRemoteDataPayload,
|
||||||
|
getSucceededRemoteData,
|
||||||
|
getFirstSucceededRemoteDataPayload, getAllSucceededRemoteData, getAllSucceededRemoteDataPayload
|
||||||
|
} from '../../core/shared/operators';
|
||||||
|
import { MetadataMap } from '../../core/shared/metadata.models';
|
||||||
|
import { SubmissionObjectDataService } from '../../core/submission/submission-object-data.service';
|
||||||
|
import { followLink } from '../../shared/utils/follow-link-config.model';
|
||||||
|
import { ItemDataService } from '../../core/data/item-data.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SubmissionObjectEffects {
|
export class SubmissionObjectEffects {
|
||||||
@@ -241,6 +249,57 @@ export class SubmissionObjectEffects {
|
|||||||
catchError(() => observableOf(new DiscardSubmissionErrorAction(action.payload.submissionId))));
|
catchError(() => observableOf(new DiscardSubmissionErrorAction(action.payload.submissionId))));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@Effect() addAllMetadataToSectionData = this.actions$.pipe(
|
||||||
|
ofType(SubmissionObjectActionTypes.UPLOAD_SECTION_DATA),
|
||||||
|
tap((v) => {
|
||||||
|
if ((v as any).payload.sectionId === 'orgUnitStep')
|
||||||
|
console.log('EFFECT', 'in', v)
|
||||||
|
}),
|
||||||
|
mergeMap((action: UpdateSectionDataAction) => {
|
||||||
|
const sectionKeys = Object.keys(action.payload.data);
|
||||||
|
|
||||||
|
// quick sanity check to prevent running the rest of the code if this clearly isn't a metadata section
|
||||||
|
const keysThatMightBeMetadataKeys = sectionKeys.find((key: string) => isNotEmpty(key) && key.indexOf('.') > 0);
|
||||||
|
if (hasValue(keysThatMightBeMetadataKeys)) {
|
||||||
|
const submissionObject$ = this.sods
|
||||||
|
.findById(action.payload.submissionId, followLink('item')).pipe(
|
||||||
|
getFirstSucceededRemoteDataPayload()
|
||||||
|
);
|
||||||
|
|
||||||
|
const item$ = submissionObject$.pipe(
|
||||||
|
switchMap((submissionObject: SubmissionObject) => (submissionObject.item as Observable<RemoteData<Item>>).pipe(
|
||||||
|
getFirstSucceededRemoteDataPayload(),
|
||||||
|
)));
|
||||||
|
|
||||||
|
const metadata$ = item$.pipe(
|
||||||
|
map((item: Item) => item.metadata)
|
||||||
|
);
|
||||||
|
|
||||||
|
const metadataKeys$ = metadata$.pipe(
|
||||||
|
map((metadata: MetadataMap) => hasValue(metadata) ? Object.keys(metadata) : undefined)
|
||||||
|
);
|
||||||
|
|
||||||
|
return metadataKeys$.pipe(
|
||||||
|
switchMap((metadataKeys: string[]) => {
|
||||||
|
if (isNotEmpty(metadataKeys)) {
|
||||||
|
const allSectionKeysInMetadata = sectionKeys.every((key: string) => metadataKeys.includes(key));
|
||||||
|
const allMetadataKeysInSection = metadataKeys.every((key: string) => sectionKeys.includes(key));
|
||||||
|
if (allSectionKeysInMetadata && !allMetadataKeysInSection) {
|
||||||
|
return metadata$.pipe(
|
||||||
|
switchMap((metadata: MetadataMap) =>
|
||||||
|
[new UpdateSectionDataAction(action.payload.submissionId, action.payload.sectionId, metadata as any, action.payload.errors)]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a notification on success and redirect to MyDSpace page
|
* Show a notification on success and redirect to MyDSpace page
|
||||||
*/
|
*/
|
||||||
@@ -262,6 +321,7 @@ export class SubmissionObjectEffects {
|
|||||||
private sectionService: SectionsService,
|
private sectionService: SectionsService,
|
||||||
private store$: Store<any>,
|
private store$: Store<any>,
|
||||||
private submissionService: SubmissionService,
|
private submissionService: SubmissionService,
|
||||||
|
private sods: SubmissionObjectDataService,
|
||||||
private translate: TranslateService) {
|
private translate: TranslateService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,12 +388,10 @@ export class SubmissionObjectEffects {
|
|||||||
|
|
||||||
const sections: WorkspaceitemSectionsObject = (item.sections && isNotEmpty(item.sections)) ? item.sections : {};
|
const sections: WorkspaceitemSectionsObject = (item.sections && isNotEmpty(item.sections)) ? item.sections : {};
|
||||||
const sectionsKeys: string[] = union(Object.keys(sections), Object.keys(errorsList));
|
const sectionsKeys: string[] = union(Object.keys(sections), Object.keys(errorsList));
|
||||||
const metadata = (item.item as Item).metadata;
|
|
||||||
const metadataKeys = hasValue(metadata) ? Object.keys(metadata) : undefined;
|
|
||||||
|
|
||||||
for (const sectionId of sectionsKeys) {
|
for (const sectionId of sectionsKeys) {
|
||||||
const sectionErrors = errorsList[sectionId] || [];
|
const sectionErrors = errorsList[sectionId] || [];
|
||||||
let sectionData = sections[sectionId] || {};
|
const sectionData = sections[sectionId] || {};
|
||||||
|
|
||||||
// When Upload section is disabled, add to submission only if there are files
|
// When Upload section is disabled, add to submission only if there are files
|
||||||
if (currentState.sections[sectionId].sectionType === SectionsType.Upload
|
if (currentState.sections[sectionId].sectionType === SectionsType.Upload
|
||||||
@@ -342,17 +400,6 @@ export class SubmissionObjectEffects {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNotEmpty(metadataKeys)) {
|
|
||||||
const sectionKeys = Object.keys(sectionData);
|
|
||||||
if (sectionKeys.every((key: string) => metadataKeys.includes(key))) {
|
|
||||||
sectionData = metadata as any;
|
|
||||||
console.log('sectionData', sectionData);
|
|
||||||
//TODO het werkt op deze branch dus ook niet voor andere relaties, zorg er dus voor dat de state opnieuw wordt opgehaald na een change
|
|
||||||
// of gewoon rechtstreeks naar het submission item kijkt.
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (notify && !currentState.sections[sectionId].enabled) {
|
if (notify && !currentState.sections[sectionId].enabled) {
|
||||||
this.submissionService.notifyNewSection(submissionId, sectionId, currentState.sections[sectionId].sectionType);
|
this.submissionService.notifyNewSection(submissionId, sectionId, currentState.sections[sectionId].sectionType);
|
||||||
}
|
}
|
||||||
|
@@ -335,6 +335,7 @@ export class SubmissionSectionformComponent extends SectionModelComponent {
|
|||||||
distinctUntilChanged())
|
distinctUntilChanged())
|
||||||
.subscribe((sectionState: SubmissionSectionObject) => {
|
.subscribe((sectionState: SubmissionSectionObject) => {
|
||||||
this.fieldsOnTheirWayToBeRemoved = new Map();
|
this.fieldsOnTheirWayToBeRemoved = new Map();
|
||||||
|
console.log('new data, update form', sectionState.data);
|
||||||
this.updateForm(sectionState.data as WorkspaceitemSectionFormObject, sectionState.errors);
|
this.updateForm(sectionState.data as WorkspaceitemSectionFormObject, sectionState.errors);
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user