mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
fix an issue where deleting bitstreamformats would show both an error and a success notification
This commit is contained in:
@@ -5,7 +5,7 @@ import { PaginatedList } from '../../../core/data/paginated-list.model';
|
||||
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
|
||||
import { BitstreamFormat } from '../../../core/shared/bitstream-format.model';
|
||||
import { BitstreamFormatDataService } from '../../../core/data/bitstream-format-data.service';
|
||||
import { map, switchMap, take } from 'rxjs/operators';
|
||||
import { map, mergeMap, switchMap, take, toArray } from 'rxjs/operators';
|
||||
import { hasValue } from '../../../shared/empty.util';
|
||||
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||
import { Router } from '@angular/router';
|
||||
@@ -13,6 +13,7 @@ import { TranslateService } from '@ngx-translate/core';
|
||||
import { NoContent } from '../../../core/shared/NoContent.model';
|
||||
import { PaginationService } from '../../../core/pagination/pagination.service';
|
||||
import { FindListOptions } from '../../../core/data/find-list-options.model';
|
||||
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
|
||||
|
||||
/**
|
||||
* This component renders a list of bitstream formats
|
||||
@@ -58,31 +59,39 @@ export class BitstreamFormatsComponent implements OnInit, OnDestroy {
|
||||
* Deletes the currently selected formats from the registry and updates the presented list
|
||||
*/
|
||||
deleteFormats() {
|
||||
this.bitstreamFormatService.clearBitStreamFormatRequests().subscribe();
|
||||
this.bitstreamFormatService.getSelectedBitstreamFormats().pipe(take(1)).subscribe(
|
||||
(formats) => {
|
||||
const tasks$ = [];
|
||||
for (const format of formats) {
|
||||
if (hasValue(format.id)) {
|
||||
tasks$.push(this.bitstreamFormatService.delete(format.id).pipe(map((response: RemoteData<NoContent>) => response.hasSucceeded)));
|
||||
}
|
||||
}
|
||||
zip(...tasks$).subscribe((results: boolean[]) => {
|
||||
const successResponses = results.filter((result: boolean) => result);
|
||||
const failedResponses = results.filter((result: boolean) => !result);
|
||||
if (successResponses.length > 0) {
|
||||
this.showNotification(true, successResponses.length);
|
||||
}
|
||||
if (failedResponses.length > 0) {
|
||||
this.showNotification(false, failedResponses.length);
|
||||
}
|
||||
this.bitstreamFormatService.clearBitStreamFormatRequests();
|
||||
this.bitstreamFormatService.getSelectedBitstreamFormats().pipe(
|
||||
take(1),
|
||||
// emit all formats in the array one at a time
|
||||
mergeMap((formats: BitstreamFormat[]) => formats),
|
||||
// delete each format
|
||||
mergeMap((format: BitstreamFormat) => this.bitstreamFormatService.delete(format.id).pipe(
|
||||
// wait for each response to come back
|
||||
getFirstCompletedRemoteData(),
|
||||
// return a boolean to indicate whether a response succeeded
|
||||
map((response: RemoteData<NoContent>) => response.hasSucceeded),
|
||||
)),
|
||||
// wait for all responses to come in and return them as a single array
|
||||
toArray()
|
||||
).subscribe((results: boolean[]) => {
|
||||
// Count the number of succeeded and failed deletions
|
||||
const successResponses = results.filter((result: boolean) => result);
|
||||
const failedResponses = results.filter((result: boolean) => !result);
|
||||
|
||||
this.deselectAll();
|
||||
|
||||
this.paginationService.resetPage(this.pageConfig.id);
|
||||
});
|
||||
// Show a notification indicating the number of succeeded and failed deletions
|
||||
if (successResponses.length > 0) {
|
||||
this.showNotification(true, successResponses.length);
|
||||
}
|
||||
);
|
||||
if (failedResponses.length > 0) {
|
||||
this.showNotification(false, failedResponses.length);
|
||||
}
|
||||
|
||||
// reset the selection
|
||||
this.deselectAll();
|
||||
|
||||
// reload the page
|
||||
this.paginationService.resetPage(this.pageConfig.id);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user