From a2605cdddd88464644c0e9c21f565aed86101d8e Mon Sep 17 00:00:00 2001 From: Rezart Vata Date: Tue, 14 Sep 2021 19:24:22 +0200 Subject: [PATCH] [CST-4504] Changed init api, disabled selected tab only for relationship edit page, fixed the related items checked, fixed the issue regarding the updated item control --- .../core/data/relationship-type.service.ts | 3 +- src/app/core/data/relationship.service.ts | 15 ++--- .../edit-relationship-list.component.ts | 63 +++++++++++++++---- .../item-relationships.component.ts | 25 ++------ ...namic-lookup-relation-modal.component.html | 4 +- ...dynamic-lookup-relation-modal.component.ts | 15 ++--- ...ic-lookup-relation-search-tab.component.ts | 62 +++++++++++++++--- 7 files changed, 127 insertions(+), 60 deletions(-) diff --git a/src/app/core/data/relationship-type.service.ts b/src/app/core/data/relationship-type.service.ts index cd0ceda55d..a4f11b217c 100644 --- a/src/app/core/data/relationship-type.service.ts +++ b/src/app/core/data/relationship-type.service.ts @@ -132,7 +132,6 @@ export class RelationshipTypeService extends DataService { */ searchByEntityType(type: string): Observable { - return this.searchBy( 'byEntityType', { @@ -142,7 +141,7 @@ export class RelationshipTypeService extends DataService { fieldValue: type } ] - }).pipe( + }, true,true,followLink('leftType'),followLink('rightType')).pipe( getFirstSucceededRemoteData(), getRemoteDataPayload(), ) as Observable; diff --git a/src/app/core/data/relationship.service.ts b/src/app/core/data/relationship.service.ts index c4507dd0be..3cc82bd0dc 100644 --- a/src/app/core/data/relationship.service.ts +++ b/src/app/core/data/relationship.service.ts @@ -470,7 +470,7 @@ export class RelationshipService extends DataService { return this.put(object); } - searchByItemsAndType(typeId: string,itemUuid: string,focusSide: string, arrayOfItemIds: string[] ): Observable { + searchByItemsAndType(typeId: string,itemUuid: string,relationshipLabel: string, arrayOfItemIds: string[] ): Observable { let searchParams = [ { @@ -483,7 +483,7 @@ export class RelationshipService extends DataService { }, { fieldName: 'relationshipLabel', - fieldValue: 'isPublicationOfAuthor' + fieldValue: relationshipLabel }, // { // fieldName: 'page', @@ -500,17 +500,14 @@ export class RelationshipService extends DataService { ) }) - - - - return this.getSearchByHref( + return this.searchBy( 'byItemsAndType', { - searchParams : searchParams + searchParams: searchParams }).pipe( - switchMap((href) => this.findByHref(href)), getFirstSucceededRemoteData(), getRemoteDataPayload(), - ); + ) as Observable; + } } 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 b67e99debb..c125dd0e93 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 @@ -140,6 +140,10 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { */ modalRef: NgbModalRef; + listOfRelatedItems = []; + + relationshipTypeInfo: string; + constructor( protected objectUpdatesService: ObjectUpdatesService, protected linkService: LinkService, @@ -210,6 +214,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { }); const modalComp: DsDynamicLookupRelationModalComponent = this.modalRef.componentInstance; modalComp.repeatable = true; + modalComp.isEditRelationship = true; modalComp.listId = this.listId; modalComp.item = this.item; modalComp.relationshipType = this.relationshipType; @@ -223,12 +228,14 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { modalComp.select = (...selectableObjects: SearchResult[]) => { selectableObjects.forEach((searchResult) => { const relatedItem: Item = searchResult.indexableObject; - this.getFieldUpdatesForRelatedItem(relatedItem) - .subscribe((identifiables) => { - identifiables.forEach((identifiable) => - this.objectUpdatesService.removeSingleFieldUpdate(this.url, identifiable.uuid) - ); - if (identifiables.length === 0) { + this.getFieldUpdatesForRelatedItemNew(relatedItem) + .subscribe((isRelated: boolean) => { + + + // identifiables.forEach((identifiable) => + // this.objectUpdatesService.removeSingleFieldUpdate(this.url, identifiable.uuid) + // ); + if (!isRelated) { this.relationshipService.getNameVariant(this.listId, relatedItem.uuid) .subscribe((nameVariant) => { const update = { @@ -301,7 +308,8 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { return searchResult; })), ).subscribe((items) => { - this.selectableListService.select(this.listId, items); + // console.log(items); + // this.selectableListService.select(this.listId, items); }); console.log(modalComp); @@ -312,7 +320,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { * @param relatedItem The item for which to get the existing field updates */ private getFieldUpdatesForRelatedItem(relatedItem: Item): Observable { - + console.log("getFieldUpdatesForRelatedItem",relatedItem); return this.updates$.pipe( take(1), map((updates) => Object.values(updates) @@ -324,14 +332,43 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { identifiables.map((identifiable) => this.getRelatedItem(identifiable.relationship)) ).pipe( defaultIfEmpty([]), - map((relatedItems) => - identifiables.filter((identifiable, index) => relatedItems[index].uuid === relatedItem.uuid) + map((relatedItems) => { + console.log("identifiables",identifiables,relatedItems); + return identifiables.filter((identifiable, index) => + { + console.log(relatedItems[index].uuid,relatedItems,relatedItem.uuid); + return relatedItems[index].uuid === relatedItem.uuid + }) + } ), + tap(res=> console.log("getFieldUpdatesForRelatedItem -> res",res)) ) - ), + ) ); } + + private getFieldUpdatesForRelatedItemNew(relatedItem: Item): Observable { + + return this.currentItemIsLeftItem$.pipe( + take(1), + map(isLeft => { + if(isLeft){ + this.relationshipType.leftwardType; + let listOfRelatedItems = this.item.allMetadataValues('relation.'+this.relationshipType.leftwardType); + return !!listOfRelatedItems.find((uuid) => uuid == relatedItem.uuid); + }else{ + this.relationshipType.rightwardType; + let listOfRelatedItems = this.item.allMetadataValues('relation.'+this.relationshipType.rightwardType); + return !!listOfRelatedItems.find((uuid) => uuid == relatedItem.uuid); + } + }) + ); + + // return this.relationshipService.searchByItemsAndType(this.relationshipType.id, this.item.uuid, this.relationshipTypeInfo ,[relatedItem.uuid]) + // .pipe(map((res:any)=> res.page)); + } + /** * Get the related item for a given relationship * @param relationship The relationship for which to get the related item @@ -382,6 +419,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { }) ); + // initialize the pagination options this.paginationConfig = new PaginationComponentOptions(); this.paginationConfig.id = `er${this.relationshipType.id}`; @@ -459,10 +497,12 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { defaultIfEmpty([]) )), switchMap((nextFields: RelationshipIdentifiable[]) => { + console.log("nextFields",nextFields); // Get a list that contains the unsaved changes for the page, as well as the page of // RelationshipIdentifiables, as a single list of FieldUpdates return this.objectUpdatesService.getFieldUpdates(this.url, nextFields).pipe( map((fieldUpdates: FieldUpdates) => { + console.log("fieldUpdates",fieldUpdates); const fieldUpdatesFiltered: FieldUpdates = {}; this.nbAddedFields$.next(0); // iterate over the fieldupdates and filter out the ones that pertain to this @@ -495,6 +535,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { startWith({}), ).subscribe((updates: FieldUpdates) => { this.loading$.next(false); + console.log(updates); this.updates$.next(updates); })); } 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 7ca78b0490..dfc6f7e576 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 @@ -81,33 +81,16 @@ 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.relationshipTypes$ = this.relationshipTypeService.searchByEntityType(label) + .pipe( + map((relationshipTypes:any) => relationshipTypes.page) + ); this.entityType$ = this.entityTypeService.getEntityTypeByLabel(label).pipe( getFirstSucceededRemoteData(), getRemoteDataPayload(), ); - this.relationshipTypes$ = this.entityType$.pipe( - switchMap((entityType) => - this.entityTypeService.getEntityTypeRelationships( - entityType.id, - true, - true, - followLink('leftType'), - followLink('rightType')) - .pipe( - getFirstSucceededRemoteData(), - getRemoteDataPayload(), - map((relationshipTypes) => relationshipTypes.page), - tap((res)=> console.log(res)) - ) - ), - ); } else { this.entityType$ = observableOf(undefined); } 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 d67d113bd8..166ace5945 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 @@ -18,7 +18,9 @@ [context]="context" [query]="query" [relationshipType]="relationshipType" + [isLeft]="isLeft" [item]="item" + [isEditRelationship]="isEditRelationship" (selectObject)="select($event)" (deselectObject)="deselect($event)" class="d-block pt-3"> @@ -42,7 +44,7 @@ - + ; + isLeft: boolean = false; + + isEditRelationship: boolean = false; + + constructor( public modal: NgbActiveModal, private selectableListService: SelectableListService, @@ -136,13 +141,9 @@ 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.currentItemIsLeftItem$.subscribe((isLeft) => { + this.isLeft = isLeft; + }); this.selection$ = this.selectableListService 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 e4fe443dd5..30685cb8f8 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 @@ -14,7 +14,7 @@ import { ActivatedRoute, Router } from '@angular/router'; import { SelectableListService } from '../../../../../object-list/selectable-list/selectable-list.service'; import { hasValue } from '../../../../../empty.util'; import { map, startWith, switchMap, take, tap } from 'rxjs/operators'; -import { getFirstSucceededRemoteData } from '../../../../../../core/shared/operators'; +import { getFirstSucceededRemoteData, getRemoteDataPayload } from '../../../../../../core/shared/operators'; import { RouteService } from '../../../../../../core/services/route.service'; import { CollectionElementLinkType } from '../../../../../object-collection/collection-element-link.type'; import { Context } from '../../../../../../core/shared/context.model'; @@ -24,6 +24,16 @@ import { RelationshipService } from '../../../../../../core/data/relationship.se import { RelationshipType } from '../../../../../../core/shared/item-relationships/relationship-type.model'; import { RelationshipTypeService } from '../../../../../../core/data/relationship-type.service'; +import { ItemSearchResult } from '../../../../../../shared/object-collection/shared/item-search-result.model'; + +import { Relationship } from '../../../../../../core/shared/item-relationships/relationship.model'; +import { + FieldUpdate, + FieldUpdates, + RelationshipIdentifiable +} from '../../../../../../core/data/object-updates/object-updates.reducer'; + + @Component({ selector: 'ds-dynamic-lookup-relation-search-tab', styleUrls: ['./dynamic-lookup-relation-search-tab.component.scss'], @@ -76,6 +86,16 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest */ @Input() item: Item; + /** + * Check if is left type or right type + */ + @Input() isLeft: boolean; + + /** + * Check if is being utilized by edit relationship component + */ + @Input() isEditRelationship: boolean; + /** * Send an event to deselect an object from the list */ @@ -142,7 +162,6 @@ 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); @@ -150,13 +169,12 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest switchMap((options) => this.lookupRelationService.getLocalResults(this.relationship, options).pipe( startWith(undefined), tap(res=> { - if(!!res && res.state == 'Success'){ + if(!!res && res.state == 'Success' && this.isEditRelationship){ const idOfItems = res.payload.page.map(itemSearchResult => { return itemSearchResult.indexableObject.uuid; }); - this.setSelectedIds(idOfItems); + this.setSelectedIds(idOfItems,res.payload.page); } - }) )) ); @@ -226,10 +244,30 @@ 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); + setSelectedIds(idOfItems, resultListOfItems) { + let relationType = this.relationshipType.rightwardType; + if(this.isLeft){ + relationType = this.relationshipType.leftwardType; + } + this.relationshipService.searchByItemsAndType(this.relationshipType.id, this.item.uuid, relationType ,idOfItems).subscribe((res: any)=>{ + + const selectableObject = res.page.map((relationship: Relationship) => { + + let arrUrl = []; + if(this.isLeft){ + arrUrl = relationship._links.rightItem.href.split('/'); + }else{ + arrUrl = relationship._links.leftItem.href.split('/'); + } + let uuid = arrUrl[arrUrl.length-1]; + + return this.getRelatedItem(uuid,resultListOfItems); + + }); + // console.log(selectableObject); + if(selectableObject.length > 0){ + this.selectableListService.select(this.listId, selectableObject); + } }); } @@ -244,6 +282,12 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest this.selectableListService.deselectAll(this.listId); } + getRelatedItem(uuid,resultList){ + return resultList.find((resultItem) => { + return resultItem.indexableObject.uuid == uuid; + }); + } + ngOnDestroy(): void { if (hasValue(this.subscription)) { this.subscription.unsubscribe();