mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
55946: Exclude already mapped collections from Map tab
This commit is contained in:
@@ -20,6 +20,7 @@ import { TranslateService } from '@ngx-translate/core';
|
|||||||
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||||
import { C } from '@angular/core/src/render3';
|
import { C } from '@angular/core/src/render3';
|
||||||
import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model';
|
import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model';
|
||||||
|
import { isNotEmpty } from '../../../shared/empty.util';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-item-collection-mapper',
|
selector: 'ds-item-collection-mapper',
|
||||||
@@ -82,9 +83,15 @@ export class ItemCollectionMapperComponent implements OnInit {
|
|||||||
map((itemRD: RemoteData<Item>) => itemRD.payload),
|
map((itemRD: RemoteData<Item>) => itemRD.payload),
|
||||||
switchMap((item: Item) => this.itemDataService.getMappedCollections(item.id))
|
switchMap((item: Item) => this.itemDataService.getMappedCollections(item.id))
|
||||||
);
|
);
|
||||||
this.mappingCollectionsRD$ = this.searchOptions$.pipe(
|
|
||||||
switchMap((searchOptions: PaginatedSearchOptions) => {
|
const itemCollectionsAndOptions$ = Observable.combineLatest(
|
||||||
return this.searchService.search(Object.assign(searchOptions, {
|
this.itemCollectionsRD$,
|
||||||
|
this.searchOptions$
|
||||||
|
);
|
||||||
|
this.mappingCollectionsRD$ = itemCollectionsAndOptions$.pipe(
|
||||||
|
switchMap(([itemCollectionsRD, searchOptions]) => {
|
||||||
|
return this.searchService.search(Object.assign(new PaginatedSearchOptions(searchOptions), {
|
||||||
|
query: this.buildQuery(itemCollectionsRD.payload.page, searchOptions.query),
|
||||||
dsoType: DSpaceObjectType.COLLECTION
|
dsoType: DSpaceObjectType.COLLECTION
|
||||||
}));
|
}));
|
||||||
}),
|
}),
|
||||||
@@ -196,4 +203,31 @@ export class ItemCollectionMapperComponent implements OnInit {
|
|||||||
return this.router.url;
|
return this.router.url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a query to exclude collections from
|
||||||
|
* @param collections The collections their UUIDs
|
||||||
|
* @param query The query to add to it
|
||||||
|
*/
|
||||||
|
buildQuery(collections: Collection[], query: string): string {
|
||||||
|
let result = query;
|
||||||
|
for (const collection of collections) {
|
||||||
|
result = this.addExcludeCollection(collection.id, result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an exclusion of a collection to a query
|
||||||
|
* @param collectionId The collection's UUID
|
||||||
|
* @param query The query to add the exclusion to
|
||||||
|
*/
|
||||||
|
addExcludeCollection(collectionId: string, query: string): string {
|
||||||
|
const excludeQuery = `-search.resourceid:${collectionId}`;
|
||||||
|
if (isNotEmpty(query)) {
|
||||||
|
return `${query} AND ${excludeQuery}`;
|
||||||
|
} else {
|
||||||
|
return excludeQuery;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user