diff --git a/src/app/core/submission/submission-response-parsing.service.ts b/src/app/core/submission/submission-response-parsing.service.ts index 6afd20ae9d..2d55743307 100644 --- a/src/app/core/submission/submission-response-parsing.service.ts +++ b/src/app/core/submission/submission-response-parsing.service.ts @@ -144,7 +144,7 @@ export class SubmissionResponseParsingService extends BaseResponseParsingService if (item instanceof WorkspaceItem || item instanceof WorkflowItem) { if (item.sections) { - const sectionConfigs = (item.submissionDefinition as SubmissionDefinitionsModel).sections.page; + const sectionConfigs = item.sections.page ? (item.submissionDefinition as SubmissionDefinitionsModel).sections.page : []; const precessedSection = Object.create({}); // Iterate over all workspaceitem's sections Object.keys(item.sections) diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html index 377c77e7f7..34922f5e04 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html @@ -7,7 +7,7 @@ [ngClass]="[getClass('element', 'label'), getClass('grid', 'label')]"> -
+
hasNoValue(list)), + switchMap(() => this.item$.pipe(take(1))), + switchMap((item) => { + const relationshipsRD$ = this.relationshipService.getItemRelationshipsByLabel(item, + relationshipOptions.relationshipType, + undefined, + followLink('leftItem'), + followLink('rightItem'), + followLink('relationshipType') + ); + + relationshipsRD$.pipe( + getFirstSucceededRemoteDataPayload(), + getPaginatedListPayload() + ).subscribe((relationships: Relationship[]) => { + // set initial namevariants for pre-existing relationships + relationships.forEach((relationship: Relationship) => { + const relationshipMD: MetadataValue = item.firstMetadata(relationshipOptions.metadataField, { authority: `${VIRTUAL_METADATA_PREFIX}${relationship.id}` }); + const nameVariantMD: MetadataValue = item.firstMetadata(this.model.metadataFields, { authority: `${VIRTUAL_METADATA_PREFIX}${relationship.id}` }); + if (hasValue(relationshipMD) && isNotEmpty(relationshipMD.value) && hasValue(nameVariantMD) && isNotEmpty(nameVariantMD.value)) { + this.relationshipService.setNameVariant(this.listId, relationshipMD.value, nameVariantMD.value); + } + }); + }); + + return relationshipsRD$.pipe( + paginatedRelationsToItems(item.uuid), + getSucceededRemoteData(), + map((items: RemoteData>) => items.payload.page.map((i) => Object.assign(new ItemSearchResult(), { indexableObject: i }))), + ) + }) + ).subscribe((relatedItems: Array>) => this.selectableListService.select(this.listId, relatedItems)); + this.subs.push(subscription); + } + this.value = Object.assign(new MetadataValue(), this.model.value); if (hasValue(this.value) && this.value.isVirtual) { const relationship$ = this.relationshipService.findById(this.value.virtualValue, followLink('leftItem'), followLink('rightItem'), followLink('relationshipType')) @@ -254,6 +303,7 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo getAllSucceededRemoteData(), getRemoteDataPayload()); this.relationshipValue$ = observableCombineLatest([this.item$.pipe(take(1)), relationship$]).pipe( + tap((v) => console.log('tapvamu', v)), switchMap(([item, relationship]: [Item, Relationship]) => relationship.leftItem.pipe( getAllSucceededRemoteData(), @@ -267,46 +317,6 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo ); } } - if (this.model.relationshipConfig || (this.isRelationship && !this.model.repeatable)) { - const config = this.model.relationshipConfig || this.model.relationship; - const relationshipOptions = Object.assign(new RelationshipOptions(), config); - this.listId = 'list-' + relationshipOptions.relationshipType; - this.setItem(); - const subscription = this.selectableListService.getSelectableList(this.listId).pipe( - find((list: SelectableListState) => hasNoValue(list)), - switchMap(() => this.item$.pipe(take(1))), - switchMap((item) => { - const relationshipsRD$ = this.relationshipService.getItemRelationshipsByLabel(item, - relationshipOptions.relationshipType, - undefined, - followLink('leftItem'), - followLink('rightItem'), - followLink('relationshipType') - ); - - relationshipsRD$.pipe( - getFirstSucceededRemoteDataPayload(), - getPaginatedListPayload() - ).subscribe((relationships: Relationship[]) => { - // set initial namevariants for pre-existing relationships - relationships.forEach((relationship: Relationship) => { - const relationshipMD: MetadataValue = item.firstMetadata(relationshipOptions.metadataField, { authority: `${VIRTUAL_METADATA_PREFIX}${relationship.id}` }); - const nameVariantMD: MetadataValue = item.firstMetadata(this.model.metadataFields, { authority: `${VIRTUAL_METADATA_PREFIX}${relationship.id}` }); - if (hasValue(relationshipMD) && isNotEmpty(relationshipMD.value) && hasValue(nameVariantMD) && isNotEmpty(nameVariantMD.value)) { - this.relationshipService.setNameVariant(this.listId, relationshipMD.value, nameVariantMD.value); - } - }); - }); - - return relationshipsRD$.pipe( - paginatedRelationsToItems(item.uuid), - getSucceededRemoteData(), - map((items: RemoteData>) => items.payload.page.map((i) => Object.assign(new ItemSearchResult(), { indexableObject: i }))), - ) - }) - ).subscribe((relatedItems: Array>) => this.selectableListService.select(this.listId, relatedItems)); - this.subs.push(subscription); - } } ngOnChanges(changes: SimpleChanges) { diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.html b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.html index e791c41d6e..6312b59002 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.html +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.html @@ -1,4 +1,4 @@ -
+
diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.ts index a3f5060c32..f951626aa7 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.ts @@ -134,6 +134,7 @@ export class ExistingRelationListElementComponent implements OnInit, OnChanges, */ ngOnChanges() { if (hasValue(this.reoRel)) { + console.log('onChanges', this.reoRel.useLeftItem ? this.reoRel.relationship._links.leftItem.href : this.reoRel.relationship._links.rightItem.href); const item$ = this.reoRel.useLeftItem ? this.reoRel.relationship.leftItem : this.reoRel.relationship.rightItem; this.subs.push(item$.pipe( @@ -144,6 +145,7 @@ export class ExistingRelationListElementComponent implements OnInit, OnChanges, this.relatedItem = item; })); } + } /** diff --git a/src/app/shared/form/builder/parsers/field-parser.ts b/src/app/shared/form/builder/parsers/field-parser.ts index 3f44ce59f7..e7a269db7e 100644 --- a/src/app/shared/form/builder/parsers/field-parser.ts +++ b/src/app/shared/form/builder/parsers/field-parser.ts @@ -99,6 +99,7 @@ export abstract class FieldParser { } else { const model = this.modelFactory(this.getInitFieldValue()); + model.submissionId = this.submissionId; if (model.hasLanguages || isNotEmpty(model.relationship)) { setLayout(model, 'grid', 'control', 'col'); } diff --git a/src/app/submission/objects/submission-objects.effects.ts b/src/app/submission/objects/submission-objects.effects.ts index 0d5c285ba0..fe9fad4846 100644 --- a/src/app/submission/objects/submission-objects.effects.ts +++ b/src/app/submission/objects/submission-objects.effects.ts @@ -328,10 +328,12 @@ export class SubmissionObjectEffects { const sections: WorkspaceitemSectionsObject = (item.sections && isNotEmpty(item.sections)) ? item.sections : {}; const sectionsKeys: string[] = union(Object.keys(sections), Object.keys(errorsList)); + const metadata = (item.item as Item).metadata; + const metadataKeys = Object.keys(metadata); for (const sectionId of sectionsKeys) { const sectionErrors = errorsList[sectionId] || []; - const sectionData = sections[sectionId] || {}; + let sectionData = sections[sectionId] || {}; // When Upload section is disabled, add to submission only if there are files if (currentState.sections[sectionId].sectionType === SectionsType.Upload @@ -340,10 +342,17 @@ export class SubmissionObjectEffects { continue; } + const sectionKeys = Object.keys(sectionData); + if (sectionKeys.every((key: string) => metadataKeys.includes(key))) { + sectionData = metadata as any; + } + + console.log('sectionData', sectionData); + + if (notify && !currentState.sections[sectionId].enabled) { this.submissionService.notifyNewSection(submissionId, sectionId, currentState.sections[sectionId].sectionType); } - console.log(sectionId, sectionData); mappedActions.push(new UpdateSectionDataAction(submissionId, sectionId, sectionData, sectionErrors)); } }); diff --git a/src/app/submission/sections/sections.service.ts b/src/app/submission/sections/sections.service.ts index 0296486e52..3b980c5454 100644 --- a/src/app/submission/sections/sections.service.ts +++ b/src/app/submission/sections/sections.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { combineLatest, Observable } from 'rxjs'; -import { distinctUntilChanged, filter, map, take } from 'rxjs/operators'; +import { distinctUntilChanged, filter, map, take, tap } from 'rxjs/operators'; import { Store } from '@ngrx/store'; import { TranslateService } from '@ngx-translate/core'; import { ScrollToConfigOptions, ScrollToService } from '@nicky-lenaers/ngx-scroll-to'; @@ -175,7 +175,9 @@ export class SectionsService { return this.store.select(submissionSectionFromIdSelector(submissionId, sectionId)).pipe( filter((sectionObj: SubmissionSectionObject) => hasValue(sectionObj)), map((sectionObj: SubmissionSectionObject) => sectionObj), - distinctUntilChanged()); + distinctUntilChanged(), + tap((v) => console.log('sectionStateChange', submissionId, sectionId, v)), + ); } /**