mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-10 19:43:04 +00:00
working on sending name variants to the server on patch
This commit is contained in:
@@ -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 { Relationship } from '../../../shared/item-relationships/relationship.model';
|
||||||
import { mapsTo, relationship } from '../../builders/build-decorators';
|
import { mapsTo, relationship } from '../../builders/build-decorators';
|
||||||
import { NormalizedObject } from '../normalized-object.model';
|
import { NormalizedObject } from '../normalized-object.model';
|
||||||
@@ -16,20 +16,20 @@ export class NormalizedRelationship extends NormalizedObject<Relationship> {
|
|||||||
/**
|
/**
|
||||||
* The identifier of this Relationship
|
* The identifier of this Relationship
|
||||||
*/
|
*/
|
||||||
@autoserialize
|
@deserialize
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The item to the left of this relationship
|
* The item to the left of this relationship
|
||||||
*/
|
*/
|
||||||
@autoserialize
|
@deserialize
|
||||||
@relationship(Item, false)
|
@relationship(Item, false)
|
||||||
leftItem: string;
|
leftItem: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The item to the right of this relationship
|
* The item to the right of this relationship
|
||||||
*/
|
*/
|
||||||
@autoserialize
|
@deserialize
|
||||||
@relationship(Item, false)
|
@relationship(Item, false)
|
||||||
rightItem: string;
|
rightItem: string;
|
||||||
|
|
||||||
@@ -46,15 +46,27 @@ export class NormalizedRelationship extends NormalizedObject<Relationship> {
|
|||||||
rightPlace: number;
|
rightPlace: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of Relationship
|
* The name variant of the Item to the left side of this Relationship
|
||||||
*/
|
*/
|
||||||
@autoserialize
|
@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)
|
@relationship(RelationshipType, false)
|
||||||
relationshipType: string;
|
relationshipType: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The universally unique identifier of this Relationship
|
* The universally unique identifier of this Relationship
|
||||||
*/
|
*/
|
||||||
@autoserializeAs(new IDToUUIDSerializer(Relationship.type.value), 'id')
|
@deserializeAs(new IDToUUIDSerializer(Relationship.type.value), 'id')
|
||||||
uuid: string;
|
uuid: string;
|
||||||
}
|
}
|
||||||
|
@@ -292,7 +292,6 @@ export class RelationshipService extends DataService<Relationship> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getNameVariant(listID: string, itemID: string): Observable<string> {
|
public getNameVariant(listID: string, itemID: string): Observable<string> {
|
||||||
console.log(listID, itemID);
|
|
||||||
return this.appStore.pipe(
|
return this.appStore.pipe(
|
||||||
select(relationshipStateSelector(listID, itemID)), tap((t) => console.log(t)), map((state: RelationshipState) => hasValue(state) ? state.nameVariant : undefined)
|
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) {
|
public removeNameVariant(listID: string, itemID: string) {
|
||||||
this.appStore.dispatch(new RemoveNameVariantAction(listID, itemID));
|
this.appStore.dispatch(new RemoveNameVariantAction(listID, itemID));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getNameVariantsByListID(listID: string) {
|
||||||
|
return this.appStore.pipe(select(relationshipListStateSelector(listID)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -46,6 +46,16 @@ export class Relationship implements CacheableObject {
|
|||||||
*/
|
*/
|
||||||
rightPlace: number;
|
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
|
* The type of Relationship
|
||||||
*/
|
*/
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
import { Component, NgZone, OnInit } from '@angular/core';
|
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 { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||||
import { hasValue, hasValueOperator } from '../../../../empty.util';
|
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 { 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';
|
||||||
@@ -21,6 +21,8 @@ import { AppState } from '../../../../../app.reducer';
|
|||||||
import { Context } from '../../../../../core/shared/context.model';
|
import { Context } from '../../../../../core/shared/context.model';
|
||||||
import { Relationship } from '../../../../../core/shared/item-relationships/relationship.model';
|
import { Relationship } from '../../../../../core/shared/item-relationships/relationship.model';
|
||||||
import { MetadataValue } from '../../../../../core/shared/metadata.models';
|
import { MetadataValue } from '../../../../../core/shared/metadata.models';
|
||||||
|
import { ItemSearchResult } from '../../../../object-collection/shared/item-search-result.model';
|
||||||
|
import { RelationshipListState } from './relationship.reducer';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-dynamic-lookup-relation-modal',
|
selector: 'ds-dynamic-lookup-relation-modal',
|
||||||
@@ -84,8 +86,10 @@ export class DsDynamicLookupRelationModalComponent implements OnInit {
|
|||||||
|
|
||||||
combineLatest(this.itemRD$.pipe(getSucceededRemoteData()), obs)
|
combineLatest(this.itemRD$.pipe(getSucceededRemoteData()), obs)
|
||||||
.subscribe(([itemRD, obs]: [RemoteData<Item>, any[]]) => {
|
.subscribe(([itemRD, obs]: [RemoteData<Item>, any[]]) => {
|
||||||
return obs.forEach((object: any) =>
|
return obs.forEach((object: any) => {
|
||||||
this.store.dispatch(new AddRelationshipAction(itemRD.payload, object.item, this.relationshipOptions.relationshipType, object.nameVariant))
|
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(
|
() => this.itemRD$.pipe(
|
||||||
getSucceededRemoteData(),
|
getSucceededRemoteData(),
|
||||||
tap((itemRD: RemoteData<Item>) => {
|
tap((itemRD: RemoteData<Item>) => {
|
||||||
return selectableObjects.forEach((object) =>
|
return selectableObjects.forEach((object) => {
|
||||||
this.store.dispatch(new RemoveRelationshipAction(itemRD.payload, object.indexableObject, this.relationshipOptions.relationshipType))
|
this.store.dispatch(new RemoveRelationshipAction(itemRD.payload, object.indexableObject, this.relationshipOptions.relationshipType));
|
||||||
);
|
this.addSelectSubscription(object);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
).subscribe()
|
).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() {
|
setExistingNameVariants() {
|
||||||
const virtualMDs$: Observable<MetadataValue[]> = this.itemRD$.pipe(
|
const virtualMDs$: Observable<MetadataValue[]> = this.itemRD$.pipe(
|
||||||
getSucceededRemoteData(),
|
getSucceededRemoteData(),
|
||||||
@@ -119,7 +152,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit {
|
|||||||
relationship.rightItem.pipe(getSucceededRemoteData(), getRemoteDataPayload())
|
relationship.rightItem.pipe(getSucceededRemoteData(), getRemoteDataPayload())
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
),
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
const relatedItems$: Observable<Item[]> = combineLatest(relatedItemPairs$, this.itemRD$).pipe(
|
const relatedItems$: Observable<Item[]> = combineLatest(relatedItemPairs$, this.itemRD$).pipe(
|
||||||
|
Reference in New Issue
Block a user