diff --git a/src/app/+item-page/edit-item-page/item-metadata/item-metadata.component.ts b/src/app/+item-page/edit-item-page/item-metadata/item-metadata.component.ts index 2635ba3f60..a37e7b0941 100644 --- a/src/app/+item-page/edit-item-page/item-metadata/item-metadata.component.ts +++ b/src/app/+item-page/edit-item-page/item-metadata/item-metadata.component.ts @@ -100,7 +100,7 @@ export class ItemMetadataComponent extends AbstractItemUpdateComponent { * Sends all initial values of this item to the object updates service */ public initializeOriginalFields() { - this.objectUpdatesService.initialize(this.url, this.getMetadataAsListExcludingRelationships(), this.item.lastModified); + this.objectUpdatesService.initialize(this.url, this.item.metadataAsList, this.item.lastModified); } /** @@ -110,12 +110,12 @@ export class ItemMetadataComponent extends AbstractItemUpdateComponent { public submit() { this.isValid().pipe(first()).subscribe((isValid) => { if (isValid) { - const metadata$: Observable = this.objectUpdatesService.getUpdatedFields(this.url, this.getMetadataAsListExcludingRelationships()) as Observable; + const metadata$: Observable = this.objectUpdatesService.getUpdatedFields(this.url, this.item.metadataAsList) as Observable; metadata$.pipe( first(), switchMap((metadata: MetadatumViewModel[]) => { const updatedItem: Item = Object.assign(cloneDeep(this.item), { metadata: Metadata.toMetadataMap(metadata) }); - return this.updateService.update(updatedItem, ['relation.*', 'relationship.*']); + return this.updateService.update(updatedItem); }), tap(() => this.updateService.commitUpdates()), getSucceededRemoteData() diff --git a/src/app/core/data/data.service.ts b/src/app/core/data/data.service.ts index f20cc20b4c..04d1990eac 100644 --- a/src/app/core/data/data.service.ts +++ b/src/app/core/data/data.service.ts @@ -261,26 +261,14 @@ export abstract class DataService implements UpdateDa * Add a new patch to the object cache * The patch is derived from the differences between the given object and its version in the object cache * @param {DSpaceObject} object The given object - * @param ignoreMetadataFields An optional list of metadata fields to ignore updates for (* is allowed as a wildcard, for example: dc.description.*) */ - update(object: T, ignoreMetadataFields: string[] = []): Observable> { - const ignoreMetadataFieldsPrefix = ignoreMetadataFields.map((field) => field.indexOf('*') > -1 ? field.slice(0, field.indexOf('*')) : field); + update(object: T): Observable> { const oldVersion$ = this.findByHref(object.self); return oldVersion$.pipe( getSucceededRemoteData(), getRemoteDataPayload(), mergeMap((oldVersion: T) => { - // Fetch operations from difference between old version and new version - // Filter out any metadata operations for a field specified under ignoreMetadataFields - const operations = this.comparator.diff(oldVersion, object).filter((operation) => { - let ignoredFieldFound = false; - ignoreMetadataFieldsPrefix.forEach((fieldPrefix) => { - if (operation.path.indexOf('/metadata/' + fieldPrefix) > -1) { - ignoredFieldFound = true; - } - }); - return !ignoredFieldFound; - }); + const operations = this.comparator.diff(oldVersion, object); if (isNotEmpty(operations)) { this.objectCache.addPatch(object.self, operations); } diff --git a/src/app/core/data/item-template-data.service.ts b/src/app/core/data/item-template-data.service.ts index e5b862b947..aaa664d7ec 100644 --- a/src/app/core/data/item-template-data.service.ts +++ b/src/app/core/data/item-template-data.service.ts @@ -158,8 +158,8 @@ export class ItemTemplateDataService implements UpdateDataService { /** * Add a new patch to the object cache */ - update(object: Item, ignoreMetadataFields: string[] = []): Observable> { - return this.dataService.update(object, ignoreMetadataFields); + update(object: Item): Observable> { + return this.dataService.update(object); } /** diff --git a/src/app/core/data/object-updates/object-updates.service.ts b/src/app/core/data/object-updates/object-updates.service.ts index 08745f9223..91185551ed 100644 --- a/src/app/core/data/object-updates/object-updates.service.ts +++ b/src/app/core/data/object-updates/object-updates.service.ts @@ -97,9 +97,13 @@ export class ObjectUpdatesService { let fieldUpdate = objectEntry.fieldUpdates[uuid]; if (isEmpty(fieldUpdate)) { const identifiable = initialFields.find((object: Identifiable) => object.uuid === uuid); - fieldUpdate = { field: identifiable, changeType: undefined }; + if (hasValue(identifiable)) { + fieldUpdate = {field: identifiable, changeType: undefined}; + } + } + if (hasValue(fieldUpdate)) { + fieldUpdates[uuid] = fieldUpdate; } - fieldUpdates[uuid] = fieldUpdate; }); return fieldUpdates; })) diff --git a/src/app/core/data/update-data.service.ts b/src/app/core/data/update-data.service.ts index a429be4319..34835e14c1 100644 --- a/src/app/core/data/update-data.service.ts +++ b/src/app/core/data/update-data.service.ts @@ -6,6 +6,6 @@ import { RestRequestMethod } from './rest-request-method'; * Represents a data service to update a given object */ export interface UpdateDataService { - update(object: T, ignoreMetadataFields?: string[]): Observable>; + update(object: T): Observable>; commitUpdates(method?: RestRequestMethod); }