ensure submissionsection state also contains all metadata after a save

This commit is contained in:
Art Lowel
2020-04-08 18:14:29 +02:00
parent 74db9030b0
commit e0d4eb7c9c
8 changed files with 73 additions and 49 deletions

View File

@@ -144,7 +144,7 @@ export class SubmissionResponseParsingService extends BaseResponseParsingService
if (item instanceof WorkspaceItem if (item instanceof WorkspaceItem
|| item instanceof WorkflowItem) { || item instanceof WorkflowItem) {
if (item.sections) { 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({}); const precessedSection = Object.create({});
// Iterate over all workspaceitem's sections // Iterate over all workspaceitem's sections
Object.keys(item.sections) Object.keys(item.sections)

View File

@@ -7,7 +7,7 @@
[ngClass]="[getClass('element', 'label'), getClass('grid', 'label')]"></label> [ngClass]="[getClass('element', 'label'), getClass('grid', 'label')]"></label>
<ng-container *ngTemplateOutlet="startTemplate?.templateRef; context: model"></ng-container> <ng-container *ngTemplateOutlet="startTemplate?.templateRef; context: model"></ng-container>
<!-- Should be *ngIf instead of class d-none, but that breaks the #componentViewContainer reference--> <!-- Should be *ngIf instead of class d-none, but that breaks the #componentViewContainer reference-->
<div [ngClass]="{'form-row': model.hasLanguages || isRelationship, 'd-none': value?.isVirtual}"> <div [ngClass]="{'form-row': model.hasLanguages || isRelationship, 'd-none': model.hasSelectableMetadata && value?.isVirtual}">
<div [ngClass]="getClass('grid', 'control')"> <div [ngClass]="getClass('grid', 'control')">
<ng-container #componentViewContainer></ng-container> <ng-container #componentViewContainer></ng-container>
<small *ngIf="hasHint && context?.index === 0 && (!showErrorMessages || errorMessages.length === 0)" <small *ngIf="hasHint && context?.index === 0 && (!showErrorMessages || errorMessages.length === 0)"

View File

@@ -244,9 +244,58 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
*/ */
ngOnInit(): void { ngOnInit(): void {
this.isRelationship = hasValue(this.model.relationship); this.isRelationship = hasValue(this.model.relationship);
if (this.isRelationship) { const isWrapperAroundRelationshipList = hasValue(this.model.relationshipConfig);
this.listId = 'list-' + this.model.relationship.relationshipType;
if(this.isRelationship) {
console.log('isRelationship', this.model, this.model.value);
}
if (isWrapperAroundRelationshipList) {
console.log('isWrapperAroundRelationshipList', this.model, this.model.value)
}
if (this.isRelationship || isWrapperAroundRelationshipList) {
const config = this.model.relationshipConfig || this.model.relationship;
const relationshipOptions = Object.assign(new RelationshipOptions(), config);
this.listId = 'list-' + relationshipOptions.relationshipType;
this.setItem(); this.setItem();
if (isWrapperAroundRelationshipList || !this.model.repeatable) {
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<PaginatedList<Item>>) => items.payload.page.map((i) => Object.assign(new ItemSearchResult(), { indexableObject: i }))),
)
})
).subscribe((relatedItems: Array<SearchResult<Item>>) => this.selectableListService.select(this.listId, relatedItems));
this.subs.push(subscription);
}
this.value = Object.assign(new MetadataValue(), this.model.value); this.value = Object.assign(new MetadataValue(), this.model.value);
if (hasValue(this.value) && this.value.isVirtual) { if (hasValue(this.value) && this.value.isVirtual) {
const relationship$ = this.relationshipService.findById(this.value.virtualValue, followLink('leftItem'), followLink('rightItem'), followLink('relationshipType')) const relationship$ = this.relationshipService.findById(this.value.virtualValue, followLink('leftItem'), followLink('rightItem'), followLink('relationshipType'))
@@ -254,6 +303,7 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
getAllSucceededRemoteData(), getAllSucceededRemoteData(),
getRemoteDataPayload()); getRemoteDataPayload());
this.relationshipValue$ = observableCombineLatest([this.item$.pipe(take(1)), relationship$]).pipe( this.relationshipValue$ = observableCombineLatest([this.item$.pipe(take(1)), relationship$]).pipe(
tap((v) => console.log('tapvamu', v)),
switchMap(([item, relationship]: [Item, Relationship]) => switchMap(([item, relationship]: [Item, Relationship]) =>
relationship.leftItem.pipe( relationship.leftItem.pipe(
getAllSucceededRemoteData(), 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<PaginatedList<Item>>) => items.payload.page.map((i) => Object.assign(new ItemSearchResult(), { indexableObject: i }))),
)
})
).subscribe((relatedItems: Array<SearchResult<Item>>) => this.selectableListService.select(this.listId, relatedItems));
this.subs.push(subscription);
}
} }
ngOnChanges(changes: SimpleChanges) { ngOnChanges(changes: SimpleChanges) {

View File

@@ -1,4 +1,4 @@
<div class="d-flex"> <div class="d-flex mt-2">
<span class="mr-auto text-contents"> <span class="mr-auto text-contents">
<ng-container *ngIf="!relatedItem"> <ng-container *ngIf="!relatedItem">
<ds-loading [showMessage]="false"></ds-loading> <ds-loading [showMessage]="false"></ds-loading>

View File

@@ -134,6 +134,7 @@ export class ExistingRelationListElementComponent implements OnInit, OnChanges,
*/ */
ngOnChanges() { ngOnChanges() {
if (hasValue(this.reoRel)) { 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 ? const item$ = this.reoRel.useLeftItem ?
this.reoRel.relationship.leftItem : this.reoRel.relationship.rightItem; this.reoRel.relationship.leftItem : this.reoRel.relationship.rightItem;
this.subs.push(item$.pipe( this.subs.push(item$.pipe(
@@ -144,6 +145,7 @@ export class ExistingRelationListElementComponent implements OnInit, OnChanges,
this.relatedItem = item; this.relatedItem = item;
})); }));
} }
} }
/** /**

View File

@@ -99,6 +99,7 @@ export abstract class FieldParser {
} else { } else {
const model = this.modelFactory(this.getInitFieldValue()); const model = this.modelFactory(this.getInitFieldValue());
model.submissionId = this.submissionId;
if (model.hasLanguages || isNotEmpty(model.relationship)) { if (model.hasLanguages || isNotEmpty(model.relationship)) {
setLayout(model, 'grid', 'control', 'col'); setLayout(model, 'grid', 'control', 'col');
} }

View File

@@ -328,10 +328,12 @@ 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 = Object.keys(metadata);
for (const sectionId of sectionsKeys) { for (const sectionId of sectionsKeys) {
const sectionErrors = errorsList[sectionId] || []; 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 // 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
@@ -340,10 +342,17 @@ export class SubmissionObjectEffects {
continue; 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) { if (notify && !currentState.sections[sectionId].enabled) {
this.submissionService.notifyNewSection(submissionId, sectionId, currentState.sections[sectionId].sectionType); this.submissionService.notifyNewSection(submissionId, sectionId, currentState.sections[sectionId].sectionType);
} }
console.log(sectionId, sectionData);
mappedActions.push(new UpdateSectionDataAction(submissionId, sectionId, sectionData, sectionErrors)); mappedActions.push(new UpdateSectionDataAction(submissionId, sectionId, sectionData, sectionErrors));
} }
}); });

View File

@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { combineLatest, Observable } from 'rxjs'; 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 { Store } from '@ngrx/store';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { ScrollToConfigOptions, ScrollToService } from '@nicky-lenaers/ngx-scroll-to'; import { ScrollToConfigOptions, ScrollToService } from '@nicky-lenaers/ngx-scroll-to';
@@ -175,7 +175,9 @@ export class SectionsService {
return this.store.select(submissionSectionFromIdSelector(submissionId, sectionId)).pipe( return this.store.select(submissionSectionFromIdSelector(submissionId, sectionId)).pipe(
filter((sectionObj: SubmissionSectionObject) => hasValue(sectionObj)), filter((sectionObj: SubmissionSectionObject) => hasValue(sectionObj)),
map((sectionObj: SubmissionSectionObject) => sectionObj), map((sectionObj: SubmissionSectionObject) => sectionObj),
distinctUntilChanged()); distinctUntilChanged(),
tap((v) => console.log('sectionStateChange', submissionId, sectionId, v)),
);
} }
/** /**