mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
sending name variant update requests to the server
This commit is contained in:
@@ -184,17 +184,19 @@ export abstract class DataService<T extends CacheableObject> {
|
|||||||
* @return {Observable<RemoteData<PaginatedList<T>>}
|
* @return {Observable<RemoteData<PaginatedList<T>>}
|
||||||
* Return an observable that emits response from the server
|
* Return an observable that emits response from the server
|
||||||
*/
|
*/
|
||||||
protected searchBy(searchMethod: string, options: FindAllOptions = {}): Observable<RemoteData<PaginatedList<T>>> {
|
protected searchBy(searchMethod: string, options: FindAllOptions = {}, refresh: boolean = false): Observable<RemoteData<PaginatedList<T>>> {
|
||||||
|
|
||||||
const hrefObs = this.getSearchByHref(searchMethod, options);
|
const hrefObs = this.getSearchByHref(searchMethod, options);
|
||||||
|
|
||||||
hrefObs.pipe(
|
hrefObs.pipe(
|
||||||
first((href: string) => hasValue(href)))
|
find((href: string) => hasValue(href)))
|
||||||
.subscribe((href: string) => {
|
.subscribe((href: string) => {
|
||||||
|
if (refresh) {
|
||||||
|
this.requestService.removeByHrefSubstring(href);
|
||||||
|
}
|
||||||
const request = new FindAllRequest(this.requestService.generateRequestId(), href, options);
|
const request = new FindAllRequest(this.requestService.generateRequestId(), href, options);
|
||||||
this.requestService.configure(request, true);
|
this.requestService.configure(request, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.rdbService.buildList<T>(hrefObs) as Observable<RemoteData<PaginatedList<T>>>;
|
return this.rdbService.buildList<T>(hrefObs) as Observable<RemoteData<PaginatedList<T>>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +221,7 @@ export abstract class DataService<T extends CacheableObject> {
|
|||||||
if (isNotEmpty(operations)) {
|
if (isNotEmpty(operations)) {
|
||||||
this.objectCache.addPatch(object.self, operations);
|
this.objectCache.addPatch(object.self, operations);
|
||||||
}
|
}
|
||||||
return this.findById(object.uuid);
|
return this.findByHref(object.self);
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@@ -26,9 +26,9 @@ import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|||||||
import { DefaultChangeAnalyzer } from './default-change-analyzer.service';
|
import { DefaultChangeAnalyzer } from './default-change-analyzer.service';
|
||||||
import { SearchParam } from '../cache/models/search-param.model';
|
import { SearchParam } from '../cache/models/search-param.model';
|
||||||
import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
|
import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
|
||||||
import { RemoveNameVariantAction, SetNameVariantAction } from '../../shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/relationship.actions';
|
|
||||||
import { AppState, keySelector } from '../../app.reducer';
|
import { AppState, keySelector } from '../../app.reducer';
|
||||||
import { NameVariantListState, RelationshipState } from '../../shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/name-variant.reducer';
|
import { NameVariantListState } from '../../shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/name-variant.reducer';
|
||||||
|
import { RemoveNameVariantAction, SetNameVariantAction } from '../../shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/name-variant.actions';
|
||||||
|
|
||||||
|
|
||||||
const relationshipListsStateSelector = (state: AppState) => state.relationshipLists;
|
const relationshipListsStateSelector = (state: AppState) => state.relationshipLists;
|
||||||
@@ -37,8 +37,8 @@ const relationshipListStateSelector = (listID: string): MemoizedSelector<AppStat
|
|||||||
return keySelector<NameVariantListState>(listID, relationshipListsStateSelector);
|
return keySelector<NameVariantListState>(listID, relationshipListsStateSelector);
|
||||||
};
|
};
|
||||||
|
|
||||||
const relationshipStateSelector = (listID: string, itemID: string): MemoizedSelector<AppState, RelationshipState> => {
|
const relationshipStateSelector = (listID: string, itemID: string): MemoizedSelector<AppState, string> => {
|
||||||
return keySelector<RelationshipState>(itemID, relationshipListStateSelector(listID));
|
return keySelector<string>(itemID, relationshipListStateSelector(listID));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -225,7 +225,7 @@ export class RelationshipService extends DataService<Relationship> {
|
|||||||
} else {
|
} else {
|
||||||
findAllOptions.searchParams = searchParams;
|
findAllOptions.searchParams = searchParams;
|
||||||
}
|
}
|
||||||
return this.searchBy('byLabel', findAllOptions);
|
return this.searchBy('byLabel', findAllOptions, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -263,6 +263,7 @@ export class RelationshipService extends DataService<Relationship> {
|
|||||||
return this.getItemRelationshipsByLabel(item1, label)
|
return this.getItemRelationshipsByLabel(item1, label)
|
||||||
.pipe(
|
.pipe(
|
||||||
getSucceededRemoteData(),
|
getSucceededRemoteData(),
|
||||||
|
tap((t) => console.log(t)),
|
||||||
map((relationshipListRD: RemoteData<PaginatedList<Relationship>>) => relationshipListRD.payload.page),
|
map((relationshipListRD: RemoteData<PaginatedList<Relationship>>) => relationshipListRD.payload.page),
|
||||||
mergeMap((relationships: Relationship[]) => {
|
mergeMap((relationships: Relationship[]) => {
|
||||||
return observableCombineLatest(...relationships.map((relationship: Relationship) => {
|
return observableCombineLatest(...relationships.map((relationship: Relationship) => {
|
||||||
@@ -293,7 +294,7 @@ export class RelationshipService extends DataService<Relationship> {
|
|||||||
|
|
||||||
public getNameVariant(listID: string, itemID: string): Observable<string> {
|
public getNameVariant(listID: string, itemID: string): Observable<string> {
|
||||||
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))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,4 +305,29 @@ export class RelationshipService extends DataService<Relationship> {
|
|||||||
public getNameVariantsByListID(listID: string) {
|
public getNameVariantsByListID(listID: string) {
|
||||||
return this.appStore.pipe(select(relationshipListStateSelector(listID)));
|
return this.appStore.pipe(select(relationshipListStateSelector(listID)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public updateNameVariant(item1: Item, item2: Item, relationshipLabel: string, nameVariant: string): Observable<RemoteData<Relationship>> {
|
||||||
|
return this.getRelationshipByItemsAndLabel(item1, item2, relationshipLabel)
|
||||||
|
.pipe(
|
||||||
|
switchMap((relation: Relationship) =>
|
||||||
|
relation.relationshipType.pipe(
|
||||||
|
getSucceededRemoteData(),
|
||||||
|
getRemoteDataPayload(),
|
||||||
|
map(type => {
|
||||||
|
return { relation, type }
|
||||||
|
})
|
||||||
|
)
|
||||||
|
),
|
||||||
|
switchMap((relationshipAndType: {relation: Relationship, type: RelationshipType}) => {
|
||||||
|
const { relation, type } = relationshipAndType;
|
||||||
|
let updatedRelationship;
|
||||||
|
if (relationshipLabel === type.leftwardType) {
|
||||||
|
updatedRelationship = Object.assign(new Relationship(), relation, { rightWardValue: nameVariant });
|
||||||
|
} else {
|
||||||
|
updatedRelationship = Object.assign(new Relationship(), relation, { leftWardValue: nameVariant });
|
||||||
|
}
|
||||||
|
return this.update(updatedRelationship);
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -47,6 +47,7 @@ export const getResponseFromEntry = () =>
|
|||||||
export const getResourceLinksFromResponse = () =>
|
export const getResourceLinksFromResponse = () =>
|
||||||
(source: Observable<RequestEntry>): Observable<string[]> =>
|
(source: Observable<RequestEntry>): Observable<string[]> =>
|
||||||
source.pipe(
|
source.pipe(
|
||||||
|
tap((t) => console.log(t)),
|
||||||
filterSuccessfulResponses(),
|
filterSuccessfulResponses(),
|
||||||
map((response: DSOSuccessResponse) => response.resourceSelfLinks),
|
map((response: DSOSuccessResponse) => response.resourceSelfLinks),
|
||||||
);
|
);
|
||||||
|
@@ -47,7 +47,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit {
|
|||||||
metadataFields: string;
|
metadataFields: string;
|
||||||
subMap: {
|
subMap: {
|
||||||
[uuid: string]: Subscription
|
[uuid: string]: Subscription
|
||||||
};
|
} = {};
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public modal: NgbActiveModal,
|
public modal: NgbActiveModal,
|
||||||
@@ -78,7 +78,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit {
|
|||||||
this.subMap[sri.indexableObject.uuid] = nameVariant$
|
this.subMap[sri.indexableObject.uuid] = nameVariant$
|
||||||
.pipe(skip(1))
|
.pipe(skip(1))
|
||||||
.subscribe((nameVariant: string) =>
|
.subscribe((nameVariant: string) =>
|
||||||
this.relationshipService.updateNameVariant(this.item, sri.indexableObject, this.relationshipOptions.relationshipType, nameVariant)
|
this.relationshipService.updateNameVariant(this.item, sri.indexableObject, this.relationshipOptions.relationshipType, nameVariant).subscribe()
|
||||||
);
|
);
|
||||||
return nameVariant$
|
return nameVariant$
|
||||||
.pipe(
|
.pipe(
|
||||||
@@ -97,7 +97,6 @@ export class DsDynamicLookupRelationModalComponent implements OnInit {
|
|||||||
.subscribe((obs: any[]) => {
|
.subscribe((obs: any[]) => {
|
||||||
return obs.forEach((object: any) => {
|
return obs.forEach((object: any) => {
|
||||||
this.store.dispatch(new AddRelationshipAction(this.item, object.item, this.relationshipOptions.relationshipType, object.nameVariant));
|
this.store.dispatch(new AddRelationshipAction(this.item, object.item, this.relationshipOptions.relationshipType, object.nameVariant));
|
||||||
this.addSelectSubscription(object);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
@@ -107,39 +106,39 @@ export class DsDynamicLookupRelationModalComponent implements OnInit {
|
|||||||
deselect(...selectableObjects: SearchResult<Item>[]) {
|
deselect(...selectableObjects: SearchResult<Item>[]) {
|
||||||
this.zone.runOutsideAngular(
|
this.zone.runOutsideAngular(
|
||||||
() => selectableObjects.forEach((object) => {
|
() => selectableObjects.forEach((object) => {
|
||||||
|
this.subMap[object.indexableObject.uuid].unsubscribe();
|
||||||
this.store.dispatch(new RemoveRelationshipAction(this.item, object.indexableObject, this.relationshipOptions.relationshipType));
|
this.store.dispatch(new RemoveRelationshipAction(this.item, object.indexableObject, this.relationshipOptions.relationshipType));
|
||||||
this.addSelectSubscription(object);
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
subscriptions = new Map<string, Subscription>();
|
// subscriptions = new Map<string, Subscription>();
|
||||||
|
//
|
||||||
|
// addSelectSubscription(itemSR: SearchResult<Item>) {
|
||||||
|
// const nameVariant$ = this.relationshipService.getNameVariant(this.listId, itemSR.indexableObject.uuid).pipe(hasValueOperator());
|
||||||
|
// const subscription = nameVariant$
|
||||||
|
// .pipe(
|
||||||
|
// switchMap((nameVariant: string) => {
|
||||||
|
// return this.relationshipService.getRelationshipByItemsAndLabel(this.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);
|
||||||
|
// }
|
||||||
|
|
||||||
addSelectSubscription(itemSR: SearchResult<Item>) {
|
// removeSelectSubscription(itemSR: SearchResult<Item>) {
|
||||||
const nameVariant$ = this.relationshipService.getNameVariant(this.listId, itemSR.indexableObject.uuid).pipe(hasValueOperator());
|
// this.subscriptions.get(itemSR.indexableObject.uuid).unsubscribe();
|
||||||
const subscription = nameVariant$
|
// }
|
||||||
.pipe(
|
//
|
||||||
switchMap((nameVariant: string) => {
|
// ngOnDestroy() {
|
||||||
return this.relationshipService.getRelationshipByItemsAndLabel(this.item, itemSR.indexableObject, this.relationshipOptions.relationshipType)
|
// let sub;
|
||||||
.pipe(map((relationship: Relationship) => Object.assign(new Relationship(), relationship, { leftwardValue: nameVariant })))
|
// while (sub = this.subscriptions.values().next(), !sub.done) {
|
||||||
}),
|
// sub.unsubscribe();
|
||||||
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.item.allMetadata(this.metadataFields).filter((mdValue) => mdValue.isVirtual);
|
const virtualMDs$: Observable<MetadataValue[]> = this.item.allMetadata(this.metadataFields).filter((mdValue) => mdValue.isVirtual);
|
||||||
|
Reference in New Issue
Block a user