From ffee36607de1f03b51b5051663b0fff0c9ddea7d Mon Sep 17 00:00:00 2001 From: Rezart Vata Date: Fri, 10 Sep 2021 18:49:23 +0200 Subject: [PATCH] [CST-5404] Started working on new feature,added services and started working on selection --- .../core/data/relationship-type.service.ts | 31 ++++++++++++- src/app/core/data/relationship.service.ts | 44 +++++++++++++++++++ .../edit-relationship-list.component.ts | 9 ++++ .../item-relationships.component.ts | 12 ++++- ...namic-lookup-relation-modal.component.html | 2 + ...dynamic-lookup-relation-modal.component.ts | 13 ++++++ ...ic-lookup-relation-search-tab.component.ts | 36 ++++++++++++++- ...lookup-relation-selection-tab.component.ts | 5 ++- 8 files changed, 147 insertions(+), 5 deletions(-) diff --git a/src/app/core/data/relationship-type.service.ts b/src/app/core/data/relationship-type.service.ts index 4dac044090..cd0ceda55d 100644 --- a/src/app/core/data/relationship-type.service.ts +++ b/src/app/core/data/relationship-type.service.ts @@ -15,7 +15,7 @@ import { HALEndpointService } from '../shared/hal-endpoint.service'; import { ItemType } from '../shared/item-relationships/item-type.model'; import { RelationshipType } from '../shared/item-relationships/relationship-type.model'; import { RELATIONSHIP_TYPE } from '../shared/item-relationships/relationship-type.resource-type'; -import { getFirstSucceededRemoteData, getFirstCompletedRemoteData } from '../shared/operators'; +import { getFirstSucceededRemoteData, getFirstCompletedRemoteData, getRemoteDataPayload } from '../shared/operators'; import { DataService } from './data.service'; import { DefaultChangeAnalyzer } from './default-change-analyzer.service'; import { ItemDataService } from './item-data.service'; @@ -120,4 +120,33 @@ export class RelationshipTypeService extends DataService { }) ); } + + /** + * Check if the given RelationshipType has the given itemTypes on its left and right sides. + * Returns an observable of the given RelationshipType if it matches, null if it doesn't + * + * @param type The RelationshipType to check + * @param leftItemType The item type that should be on the left side + * @param rightItemType The item type that should be on the right side + * @private + */ + searchByEntityType(type: string): Observable { + + + return this.searchBy( + 'byEntityType', + { + searchParams: [ + { + fieldName: 'type', + fieldValue: type + } + ] + }).pipe( + getFirstSucceededRemoteData(), + getRemoteDataPayload(), + ) as Observable; + } + + } diff --git a/src/app/core/data/relationship.service.ts b/src/app/core/data/relationship.service.ts index 727cd105e6..c4507dd0be 100644 --- a/src/app/core/data/relationship.service.ts +++ b/src/app/core/data/relationship.service.ts @@ -469,4 +469,48 @@ export class RelationshipService extends DataService { update(object: Relationship): Observable> { return this.put(object); } + + searchByItemsAndType(typeId: string,itemUuid: string,focusSide: string, arrayOfItemIds: string[] ): Observable { + + let searchParams = [ + { + fieldName: 'typeId', + fieldValue: typeId + }, + { + fieldName: 'focusItem', + fieldValue: itemUuid + }, + { + fieldName: 'relationshipLabel', + fieldValue: 'isPublicationOfAuthor' + }, + // { + // fieldName: 'page', + // fieldValue: 1 + // }, + ]; + + arrayOfItemIds.forEach((itemId)=>{ + searchParams.push( + { + fieldName: 'relatedItem', + fieldValue: itemId + }, + ) + }) + + + + + return this.getSearchByHref( + 'byItemsAndType', + { + searchParams : searchParams + }).pipe( + switchMap((href) => this.findByHref(href)), + getFirstSucceededRemoteData(), + getRemoteDataPayload(), + ); + } } diff --git a/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts b/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts index 9f417ab799..b67e99debb 100644 --- a/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts +++ b/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts @@ -49,6 +49,8 @@ import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject'; import { Subscription } from 'rxjs/internal/Subscription'; import { PaginationComponentOptions } from '../../../../shared/pagination/pagination-component-options.model'; import { PaginationService } from '../../../../core/pagination/pagination.service'; +import { RelationshipTypeService } from '../../../../core/data/relationship-type.service'; + @Component({ selector: 'ds-edit-relationship-list', @@ -142,6 +144,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { protected objectUpdatesService: ObjectUpdatesService, protected linkService: LinkService, protected relationshipService: RelationshipService, + protected relationshipTypeService: RelationshipTypeService, protected modalService: NgbModal, protected paginationService: PaginationService, protected selectableListService: SelectableListService, @@ -209,6 +212,9 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { modalComp.repeatable = true; modalComp.listId = this.listId; modalComp.item = this.item; + modalComp.relationshipType = this.relationshipType; + modalComp.currentItemIsLeftItem$ = this.currentItemIsLeftItem$; + this.item.owningCollection.pipe( getFirstSucceededRemoteDataPayload() ).subscribe((collection: Collection) => { @@ -297,6 +303,8 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { ).subscribe((items) => { this.selectableListService.select(this.listId, items); }); + + console.log(modalComp); } /** @@ -337,6 +345,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { } ngOnInit(): void { + // store the left and right type of the relationship in a single observable this.relationshipLeftAndRightType$ = observableCombineLatest([ this.relationshipType.leftType, diff --git a/src/app/item-page/edit-item-page/item-relationships/item-relationships.component.ts b/src/app/item-page/edit-item-page/item-relationships/item-relationships.component.ts index e22ad8ddcb..7ca78b0490 100644 --- a/src/app/item-page/edit-item-page/item-relationships/item-relationships.component.ts +++ b/src/app/item-page/edit-item-page/item-relationships/item-relationships.component.ts @@ -7,7 +7,7 @@ import { RelationshipIdentifiable, } from '../../../core/data/object-updates/object-updates.reducer'; import { Observable } from 'rxjs/internal/Observable'; -import { map, startWith, switchMap, take } from 'rxjs/operators'; +import { map, startWith, switchMap, take, tap } from 'rxjs/operators'; import { combineLatest as observableCombineLatest, of as observableOf, @@ -32,6 +32,8 @@ import { FieldChangeType } from '../../../core/data/object-updates/object-update import { Relationship } from '../../../core/shared/item-relationships/relationship.model'; import { NoContent } from '../../../core/shared/NoContent.model'; import { hasValue } from '../../../shared/empty.util'; +import { RelationshipTypeService } from '../../../core/data/relationship-type.service'; +import { PaginatedList } from '../../../core/data/paginated-list.model'; @Component({ selector: 'ds-item-relationships', @@ -65,6 +67,7 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent { public objectCache: ObjectCacheService, public requestService: RequestService, public entityTypeService: EntityTypeService, + protected relationshipTypeService: RelationshipTypeService, public cdr: ChangeDetectorRef, ) { super(itemService, objectUpdatesService, router, notificationsService, translateService, route); @@ -78,6 +81,12 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent { const label = this.item.firstMetadataValue('dspace.entity.type'); if (label !== undefined) { + // this.relationshipTypes$ = this.relationshipTypeService.searchByEntityType(label) + // .pipe( + // map((relationship:any) => relationship.page), + // tap(res => console.log(res)) + // ); + this.entityType$ = this.entityTypeService.getEntityTypeByLabel(label).pipe( getFirstSucceededRemoteData(), getRemoteDataPayload(), @@ -95,6 +104,7 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent { getFirstSucceededRemoteData(), getRemoteDataPayload(), map((relationshipTypes) => relationshipTypes.page), + tap((res)=> console.log(res)) ) ), ); diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.html b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.html index 339f6f278d..d67d113bd8 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.html +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.html @@ -17,6 +17,8 @@ [repeatable]="repeatable" [context]="context" [query]="query" + [relationshipType]="relationshipType" + [item]="item" (selectObject)="select($event)" (deselectObject)="deselect($event)" class="d-block pt-3"> diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.ts index 5ce451d6c2..4b99e69d9f 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.ts @@ -114,6 +114,9 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy */ totalExternal$: Observable; + relationshipType; + + currentItemIsLeftItem$ : Observable; constructor( public modal: NgbActiveModal, @@ -132,6 +135,16 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy } ngOnInit(): void { + + // this.currentItemIsLeftItem$.subscribe((isLeft) => { + // if(isLeft){ + // console.log(this.relationshipType.leftwardType); + // }else{ + // console.log(this.relationshipType.rightwardType); + // } + // }); + + this.selection$ = this.selectableListService .getSelectableList(this.listId) .pipe(map((listState: SelectableListState) => hasValue(listState) && hasValue(listState.selection) ? listState.selection : [])); diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.ts index c6771f8d16..e4fe443dd5 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.ts @@ -20,6 +20,9 @@ import { CollectionElementLinkType } from '../../../../../object-collection/coll import { Context } from '../../../../../../core/shared/context.model'; import { LookupRelationService } from '../../../../../../core/data/lookup-relation.service'; import { PaginationService } from '../../../../../../core/pagination/pagination.service'; +import { RelationshipService } from '../../../../../../core/data/relationship.service'; +import { RelationshipType } from '../../../../../../core/shared/item-relationships/relationship-type.model'; +import { RelationshipTypeService } from '../../../../../../core/data/relationship-type.service'; @Component({ selector: 'ds-dynamic-lookup-relation-search-tab', @@ -63,6 +66,16 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest */ @Input() context: Context; + /** + * The type of relationship + */ + @Input() relationshipType: RelationshipType; + + /** + * The item being viewed + */ + @Input() item: Item; + /** * Send an event to deselect an object from the list */ @@ -119,6 +132,8 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest public searchConfigService: SearchConfigurationService, private routeService: RouteService, public lookupRelationService: LookupRelationService, + private relationshipService: RelationshipService, + private relationshipTypeService: RelationshipTypeService, private paginationService: PaginationService ) { } @@ -127,11 +142,23 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest * Sets up the pagination and fixed query parameters */ ngOnInit(): void { + console.log(this.item); this.resetRoute(); this.routeService.setParameter('fixedFilterQuery', this.relationship.filter); this.routeService.setParameter('configuration', this.relationship.searchConfiguration); this.resultsRD$ = this.searchConfigService.paginatedSearchOptions.pipe( - switchMap((options) => this.lookupRelationService.getLocalResults(this.relationship, options).pipe(startWith(undefined))) + switchMap((options) => this.lookupRelationService.getLocalResults(this.relationship, options).pipe( + startWith(undefined), + tap(res=> { + if(!!res && res.state == 'Success'){ + const idOfItems = res.payload.page.map(itemSearchResult => { + return itemSearchResult.indexableObject.uuid; + }); + this.setSelectedIds(idOfItems); + } + + }) + )) ); } @@ -199,6 +226,13 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest ); } + setSelectedIds(idOfItems){ + console.log(this.relationshipType) + this.relationshipService.searchByItemsAndType(this.relationshipType.id, this.item.uuid, this.relationship.relationshipType ,idOfItems).subscribe((res)=>{ + console.log(res); + }); + } + /** * Deselect all items */ diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/selection-tab/dynamic-lookup-relation-selection-tab.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/selection-tab/dynamic-lookup-relation-selection-tab.component.ts index 79228a1376..78f8b6fa21 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/selection-tab/dynamic-lookup-relation-selection-tab.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/selection-tab/dynamic-lookup-relation-selection-tab.component.ts @@ -4,7 +4,7 @@ import { SearchConfigurationService } from '../../../../../../core/shared/search import { Observable } from 'rxjs'; import { ListableObject } from '../../../../../object-collection/shared/listable-object.model'; import { RemoteData } from '../../../../../../core/data/remote-data'; -import { map, switchMap, take } from 'rxjs/operators'; +import { map, switchMap, take, tap } from 'rxjs/operators'; import { PaginationComponentOptions } from '../../../../../pagination/pagination-component-options.model'; import { PaginatedList, @@ -115,7 +115,8 @@ export class DsDynamicLookupRelationSelectionTabComponent { totalPages: Math.ceil(selected.length / pagination.pageSize) }); return createSuccessfulRemoteDataObject(buildPaginatedList(pageInfo, selection)); - }) + }), + tap((res)=> console.log(res)) ); }) );