[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

This commit is contained in:
Rezart Vata
2021-09-14 19:24:22 +02:00
parent ffee36607d
commit a2605cdddd
7 changed files with 127 additions and 60 deletions

View File

@@ -132,7 +132,6 @@ export class RelationshipTypeService extends DataService<RelationshipType> {
*/
searchByEntityType(type: string): Observable<RelationshipType[]> {
return this.searchBy(
'byEntityType',
{
@@ -142,7 +141,7 @@ export class RelationshipTypeService extends DataService<RelationshipType> {
fieldValue: type
}
]
}).pipe(
}, true,true,followLink('leftType'),followLink('rightType')).pipe(
getFirstSucceededRemoteData(),
getRemoteDataPayload(),
) as Observable<RelationshipType[]>;

View File

@@ -470,7 +470,7 @@ export class RelationshipService extends DataService<Relationship> {
return this.put(object);
}
searchByItemsAndType(typeId: string,itemUuid: string,focusSide: string, arrayOfItemIds: string[] ): Observable<Relationship> {
searchByItemsAndType(typeId: string,itemUuid: string,relationshipLabel: string, arrayOfItemIds: string[] ): Observable<Relationship[]> {
let searchParams = [
{
@@ -483,7 +483,7 @@ export class RelationshipService extends DataService<Relationship> {
},
{
fieldName: 'relationshipLabel',
fieldValue: 'isPublicationOfAuthor'
fieldValue: relationshipLabel
},
// {
// fieldName: 'page',
@@ -500,17 +500,14 @@ export class RelationshipService extends DataService<Relationship> {
)
})
return this.getSearchByHref(
return this.searchBy(
'byItemsAndType',
{
searchParams : searchParams
searchParams: searchParams
}).pipe(
switchMap((href) => this.findByHref(href)),
getFirstSucceededRemoteData(),
getRemoteDataPayload(),
);
) as Observable<Relationship[]>;
}
}

View File

@@ -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<Item>[]) => {
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<RelationshipIdentifiable[]> {
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<boolean> {
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);
}));
}

View File

@@ -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);
}

View File

@@ -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 @@
</ds-dynamic-lookup-relation-external-source-tab>
</ng-template>
</ngb-tab>
<ngb-tab [title]="'submission.sections.describe.relationship-lookup.selection-tab.tab-title' | translate : {count: (selection$ | async)?.length}">
<ngb-tab [disabled]="isEditRelationship" [title]="'submission.sections.describe.relationship-lookup.selection-tab.tab-title' | translate : {count: (selection$ | async)?.length}">
<ng-template ngbTabContent>
<ds-dynamic-lookup-relation-selection-tab
[selection$]="selection$"

View File

@@ -118,6 +118,11 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
currentItemIsLeftItem$ : Observable<boolean>;
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

View File

@@ -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();