working on sending name variants to the server on patch

This commit is contained in:
lotte
2019-10-25 16:35:10 +02:00
parent 5925b50141
commit 2e50d99fc4
4 changed files with 73 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
import { autoserialize, autoserializeAs, inheritSerialization } from 'cerialize';
import { autoserialize, deserialize, deserializeAs, inheritSerialization } from 'cerialize';
import { Relationship } from '../../../shared/item-relationships/relationship.model';
import { mapsTo, relationship } from '../../builders/build-decorators';
import { NormalizedObject } from '../normalized-object.model';
@@ -16,20 +16,20 @@ export class NormalizedRelationship extends NormalizedObject<Relationship> {
/**
* The identifier of this Relationship
*/
@autoserialize
@deserialize
id: string;
/**
* The item to the left of this relationship
*/
@autoserialize
@deserialize
@relationship(Item, false)
leftItem: string;
/**
* The item to the right of this relationship
*/
@autoserialize
@deserialize
@relationship(Item, false)
rightItem: string;
@@ -46,15 +46,27 @@ export class NormalizedRelationship extends NormalizedObject<Relationship> {
rightPlace: number;
/**
* The type of Relationship
* The name variant of the Item to the left side of this Relationship
*/
@autoserialize
leftwardValue: string;
/**
* The name variant of the Item to the right side of this Relationship
*/
@autoserialize
rightwardValue: string;
/**
* The type of Relationship
*/
@deserialize
@relationship(RelationshipType, false)
relationshipType: string;
/**
* The universally unique identifier of this Relationship
*/
@autoserializeAs(new IDToUUIDSerializer(Relationship.type.value), 'id')
@deserializeAs(new IDToUUIDSerializer(Relationship.type.value), 'id')
uuid: string;
}

View File

@@ -292,7 +292,6 @@ export class RelationshipService extends DataService<Relationship> {
}
public getNameVariant(listID: string, itemID: string): Observable<string> {
console.log(listID, itemID);
return this.appStore.pipe(
select(relationshipStateSelector(listID, itemID)), tap((t) => console.log(t)), map((state: RelationshipState) => hasValue(state) ? state.nameVariant : undefined)
);
@@ -301,4 +300,8 @@ export class RelationshipService extends DataService<Relationship> {
public removeNameVariant(listID: string, itemID: string) {
this.appStore.dispatch(new RemoveNameVariantAction(listID, itemID));
}
public getNameVariantsByListID(listID: string) {
return this.appStore.pipe(select(relationshipListStateSelector(listID)));
}
}

View File

@@ -46,6 +46,16 @@ export class Relationship implements CacheableObject {
*/
rightPlace: number;
/**
* The name variant of the Item to the left side of this Relationship
*/
leftwardValue: string;
/**
* The name variant of the Item to the right side of this Relationship
*/
rightwardValue: string;
/**
* The type of Relationship
*/

View File

@@ -1,8 +1,8 @@
import { Component, NgZone, OnInit } from '@angular/core';
import { combineLatest, Observable } from 'rxjs';
import { combineLatest, Observable, Subscription } from 'rxjs';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { hasValue, hasValueOperator } from '../../../../empty.util';
import { filter, map, switchMap, take, tap } from 'rxjs/operators';
import { map, switchMap, take, tap } from 'rxjs/operators';
import { SEARCH_CONFIG_SERVICE } from '../../../../../+my-dspace-page/my-dspace-page.component';
import { SearchConfigurationService } from '../../../../../core/shared/search/search-configuration.service';
import { SelectableListService } from '../../../../object-list/selectable-list/selectable-list.service';
@@ -21,6 +21,8 @@ import { AppState } from '../../../../../app.reducer';
import { Context } from '../../../../../core/shared/context.model';
import { Relationship } from '../../../../../core/shared/item-relationships/relationship.model';
import { MetadataValue } from '../../../../../core/shared/metadata.models';
import { ItemSearchResult } from '../../../../object-collection/shared/item-search-result.model';
import { RelationshipListState } from './relationship.reducer';
@Component({
selector: 'ds-dynamic-lookup-relation-modal',
@@ -84,8 +86,10 @@ export class DsDynamicLookupRelationModalComponent implements OnInit {
combineLatest(this.itemRD$.pipe(getSucceededRemoteData()), obs)
.subscribe(([itemRD, obs]: [RemoteData<Item>, any[]]) => {
return obs.forEach((object: any) =>
this.store.dispatch(new AddRelationshipAction(itemRD.payload, object.item, this.relationshipOptions.relationshipType, object.nameVariant))
return obs.forEach((object: any) => {
this.store.dispatch(new AddRelationshipAction(itemRD.payload, object.item, this.relationshipOptions.relationshipType, object.nameVariant));
this.addSelectSubscription(object);
}
);
})
});
@@ -96,15 +100,44 @@ export class DsDynamicLookupRelationModalComponent implements OnInit {
() => this.itemRD$.pipe(
getSucceededRemoteData(),
tap((itemRD: RemoteData<Item>) => {
return selectableObjects.forEach((object) =>
this.store.dispatch(new RemoveRelationshipAction(itemRD.payload, object.indexableObject, this.relationshipOptions.relationshipType))
);
return selectableObjects.forEach((object) => {
this.store.dispatch(new RemoveRelationshipAction(itemRD.payload, object.indexableObject, this.relationshipOptions.relationshipType));
this.addSelectSubscription(object);
});
}
)
).subscribe()
);
}
subscriptions = new Map<string, Subscription>();
addSelectSubscription(itemSR: SearchResult<Item>) {
const item$ = this.itemRD$.pipe(getSucceededRemoteData(), getRemoteDataPayload());
const nameVariant$ = this.relationshipService.getNameVariant(this.listId, itemSR.indexableObject.uuid).pipe(hasValueOperator());
const subscription = combineLatest(item$, nameVariant$)
.pipe(
switchMap(([item, nameVariant]: [Item, string]) => {
return this.relationshipService.getRelationshipByItemsAndLabel(item, itemSR.indexableObject, this.relationshipOptions.relationshipType)
.pipe(map((relationship: Relationship) => Object.assign(new Relationship(), relationship, { leftwardValue: nameVariant })))
}),
switchMap((updatedRelation: Relationship) => this.relationshipService.update(updatedRelation))
)
.subscribe();
this.subscriptions.set(itemSR.indexableObject.uuid, subscription);
}
removeSelectSubscription(itemSR: SearchResult<Item>) {
this.subscriptions.get(itemSR.indexableObject.uuid).unsubscribe();
}
ngOnDestroy() {
let sub;
while (sub = this.subscriptions.values().next(), !sub.done) {
sub.unsubscribe();
}
}
setExistingNameVariants() {
const virtualMDs$: Observable<MetadataValue[]> = this.itemRD$.pipe(
getSucceededRemoteData(),
@@ -119,7 +152,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit {
relationship.rightItem.pipe(getSucceededRemoteData(), getRemoteDataPayload())
))
)
),
)
);
const relatedItems$: Observable<Item[]> = combineLatest(relatedItemPairs$, this.itemRD$).pipe(