From 78403d96965646df506c452676b348e829ee23dc Mon Sep 17 00:00:00 2001 From: Rezart Vata Date: Tue, 19 Oct 2021 14:04:39 +0200 Subject: [PATCH] [CST-4504] Fixed discard issue and submit issue --- .../object-updates/object-updates.service.ts | 19 ------------ .../edit-relationship-list.component.ts | 30 +++++++++++-------- .../item-relationships.component.ts | 9 +++--- ...namic-lookup-relation-modal.component.html | 1 + ...dynamic-lookup-relation-modal.component.ts | 2 +- ...ic-lookup-relation-search-tab.component.ts | 16 +++++++++- 6 files changed, 39 insertions(+), 38 deletions(-) diff --git a/src/app/core/data/object-updates/object-updates.service.ts b/src/app/core/data/object-updates/object-updates.service.ts index 16ff5debf6..88c7c0e453 100644 --- a/src/app/core/data/object-updates/object-updates.service.ts +++ b/src/app/core/data/object-updates/object-updates.service.ts @@ -151,25 +151,6 @@ export class ObjectUpdatesService { })); } - /** - * Method that combines the state's updates (excluding updates that aren't part of the initialFields) with - * the initial values (when there's no update) to create a FieldUpdates object - * @param url The URL of the page for which the FieldUpdates should be requested - * @param initialFields The initial values of the fields - */ - getFieldUpdatesAll(url: string, initialFields: Identifiable[]): Observable { - const objectUpdates = this.getObjectEntry(url); - return objectUpdates.pipe( - hasValueOperator(), - map((objectEntry) => { - console.log(objectEntry,initialFields); - const fieldUpdates: FieldUpdates = {}; - for (const key of Object.keys(objectEntry.fieldUpdates)) { - fieldUpdates[key] = objectEntry.fieldUpdates[key]; - } - return fieldUpdates; - })); - } /** * Method to check if a specific field is currently editable in the store * @param url The URL of the page on which the field resides 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 e167e1c1d5..62af521421 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 @@ -75,7 +75,6 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { */ @Output() submit: EventEmitter = new EventEmitter(); - /** * Observable that emits the left and right item type of {@link relationshipType} simultaneously. */ @@ -233,9 +232,8 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { this.getIsRelatedItem(relatedItem) .subscribe((isRelated: boolean) => { - - if (!isRelated) { - modalComp.toAdd.push(relatedItem); + if (!isRelated ) { + modalComp.toAdd.push(searchResult); } this.loading$.next(true); @@ -249,12 +247,12 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { selectableObjects.forEach((searchResult) => { const relatedItem: Item = searchResult.indexableObject; - const foundIndex = modalComp.toAdd.findIndex( el => el.uuid === relatedItem.uuid); + const foundIndex = modalComp.toAdd.findIndex( el => el.indexableObject.uuid === relatedItem.uuid); if (foundIndex !== -1) { modalComp.toAdd.splice(foundIndex,1); } else { - modalComp.toRemove.push(relatedItem); + modalComp.toRemove.push(searchResult); } }); }; @@ -265,11 +263,12 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { const subscriptions = []; - modalComp.toAdd.forEach((relatedItem) => { + modalComp.toAdd.forEach((searchResult: SearchResult) => { + const relatedItem = searchResult.indexableObject; subscriptions.push(this.relationshipService.getNameVariant(this.listId, relatedItem.uuid).pipe( map((nameVariant) => { const update = { - uuid: this.relationshipType.id + '-' + relatedItem.uuid, + uuid: this.relationshipType.id + '-' + searchResult.indexableObject.uuid, nameVariant, type: this.relationshipType, relatedItem, @@ -280,10 +279,10 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { )); }); - modalComp.toRemove.forEach( (relatedItem) => { - subscriptions.push(this.relationshipService.getNameVariant(this.listId, relatedItem.uuid).pipe( + modalComp.toRemove.forEach( (searchResult) => { + subscriptions.push(this.relationshipService.getNameVariant(this.listId, searchResult.indexableObjectuuid).pipe( switchMap((nameVariant) => { - return this.getRelationFromId(relatedItem).pipe( + return this.getRelationFromId(searchResult.indexableObject).pipe( map( (relationship: Relationship) => { const update = { uuid: relationship.id, @@ -297,7 +296,6 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { ); }) )); - }); observableCombineLatest(subscriptions).subscribe( (res) => { @@ -312,6 +310,14 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { modalComp.discardEv = () => { + modalComp.toAdd.forEach((searchResult)=>{ + this.selectableListService.deselectSingle(this.listId,searchResult); + }) + + modalComp.toRemove.forEach((searchResult)=>{ + this.selectableListService.selectSingle(this.listId,searchResult); + }) + modalComp.toAdd = []; modalComp.toRemove = []; }; 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 78c478fefb..29b14500fd 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 @@ -113,13 +113,12 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent { Object.assign(new Relationship(), relationship, { uuid: relationship.id }) )), switchMap((relationships: Relationship[]) => { - return this.objectUpdatesService.getFieldUpdates(this.url, relationships) as Observable; + return this.objectUpdatesService.getFieldUpdatesExclusive(this.url, relationships) as Observable; }), - map((fieldUpdates: FieldUpdates) => { - return Object.values(fieldUpdates) + map((fieldUpdates: FieldUpdates) => + Object.values(fieldUpdates) .filter((fieldUpdate: FieldUpdate) => fieldUpdate.changeType === FieldChangeType.REMOVE) - .map((fieldUpdate: FieldUpdate) => fieldUpdate.field as DeleteRelationship); - } + .map((fieldUpdate: FieldUpdate) => fieldUpdate.field as DeleteRelationship) ), ); 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 6e83091324..ab4984f2fe 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 @@ -21,6 +21,7 @@ [isLeft]="isLeft" [item]="item" [isEditRelationship]="isEditRelationship" + [toRemove]="toRemove" (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 ced637a4ff..29e403ee55 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 @@ -168,7 +168,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy } ngOnInit(): void { - + console.log(this.toRemove); if (!!this.currentItemIsLeftItem$) { this.currentItemIsLeftItem$.subscribe((isLeft) => { this.isLeft = isLeft; 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 c0ca430c89..46e8d2b7e8 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 @@ -83,6 +83,12 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest */ @Input() isLeft: boolean; + /** + * Check if is left type or right type + */ + @Input() toRemove: SearchResult[]; + + /** * Check if is being utilized by edit relationship component */ @@ -251,7 +257,7 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest getRemoteDataPayload(), ).subscribe( (res: PaginatedList) => { - const selectableObject = res.page.map( (relationship: any) => { + let selectableObject = res.page.map( (relationship: any) => { let arrUrl = []; if ( this.isLeft ) { @@ -264,6 +270,10 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest return this.getRelatedItem(uuid,resultListOfItems); }); + selectableObject = selectableObject.filter((selObject)=>{ + return !this.getIfInRemove(selObject.indexableObject.uuid); + }) + if ( selectableObject.length > 0 ) { this.selectableListService.select(this.listId, selectableObject); } @@ -287,6 +297,10 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest }); } + getIfInRemove(uuid: string) { + return !!this.toRemove.find((searchResult)=> searchResult.indexableObject.uuid == uuid); + } + ngOnDestroy(): void { if (hasValue(this.subscription)) { this.subscription.unsubscribe();