mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
ensure submissionsection state also contains all metadata after a save
This commit is contained in:
@@ -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)
|
||||
|
@@ -7,7 +7,7 @@
|
||||
[ngClass]="[getClass('element', 'label'), getClass('grid', 'label')]"></label>
|
||||
<ng-container *ngTemplateOutlet="startTemplate?.templateRef; context: model"></ng-container>
|
||||
<!-- 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')">
|
||||
<ng-container #componentViewContainer></ng-container>
|
||||
<small *ngIf="hasHint && context?.index === 0 && (!showErrorMessages || errorMessages.length === 0)"
|
||||
|
@@ -244,9 +244,58 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
this.isRelationship = hasValue(this.model.relationship);
|
||||
if (this.isRelationship) {
|
||||
this.listId = 'list-' + this.model.relationship.relationshipType;
|
||||
const isWrapperAroundRelationshipList = hasValue(this.model.relationshipConfig);
|
||||
|
||||
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();
|
||||
|
||||
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);
|
||||
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<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) {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<div class="d-flex">
|
||||
<div class="d-flex mt-2">
|
||||
<span class="mr-auto text-contents">
|
||||
<ng-container *ngIf="!relatedItem">
|
||||
<ds-loading [showMessage]="false"></ds-loading>
|
||||
|
@@ -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;
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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');
|
||||
}
|
||||
|
@@ -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));
|
||||
}
|
||||
});
|
||||
|
@@ -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)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user