diff --git a/src/app/core/cache/object-cache.reducer.ts b/src/app/core/cache/object-cache.reducer.ts index afc040bf59..53a656e774 100644 --- a/src/app/core/cache/object-cache.reducer.ts +++ b/src/app/core/cache/object-cache.reducer.ts @@ -10,6 +10,7 @@ import { hasValue, isNotEmpty } from '../../shared/empty.util'; import { CacheEntry } from './cache-entry'; import { ResourceType } from '../shared/resource-type'; import { applyPatch, Operation } from 'fast-json-patch'; +import { NormalizedItem } from './models/normalized-item.model'; export enum DirtyType { Created = 'Created', @@ -64,6 +65,7 @@ export class ObjectCacheEntry implements CacheEntry { patches: Patch[] = []; isDirty: boolean; } + /* tslint:enable:max-classes-per-file */ /** @@ -93,10 +95,14 @@ export function objectCacheReducer(state = initialState, action: ObjectCacheActi switch (action.type) { case ObjectCacheActionTypes.ADD: { + if ((action.payload as any).objectToCache instanceof NormalizedItem) { + console.log('ADD', (action.payload as any).objectToCache.self); + } return addToObjectCache(state, action as AddToObjectCacheAction); } case ObjectCacheActionTypes.REMOVE: { + console.log('REMOVE', action.payload); return removeFromObjectCache(state, action as RemoveFromObjectCacheAction) } diff --git a/src/app/core/cache/server-sync-buffer.reducer.ts b/src/app/core/cache/server-sync-buffer.reducer.ts index c86a0d5654..5870a2d10b 100644 --- a/src/app/core/cache/server-sync-buffer.reducer.ts +++ b/src/app/core/cache/server-sync-buffer.reducer.ts @@ -9,7 +9,7 @@ import { RestRequestMethod } from '../data/rest-request-method'; /** * An entry in the ServerSyncBufferState - * href: unique href of an ObjectCacheEntry + * href: unique href of an ServerSyncBufferEntry * method: RestRequestMethod type */ export class ServerSyncBufferEntry { @@ -48,6 +48,7 @@ export function serverSyncBufferReducer(state = initialState, action: ServerSync case ServerSyncBufferActionTypes.EMPTY: { return emptyServerSyncQueue(state, action as EmptySSBAction); } + default: { return state; } @@ -69,6 +70,7 @@ function addToServerSyncQueue(state: ServerSyncBufferState, action: AddToSSBActi if (hasNoValue(state.buffer.find((entry) => entry.href === actionEntry.href && entry.method === actionEntry.method))) { return Object.assign({}, state, { buffer: state.buffer.concat(actionEntry) }); } + return state; } /** diff --git a/src/app/core/data/relationship.service.ts b/src/app/core/data/relationship.service.ts index 0d58d16409..f1e833b9ac 100644 --- a/src/app/core/data/relationship.service.ts +++ b/src/app/core/data/relationship.service.ts @@ -60,7 +60,7 @@ export class RelationshipService extends DataService { protected notificationsService: NotificationsService, protected http: HttpClient, protected comparator: DefaultChangeAnalyzer, - protected appStore: Store) { + protected appStore: Store,) { super(); } @@ -86,11 +86,11 @@ export class RelationshipService extends DataService { return this.getRelationshipEndpoint(id).pipe( isNotEmptyOperator(), take(1), - tap(() => this.removeRelationshipItemsFromCacheByRelationship(id)), map((endpointURL: string) => new DeleteRequest(this.requestService.generateRequestId(), endpointURL)), configureRequest(this.requestService), switchMap((restRequest: RestRequest) => this.requestService.getByUUID(restRequest.uuid)), getResponseFromEntry(), + tap(() => this.refreshRelationshipItemsInCacheByRelationship(id)), ); } @@ -117,8 +117,8 @@ export class RelationshipService extends DataService { configureRequest(this.requestService), switchMap((restRequest: RestRequest) => this.requestService.getByUUID(restRequest.uuid)), getResponseFromEntry(), - tap(() => this.removeRelationshipItemsFromCache(item1)), - tap(() => this.removeRelationshipItemsFromCache(item2)) + tap(() => this.refreshRelationshipItemsInCache(item1)), + tap(() => this.refreshRelationshipItemsInCache(item2)) ) as Observable; } @@ -126,7 +126,7 @@ export class RelationshipService extends DataService { * Method to remove two items of a relationship from the cache using the identifier of the relationship * @param relationshipId The identifier of the relationship */ - private removeRelationshipItemsFromCacheByRelationship(relationshipId: string) { + private refreshRelationshipItemsInCacheByRelationship(relationshipId: string) { this.findById(relationshipId).pipe( getSucceededRemoteData(), getRemoteDataPayload(), @@ -137,8 +137,8 @@ export class RelationshipService extends DataService { ), take(1) ).subscribe(([item1, item2]) => { - this.removeRelationshipItemsFromCache(item1); - this.removeRelationshipItemsFromCache(item2); + this.refreshRelationshipItemsInCache(item1); + this.refreshRelationshipItemsInCache(item2); }) } @@ -146,17 +146,21 @@ export class RelationshipService extends DataService { * Method to remove an item that's part of a relationship from the cache * @param item The item to remove from the cache */ - private removeRelationshipItemsFromCache(item) { - this.objectCache.remove(item.self); - this.requestService.removeByHrefSubstring(item.uuid); - combineLatest( - this.objectCache.hasBySelfLinkObservable(item.self), - this.requestService.hasByHrefObservable(item.uuid) - ).pipe( - filter(([existsInOC, existsInRC]) => !existsInOC && !existsInRC), - take(1), - switchMap(() => this.itemService.findByHref(item.self).pipe(take(1))) - ).subscribe(); + private refreshRelationshipItemsInCache(item) { + setTimeout(() => { + + this.objectCache.remove(item.self); + this.requestService.removeByHrefSubstring(item.uuid); + combineLatest( + this.objectCache.hasBySelfLinkObservable(item.self), + this.requestService.hasByHrefObservable(item.self) + ).pipe( + filter(([existsInOC, existsInRC]) => !existsInOC && !existsInRC), + take(1), + switchMap(() => this.itemService.findByHref(item.self).pipe(take(1))) + ).subscribe(); + }, 1000) + } /** @@ -288,16 +292,17 @@ export class RelationshipService extends DataService { getSucceededRemoteData(), isNotEmptyOperator(), map((relationshipListRD: RemoteData>) => relationshipListRD.payload.page), - mergeMap((relationships: Relationship[]) => { + switchMap((relationships: Relationship[]) => { return observableCombineLatest(...relationships.map((relationship: Relationship) => { - return observableCombineLatest( - this.isItemMatchWithItemRD(relationship.leftItem, item2), - this.isItemMatchWithItemRD(relationship.rightItem, item2) - ).pipe( - map(([isLeftItem, isRightItem]) => isLeftItem || isRightItem), - map((isMatch) => isMatch ? relationship : undefined) - ); - })) + return observableCombineLatest( + this.isItemMatchWithItemRD(this.itemService.findByHref(relationship._links.leftItem), item2), + this.isItemMatchWithItemRD(this.itemService.findByHref(relationship._links.rightItem), item2) + ).pipe( + map(([isLeftItem, isRightItem]) => isLeftItem || isRightItem), + map((isMatch) => isMatch ? relationship : undefined) + ); + }) + ) }), map((relationships: Relationship[]) => relationships.find(((relationship) => hasValue(relationship)))) ) @@ -357,6 +362,7 @@ export class RelationshipService extends DataService { * @param nameVariant The name variant to set for the matching relationship */ public updateNameVariant(item1: Item, item2: Item, relationshipLabel: string, nameVariant: string): Observable> { + let count = 0 const update$: Observable> = this.getRelationshipByItemsAndLabel(item1, item2, relationshipLabel) .pipe( switchMap((relation: Relationship) => @@ -378,16 +384,15 @@ export class RelationshipService extends DataService { } return this.update(updatedRelationship); }), + tap((relationshipRD: RemoteData) => { + console.log(relationshipRD); + if (relationshipRD.hasSucceeded && count < 1) { + count++; + this.refreshRelationshipItemsInCache(item1); + this.refreshRelationshipItemsInCache(item2); + } + }) ); - - update$.pipe( - filter((relationshipRD: RemoteData) => relationshipRD.state === RemoteDataState.RequestPending), - take(1), - ).subscribe(() => { - this.removeRelationshipItemsFromCache(item1); - this.removeRelationshipItemsFromCache(item2); - }); - return update$ } @@ -411,7 +416,7 @@ export class RelationshipService extends DataService { take(1), ).subscribe((relationshipRD: RemoteData) => { if (relationshipRD.state === RemoteDataState.ResponsePending) { - this.removeRelationshipItemsFromCacheByRelationship(reoRel.relationship.id); + this.refreshRelationshipItemsInCacheByRelationship(reoRel.relationship.id); } }); diff --git a/src/app/core/shared/item-relationships/relationship.model.ts b/src/app/core/shared/item-relationships/relationship.model.ts index 2adcf42c04..1a31274707 100644 --- a/src/app/core/shared/item-relationships/relationship.model.ts +++ b/src/app/core/shared/item-relationships/relationship.model.ts @@ -4,6 +4,7 @@ import { RemoteData } from '../../data/remote-data'; import { ResourceType } from '../resource-type'; import { RelationshipType } from './relationship-type.model'; import { Item } from '../item.model'; +import { deserialize } from 'cerialize'; /** * Describes a Relationship between two Items @@ -60,4 +61,8 @@ export class Relationship implements CacheableObject { * The type of Relationship */ relationshipType: Observable>; + + _links: { + [name: string]: string + }; } diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html index e1e6435796..222e821bcf 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html @@ -37,7 +37,7 @@