forked from hazza/dspace-angular
73014: Remove sending patch to cache + small refactoring changes
This commit is contained in:
@@ -20,7 +20,6 @@ import { AlertType } from '../../../shared/alert/aletr-type';
|
|||||||
import { Operation } from 'fast-json-patch';
|
import { Operation } from 'fast-json-patch';
|
||||||
import { METADATA_PATCH_OPERATION_SERVICE_TOKEN } from '../../../core/data/object-updates/patch-operation-service/metadata-patch-operation.service';
|
import { METADATA_PATCH_OPERATION_SERVICE_TOKEN } from '../../../core/data/object-updates/patch-operation-service/metadata-patch-operation.service';
|
||||||
import { DSOSuccessResponse } from '../../../core/cache/response.models';
|
import { DSOSuccessResponse } from '../../../core/cache/response.models';
|
||||||
import { ObjectCacheService } from '../../../core/cache/object-cache.service';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-item-metadata',
|
selector: 'ds-item-metadata',
|
||||||
@@ -57,7 +56,6 @@ export class ItemMetadataComponent extends AbstractItemUpdateComponent {
|
|||||||
public translateService: TranslateService,
|
public translateService: TranslateService,
|
||||||
public route: ActivatedRoute,
|
public route: ActivatedRoute,
|
||||||
public metadataFieldService: RegistryService,
|
public metadataFieldService: RegistryService,
|
||||||
public objectCacheService: ObjectCacheService,
|
|
||||||
) {
|
) {
|
||||||
super(itemService, objectUpdatesService, router, notificationsService, translateService, route);
|
super(itemService, objectUpdatesService, router, notificationsService, translateService, route);
|
||||||
}
|
}
|
||||||
@@ -115,9 +113,7 @@ export class ItemMetadataComponent extends AbstractItemUpdateComponent {
|
|||||||
return this.updateService.patch(this.item, patch).pipe(
|
return this.updateService.patch(this.item, patch).pipe(
|
||||||
switchMap((response: DSOSuccessResponse) => {
|
switchMap((response: DSOSuccessResponse) => {
|
||||||
if (isNotEmpty(response.resourceSelfLinks)) {
|
if (isNotEmpty(response.resourceSelfLinks)) {
|
||||||
const selfLink = response.resourceSelfLinks[0];
|
return this.itemService.findByHref(response.resourceSelfLinks[0]);
|
||||||
this.objectCacheService.addPatch(selfLink, patch, false);
|
|
||||||
return this.itemService.findByHref(selfLink);
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
getSucceededRemoteData()
|
getSucceededRemoteData()
|
||||||
|
12
src/app/core/cache/object-cache.service.ts
vendored
12
src/app/core/cache/object-cache.service.ts
vendored
@@ -270,16 +270,14 @@ export class ObjectCacheService {
|
|||||||
/**
|
/**
|
||||||
* Add operations to the existing list of operations for an ObjectCacheEntry
|
* Add operations to the existing list of operations for an ObjectCacheEntry
|
||||||
* Makes sure the ServerSyncBuffer for this ObjectCacheEntry is updated
|
* Makes sure the ServerSyncBuffer for this ObjectCacheEntry is updated
|
||||||
* @param {string} uuid
|
* @param selfLink
|
||||||
* the uuid of the ObjectCacheEntry
|
* the uuid of the ObjectCacheEntry
|
||||||
* @param {Operation[]} patch
|
* @param {Operation[]} patch
|
||||||
* list of operations to perform
|
* list of operations to perform
|
||||||
*/
|
*/
|
||||||
public addPatch(selfLink: string, patch: Operation[], addToSSD = true) {
|
public addPatch(selfLink: string, patch: Operation[]) {
|
||||||
this.store.dispatch(new AddPatchObjectCacheAction(selfLink, patch));
|
this.store.dispatch(new AddPatchObjectCacheAction(selfLink, patch));
|
||||||
if (addToSSD) {
|
this.store.dispatch(new AddToSSBAction(selfLink, RestRequestMethod.PATCH));
|
||||||
this.store.dispatch(new AddToSSBAction(selfLink, RestRequestMethod.PATCH));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -297,8 +295,8 @@ export class ObjectCacheService {
|
|||||||
/**
|
/**
|
||||||
* Apply the existing operations on an ObjectCacheEntry in the store
|
* Apply the existing operations on an ObjectCacheEntry in the store
|
||||||
* NB: this does not make any server side changes
|
* NB: this does not make any server side changes
|
||||||
* @param {string} uuid
|
* @param selfLink
|
||||||
* the uuid of the ObjectCacheEntry
|
* the link of the ObjectCacheEntry
|
||||||
*/
|
*/
|
||||||
private applyPatchesToCachedObject(selfLink: string) {
|
private applyPatchesToCachedObject(selfLink: string) {
|
||||||
this.store.dispatch(new ApplyPatchObjectCacheAction(selfLink));
|
this.store.dispatch(new ApplyPatchObjectCacheAction(selfLink));
|
||||||
|
@@ -22,7 +22,6 @@ export class MetadataPatchAddOperation extends MetadataPatchOperation {
|
|||||||
* using the information provided.
|
* using the information provided.
|
||||||
*/
|
*/
|
||||||
toOperation(): Operation {
|
toOperation(): Operation {
|
||||||
const path = `/metadata/${this.field}/-`;
|
return { op: this.op as any, path: `/metadata/${this.field}/-`, value: this.value };
|
||||||
return { op: this.op as any, path, value: this.value };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
import { MetadataPatchOperation } from './metadata-patch-operation.model';
|
import { MetadataPatchOperation } from './metadata-patch-operation.model';
|
||||||
import { Operation } from 'fast-json-patch';
|
import { Operation } from 'fast-json-patch';
|
||||||
import { hasValue } from '../../../../../../shared/empty.util';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper object for a metadata patch remove Operation
|
* Wrapper object for a metadata patch remove Operation
|
||||||
@@ -23,10 +22,6 @@ export class MetadataPatchRemoveOperation extends MetadataPatchOperation {
|
|||||||
* using the information provided.
|
* using the information provided.
|
||||||
*/
|
*/
|
||||||
toOperation(): Operation {
|
toOperation(): Operation {
|
||||||
let path = `/metadata/${this.field}`;
|
return { op: this.op as any, path: `/metadata/${this.field}/${this.place}` };
|
||||||
if (hasValue(this.place)) {
|
|
||||||
path += `/${this.place}`;
|
|
||||||
}
|
|
||||||
return { op: this.op as any, path };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
import { MetadataPatchOperation } from './metadata-patch-operation.model';
|
import { MetadataPatchOperation } from './metadata-patch-operation.model';
|
||||||
import { Operation } from 'fast-json-patch';
|
import { Operation } from 'fast-json-patch';
|
||||||
import { hasValue } from '../../../../../../shared/empty.util';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper object for a metadata patch replace Operation
|
* Wrapper object for a metadata patch replace Operation
|
||||||
@@ -29,10 +28,6 @@ export class MetadataPatchReplaceOperation extends MetadataPatchOperation {
|
|||||||
* using the information provided.
|
* using the information provided.
|
||||||
*/
|
*/
|
||||||
toOperation(): Operation {
|
toOperation(): Operation {
|
||||||
let path = `/metadata/${this.field}`;
|
return { op: this.op as any, path: `/metadata/${this.field}/${this.place}`, value: this.value };
|
||||||
if (hasValue(this.place)) {
|
|
||||||
path += `/${this.place}`;
|
|
||||||
}
|
|
||||||
return { op: this.op as any, path, value: this.value };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user