fix issue where namvariants wouldn't work

This commit is contained in:
Art Lowel
2020-04-02 14:14:36 +02:00
parent f93df688e4
commit 924e623b6a
5 changed files with 61 additions and 23 deletions

View File

@@ -25,6 +25,7 @@ import { Observable } from 'rxjs/internal/Observable';
import { RestRequestMethod } from '../data/rest-request-method'; import { RestRequestMethod } from '../data/rest-request-method';
import { ObjectCacheEntry } from './object-cache.reducer'; import { ObjectCacheEntry } from './object-cache.reducer';
import { Operation } from 'fast-json-patch'; import { Operation } from 'fast-json-patch';
import { RESTURLCombiner } from '../url-combiner/rest-url-combiner';
@Injectable() @Injectable()
export class ServerSyncBufferEffects { export class ServerSyncBufferEffects {
@@ -98,22 +99,49 @@ export class ServerSyncBufferEffects {
* @returns {Observable<Action>} ApplyPatchObjectCacheAction to be dispatched * @returns {Observable<Action>} ApplyPatchObjectCacheAction to be dispatched
*/ */
private applyPatch(href: string): Observable<Action> { private applyPatch(href: string): Observable<Action> {
const patchObject = this.objectCache.getBySelfLink(href).pipe(take(1)); if (isNotEmpty(href.match(/^http.*\/core\/relationships\/\d+$/))) {
return this.sendPatchAsPut(href);
} else {
const patchObject = this.objectCache.getBySelfLink(href).pipe(take(1));
return patchObject.pipe(
map((entry: ObjectCacheEntry) => {
if (isNotEmpty(entry.patches)) {
const flatPatch: Operation[] = [].concat(...entry.patches.map((patch) => patch.operations));
if (isNotEmpty(flatPatch)) {
this.requestService.configure(new PatchRequest(this.requestService.generateRequestId(), href, flatPatch));
}
}
return new ApplyPatchObjectCacheAction(href);
})
);
}
}
/**
* Send a list of PATCH operations made by the UI as a PUT request to the REST API
* This allows us to use PATCH in the UI while PATCH support for the endpoint is still
* under developent.
*
* @param {string} href The self link of the cache entry
* @returns {Observable<Action>} ApplyPatchObjectCacheAction to be dispatched
*/
private sendPatchAsPut(href: string): Observable<Action> {
const patchObject = this.objectCache.getObjectBySelfLink(href).pipe(take(1));
return patchObject.pipe( return patchObject.pipe(
map((entry: ObjectCacheEntry) => { map((object) => {
if (isNotEmpty(entry.patches)) { const serializedObject = new DSpaceSerializer(object.constructor as GenericConstructor<{}>).serialize(object);
const flatPatch: Operation[] = [].concat(...entry.patches.map((patch) => patch.operations));
if (isNotEmpty(flatPatch)) { this.requestService.configure(new PutRequest(this.requestService.generateRequestId(), href, serializedObject));
// if (href.match(/https://dspace7-ben.atmire.com/server/api/core/relationships/\d+/))
this.requestService.configure(new PatchRequest(this.requestService.generateRequestId(), href, flatPatch)); return new ApplyPatchObjectCacheAction(href)
}
}
return new ApplyPatchObjectCacheAction(href);
}) })
); )
} }
constructor(private actions$: Actions, constructor(private actions$: Actions,
private store: Store<CoreState>, private store: Store<CoreState>,
private requestService: RequestService, private requestService: RequestService,

View File

@@ -3,7 +3,16 @@ import { Injectable } from '@angular/core';
import { MemoizedSelector, select, Store } from '@ngrx/store'; import { MemoizedSelector, select, Store } from '@ngrx/store';
import { combineLatest as observableCombineLatest } from 'rxjs'; import { combineLatest as observableCombineLatest } from 'rxjs';
import { Observable } from 'rxjs/internal/Observable'; import { Observable } from 'rxjs/internal/Observable';
import { distinctUntilChanged, filter, map, startWith, switchMap, take, tap } from 'rxjs/operators'; import {
distinctUntilChanged,
filter,
map,
startWith,
switchMap,
take,
tap,
mergeMap
} from 'rxjs/operators';
import { import {
compareArraysUsingIds, compareArraysUsingIds,
paginatedRelationsToItems, paginatedRelationsToItems,
@@ -306,7 +315,7 @@ export class RelationshipService extends DataService<Relationship> {
getSucceededRemoteData(), getSucceededRemoteData(),
isNotEmptyOperator(), isNotEmptyOperator(),
map((relationshipListRD: RemoteData<PaginatedList<Relationship>>) => relationshipListRD.payload.page), map((relationshipListRD: RemoteData<PaginatedList<Relationship>>) => relationshipListRD.payload.page),
switchMap((relationships: Relationship[]) => { mergeMap((relationships: Relationship[]) => {
return observableCombineLatest(...relationships.map((relationship: Relationship) => { return observableCombineLatest(...relationships.map((relationship: Relationship) => {
return observableCombineLatest( return observableCombineLatest(
this.isItemMatchWithItemRD(this.itemService.findByHref(relationship._links.leftItem.href), item2), this.isItemMatchWithItemRD(this.itemService.findByHref(relationship._links.leftItem.href), item2),
@@ -378,6 +387,7 @@ export class RelationshipService extends DataService<Relationship> {
let count = 0 let count = 0
const update$: Observable<RemoteData<Relationship>> = this.getRelationshipByItemsAndLabel(item1, item2, relationshipLabel) const update$: Observable<RemoteData<Relationship>> = this.getRelationshipByItemsAndLabel(item1, item2, relationshipLabel)
.pipe( .pipe(
tap((v) => console.log('updateNameVariant after getRelationshipByItemsAndLabel', v)),
filter((relation: Relationship) => hasValue(relation)), filter((relation: Relationship) => hasValue(relation)),
switchMap((relation: Relationship) => switchMap((relation: Relationship) =>
relation.relationshipType.pipe( relation.relationshipType.pipe(
@@ -389,6 +399,7 @@ export class RelationshipService extends DataService<Relationship> {
) )
), ),
switchMap((relationshipAndType: { relation: Relationship, type: RelationshipType }) => { switchMap((relationshipAndType: { relation: Relationship, type: RelationshipType }) => {
console.log('updateNameVariant switchMap', relationshipAndType);
const { relation, type } = relationshipAndType; const { relation, type } = relationshipAndType;
let updatedRelationship; let updatedRelationship;
if (relationshipLabel === type.leftwardType) { if (relationshipLabel === type.leftwardType) {

View File

@@ -167,14 +167,14 @@ export class ReorderableRelationship extends Reorderable {
templateUrl: './existing-metadata-list-element.component.html', templateUrl: './existing-metadata-list-element.component.html',
styleUrls: ['./existing-metadata-list-element.component.scss'] styleUrls: ['./existing-metadata-list-element.component.scss']
}) })
export class ExistingMetadataListElementComponent implements OnChanges, OnDestroy { export class ExistingMetadataListElementComponent implements OnInit, OnChanges, OnDestroy {
@Input() listId: string; @Input() listId: string;
@Input() submissionItem: Item; @Input() submissionItem: Item;
@Input() reoRel: ReorderableRelationship; @Input() reoRel: ReorderableRelationship;
@Input() metadataFields: string[]; @Input() metadataFields: string[];
@Input() relationshipOptions: RelationshipOptions; @Input() relationshipOptions: RelationshipOptions;
@Input() submissionId: string; @Input() submissionId: string;
metadataRepresentation$: BehaviorSubject<MetadataRepresentation>; metadataRepresentation$: BehaviorSubject<MetadataRepresentation> = new BehaviorSubject<MetadataRepresentation>(undefined);
relatedItem: Item; relatedItem: Item;
/** /**
@@ -188,6 +188,10 @@ export class ExistingMetadataListElementComponent implements OnChanges, OnDestro
) { ) {
} }
ngOnInit(): void {
this.ngOnChanges();
}
/** /**
* Change callback for the component * Change callback for the component
*/ */
@@ -208,11 +212,7 @@ export class ExistingMetadataListElementComponent implements OnChanges, OnDestro
new ItemMetadataRepresentation(metadataRepresentationMD), new ItemMetadataRepresentation(metadataRepresentationMD),
this.relatedItem this.relatedItem
); );
if (hasValue(this.metadataRepresentation$)) { this.metadataRepresentation$.next(nextValue);
this.metadataRepresentation$.next(nextValue);
} else {
this.metadataRepresentation$ = new BehaviorSubject<MetadataRepresentation>(nextValue);
}
} }
})); }));
} }

View File

@@ -2,7 +2,7 @@ import { Component, EventEmitter, NgZone, OnDestroy, OnInit, Output } from '@ang
import { combineLatest, Observable, Subscription, zip as observableZip } from 'rxjs'; import { combineLatest, Observable, Subscription, zip as observableZip } from 'rxjs';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { hasValue } from '../../../../empty.util'; import { hasValue } from '../../../../empty.util';
import { map, skip, switchMap, take } from 'rxjs/operators'; import { map, skip, switchMap, take, tap, filter } from 'rxjs/operators';
import { SEARCH_CONFIG_SERVICE } from '../../../../../+my-dspace-page/my-dspace-page.component'; import { SEARCH_CONFIG_SERVICE } from '../../../../../+my-dspace-page/my-dspace-page.component';
import { SearchConfigurationService } from '../../../../../core/shared/search/search-configuration.service'; import { SearchConfigurationService } from '../../../../../core/shared/search/search-configuration.service';
import { SelectableListService } from '../../../../object-list/selectable-list/selectable-list.service'; import { SelectableListService } from '../../../../object-list/selectable-list/selectable-list.service';
@@ -165,7 +165,6 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
.subscribe((arr: any[]) => { .subscribe((arr: any[]) => {
return arr.forEach((object: any) => { return arr.forEach((object: any) => {
const addRelationshipAction = new AddRelationshipAction(this.item, object.item, this.relationshipOptions.relationshipType, this.submissionId, object.nameVariant); const addRelationshipAction = new AddRelationshipAction(this.item, object.item, this.relationshipOptions.relationshipType, this.submissionId, object.nameVariant);
console.log('addRelationshipAction', addRelationshipAction);
this.store.dispatch(addRelationshipAction); this.store.dispatch(addRelationshipAction);
} }
); );

View File

@@ -98,7 +98,7 @@ export class RelationshipEffects {
const { item1, item2, relationshipType, submissionId, nameVariant } = action.payload; const { item1, item2, relationshipType, submissionId, nameVariant } = action.payload;
const identifier: string = this.createIdentifier(item1, item2, relationshipType); const identifier: string = this.createIdentifier(item1, item2, relationshipType);
const inProgress = hasValue(this.debounceMap[identifier]); const inProgress = hasValue(this.debounceMap[identifier]);
if (inProgress) { if (inProgress) {
this.nameVariantUpdates[identifier] = nameVariant; this.nameVariantUpdates[identifier] = nameVariant;
} else { } else {
this.relationshipService.updateNameVariant(item1, item2, relationshipType, nameVariant).pipe(take(1)) this.relationshipService.updateNameVariant(item1, item2, relationshipType, nameVariant).pipe(take(1))