Skip to content

Commit bee8bde

Browse files
committed
Merge branch 'item-edit-bitstreams-table-7.6' into item-edit-bitstreams-table-7_x
2 parents b0900d5 + 5a88ced commit bee8bde

File tree

7 files changed

+71
-10
lines changed

7 files changed

+71
-10
lines changed

src/app/item-page/edit-item-page/item-bitstreams/item-bitstreams.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
</button>
3232
</div>
3333

34-
<div *ngIf="item && bundles?.length > 0" class="mt-4 table-border scrollable-table">
34+
<div *ngIf="item && bundles?.length > 0" class="mt-4 table-border scrollable-table" [ngClass]="{'disabled-overlay': (isProcessingMoveRequest | async)}">
3535
<ds-item-edit-bitstream-bundle *ngFor="let bundle of bundles; first as isFirst"
3636
[bundle]="bundle"
3737
[item]="item"
@@ -70,3 +70,5 @@
7070
</div>
7171
</div>
7272
</div>
73+
74+
<ds-themed-loading *ngIf="isProcessingMoveRequest | async" class="loading-overlay"></ds-themed-loading>

src/app/item-page/edit-item-page/item-bitstreams/item-bitstreams.component.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,13 @@
4343
.scrollable-table {
4444
overflow-x: auto;
4545
}
46+
47+
.disabled-overlay {
48+
opacity: 0.6;
49+
}
50+
51+
.loading-overlay {
52+
position: fixed;
53+
top: 50%;
54+
left: 50%;
55+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
5959
*/
6060
itemUpdateSubscription: Subscription;
6161

62+
/**
63+
* An observable which emits a boolean which represents whether the service is currently handling a 'move' request
64+
*/
65+
isProcessingMoveRequest: Observable<boolean>;
66+
6267
constructor(
6368
public itemService: ItemDataService,
6469
public objectUpdatesService: ObjectUpdatesService,
@@ -84,6 +89,7 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
8489
*/
8590
postItemInit(): void {
8691
const bundlesOptions = this.itemBitstreamsService.getInitialBundlesPaginationOptions();
92+
this.isProcessingMoveRequest = this.itemBitstreamsService.getPerformingMoveRequest$();
8793

8894
this.bundles$ = this.itemService.getBundles(this.item.id, new PaginatedSearchOptions({pagination: bundlesOptions})).pipe(
8995
getFirstSucceededRemoteData(),

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,6 @@ describe('ItemBitstreamsService', () => {
573573
const to = 7;
574574
const callback = createSpy('callbackFunction');
575575

576-
console.log('bundle:', bundle);
577-
578576
it('should correctly create the Move request', () => {
579577
const expectedOperation: MoveOperation = {
580578
op: 'move',
@@ -601,6 +599,22 @@ describe('ItemBitstreamsService', () => {
601599
service.performBitstreamMoveRequest(bundle, from, to, callback);
602600
expect(callback).toHaveBeenCalled();
603601
});
602+
603+
it('should emit at the start and end of the request', fakeAsync(() => {
604+
const emittedActions = [];
605+
606+
service.getPerformingMoveRequest$().subscribe(selected => emittedActions.push(selected));
607+
608+
expect(emittedActions.length).toBe(1);
609+
expect(emittedActions[0]).toBeFalse();
610+
611+
service.performBitstreamMoveRequest(bundle, from, to, callback);
612+
tick();
613+
614+
expect(emittedActions.length).toBe(3);
615+
expect(emittedActions[1]).toBeTrue();
616+
expect(emittedActions[2]).toBeFalse();
617+
}));
604618
});
605619

606620
describe('displayNotifications', () => {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export class ItemBitstreamsServiceStub {
3030

3131
performBitstreamMoveRequest = jasmine.createSpy('performBitstreamMoveRequest');
3232

33+
getPerformingMoveRequest = jasmine.createSpy('getPerformingMoveRequest').and.returnValue(false);
34+
35+
getPerformingMoveRequest$ = jasmine.createSpy('getPerformingMoveRequest$').and.returnValue(of(false));
36+
3337
getInitialBundlesPaginationOptions = jasmine.createSpy('getInitialBundlesPaginationOptions').and
3438
.returnValue(new PaginationComponentOptions());
3539

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

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export class ItemBitstreamsService {
119119
*/
120120
protected selectionAction$: BehaviorSubject<SelectionAction> = new BehaviorSubject(null);
121121

122-
protected isPerformingMoveRequest = false;
122+
protected isPerformingMoveRequest: BehaviorSubject<boolean> = new BehaviorSubject(false);
123123

124124
constructor(
125125
protected notificationsService: NotificationsService,
@@ -221,7 +221,7 @@ export class ItemBitstreamsService {
221221
cancelSelection() {
222222
const selected = this.getSelectedBitstream();
223223

224-
if (hasNoValue(selected) || this.isPerformingMoveRequest) {
224+
if (hasNoValue(selected) || this.getPerformingMoveRequest()) {
225225
return;
226226
}
227227

@@ -247,7 +247,7 @@ export class ItemBitstreamsService {
247247
moveSelectedBitstreamUp() {
248248
const selected = this.getSelectedBitstream();
249249

250-
if (hasNoValue(selected) || this.isPerformingMoveRequest) {
250+
if (hasNoValue(selected) || this.getPerformingMoveRequest()) {
251251
return;
252252
}
253253

@@ -272,7 +272,7 @@ export class ItemBitstreamsService {
272272
moveSelectedBitstreamDown() {
273273
const selected = this.getSelectedBitstream();
274274

275-
if (hasNoValue(selected) || this.isPerformingMoveRequest) {
275+
if (hasNoValue(selected) || this.getPerformingMoveRequest()) {
276276
return;
277277
}
278278

@@ -299,7 +299,7 @@ export class ItemBitstreamsService {
299299
* @param finish Optional: Function to execute once the response has been received
300300
*/
301301
performBitstreamMoveRequest(bundle: Bundle, fromIndex: number, toIndex: number, finish?: () => void) {
302-
if (this.isPerformingMoveRequest) {
302+
if (this.getPerformingMoveRequest()) {
303303
console.warn('Attempted to perform move request while previous request has not completed yet');
304304
return;
305305
}
@@ -310,18 +310,33 @@ export class ItemBitstreamsService {
310310
path: `/_links/bitstreams/${toIndex}/href`,
311311
};
312312

313-
this.isPerformingMoveRequest = true;
313+
this.announceLoading();
314+
this.isPerformingMoveRequest.next(true);
314315
this.bundleService.patch(bundle, [moveOperation]).pipe(
315316
getFirstCompletedRemoteData(),
316317
tap((response: RemoteData<Bundle>) => this.displayFailedResponseNotifications(MOVE_KEY, [response])),
317318
switchMap(() => this.requestService.setStaleByHrefSubstring(bundle.self)),
318319
take(1),
319320
).subscribe(() => {
320-
this.isPerformingMoveRequest = false;
321+
this.isPerformingMoveRequest.next(false);
321322
finish?.();
322323
});
323324
}
324325

326+
/**
327+
* Whether the service currently is processing a 'move' request
328+
*/
329+
getPerformingMoveRequest(): boolean {
330+
return this.isPerformingMoveRequest.value;
331+
}
332+
333+
/**
334+
* Returns an observable which emits when the service starts, or ends, processing a 'move' request
335+
*/
336+
getPerformingMoveRequest$(): Observable<boolean> {
337+
return this.isPerformingMoveRequest;
338+
}
339+
325340
/**
326341
* Returns the pagination options to use when fetching the bundles
327342
*/
@@ -526,4 +541,12 @@ export class ItemBitstreamsService {
526541
{ bitstream: bitstreamName });
527542
this.liveRegionService.addMessage(message);
528543
}
544+
545+
/**
546+
* Adds a message to the live region mentioning that the
547+
*/
548+
announceLoading() {
549+
const message = this.translateService.instant('item.edit.bitstreams.edit.live.loading');
550+
this.liveRegionService.addMessage(message);
551+
}
529552
}

src/assets/i18n/en.json5

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,6 +2010,8 @@
20102010

20112011
"item.edit.bitstreams.edit.live.clear": "{{ bitstream }} is no longer selected.",
20122012

2013+
"item.edit.bitstreams.edit.live.loading": "Waiting for move to complete.",
2014+
20132015
"item.edit.bitstreams.edit.live.select": "{{ bitstream }} is selected.",
20142016

20152017
"item.edit.bitstreams.edit.live.move": "{{ bitstream }} is now in position {{ toIndex }}.",

0 commit comments

Comments
 (0)