mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-09 11:03:05 +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.bundleService.patch(bundle, [moveOperation]).pipe(take(1)).subscribe((response: RestResponse) => {
|
||||||
this.zone.run(() => {
|
this.zone.run(() => {
|
||||||
this.displayNotifications('item.edit.bitstreams.notifications.move', [response]);
|
this.displayNotifications('item.edit.bitstreams.notifications.move', [response]);
|
||||||
this.requestService.removeByHrefSubstring(bundle.self);
|
// Remove all cached requests from this bundle and call the event's callback when the requests are cleared
|
||||||
event.finish();
|
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
|
* Remove all request cache providing (part of) the href
|
||||||
* This also includes href-to-uuid index cache
|
* This also includes href-to-uuid index cache
|
||||||
* @param href A substring of the request(s) href
|
* @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(
|
this.store.pipe(
|
||||||
select(uuidsFromHrefSubstringSelector(requestIndexSelector, href)),
|
select(uuidsFromHrefSubstringSelector(requestIndexSelector, href)),
|
||||||
take(1)
|
take(1)
|
||||||
@@ -213,6 +214,11 @@ export class RequestService {
|
|||||||
});
|
});
|
||||||
this.requestsOnTheirWayToTheStore = this.requestsOnTheirWayToTheStore.filter((reqHref: string) => reqHref.indexOf(href) < 0);
|
this.requestsOnTheirWayToTheStore = this.requestsOnTheirWayToTheStore.filter((reqHref: string) => reqHref.indexOf(href) < 0);
|
||||||
this.indexStore.dispatch(new RemoveFromIndexBySubstringAction(IndexName.REQUEST, href));
|
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$,
|
getByUUID: requestEntry$,
|
||||||
uriEncodeBody: jasmine.createSpy('uriEncodeBody'),
|
uriEncodeBody: jasmine.createSpy('uriEncodeBody'),
|
||||||
isCachedOrPending: false,
|
isCachedOrPending: false,
|
||||||
removeByHrefSubstring: jasmine.createSpy('removeByHrefSubstring'),
|
removeByHrefSubstring: jasmine.createSpy('removeByHrefSubstring').and.returnValue(observableOf(true)),
|
||||||
hasByHrefObservable: observableOf(false)
|
hasByHrefObservable: observableOf(false)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -75,7 +75,7 @@ export abstract class AbstractPaginatedDragAndDropListComponent<T extends DSpace
|
|||||||
/**
|
/**
|
||||||
* The amount of objects to display per page
|
* The amount of objects to display per page
|
||||||
*/
|
*/
|
||||||
pageSize = 10;
|
pageSize = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The page options to use for fetching the objects
|
* 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);
|
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
|
* List of subscriptions
|
||||||
*/
|
*/
|
||||||
@@ -157,12 +149,8 @@ export abstract class AbstractPaginatedDragAndDropListComponent<T extends DSpace
|
|||||||
distinctUntilChanged(compareArraysUsingFieldUuids())
|
distinctUntilChanged(compareArraysUsingFieldUuids())
|
||||||
).subscribe((updateValues) => {
|
).subscribe((updateValues) => {
|
||||||
this.customOrder = updateValues.map((fieldUpdate) => fieldUpdate.field.uuid);
|
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.
|
// We received new values, stop displaying a loading indicator if it's present
|
||||||
// This is to ensure the page is updated to contain the new values first, before displaying it.
|
this.loading$.next(false);
|
||||||
if (hasValue(this.stopLoadingWhenFirstIs) && isNotEmpty(this.customOrder) && this.customOrder[0] === this.stopLoadingWhenFirstIs) {
|
|
||||||
this.stopLoadingWhenFirstIs = undefined;
|
|
||||||
this.loading$.next(false);
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
// Disable the pagination when objects are loading
|
// Disable the pagination when objects are loading
|
||||||
this.loading$.subscribe((loading) => this.options.disabled = 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
|
// 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 (fromIndex !== toIndex) {
|
||||||
if (isNewPage) {
|
if (isNewPage) {
|
||||||
this.stopLoadingWhenFirstIs = this.customOrder[dragIndex];
|
|
||||||
this.customOrder = [];
|
|
||||||
this.paginationComponent.doPageChange(redirectPage);
|
|
||||||
this.loading$.next(true);
|
this.loading$.next(true);
|
||||||
}
|
}
|
||||||
this.dropObject.emit(Object.assign({
|
this.dropObject.emit(Object.assign({
|
||||||
@@ -224,7 +209,7 @@ export abstract class AbstractPaginatedDragAndDropListComponent<T extends DSpace
|
|||||||
toIndex,
|
toIndex,
|
||||||
finish: () => {
|
finish: () => {
|
||||||
if (isNewPage) {
|
if (isNewPage) {
|
||||||
this.currentPage$.next(redirectPage);
|
this.paginationComponent.doPageChange(redirectPage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
Reference in New Issue
Block a user