mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
71380: Remove redundant code and add subscribable removeByHrefSubstring
This commit is contained in:
@@ -198,8 +198,11 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
|
||||
this.bundleService.patch(bundle, [moveOperation]).pipe(take(1)).subscribe((response: RestResponse) => {
|
||||
this.zone.run(() => {
|
||||
this.displayNotifications('item.edit.bitstreams.notifications.move', [response]);
|
||||
this.requestService.removeByHrefSubstring(bundle.self);
|
||||
event.finish();
|
||||
// Remove all cached requests from this bundle and call the event's callback when the requests are cleared
|
||||
this.requestService.removeByHrefSubstring(bundle.self).pipe(
|
||||
filter((isCached) => isCached),
|
||||
take(1)
|
||||
).subscribe(() => event.finish());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@@ -201,8 +201,9 @@ export class RequestService {
|
||||
* Remove all request cache providing (part of) the href
|
||||
* This also includes href-to-uuid index cache
|
||||
* @param href A substring of the request(s) href
|
||||
* @return Returns an observable emitting whether or not the cache is removed
|
||||
*/
|
||||
removeByHrefSubstring(href: string) {
|
||||
removeByHrefSubstring(href: string): Observable<boolean> {
|
||||
this.store.pipe(
|
||||
select(uuidsFromHrefSubstringSelector(requestIndexSelector, href)),
|
||||
take(1)
|
||||
@@ -213,6 +214,11 @@ export class RequestService {
|
||||
});
|
||||
this.requestsOnTheirWayToTheStore = this.requestsOnTheirWayToTheStore.filter((reqHref: string) => reqHref.indexOf(href) < 0);
|
||||
this.indexStore.dispatch(new RemoveFromIndexBySubstringAction(IndexName.REQUEST, href));
|
||||
|
||||
return this.store.pipe(
|
||||
select(uuidsFromHrefSubstringSelector(requestIndexSelector, href)),
|
||||
map((uuids) => isEmpty(uuids))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -11,7 +11,7 @@ export function getMockRequestService(requestEntry$: Observable<RequestEntry> =
|
||||
getByUUID: requestEntry$,
|
||||
uriEncodeBody: jasmine.createSpy('uriEncodeBody'),
|
||||
isCachedOrPending: false,
|
||||
removeByHrefSubstring: jasmine.createSpy('removeByHrefSubstring'),
|
||||
removeByHrefSubstring: jasmine.createSpy('removeByHrefSubstring').and.returnValue(observableOf(true)),
|
||||
hasByHrefObservable: observableOf(false)
|
||||
});
|
||||
}
|
||||
|
@@ -75,7 +75,7 @@ export abstract class AbstractPaginatedDragAndDropListComponent<T extends DSpace
|
||||
/**
|
||||
* The amount of objects to display per page
|
||||
*/
|
||||
pageSize = 10;
|
||||
pageSize = 2;
|
||||
|
||||
/**
|
||||
* The page options to use for fetching the objects
|
||||
@@ -100,14 +100,6 @@ export abstract class AbstractPaginatedDragAndDropListComponent<T extends DSpace
|
||||
*/
|
||||
loading$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
||||
|
||||
/**
|
||||
* ID of the object the page's first element needs to match in order to stop the loading animation.
|
||||
* This is to ensure the new page is fully loaded containing the latest data from the REST API whenever an object is
|
||||
* dropped on a new page. This allows the component to expect the dropped object to be present on top of the new page,
|
||||
* while displaying a loading animation until this is the case.
|
||||
*/
|
||||
stopLoadingWhenFirstIs: string;
|
||||
|
||||
/**
|
||||
* List of subscriptions
|
||||
*/
|
||||
@@ -157,12 +149,8 @@ export abstract class AbstractPaginatedDragAndDropListComponent<T extends DSpace
|
||||
distinctUntilChanged(compareArraysUsingFieldUuids())
|
||||
).subscribe((updateValues) => {
|
||||
this.customOrder = updateValues.map((fieldUpdate) => fieldUpdate.field.uuid);
|
||||
// Check if stopLoadingWhenFirstIs contains a value. If it does and it equals the first value in customOrder, stop the loading animation.
|
||||
// This is to ensure the page is updated to contain the new values first, before displaying it.
|
||||
if (hasValue(this.stopLoadingWhenFirstIs) && isNotEmpty(this.customOrder) && this.customOrder[0] === this.stopLoadingWhenFirstIs) {
|
||||
this.stopLoadingWhenFirstIs = undefined;
|
||||
// We received new values, stop displaying a loading indicator if it's present
|
||||
this.loading$.next(false);
|
||||
}
|
||||
}),
|
||||
// Disable the pagination when objects are loading
|
||||
this.loading$.subscribe((loading) => this.options.disabled = loading)
|
||||
@@ -214,9 +202,6 @@ export abstract class AbstractPaginatedDragAndDropListComponent<T extends DSpace
|
||||
// Send out a drop event (and navigate to the new page) when the "from" and "to" indexes are different from each other
|
||||
if (fromIndex !== toIndex) {
|
||||
if (isNewPage) {
|
||||
this.stopLoadingWhenFirstIs = this.customOrder[dragIndex];
|
||||
this.customOrder = [];
|
||||
this.paginationComponent.doPageChange(redirectPage);
|
||||
this.loading$.next(true);
|
||||
}
|
||||
this.dropObject.emit(Object.assign({
|
||||
@@ -224,7 +209,7 @@ export abstract class AbstractPaginatedDragAndDropListComponent<T extends DSpace
|
||||
toIndex,
|
||||
finish: () => {
|
||||
if (isNewPage) {
|
||||
this.currentPage$.next(redirectPage);
|
||||
this.paginationComponent.doPageChange(redirectPage);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
Reference in New Issue
Block a user