Skip to content

Commit

Permalink
Merge branch 'item-edit-bitstreams-table-7.6' into item-edit-bitstrea…
Browse files Browse the repository at this point in the history
…ms-table-main
  • Loading branch information
AAwouters committed Oct 23, 2024
2 parents 6181adc + 1a81622 commit 430f716
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</button>
</div>

<div *ngIf="item && bundles?.length > 0" class="mt-4 table-border scrollable-table">
<div *ngIf="item && bundles?.length > 0" class="mt-4 table-border scrollable-table" [ngClass]="{'disabled-overlay': (isProcessingMoveRequest | async)}">
<ds-item-edit-bitstream-bundle *ngFor="let bundle of bundles; first as isFirst"
[bundle]="bundle"
[item]="item"
Expand Down Expand Up @@ -70,3 +70,5 @@
</div>
</div>
</div>

<ds-loading *ngIf="isProcessingMoveRequest | async" class="loading-overlay"></ds-loading>
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,13 @@
.scrollable-table {
overflow-x: auto;
}

.disabled-overlay {
opacity: 0.6;
}

.loading-overlay {
position: fixed;
top: 50%;
left: 50%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
*/
itemUpdateSubscription: Subscription;

/**
* An observable which emits a boolean which represents whether the service is currently handling a 'move' request
*/
isProcessingMoveRequest: Observable<boolean>;

constructor(
public itemService: ItemDataService,
public objectUpdatesService: ObjectUpdatesService,
Expand All @@ -123,6 +128,7 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
*/
postItemInit(): void {
const bundlesOptions = this.itemBitstreamsService.getInitialBundlesPaginationOptions();
this.isProcessingMoveRequest = this.itemBitstreamsService.getPerformingMoveRequest$();

this.bundles$ = this.itemService.getBundles(this.item.id, new PaginatedSearchOptions({ pagination: bundlesOptions })).pipe(
getFirstSucceededRemoteData(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,6 @@ describe('ItemBitstreamsService', () => {
const to = 7;
const callback = createSpy('callbackFunction');

console.log('bundle:', bundle);

it('should correctly create the Move request', () => {
const expectedOperation: MoveOperation = {
op: 'move',
Expand All @@ -608,6 +606,22 @@ describe('ItemBitstreamsService', () => {
service.performBitstreamMoveRequest(bundle, from, to, callback);
expect(callback).toHaveBeenCalled();
});

it('should emit at the start and end of the request', fakeAsync(() => {
const emittedActions = [];

service.getPerformingMoveRequest$().subscribe(selected => emittedActions.push(selected));

expect(emittedActions.length).toBe(1);
expect(emittedActions[0]).toBeFalse();

service.performBitstreamMoveRequest(bundle, from, to, callback);
tick();

expect(emittedActions.length).toBe(3);
expect(emittedActions[1]).toBeTrue();
expect(emittedActions[2]).toBeFalse();
}));
});

describe('displayNotifications', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export class ItemBitstreamsServiceStub {

performBitstreamMoveRequest = jasmine.createSpy('performBitstreamMoveRequest');

getPerformingMoveRequest = jasmine.createSpy('getPerformingMoveRequest').and.returnValue(false);

getPerformingMoveRequest$ = jasmine.createSpy('getPerformingMoveRequest$').and.returnValue(of(false));

getInitialBundlesPaginationOptions = jasmine.createSpy('getInitialBundlesPaginationOptions').and
.returnValue(new PaginationComponentOptions());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class ItemBitstreamsService {
*/
protected selectionAction$: BehaviorSubject<SelectionAction> = new BehaviorSubject(null);

protected isPerformingMoveRequest = false;
protected isPerformingMoveRequest: BehaviorSubject<boolean> = new BehaviorSubject(false);

constructor(
protected notificationsService: NotificationsService,
Expand Down Expand Up @@ -237,7 +237,7 @@ export class ItemBitstreamsService {
cancelSelection() {
const selected = this.getSelectedBitstream();

if (hasNoValue(selected) || this.isPerformingMoveRequest) {
if (hasNoValue(selected) || this.getPerformingMoveRequest()) {
return;
}

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

if (hasNoValue(selected) || this.isPerformingMoveRequest) {
if (hasNoValue(selected) || this.getPerformingMoveRequest()) {
return;
}

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

if (hasNoValue(selected) || this.isPerformingMoveRequest) {
if (hasNoValue(selected) || this.getPerformingMoveRequest()) {
return;
}

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

this.isPerformingMoveRequest = true;
this.announceLoading();
this.isPerformingMoveRequest.next(true);
this.bundleService.patch(bundle, [moveOperation]).pipe(
getFirstCompletedRemoteData(),
tap((response: RemoteData<Bundle>) => this.displayFailedResponseNotifications(MOVE_KEY, [response])),
switchMap(() => this.requestService.setStaleByHrefSubstring(bundle.self)),
take(1),
).subscribe(() => {
this.isPerformingMoveRequest = false;
console.log('got here!');
this.isPerformingMoveRequest.next(false);
finish?.();
});
}

/**
* Whether the service currently is processing a 'move' request
*/
getPerformingMoveRequest(): boolean {
return this.isPerformingMoveRequest.value;
}

/**
* Returns an observable which emits when the service starts, or ends, processing a 'move' request
*/
getPerformingMoveRequest$(): Observable<boolean> {
return this.isPerformingMoveRequest;
}

/**
* Returns the pagination options to use when fetching the bundles
*/
Expand Down Expand Up @@ -542,4 +558,12 @@ export class ItemBitstreamsService {
{ bitstream: bitstreamName });
this.liveRegionService.addMessage(message);
}

/**
* Adds a message to the live region mentioning that the
*/
announceLoading() {
const message = this.translateService.instant('item.edit.bitstreams.edit.live.loading');
this.liveRegionService.addMessage(message);
}
}
2 changes: 2 additions & 0 deletions src/assets/i18n/en.json5
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,8 @@

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

"item.edit.bitstreams.edit.live.loading": "Waiting for move to complete.",

"item.edit.bitstreams.edit.live.select": "{{ bitstream }} is selected.",

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

0 comments on commit 430f716

Please sign in to comment.