mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
fixed issue with adding/selecting relation
This commit is contained in:
@@ -250,9 +250,10 @@ export class RelationshipService extends DataService<Relationship> {
|
|||||||
.pipe(
|
.pipe(
|
||||||
switchMap((relationships: Relationship[]) => {
|
switchMap((relationships: Relationship[]) => {
|
||||||
return observableCombineLatest(...relationships.map((relationship: Relationship) => {
|
return observableCombineLatest(...relationships.map((relationship: Relationship) => {
|
||||||
|
console.log('relationship: ', relationship.uuid);
|
||||||
return observableCombineLatest(
|
return observableCombineLatest(
|
||||||
this.isItemMatchWithItemRD(relationship.leftItem, item2),
|
this.isItemMatchWithItemRD(relationship.leftItem, item2, 'left'),
|
||||||
this.isItemMatchWithItemRD(relationship.rightItem, item2)
|
this.isItemMatchWithItemRD(relationship.rightItem, item2, 'right')
|
||||||
).pipe(
|
).pipe(
|
||||||
filter(([isLeftItem, isRightItem]) => isLeftItem || isRightItem),
|
filter(([isLeftItem, isRightItem]) => isLeftItem || isRightItem),
|
||||||
map(() => relationship),
|
map(() => relationship),
|
||||||
@@ -265,10 +266,11 @@ export class RelationshipService extends DataService<Relationship> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private isItemMatchWithItemRD(itemRD$: Observable<RemoteData<Item>>, itemCheck: Item): Observable<boolean> {
|
private isItemMatchWithItemRD(itemRD$: Observable<RemoteData<Item>>, itemCheck: Item, side: string): Observable<boolean> {
|
||||||
return itemRD$.pipe(
|
return itemRD$.pipe(
|
||||||
getSucceededRemoteData(),
|
getSucceededRemoteData(),
|
||||||
map((itemRD: RemoteData<Item>) => itemRD.payload),
|
map((itemRD: RemoteData<Item>) => itemRD.payload),
|
||||||
|
tap((item) => console.log(side, ': ', item.uuid)),
|
||||||
map((item: Item) => item.uuid === itemCheck.uuid)
|
map((item: Item) => item.uuid === itemCheck.uuid)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -69,7 +69,7 @@ import { DsDynamicFormArrayComponent } from './models/array-group/dynamic-form-a
|
|||||||
import { DsDynamicRelationGroupComponent } from './models/relation-group/dynamic-relation-group.components';
|
import { DsDynamicRelationGroupComponent } from './models/relation-group/dynamic-relation-group.components';
|
||||||
import { DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP } from './models/relation-group/dynamic-relation-group.model';
|
import { DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP } from './models/relation-group/dynamic-relation-group.model';
|
||||||
import { DsDatePickerInlineComponent } from './models/date-picker-inline/dynamic-date-picker-inline.component';
|
import { DsDatePickerInlineComponent } from './models/date-picker-inline/dynamic-date-picker-inline.component';
|
||||||
import { map, switchMap, tap } from 'rxjs/operators';
|
import { map, switchMap, take, tap } from 'rxjs/operators';
|
||||||
import { SelectableListState } from '../../../object-list/selectable-list/selectable-list.reducer';
|
import { SelectableListState } from '../../../object-list/selectable-list/selectable-list.reducer';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { SearchResult } from '../../../search/search-result.model';
|
import { SearchResult } from '../../../search/search-result.model';
|
||||||
@@ -92,6 +92,8 @@ import { DsDynamicInputModel } from './models/ds-dynamic-input.model';
|
|||||||
import { getSucceededRemoteData } from '../../../../core/shared/operators';
|
import { getSucceededRemoteData } from '../../../../core/shared/operators';
|
||||||
import { RemoteData } from '../../../../core/data/remote-data';
|
import { RemoteData } from '../../../../core/data/remote-data';
|
||||||
import { Item } from '../../../../core/shared/item.model';
|
import { Item } from '../../../../core/shared/item.model';
|
||||||
|
import { Relationship } from '../../../../core/shared/item-relationships/relationship.model';
|
||||||
|
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||||
|
|
||||||
export function dsDynamicFormControlMapFn(model: DynamicFormControlModel): Type<DynamicFormControl> | null {
|
export function dsDynamicFormControlMapFn(model: DynamicFormControlModel): Type<DynamicFormControl> | null {
|
||||||
switch (model.type) {
|
switch (model.type) {
|
||||||
@@ -182,7 +184,7 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
|||||||
modelValueMDRepresentation;
|
modelValueMDRepresentation;
|
||||||
listId: string;
|
listId: string;
|
||||||
searchConfig: string;
|
searchConfig: string;
|
||||||
|
uuid;
|
||||||
/* tslint:disable:no-output-rename */
|
/* tslint:disable:no-output-rename */
|
||||||
@Output('dfBlur') blur: EventEmitter<DynamicFormControlEvent> = new EventEmitter<DynamicFormControlEvent>();
|
@Output('dfBlur') blur: EventEmitter<DynamicFormControlEvent> = new EventEmitter<DynamicFormControlEvent>();
|
||||||
@Output('dfChange') change: EventEmitter<DynamicFormControlEvent> = new EventEmitter<DynamicFormControlEvent>();
|
@Output('dfChange') change: EventEmitter<DynamicFormControlEvent> = new EventEmitter<DynamicFormControlEvent>();
|
||||||
@@ -205,6 +207,8 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
|||||||
private modalService: NgbModal,
|
private modalService: NgbModal,
|
||||||
private relationService: RelationshipService,
|
private relationService: RelationshipService,
|
||||||
private selectableListService: SelectableListService,
|
private selectableListService: SelectableListService,
|
||||||
|
private itemService: ItemDataService,
|
||||||
|
private relationshipService: RelationshipService,
|
||||||
) {
|
) {
|
||||||
super(componentFactoryResolver, layoutService, validationService);
|
super(componentFactoryResolver, layoutService, validationService);
|
||||||
}
|
}
|
||||||
@@ -215,8 +219,9 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
|||||||
this.listId = 'list-' + this.model.relationship.relationshipType;
|
this.listId = 'list-' + this.model.relationship.relationshipType;
|
||||||
this.model.workspaceItem.item.pipe(
|
this.model.workspaceItem.item.pipe(
|
||||||
getSucceededRemoteData(),
|
getSucceededRemoteData(),
|
||||||
|
tap((itemRD: RemoteData<Item>) => this.uuid = itemRD.payload.uuid),
|
||||||
switchMap((itemRD: RemoteData<Item>) => this.relationService.getRelatedItemsByLabel(itemRD.payload, this.model.relationship.relationshipType)),
|
switchMap((itemRD: RemoteData<Item>) => this.relationService.getRelatedItemsByLabel(itemRD.payload, this.model.relationship.relationshipType)),
|
||||||
map((items: Item[]) => items.map((item) => Object.assign(new SearchResult(), { indexableObject: item })))
|
map((items: Item[]) => items.map((item) => Object.assign(new SearchResult(), { indexableObject: item }))),
|
||||||
).subscribe((relatedItems) => this.selectableListService.select(this.listId, relatedItems));
|
).subscribe((relatedItems) => this.selectableListService.select(this.listId, relatedItems));
|
||||||
|
|
||||||
this.model.value = this.selectableListService.getSelectableList(this.listId).pipe(
|
this.model.value = this.selectableListService.getSelectableList(this.listId).pipe(
|
||||||
@@ -275,10 +280,17 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
|||||||
modalComp.listId = this.listId;
|
modalComp.listId = this.listId;
|
||||||
modalComp.relationship = this.model.relationship;
|
modalComp.relationship = this.model.relationship;
|
||||||
modalComp.label = this.model.label;
|
modalComp.label = this.model.label;
|
||||||
modalComp.itemRD$ = this.model.workspaceItem.item;
|
modalComp.uuid = this.uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
removeSelection(object: SearchResult<DSpaceObject>) {
|
removeSelection(object: SearchResult<Item>) {
|
||||||
this.selectableListService.deselectSingle(this.listId, object);
|
this.selectableListService.deselectSingle(this.listId, object);
|
||||||
|
setTimeout(() => this.itemService.findById(this.uuid).pipe(
|
||||||
|
getSucceededRemoteData(),
|
||||||
|
switchMap((itemRD: RemoteData<Item>) => this.relationshipService.getRelationshipByItemsAndLabel(itemRD.payload, object.indexableObject, this.model.relationship.relationshipType)),
|
||||||
|
tap(t => console.log(t)),
|
||||||
|
switchMap((relationship: Relationship) => this.relationshipService.deleteRelationship(relationship.id)),
|
||||||
|
take(1)
|
||||||
|
).subscribe(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,7 @@ import { Item } from '../../../../../core/shared/item.model';
|
|||||||
import { RelationshipOptions } from '../../models/relationship-options.model';
|
import { RelationshipOptions } from '../../models/relationship-options.model';
|
||||||
import { Relationship } from '../../../../../core/shared/item-relationships/relationship.model';
|
import { Relationship } from '../../../../../core/shared/item-relationships/relationship.model';
|
||||||
import { ItemDataService } from '../../../../../core/data/item-data.service';
|
import { ItemDataService } from '../../../../../core/data/item-data.service';
|
||||||
|
import { ObjectCacheService } from '../../../../../core/cache/object-cache.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-dynamic-lookup-relation-modal',
|
selector: 'ds-dynamic-lookup-relation-modal',
|
||||||
@@ -40,7 +41,6 @@ import { ItemDataService } from '../../../../../core/data/item-data.service';
|
|||||||
export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy {
|
export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy {
|
||||||
label: string;
|
label: string;
|
||||||
relationship: RelationshipOptions;
|
relationship: RelationshipOptions;
|
||||||
itemRD$: Observable<RemoteData<Item>>;
|
|
||||||
listId: string;
|
listId: string;
|
||||||
resultsRD$: Observable<RemoteData<PaginatedList<SearchResult<Item>>>>;
|
resultsRD$: Observable<RemoteData<PaginatedList<SearchResult<Item>>>>;
|
||||||
searchConfig: PaginatedSearchOptions;
|
searchConfig: PaginatedSearchOptions;
|
||||||
@@ -55,6 +55,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
pageSize: 10
|
pageSize: 10
|
||||||
});
|
});
|
||||||
selection$: Observable<ListableObject[]>;
|
selection$: Observable<ListableObject[]>;
|
||||||
|
uuid;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public modal: NgbActiveModal,
|
public modal: NgbActiveModal,
|
||||||
@@ -65,12 +66,12 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
private routeService: RouteService,
|
private routeService: RouteService,
|
||||||
private relationshipService: RelationshipService,
|
private relationshipService: RelationshipService,
|
||||||
private relationshipTypeService: RelationshipTypeService,
|
private relationshipTypeService: RelationshipTypeService,
|
||||||
private itemService: ItemDataService
|
private itemService: ItemDataService,
|
||||||
|
private objectCache: ObjectCacheService,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.itemRD$.subscribe(t => console.log('subscription', t));
|
|
||||||
this.resetRoute();
|
this.resetRoute();
|
||||||
this.routeService.setParameter('fixedFilterQuery', this.relationship.filter);
|
this.routeService.setParameter('fixedFilterQuery', this.relationship.filter);
|
||||||
this.routeService.setParameter('configuration', this.relationship.searchConfiguration);
|
this.routeService.setParameter('configuration', this.relationship.searchConfiguration);
|
||||||
@@ -96,7 +97,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
) as any
|
) as any
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,9 +150,8 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
|
|
||||||
|
|
||||||
select(selectableObject: SearchResult<Item>) {
|
select(selectableObject: SearchResult<Item>) {
|
||||||
this.itemRD$
|
this.itemService.findById(this.uuid)
|
||||||
.pipe(
|
.pipe(
|
||||||
tap((t) => console.log('tap',t)),
|
|
||||||
getSucceededRemoteData(),
|
getSucceededRemoteData(),
|
||||||
mergeMap((itemRD: RemoteData<Item>) => {
|
mergeMap((itemRD: RemoteData<Item>) => {
|
||||||
const type1: string = itemRD.payload.firstMetadataValue('relationship.type');
|
const type1: string = itemRD.payload.firstMetadataValue('relationship.type');
|
||||||
@@ -165,8 +165,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
return this.relationshipService.addRelationship(type.id, itemRD.payload, selectableObject.indexableObject);
|
return this.relationshipService.addRelationship(type.id, itemRD.payload, selectableObject.indexableObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
),
|
)
|
||||||
tap(() => this.itemRD$ = this.itemService.findById(itemRD.payload.uuid))
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}),
|
}),
|
||||||
@@ -177,7 +176,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
|
|
||||||
|
|
||||||
deselect(selectableObject: SearchResult<Item>) {
|
deselect(selectableObject: SearchResult<Item>) {
|
||||||
const subscription = this.itemRD$.pipe(
|
this.itemService.findById(this.uuid).pipe(
|
||||||
getSucceededRemoteData(),
|
getSucceededRemoteData(),
|
||||||
switchMap((itemRD: RemoteData<Item>) => this.relationshipService.getRelationshipByItemsAndLabel(itemRD.payload, selectableObject.indexableObject, this.relationship.relationshipType)),
|
switchMap((itemRD: RemoteData<Item>) => this.relationshipService.getRelationshipByItemsAndLabel(itemRD.payload, selectableObject.indexableObject, this.relationship.relationshipType)),
|
||||||
switchMap((relationship: Relationship) => this.relationshipService.deleteRelationship(relationship.id)),
|
switchMap((relationship: Relationship) => this.relationshipService.deleteRelationship(relationship.id)),
|
||||||
|
Reference in New Issue
Block a user