dynamic-lookup-relation-search-tab.component.ts (dspace-angular-dspace-7.0) | : | dynamic-lookup-relation-search-tab.component.ts (dspace-angular-dspace-7.1) | ||
---|---|---|---|---|
skipping to change at line 16 | skipping to change at line 16 | |||
import { PaginatedList } from '../../../../../../core/data/paginated-list.model' ; | import { PaginatedList } from '../../../../../../core/data/paginated-list.model' ; | |||
import { RemoteData } from '../../../../../../core/data/remote-data'; | import { RemoteData } from '../../../../../../core/data/remote-data'; | |||
import { Observable } from 'rxjs'; | import { Observable } from 'rxjs'; | |||
import { RelationshipOptions } from '../../../models/relationship-options.model' ; | import { RelationshipOptions } from '../../../models/relationship-options.model' ; | |||
import { PaginationComponentOptions } from '../../../../../pagination/pagination -component-options.model'; | import { PaginationComponentOptions } from '../../../../../pagination/pagination -component-options.model'; | |||
import { ListableObject } from '../../../../../object-collection/shared/listable -object.model'; | import { ListableObject } from '../../../../../object-collection/shared/listable -object.model'; | |||
import { SearchService } from '../../../../../../core/shared/search/search.servi ce'; | import { SearchService } from '../../../../../../core/shared/search/search.servi ce'; | |||
import { ActivatedRoute, Router } from '@angular/router'; | import { ActivatedRoute, Router } from '@angular/router'; | |||
import { SelectableListService } from '../../../../../object-list/selectable-lis t/selectable-list.service'; | import { SelectableListService } from '../../../../../object-list/selectable-lis t/selectable-list.service'; | |||
import { hasValue } from '../../../../../empty.util'; | import { hasValue } from '../../../../../empty.util'; | |||
import { map, startWith, switchMap, take, tap } from 'rxjs/operators'; | import { map, mapTo, startWith, switchMap, take, tap } from 'rxjs/operators'; | |||
import { getFirstSucceededRemoteData } from '../../../../../../core/shared/opera | import { getFirstSucceededRemoteData, getRemoteDataPayload } from '../../../../. | |||
tors'; | ./../core/shared/operators'; | |||
import { RouteService } from '../../../../../../core/services/route.service'; | import { RouteService } from '../../../../../../core/services/route.service'; | |||
import { CollectionElementLinkType } from '../../../../../object-collection/coll ection-element-link.type'; | import { CollectionElementLinkType } from '../../../../../object-collection/coll ection-element-link.type'; | |||
import { Context } from '../../../../../../core/shared/context.model'; | import { Context } from '../../../../../../core/shared/context.model'; | |||
import { LookupRelationService } from '../../../../../../core/data/lookup-relati on.service'; | import { LookupRelationService } from '../../../../../../core/data/lookup-relati on.service'; | |||
import { PaginationService } from '../../../../../../core/pagination/pagination. service'; | import { PaginationService } from '../../../../../../core/pagination/pagination. service'; | |||
import { RelationshipService } from '../../../../../../core/data/relationship.se | ||||
rvice'; | ||||
import { RelationshipType } from '../../../../../../core/shared/item-relationshi | ||||
ps/relationship-type.model'; | ||||
import { Relationship } from '../../../../../../core/shared/item-relationships/r | ||||
elationship.model'; | ||||
@Component({ | @Component({ | |||
selector: 'ds-dynamic-lookup-relation-search-tab', | selector: 'ds-dynamic-lookup-relation-search-tab', | |||
styleUrls: ['./dynamic-lookup-relation-search-tab.component.scss'], | styleUrls: ['./dynamic-lookup-relation-search-tab.component.scss'], | |||
templateUrl: './dynamic-lookup-relation-search-tab.component.html', | templateUrl: './dynamic-lookup-relation-search-tab.component.html', | |||
providers: [ | providers: [ | |||
{ | { | |||
provide: SEARCH_CONFIG_SERVICE, | provide: SEARCH_CONFIG_SERVICE, | |||
useClass: SearchConfigurationService | useClass: SearchConfigurationService | |||
} | } | |||
skipping to change at line 67 | skipping to change at line 71 | |||
* The list of selected items | * The list of selected items | |||
*/ | */ | |||
@Input() selection$: Observable<ListableObject[]>; | @Input() selection$: Observable<ListableObject[]>; | |||
/** | /** | |||
* The context to display lists | * The context to display lists | |||
*/ | */ | |||
@Input() context: Context; | @Input() context: Context; | |||
/** | /** | |||
* The type of relationship | ||||
*/ | ||||
@Input() relationshipType: RelationshipType; | ||||
/** | ||||
* The item being viewed | ||||
*/ | ||||
@Input() item: Item; | ||||
/** | ||||
* Check if is left type or right type | ||||
*/ | ||||
@Input() isLeft: boolean; | ||||
/** | ||||
* Check if is left type or right type | ||||
*/ | ||||
@Input() toRemove: SearchResult<Item>[]; | ||||
/** | ||||
* Check if is being utilized by edit relationship component | ||||
*/ | ||||
@Input() isEditRelationship: boolean; | ||||
/** | ||||
* Send an event to deselect an object from the list | * Send an event to deselect an object from the list | |||
*/ | */ | |||
@Output() deselectObject: EventEmitter<ListableObject> = new EventEmitter<List ableObject>(); | @Output() deselectObject: EventEmitter<ListableObject> = new EventEmitter<List ableObject>(); | |||
/** | /** | |||
* Send an event to select an object from the list | * Send an event to select an object from the list | |||
*/ | */ | |||
@Output() selectObject: EventEmitter<ListableObject> = new EventEmitter<Listab leObject>(); | @Output() selectObject: EventEmitter<ListableObject> = new EventEmitter<Listab leObject>(); | |||
/** | /** | |||
skipping to change at line 122 | skipping to change at line 151 | |||
linkTypes = CollectionElementLinkType; | linkTypes = CollectionElementLinkType; | |||
constructor( | constructor( | |||
private searchService: SearchService, | private searchService: SearchService, | |||
private router: Router, | private router: Router, | |||
private route: ActivatedRoute, | private route: ActivatedRoute, | |||
private selectableListService: SelectableListService, | private selectableListService: SelectableListService, | |||
public searchConfigService: SearchConfigurationService, | public searchConfigService: SearchConfigurationService, | |||
private routeService: RouteService, | private routeService: RouteService, | |||
public lookupRelationService: LookupRelationService, | public lookupRelationService: LookupRelationService, | |||
private relationshipService: RelationshipService, | ||||
private paginationService: PaginationService | private paginationService: PaginationService | |||
) { | ) { | |||
} | } | |||
/** | /** | |||
* Sets up the pagination and fixed query parameters | * Sets up the pagination and fixed query parameters | |||
*/ | */ | |||
ngOnInit(): void { | ngOnInit(): void { | |||
this.resetRoute(); | this.resetRoute(); | |||
this.routeService.setParameter('fixedFilterQuery', this.relationship.filter) ; | this.routeService.setParameter('fixedFilterQuery', this.relationship.filter) ; | |||
this.routeService.setParameter('configuration', this.relationship.searchConf iguration); | this.routeService.setParameter('configuration', this.relationship.searchConf iguration); | |||
this.resultsRD$ = this.searchConfigService.paginatedSearchOptions.pipe( | this.resultsRD$ = this.searchConfigService.paginatedSearchOptions.pipe( | |||
switchMap((options) => this.lookupRelationService.getLocalResults(this.rel | switchMap((options) => this.lookupRelationService.getLocalResults(this.rel | |||
ationship, options).pipe(startWith(undefined))) | ationship, options).pipe( | |||
tap( res => { | ||||
if ( !!res && res.hasSucceeded && this.isEditRelationship ) { | ||||
const idOfItems = res.payload.page.map( itemSearchResult => { | ||||
return itemSearchResult.indexableObject.uuid; | ||||
}); | ||||
this.setSelectedIds(idOfItems,res.payload.page); | ||||
} | ||||
}), | ||||
startWith(undefined), | ||||
)) | ||||
); | ); | |||
} | } | |||
/** | /** | |||
* Method to reset the route when the window is opened to make sure no strange pagination issues appears | * Method to reset the route when the window is opened to make sure no strange pagination issues appears | |||
*/ | */ | |||
resetRoute() { | resetRoute() { | |||
this.paginationService.updateRoute(this.searchConfigService.paginationID, th is.initialPagination); | this.paginationService.updateRoute(this.searchConfigService.paginationID, th is.initialPagination); | |||
} | } | |||
skipping to change at line 190 | skipping to change at line 230 | |||
const fullPagination = Object.assign(new PaginationComponentOptions(), { | const fullPagination = Object.assign(new PaginationComponentOptions(), { | |||
currentPage: 1, | currentPage: 1, | |||
pageSize: 9999 | pageSize: 9999 | |||
}); | }); | |||
const fullSearchConfig = Object.assign(this.lookupRelationService.searchConf ig, { pagination: fullPagination }); | const fullSearchConfig = Object.assign(this.lookupRelationService.searchConf ig, { pagination: fullPagination }); | |||
const results$ = this.searchService.search<Item>(fullSearchConfig); | const results$ = this.searchService.search<Item>(fullSearchConfig); | |||
results$.pipe( | results$.pipe( | |||
getFirstSucceededRemoteData(), | getFirstSucceededRemoteData(), | |||
map((resultsRD) => resultsRD.payload.page), | map((resultsRD) => resultsRD.payload.page), | |||
tap(() => this.selectAllLoading = false), | tap(() => this.selectAllLoading = false), | |||
switchMap((results) => this.selection$.pipe( | ||||
take(1), | ||||
tap((selection: SearchResult<Item>[]) => { | ||||
const filteredResults = results.filter((pageItem) => selection.findInd | ||||
ex((selected) => selected.equals(pageItem)) < 0); | ||||
this.selectObject.emit(...filteredResults); | ||||
}), | ||||
mapTo(results) | ||||
)) | ||||
).subscribe((results) => { | ).subscribe((results) => { | |||
this.selection$ | ||||
.pipe(take(1)) | ||||
.subscribe((selection: SearchResult<Item>[]) => { | ||||
const filteredResults = results.filter((pageItem) => selection.findI | ||||
ndex((selected) => selected.equals(pageItem)) < 0); | ||||
this.selectObject.emit(...filteredResults); | ||||
}); | ||||
this.selectableListService.select(this.listId, results); | this.selectableListService.select(this.listId, results); | |||
} | }); | |||
); | } | |||
/** | ||||
* setSelectedIds select all the items from the results that have relationship | ||||
* @param idOfItems the uuid of items that are being checked | ||||
* @param resultListOfItems the list of results of the items | ||||
*/ | ||||
setSelectedIds(idOfItems, resultListOfItems) { | ||||
let relationType = this.relationshipType.rightwardType; | ||||
if ( this.isLeft ) { | ||||
relationType = this.relationshipType.leftwardType; | ||||
} | ||||
this.relationshipService.searchByItemsAndType( this.relationshipType.id, thi | ||||
s.item.uuid, relationType ,idOfItems ).pipe( | ||||
getFirstSucceededRemoteData(), | ||||
getRemoteDataPayload(), | ||||
).subscribe( (res: PaginatedList<Relationship>) => { | ||||
let selectableObject = res.page.map( (relationship: any) => { | ||||
let arrUrl = []; | ||||
if ( this.isLeft ) { | ||||
arrUrl = relationship._links.rightItem.href.split('/'); | ||||
} else { | ||||
arrUrl = relationship._links.leftItem.href.split('/'); | ||||
} | ||||
const uuid = arrUrl[ arrUrl.length - 1 ]; | ||||
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); | ||||
} | ||||
}); | ||||
} | } | |||
/** | /** | |||
* Deselect all items | * Deselect all items | |||
*/ | */ | |||
deselectAll() { | deselectAll() { | |||
this.allSelected = false; | this.allSelected = false; | |||
this.selection$ | this.selection$ | |||
.pipe(take(1)) | .pipe(take(1)) | |||
.subscribe((selection: SearchResult<Item>[]) => this.deselectObject.emit(. ..selection)); | .subscribe((selection: SearchResult<Item>[]) => this.deselectObject.emit(. ..selection)); | |||
this.selectableListService.deselectAll(this.listId); | this.selectableListService.deselectAll(this.listId); | |||
} | } | |||
getRelatedItem(uuid: string, resultList: SearchResult<Item>[]) { | ||||
return resultList.find( (resultItem) => { | ||||
return resultItem.indexableObject.uuid === uuid; | ||||
}); | ||||
} | ||||
getIfInRemove(uuid: string) { | ||||
return !!this.toRemove.find( (searchResult) => searchResult.indexableObject. | ||||
uuid === uuid); | ||||
} | ||||
ngOnDestroy(): void { | ngOnDestroy(): void { | |||
if (hasValue(this.subscription)) { | if (hasValue(this.subscription)) { | |||
this.subscription.unsubscribe(); | this.subscription.unsubscribe(); | |||
} | } | |||
} | } | |||
} | } | |||
End of changes. 9 change blocks. | ||||
14 lines changed or deleted | 108 lines changed or added |