mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
62589: Refactoring mapping endpoint and methods to mapped + collection-list sorting bugfix
This commit is contained in:
@@ -34,7 +34,7 @@
|
||||
<div>
|
||||
<ds-item-select class="mt-2"
|
||||
[key]="'map'"
|
||||
[dsoRD$]="mappingItemsRD$"
|
||||
[dsoRD$]="mappedItemsRD$"
|
||||
[paginationOptions]="(searchOptions$ | async)?.pagination"
|
||||
[confirmButton]="'collection.item-mapper.confirm'"
|
||||
(confirm)="mapItems($event)"></ds-item-select>
|
||||
|
@@ -93,7 +93,7 @@ describe('CollectionItemMapperComponent', () => {
|
||||
const collectionDataServiceStub = {
|
||||
getMappedItems: () => of(emptyList),
|
||||
/* tslint:disable:no-empty */
|
||||
clearMappingItemsRequests: () => {}
|
||||
clearMappedItemsRequests: () => {}
|
||||
/* tslint:enable:no-empty */
|
||||
};
|
||||
const routeServiceStub = {
|
||||
|
@@ -64,7 +64,7 @@ export class CollectionItemMapperComponent implements OnInit {
|
||||
* List of items to show under the "Map" tab
|
||||
* Items outside the collection
|
||||
*/
|
||||
mappingItemsRD$: Observable<RemoteData<PaginatedList<DSpaceObject>>>;
|
||||
mappedItemsRD$: Observable<RemoteData<PaginatedList<DSpaceObject>>>;
|
||||
|
||||
/**
|
||||
* Sort on title ASC by default
|
||||
@@ -96,7 +96,7 @@ export class CollectionItemMapperComponent implements OnInit {
|
||||
|
||||
/**
|
||||
* Load collectionItemsRD$ with a fixed scope to only obtain the items this collection owns
|
||||
* Load mappingItemsRD$ to only obtain items this collection doesn't own
|
||||
* Load mappedItemsRD$ to only obtain items this collection doesn't own
|
||||
*/
|
||||
loadItemLists() {
|
||||
this.shouldUpdate$ = new BehaviorSubject<boolean>(true);
|
||||
@@ -114,7 +114,7 @@ export class CollectionItemMapperComponent implements OnInit {
|
||||
}
|
||||
})
|
||||
);
|
||||
this.mappingItemsRD$ = collectionAndOptions$.pipe(
|
||||
this.mappedItemsRD$ = collectionAndOptions$.pipe(
|
||||
switchMap(([collectionRD, options, shouldUpdate]) => {
|
||||
if (shouldUpdate) {
|
||||
return this.searchService.search(Object.assign(new PaginatedSearchOptions(options), {
|
||||
@@ -190,7 +190,7 @@ export class CollectionItemMapperComponent implements OnInit {
|
||||
*/
|
||||
private clearRequestCache() {
|
||||
this.collectionRD$.pipe(take(1)).subscribe((collectionRD: RemoteData<Collection>) => {
|
||||
this.collectionDataService.clearMappingItemsRequests(collectionRD.payload.id);
|
||||
this.collectionDataService.clearMappedItemsRequests(collectionRD.payload.id);
|
||||
this.searchService.clearDiscoveryRequests();
|
||||
});
|
||||
}
|
||||
|
@@ -32,8 +32,9 @@
|
||||
<div>
|
||||
<ds-collection-select class="mt-2"
|
||||
[key]="'map'"
|
||||
[dsoRD$]="mappingCollectionsRD$"
|
||||
[dsoRD$]="mappedCollectionsRD$"
|
||||
[paginationOptions]="(searchOptions$ | async)?.pagination"
|
||||
[sortOptions]="(searchOptions$ | async)?.sort"
|
||||
[confirmButton]="'item.edit.item-mapper.buttons.add'"
|
||||
(confirm)="mapCollections($event)"></ds-collection-select>
|
||||
</div>
|
||||
|
@@ -54,7 +54,7 @@ export class ItemCollectionMapperComponent implements OnInit {
|
||||
* List of collections to show under the "Map" tab
|
||||
* Collections that are not mapped to the item
|
||||
*/
|
||||
mappingCollectionsRD$: Observable<RemoteData<PaginatedList<Collection>>>;
|
||||
mappedCollectionsRD$: Observable<RemoteData<PaginatedList<Collection>>>;
|
||||
|
||||
/**
|
||||
* Firing this observable (shouldUpdate$.next(true)) forces the two lists to reload themselves
|
||||
@@ -79,7 +79,7 @@ export class ItemCollectionMapperComponent implements OnInit {
|
||||
|
||||
/**
|
||||
* Load itemCollectionsRD$ with a fixed scope to only obtain the collections that own this item
|
||||
* Load mappingCollectionsRD$ to only obtain collections that don't own this item
|
||||
* Load mappedCollectionsRD$ to only obtain collections that don't own this item
|
||||
*/
|
||||
loadCollectionLists() {
|
||||
this.shouldUpdate$ = new BehaviorSubject<boolean>(true);
|
||||
@@ -96,7 +96,7 @@ export class ItemCollectionMapperComponent implements OnInit {
|
||||
this.itemCollectionsRD$,
|
||||
this.searchOptions$
|
||||
);
|
||||
this.mappingCollectionsRD$ = itemCollectionsAndOptions$.pipe(
|
||||
this.mappedCollectionsRD$ = itemCollectionsAndOptions$.pipe(
|
||||
switchMap(([itemCollectionsRD, searchOptions]) => {
|
||||
return this.searchService.search(Object.assign(new PaginatedSearchOptions(searchOptions), {
|
||||
query: this.buildQuery(itemCollectionsRD.payload.page, searchOptions.query),
|
||||
|
@@ -69,10 +69,10 @@ export class CollectionDataService extends ComColDataService<Collection> {
|
||||
* Fetches the endpoint used for mapping items to a collection
|
||||
* @param collectionId The id of the collection to map items to
|
||||
*/
|
||||
getMappingItemsEndpoint(collectionId): Observable<string> {
|
||||
getMappedItemsEndpoint(collectionId): Observable<string> {
|
||||
return this.halService.getEndpoint(this.linkPath).pipe(
|
||||
map((endpoint: string) => this.getIDHref(endpoint, collectionId)),
|
||||
map((endpoint: string) => `${endpoint}/mappingItems`)
|
||||
map((endpoint: string) => `${endpoint}/mappedItems`)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ export class CollectionDataService extends ComColDataService<Collection> {
|
||||
getMappedItems(collectionId: string, searchOptions?: PaginatedSearchOptions): Observable<RemoteData<PaginatedList<DSpaceObject>>> {
|
||||
const requestUuid = this.requestService.generateRequestId();
|
||||
|
||||
const href$ = this.getMappingItemsEndpoint(collectionId).pipe(
|
||||
const href$ = this.getMappedItemsEndpoint(collectionId).pipe(
|
||||
isNotEmptyOperator(),
|
||||
distinctUntilChanged(),
|
||||
map((endpoint: string) => hasValue(searchOptions) ? searchOptions.toRestUrl(endpoint) : endpoint)
|
||||
@@ -106,11 +106,11 @@ export class CollectionDataService extends ComColDataService<Collection> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all requests (from cache) connected to the mappingItems endpoint
|
||||
* Clears all requests (from cache) connected to the mappedItems endpoint
|
||||
* @param collectionId
|
||||
*/
|
||||
clearMappingItemsRequests(collectionId: string) {
|
||||
this.getMappingItemsEndpoint(collectionId).pipe(take(1)).subscribe((href: string) => {
|
||||
clearMappedItemsRequests(collectionId: string) {
|
||||
this.getMappedItemsEndpoint(collectionId).pipe(take(1)).subscribe((href: string) => {
|
||||
this.requestService.removeByHrefSubstring(href);
|
||||
});
|
||||
}
|
||||
|
@@ -80,7 +80,7 @@ export class ItemDataService extends DataService<Item> {
|
||||
* @param itemId The item's id
|
||||
* @param collectionId The collection's id (optional)
|
||||
*/
|
||||
public getMappingCollectionsEndpoint(itemId: string, collectionId?: string): Observable<string> {
|
||||
public getMappedCollectionsEndpoint(itemId: string, collectionId?: string): Observable<string> {
|
||||
return this.halService.getEndpoint(this.linkPath).pipe(
|
||||
map((endpoint: string) => this.getIDHref(endpoint, itemId)),
|
||||
map((endpoint: string) => `${endpoint}/mappedCollections${collectionId ? `/${collectionId}` : ''}`)
|
||||
@@ -93,7 +93,7 @@ export class ItemDataService extends DataService<Item> {
|
||||
* @param collectionId The collection's id
|
||||
*/
|
||||
public removeMappingFromCollection(itemId: string, collectionId: string): Observable<RestResponse> {
|
||||
return this.getMappingCollectionsEndpoint(itemId, collectionId).pipe(
|
||||
return this.getMappedCollectionsEndpoint(itemId, collectionId).pipe(
|
||||
isNotEmptyOperator(),
|
||||
distinctUntilChanged(),
|
||||
map((endpointURL: string) => new DeleteRequest(this.requestService.generateRequestId(), endpointURL)),
|
||||
@@ -109,7 +109,7 @@ export class ItemDataService extends DataService<Item> {
|
||||
* @param collectionHref The collection's self link
|
||||
*/
|
||||
public mapToCollection(itemId: string, collectionHref: string): Observable<RestResponse> {
|
||||
return this.getMappingCollectionsEndpoint(itemId).pipe(
|
||||
return this.getMappedCollectionsEndpoint(itemId).pipe(
|
||||
isNotEmptyOperator(),
|
||||
distinctUntilChanged(),
|
||||
map((endpointURL: string) => {
|
||||
@@ -130,7 +130,7 @@ export class ItemDataService extends DataService<Item> {
|
||||
* @param itemId The item's id
|
||||
*/
|
||||
public getMappedCollections(itemId: string): Observable<RemoteData<PaginatedList<Collection>>> {
|
||||
const request$ = this.getMappingCollectionsEndpoint(itemId).pipe(
|
||||
const request$ = this.getMappedCollectionsEndpoint(itemId).pipe(
|
||||
isNotEmptyOperator(),
|
||||
distinctUntilChanged(),
|
||||
map((endpointURL: string) => new MappedCollectionsRequest(this.requestService.generateRequestId(), endpointURL)),
|
||||
@@ -149,11 +149,11 @@ export class ItemDataService extends DataService<Item> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all requests (from cache) connected to the mappingCollections endpoint
|
||||
* Clears all requests (from cache) connected to the mappedCollections endpoint
|
||||
* @param itemId
|
||||
*/
|
||||
public clearMappedCollectionsRequests(itemId: string) {
|
||||
this.getMappingCollectionsEndpoint(itemId).pipe(take(1)).subscribe((href: string) => {
|
||||
this.getMappedCollectionsEndpoint(itemId).pipe(take(1)).subscribe((href: string) => {
|
||||
this.requestService.removeByHrefSubstring(href);
|
||||
});
|
||||
}
|
||||
|
@@ -18,18 +18,18 @@ export class MappedCollectionsReponseParsingService implements ResponseParsingSe
|
||||
if (payload._embedded && payload._embedded.mappedCollections) {
|
||||
const mappedCollections = payload._embedded.mappedCollections;
|
||||
// TODO: When the API supports it, change this to fetch a paginated list, instead of creating static one
|
||||
// Reason: Pagination is currently not supported on the mappingCollections endpoint
|
||||
const paginatedMappingCollections = new PaginatedList(Object.assign(new PageInfo(), {
|
||||
// Reason: Pagination is currently not supported on the mappedCollections endpoint
|
||||
const paginatedMappedCollections = new PaginatedList(Object.assign(new PageInfo(), {
|
||||
elementsPerPage: mappedCollections.length,
|
||||
totalElements: mappedCollections.length,
|
||||
totalPages: 1,
|
||||
currentPage: 1
|
||||
}), mappedCollections);
|
||||
return new GenericSuccessResponse(paginatedMappingCollections, data.statusCode, data.statusText);
|
||||
return new GenericSuccessResponse(paginatedMappedCollections, data.statusCode, data.statusText);
|
||||
} else {
|
||||
return new ErrorResponse(
|
||||
Object.assign(
|
||||
new Error('Unexpected response from mappingCollections endpoint'), data
|
||||
new Error('Unexpected response from mappedCollections endpoint'), data
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
<ds-pagination
|
||||
*ngIf="collectionsRD?.payload?.totalElements > 0"
|
||||
[paginationOptions]="paginationOptions"
|
||||
[sortOptions]="sortOptions"
|
||||
[pageInfoState]="collectionsRD?.payload"
|
||||
[collectionSize]="collectionsRD?.payload?.totalElements"
|
||||
[hidePagerWhenSinglePage]="true"
|
||||
|
@@ -2,6 +2,7 @@
|
||||
<ds-pagination
|
||||
*ngIf="itemsRD?.payload?.totalElements > 0"
|
||||
[paginationOptions]="paginationOptions"
|
||||
[sortOptions]="sortOptions"
|
||||
[pageInfoState]="itemsRD?.payload"
|
||||
[collectionSize]="itemsRD?.payload?.totalElements"
|
||||
[hidePagerWhenSinglePage]="true"
|
||||
|
@@ -5,6 +5,7 @@ import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { PaginatedList } from '../../../core/data/paginated-list';
|
||||
import { PaginationComponentOptions } from '../../pagination/pagination-component-options.model';
|
||||
import { ObjectSelectService } from '../object-select.service';
|
||||
import { SortOptions } from '../../../core/cache/models/sort-options.model';
|
||||
|
||||
/**
|
||||
* An abstract component used to select DSpaceObjects from a specific list and returning the UUIDs of the selected DSpaceObjects
|
||||
@@ -26,6 +27,12 @@ export abstract class ObjectSelectComponent<TDomain> implements OnInit, OnDestro
|
||||
@Input()
|
||||
paginationOptions: PaginationComponentOptions;
|
||||
|
||||
/**
|
||||
* The sorting options used to display the DSpaceObjects
|
||||
*/
|
||||
@Input()
|
||||
sortOptions: SortOptions;
|
||||
|
||||
/**
|
||||
* The message key used for the confirm button
|
||||
* @type {string}
|
||||
|
Reference in New Issue
Block a user