mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 15:33:04 +00:00
Merge branch 'metadata-and-relationships-combined-in-submission' into w2p-70237_entities-orgunit-submission-fix
This commit is contained in:
@@ -34,7 +34,7 @@ import {
|
||||
} from '../../../../../../core/shared/operators';
|
||||
import { SubmissionObject } from '../../../../../../core/submission/models/submission-object.model';
|
||||
import { SubmissionObjectDataService } from '../../../../../../core/submission/submission-object-data.service';
|
||||
import { hasValue } from '../../../../../empty.util';
|
||||
import { hasValue, isNotEmpty } from '../../../../../empty.util';
|
||||
import { FormFieldMetadataValueObject } from '../../../models/form-field-metadata-value.model';
|
||||
import {
|
||||
Reorderable,
|
||||
@@ -47,6 +47,7 @@ import { Store } from '@ngrx/store';
|
||||
import { SubmissionService } from '../../../../../../submission/submission.service';
|
||||
import { AppState } from '../../../../../../app.reducer';
|
||||
import { followLink } from '../../../../../utils/follow-link-config.model';
|
||||
import { ObjectCacheService } from '../../../../../../core/cache/object-cache.service';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-dynamic-form-array',
|
||||
@@ -74,6 +75,7 @@ export class DsDynamicFormArrayComponent extends DynamicFormArrayComponent imple
|
||||
|
||||
constructor(protected layoutService: DynamicFormLayoutService,
|
||||
protected validationService: DynamicFormValidationService,
|
||||
protected objectCacheService: ObjectCacheService,
|
||||
protected relationshipService: RelationshipService,
|
||||
protected changeDetectorRef: ChangeDetectorRef,
|
||||
protected submissionObjectService: SubmissionObjectDataService,
|
||||
@@ -179,7 +181,7 @@ export class DsDynamicFormArrayComponent extends DynamicFormArrayComponent imple
|
||||
this.reorderables = reorderables;
|
||||
|
||||
if (shouldPropagateChanges) {
|
||||
const updatedReorderables: Array<Observable<any>> = [];
|
||||
const movedReoRels: Array<Reorderable> = [];
|
||||
let hasMetadataField = false;
|
||||
this.reorderables.forEach((reorderable: Reorderable, index: number) => {
|
||||
if (reorderable.hasMoved) {
|
||||
@@ -187,8 +189,9 @@ export class DsDynamicFormArrayComponent extends DynamicFormArrayComponent imple
|
||||
const updatedReorderable = reorderable.update().pipe(take(1));
|
||||
updatedReorderables.push(updatedReorderable);
|
||||
if (reorderable instanceof ReorderableFormFieldMetadataValue) {
|
||||
const prevIndex = reorderable.oldIndex;
|
||||
hasMetadataField = true;
|
||||
updatedReorderable.subscribe((v) => {
|
||||
reorderable.update().pipe(take(1)).subscribe((v) => {
|
||||
const reoMD = reorderable as ReorderableFormFieldMetadataValue;
|
||||
reoMD.model.value = reoMD.metadataValue;
|
||||
this.onChange({
|
||||
@@ -200,18 +203,22 @@ export class DsDynamicFormArrayComponent extends DynamicFormArrayComponent imple
|
||||
type: DynamicFormControlEventType.Change
|
||||
});
|
||||
});
|
||||
} else if (reorderable instanceof ReorderableRelationship) {
|
||||
movedReoRels.push(reorderable)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
observableCombineLatest(updatedReorderables).pipe(
|
||||
if (isNotEmpty(movedReoRels) && hasMetadataField && hasValue(this.model.relationshipConfig)) {
|
||||
// if it's a mix between entities and regular metadata fields,
|
||||
// we need to save, since they use different endpoints and
|
||||
// otherwise they'll get out of sync.
|
||||
this.submissionService.dispatchSave(this.model.submissionId);
|
||||
}
|
||||
|
||||
observableCombineLatest(
|
||||
movedReoRels.map((movedReoRel) => movedReoRel.update().pipe(take(1)))
|
||||
).subscribe(() => {
|
||||
if (hasMetadataField && hasValue(this.model.relationshipConfig)) {
|
||||
// if it's a mix between entities and regular metadata fields,
|
||||
// we need to save after every operation, since they use different
|
||||
// endpoints and otherwise they'll get out of sync.
|
||||
this.submissionService.dispatchSave(this.model.submissionId);
|
||||
}
|
||||
this.changeDetectorRef.detectChanges();
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user