Skip to content

Commit 0920a21

Browse files
committed
118223: Stop sending success notificiations on every move
1 parent 2e1b148 commit 0920a21

2 files changed

Lines changed: 58 additions & 13 deletions

File tree

src/app/item-page/edit-item-page/item-bitstreams/item-bitstreams.service.ts

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { PaginationComponentOptions } from '../../../shared/pagination/paginatio
33
import { ResponsiveTableSizes } from '../../../shared/responsive-table-sizes/responsive-table-sizes';
44
import { ResponsiveColumnSizes } from '../../../shared/responsive-table-sizes/responsive-column-sizes';
55
import { RemoteData } from '../../../core/data/remote-data';
6-
import { isNotEmpty, hasValue, hasNoValue } from '../../../shared/empty.util';
6+
import { hasValue, hasNoValue } from '../../../shared/empty.util';
77
import { Bundle } from '../../../core/shared/bundle.model';
88
import { NotificationsService } from '../../../shared/notifications/notifications.service';
99
import { TranslateService } from '@ngx-translate/core';
@@ -25,6 +25,8 @@ import { BundleDataService } from '../../../core/data/bundle-data.service';
2525
import { RequestService } from '../../../core/data/request.service';
2626
import { LiveRegionService } from '../../../shared/live-region/live-region.service';
2727

28+
export const MOVE_KEY = 'item.edit.bitstreams.notifications.move';
29+
2830
/**
2931
* Interface storing all the information necessary to create a row in the bitstream edit table
3032
*/
@@ -164,6 +166,10 @@ export class ItemBitstreamsService {
164166
if (hasValue(selected)) {
165167
this.updateSelectedBitstream(null);
166168
this.announceClear(selected.bitstream.name);
169+
170+
if (selected.currentPosition !== selected.originalPosition) {
171+
this.displaySuccessNotification(MOVE_KEY);
172+
}
167173
}
168174
}
169175

@@ -265,7 +271,7 @@ export class ItemBitstreamsService {
265271
this.isPerformingMoveRequest = true;
266272
this.bundleService.patch(bundle, [moveOperation]).pipe(
267273
getFirstCompletedRemoteData(),
268-
tap((response: RemoteData<Bundle>) => this.displayNotifications('item.edit.bitstreams.notifications.move', [response])),
274+
tap((response: RemoteData<Bundle>) => this.displayFailedResponseNotifications(MOVE_KEY, [response])),
269275
switchMap(() => this.requestService.setStaleByHrefSubstring(bundle.self)),
270276
take(1),
271277
).subscribe(() => {
@@ -321,19 +327,51 @@ export class ItemBitstreamsService {
321327
* @param responses The returned responses to display notifications for
322328
*/
323329
displayNotifications(key: string, responses: RemoteData<any>[]) {
324-
if (isNotEmpty(responses)) {
325-
const failedResponses = responses.filter((response: RemoteData<Bundle>) => hasValue(response) && response.hasFailed);
326-
const successfulResponses = responses.filter((response: RemoteData<Bundle>) => hasValue(response) && response.hasSucceeded);
327-
328-
failedResponses.forEach((response: RemoteData<Bundle>) => {
329-
this.notificationsService.error(this.translateService.instant(`${key}.failed.title`), response.errorMessage);
330-
});
331-
if (successfulResponses.length > 0) {
332-
this.notificationsService.success(this.translateService.instant(`${key}.saved.title`), this.translateService.instant(`${key}.saved.content`));
333-
}
330+
this.displayFailedResponseNotifications(key, responses);
331+
this.displaySuccessFulResponseNotifications(key, responses);
332+
}
333+
334+
/**
335+
* Display an error notification for each failed response with their message
336+
* @param key The i18n key for the notification messages
337+
* @param responses The returned responses to display notifications for
338+
*/
339+
displayFailedResponseNotifications(key: string, responses: RemoteData<any>[]) {
340+
const failedResponses = responses.filter((response: RemoteData<Bundle>) => hasValue(response) && response.hasFailed);
341+
failedResponses.forEach((response: RemoteData<Bundle>) => {
342+
this.displayErrorNotification(key, response.errorMessage);
343+
});
344+
}
345+
346+
/**
347+
* Display an error notification with the provided key and message
348+
* @param key The i18n key for the notification messages
349+
* @param errorMessage The error message to display
350+
*/
351+
displayErrorNotification(key: string, errorMessage: string) {
352+
this.notificationsService.error(this.translateService.instant(`${key}.failed.title`), errorMessage);
353+
}
354+
355+
/**
356+
* Display a success notification in case there's at least one successful response
357+
* @param key The i18n key for the notification messages
358+
* @param responses The returned responses to display notifications for
359+
*/
360+
displaySuccessFulResponseNotifications(key: string, responses: RemoteData<any>[]) {
361+
const successfulResponses = responses.filter((response: RemoteData<Bundle>) => hasValue(response) && response.hasSucceeded);
362+
if (successfulResponses.length > 0) {
363+
this.displaySuccessNotification(key);
334364
}
335365
}
336366

367+
/**
368+
* Display a success notification with the provided key
369+
* @param key The i18n key for the notification messages
370+
*/
371+
displaySuccessNotification(key: string) {
372+
this.notificationsService.success(this.translateService.instant(`${key}.saved.title`), this.translateService.instant(`${key}.saved.content`));
373+
}
374+
337375
/**
338376
* Removes the bitstreams marked for deletion from the Bundles emitted by the provided observable.
339377
* @param bundles$

src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream-bundle/item-edit-bitstream-bundle.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ import { FieldUpdate } from '../../../../core/data/object-updates/field-update.m
3131
import { PaginationService } from '../../../../core/pagination/pagination.service';
3232
import { PaginationComponent } from '../../../../shared/pagination/pagination.component';
3333
import { RequestService } from '../../../../core/data/request.service';
34-
import { ItemBitstreamsService, BitstreamTableEntry, SelectedBitstreamTableEntry } from '../item-bitstreams.service';
34+
import {
35+
ItemBitstreamsService,
36+
BitstreamTableEntry,
37+
SelectedBitstreamTableEntry,
38+
MOVE_KEY
39+
} from '../item-bitstreams.service';
3540
import { CdkDragDrop } from '@angular/cdk/drag-drop';
3641
import { hasValue, hasNoValue } from '../../../../shared/empty.util';
3742

@@ -414,6 +419,8 @@ export class ItemEditBitstreamBundleComponent implements OnInit, OnDestroy {
414419
if (dropPage !== this.getCurrentPage()) {
415420
this.changeToPage(dropPage);
416421
}
422+
423+
this.itemBitstreamsService.displaySuccessNotification(MOVE_KEY);
417424
};
418425

419426
this.itemBitstreamsService.performBitstreamMoveRequest(this.bundle, fromIndex, toIndex, finish);

0 commit comments

Comments
 (0)