Skip to content

Commit cc70eaa

Browse files
committed
Merge branch 'item-edit-bitstreams-table-7.6' into item-edit-bitstreams-table-main
2 parents 6181adc + 5a88ced commit cc70eaa

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-loading *ngIf="isProcessingMoveRequest | async" class="loading-overlay"></ds-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
@@ -98,6 +98,11 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
9898
*/
9999
itemUpdateSubscription: Subscription;
100100

101+
/**
102+
* An observable which emits a boolean which represents whether the service is currently handling a 'move' request
103+
*/
104+
isProcessingMoveRequest: Observable<boolean>;
105+
101106
constructor(
102107
public itemService: ItemDataService,
103108
public objectUpdatesService: ObjectUpdatesService,
@@ -123,6 +128,7 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
123128
*/
124129
postItemInit(): void {
125130
const bundlesOptions = this.itemBitstreamsService.getInitialBundlesPaginationOptions();
131+
this.isProcessingMoveRequest = this.itemBitstreamsService.getPerformingMoveRequest$();
126132

127133
this.bundles$ = this.itemService.getBundles(this.item.id, new PaginatedSearchOptions({ pagination: bundlesOptions })).pipe(
128134
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
@@ -580,8 +580,6 @@ describe('ItemBitstreamsService', () => {
580580
const to = 7;
581581
const callback = createSpy('callbackFunction');
582582

583-
console.log('bundle:', bundle);
584-
585583
it('should correctly create the Move request', () => {
586584
const expectedOperation: MoveOperation = {
587585
op: 'move',
@@ -608,6 +606,22 @@ describe('ItemBitstreamsService', () => {
608606
service.performBitstreamMoveRequest(bundle, from, to, callback);
609607
expect(callback).toHaveBeenCalled();
610608
});
609+
610+
it('should emit at the start and end of the request', fakeAsync(() => {
611+
const emittedActions = [];
612+
613+
service.getPerformingMoveRequest$().subscribe(selected => emittedActions.push(selected));
614+
615+
expect(emittedActions.length).toBe(1);
616+
expect(emittedActions[0]).toBeFalse();
617+
618+
service.performBitstreamMoveRequest(bundle, from, to, callback);
619+
tick();
620+
621+
expect(emittedActions.length).toBe(3);
622+
expect(emittedActions[1]).toBeTrue();
623+
expect(emittedActions[2]).toBeFalse();
624+
}));
611625
});
612626

613627
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
@@ -31,6 +31,10 @@ export class ItemBitstreamsServiceStub {
3131

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

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

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
@@ -135,7 +135,7 @@ export class ItemBitstreamsService {
135135
*/
136136
protected selectionAction$: BehaviorSubject<SelectionAction> = new BehaviorSubject(null);
137137

138-
protected isPerformingMoveRequest = false;
138+
protected isPerformingMoveRequest: BehaviorSubject<boolean> = new BehaviorSubject(false);
139139

140140
constructor(
141141
protected notificationsService: NotificationsService,
@@ -237,7 +237,7 @@ export class ItemBitstreamsService {
237237
cancelSelection() {
238238
const selected = this.getSelectedBitstream();
239239

240-
if (hasNoValue(selected) || this.isPerformingMoveRequest) {
240+
if (hasNoValue(selected) || this.getPerformingMoveRequest()) {
241241
return;
242242
}
243243

@@ -263,7 +263,7 @@ export class ItemBitstreamsService {
263263
moveSelectedBitstreamUp() {
264264
const selected = this.getSelectedBitstream();
265265

266-
if (hasNoValue(selected) || this.isPerformingMoveRequest) {
266+
if (hasNoValue(selected) || this.getPerformingMoveRequest()) {
267267
return;
268268
}
269269

@@ -288,7 +288,7 @@ export class ItemBitstreamsService {
288288
moveSelectedBitstreamDown() {
289289
const selected = this.getSelectedBitstream();
290290

291-
if (hasNoValue(selected) || this.isPerformingMoveRequest) {
291+
if (hasNoValue(selected) || this.getPerformingMoveRequest()) {
292292
return;
293293
}
294294

@@ -315,7 +315,7 @@ export class ItemBitstreamsService {
315315
* @param finish Optional: Function to execute once the response has been received
316316
*/
317317
performBitstreamMoveRequest(bundle: Bundle, fromIndex: number, toIndex: number, finish?: () => void) {
318-
if (this.isPerformingMoveRequest) {
318+
if (this.getPerformingMoveRequest()) {
319319
console.warn('Attempted to perform move request while previous request has not completed yet');
320320
return;
321321
}
@@ -326,18 +326,33 @@ export class ItemBitstreamsService {
326326
path: `/_links/bitstreams/${toIndex}/href`,
327327
};
328328

329-
this.isPerformingMoveRequest = true;
329+
this.announceLoading();
330+
this.isPerformingMoveRequest.next(true);
330331
this.bundleService.patch(bundle, [moveOperation]).pipe(
331332
getFirstCompletedRemoteData(),
332333
tap((response: RemoteData<Bundle>) => this.displayFailedResponseNotifications(MOVE_KEY, [response])),
333334
switchMap(() => this.requestService.setStaleByHrefSubstring(bundle.self)),
334335
take(1),
335336
).subscribe(() => {
336-
this.isPerformingMoveRequest = false;
337+
this.isPerformingMoveRequest.next(false);
337338
finish?.();
338339
});
339340
}
340341

342+
/**
343+
* Whether the service currently is processing a 'move' request
344+
*/
345+
getPerformingMoveRequest(): boolean {
346+
return this.isPerformingMoveRequest.value;
347+
}
348+
349+
/**
350+
* Returns an observable which emits when the service starts, or ends, processing a 'move' request
351+
*/
352+
getPerformingMoveRequest$(): Observable<boolean> {
353+
return this.isPerformingMoveRequest;
354+
}
355+
341356
/**
342357
* Returns the pagination options to use when fetching the bundles
343358
*/
@@ -542,4 +557,12 @@ export class ItemBitstreamsService {
542557
{ bitstream: bitstreamName });
543558
this.liveRegionService.addMessage(message);
544559
}
560+
561+
/**
562+
* Adds a message to the live region mentioning that the
563+
*/
564+
announceLoading() {
565+
const message = this.translateService.instant('item.edit.bitstreams.edit.live.loading');
566+
this.liveRegionService.addMessage(message);
567+
}
545568
}

src/assets/i18n/en.json5

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

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

2255+
"item.edit.bitstreams.edit.live.loading": "Waiting for move to complete.",
2256+
22552257
"item.edit.bitstreams.edit.live.select": "{{ bitstream }} is selected.",
22562258

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

0 commit comments

Comments
 (0)