Merge branch 'item-edit-bitstreams-table-7.6' into item-edit-bitstreams-table-main

# Conflicts:
#	src/app/item-page/edit-item-page/edit-item-page.module.ts
#	src/app/item-page/edit-item-page/item-bitstreams/item-bitstreams.component.spec.ts
#	src/app/item-page/edit-item-page/item-bitstreams/item-bitstreams.component.ts
#	src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream-bundle/item-edit-bitstream-bundle.component.html
#	src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream-bundle/item-edit-bitstream-bundle.component.spec.ts
#	src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream-bundle/item-edit-bitstream-bundle.component.ts
#	src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream-bundle/paginated-drag-and-drop-bitstream-list/paginated-drag-and-drop-bitstream-list.component.html
#	src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream-bundle/paginated-drag-and-drop-bitstream-list/paginated-drag-and-drop-bitstream-list.component.spec.ts
#	src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream-bundle/paginated-drag-and-drop-bitstream-list/paginated-drag-and-drop-bitstream-list.component.ts
#	src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream-drag-handle/item-edit-bitstream-drag-handle.component.ts
#	src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream/item-edit-bitstream.component.html
#	src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream/item-edit-bitstream.component.spec.ts
#	src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream/item-edit-bitstream.component.ts
#	src/app/shared/notifications/models/notification-options.model.ts
#	src/app/shared/notifications/notifications-board/notifications-board.component.spec.ts
#	src/app/shared/notifications/notifications-board/notifications-board.component.ts
#	src/app/shared/pagination-drag-and-drop/abstract-paginated-drag-and-drop-list.component.spec.ts
#	src/app/shared/pagination-drag-and-drop/abstract-paginated-drag-and-drop-list.component.ts
This commit is contained in:
Andreas Awouters
2024-10-17 14:27:43 +02:00
27 changed files with 2676 additions and 1346 deletions

View File

@@ -1,11 +1,8 @@
import {
AsyncPipe,
NgForOf,
NgIf,
} from '@angular/common';
import { CommonModule } from '@angular/common';
import {
ChangeDetectorRef,
Component,
HostListener,
NgZone,
OnDestroy,
} from '@angular/core';
@@ -18,15 +15,12 @@ import {
TranslateModule,
TranslateService,
} from '@ngx-translate/core';
import { Operation } from 'fast-json-patch';
import {
combineLatest,
Observable,
Subscription,
zip as observableZip,
} from 'rxjs';
import {
filter,
map,
switchMap,
take,
@@ -36,49 +30,40 @@ import { ObjectCacheService } from '../../../core/cache/object-cache.service';
import { BitstreamDataService } from '../../../core/data/bitstream-data.service';
import { BundleDataService } from '../../../core/data/bundle-data.service';
import { ItemDataService } from '../../../core/data/item-data.service';
import { FieldChangeType } from '../../../core/data/object-updates/field-change-type.model';
import { FieldUpdate } from '../../../core/data/object-updates/field-update.model';
import { FieldUpdates } from '../../../core/data/object-updates/field-updates.model';
import { ObjectUpdatesService } from '../../../core/data/object-updates/object-updates.service';
import { PaginatedList } from '../../../core/data/paginated-list.model';
import { RemoteData } from '../../../core/data/remote-data';
import { RequestService } from '../../../core/data/request.service';
import { Bitstream } from '../../../core/shared/bitstream.model';
import { Bundle } from '../../../core/shared/bundle.model';
import { NoContent } from '../../../core/shared/NoContent.model';
import {
getFirstSucceededRemoteData,
getRemoteDataPayload,
} from '../../../core/shared/operators';
import {
hasValue,
isNotEmpty,
} from '../../../shared/empty.util';
import { AlertComponent } from '../../../shared/alert/alert.component';
import { AlertType } from '../../../shared/alert/alert-type';
import { ThemedLoadingComponent } from '../../../shared/loading/themed-loading.component';
import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { ResponsiveColumnSizes } from '../../../shared/responsive-table-sizes/responsive-column-sizes';
import { ResponsiveTableSizes } from '../../../shared/responsive-table-sizes/responsive-table-sizes';
import { PaginatedSearchOptions } from '../../../shared/search/models/paginated-search-options.model';
import { ObjectValuesPipe } from '../../../shared/utils/object-values-pipe';
import { VarDirective } from '../../../shared/utils/var.directive';
import { AbstractItemUpdateComponent } from '../abstract-item-update/abstract-item-update.component';
import { ItemBitstreamsService } from './item-bitstreams.service';
import { ItemEditBitstreamBundleComponent } from './item-edit-bitstream-bundle/item-edit-bitstream-bundle.component';
import { ItemEditBitstreamDragHandleComponent } from './item-edit-bitstream-drag-handle/item-edit-bitstream-drag-handle.component';
@Component({
selector: 'ds-item-bitstreams',
styleUrls: ['./item-bitstreams.component.scss'],
templateUrl: './item-bitstreams.component.html',
imports: [
AsyncPipe,
CommonModule,
TranslateModule,
ItemEditBitstreamBundleComponent,
RouterLink,
NgIf,
VarDirective,
ItemEditBitstreamDragHandleComponent,
NgForOf,
ThemedLoadingComponent,
AlertComponent,
],
providers: [ObjectValuesPipe],
standalone: true,
@@ -88,33 +73,18 @@ import { ItemEditBitstreamDragHandleComponent } from './item-edit-bitstream-drag
*/
export class ItemBitstreamsComponent extends AbstractItemUpdateComponent implements OnDestroy {
// Declared for use in template
protected readonly AlertType = AlertType;
/**
* The currently listed bundles
*/
bundles$: Observable<Bundle[]>;
/**
* The page options to use for fetching the bundles
*/
bundlesOptions = {
id: 'bundles-pagination-options',
currentPage: 1,
pageSize: 9999,
} as any;
/**
* The bootstrap sizes used for the columns within this table
*/
columnSizes = new ResponsiveTableSizes([
// Name column
new ResponsiveColumnSizes(2, 2, 3, 4, 4),
// Description column
new ResponsiveColumnSizes(2, 3, 3, 3, 3),
// Format column
new ResponsiveColumnSizes(2, 2, 2, 2, 2),
// Actions column
new ResponsiveColumnSizes(6, 5, 4, 3, 3),
]);
columnSizes: ResponsiveTableSizes;
/**
* Are we currently submitting the changes?
@@ -141,21 +111,81 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
public cdRef: ChangeDetectorRef,
public bundleService: BundleDataService,
public zone: NgZone,
public itemBitstreamsService: ItemBitstreamsService,
) {
super(itemService, objectUpdatesService, router, notificationsService, translateService, route);
this.columnSizes = this.itemBitstreamsService.getColumnSizes();
}
/**
* Actions to perform after the item has been initialized
*/
postItemInit(): void {
this.bundles$ = this.itemService.getBundles(this.item.id, new PaginatedSearchOptions({ pagination: this.bundlesOptions })).pipe(
const bundlesOptions = this.itemBitstreamsService.getInitialBundlesPaginationOptions();
this.bundles$ = this.itemService.getBundles(this.item.id, new PaginatedSearchOptions({ pagination: bundlesOptions })).pipe(
getFirstSucceededRemoteData(),
getRemoteDataPayload(),
map((bundlePage: PaginatedList<Bundle>) => bundlePage.page),
);
}
/**
* Handles keyboard events that should move the currently selected bitstream up
*/
@HostListener('document:keydown.arrowUp', ['$event'])
moveUp(event: KeyboardEvent) {
if (this.itemBitstreamsService.hasSelectedBitstream()) {
event.preventDefault();
this.itemBitstreamsService.moveSelectedBitstreamUp();
}
}
/**
* Handles keyboard events that should move the currently selected bitstream down
*/
@HostListener('document:keydown.arrowDown', ['$event'])
moveDown(event: KeyboardEvent) {
if (this.itemBitstreamsService.hasSelectedBitstream()) {
event.preventDefault();
this.itemBitstreamsService.moveSelectedBitstreamDown();
}
}
/**
* Handles keyboard events that should cancel the currently selected bitstream.
* A cancel means that the selected bitstream is returned to its original position and is no longer selected.
* @param event
*/
@HostListener('document:keyup.escape', ['$event'])
cancelSelection(event: KeyboardEvent) {
if (this.itemBitstreamsService.hasSelectedBitstream()) {
event.preventDefault();
this.itemBitstreamsService.cancelSelection();
}
}
/**
* Handles keyboard events that should clear the currently selected bitstream.
* A clear means that the selected bitstream remains in its current position but is no longer selected.
*/
@HostListener('document:keydown.enter', ['$event'])
@HostListener('document:keydown.space', ['$event'])
clearSelection(event: KeyboardEvent) {
// Only when no specific element is in focus do we want to clear the currently selected bitstream
// Otherwise we might clear the selection when a different action was intended, e.g. clicking a button or selecting
// a different bitstream.
if (
this.itemBitstreamsService.hasSelectedBitstream() &&
event.target instanceof Element &&
event.target.tagName === 'BODY'
) {
event.preventDefault();
this.itemBitstreamsService.clearSelection();
}
}
/**
* Initialize the notification messages prefix
*/
@@ -171,84 +201,16 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
*/
submit() {
this.submitting = true;
const bundlesOnce$ = this.bundles$.pipe(take(1));
// Fetch all removed bitstreams from the object update service
const removedBitstreams$ = bundlesOnce$.pipe(
switchMap((bundles: Bundle[]) => observableZip(
...bundles.map((bundle: Bundle) => this.objectUpdatesService.getFieldUpdates(bundle.self, [], true)),
)),
map((fieldUpdates: FieldUpdates[]) => ([] as FieldUpdate[]).concat(
...fieldUpdates.map((updates: FieldUpdates) => Object.values(updates).filter((fieldUpdate: FieldUpdate) => fieldUpdate.changeType === FieldChangeType.REMOVE)),
)),
map((fieldUpdates: FieldUpdate[]) => fieldUpdates.map((fieldUpdate: FieldUpdate) => fieldUpdate.field)),
);
// Send out delete requests for all deleted bitstreams
const removedResponses$: Observable<RemoteData<NoContent>> = removedBitstreams$.pipe(
take(1),
switchMap((removedBitstreams: Bitstream[]) => {
return this.bitstreamService.removeMultiple(removedBitstreams);
}),
);
const removedResponses$ = this.itemBitstreamsService.removeMarkedBitstreams(this.bundles$);
// Perform the setup actions from above in order and display notifications
removedResponses$.subscribe((responses: RemoteData<NoContent>) => {
this.displayNotifications('item.edit.bitstreams.notifications.remove', [responses]);
this.itemBitstreamsService.displayNotifications('item.edit.bitstreams.notifications.remove', [responses]);
this.submitting = false;
});
}
/**
* A bitstream was dropped in a new location. Send out a Move Patch request to the REST API, display notifications,
* refresh the bundle's cache (so the lists can properly reload) and call the event's callback function (which will
* navigate the user to the correct page)
* @param bundle The bundle to send patch requests to
* @param event The event containing the index the bitstream came from and was dropped to
*/
dropBitstream(bundle: Bundle, event: any) {
this.zone.runOutsideAngular(() => {
if (hasValue(event) && hasValue(event.fromIndex) && hasValue(event.toIndex) && hasValue(event.finish)) {
const moveOperation = {
op: 'move',
from: `/_links/bitstreams/${event.fromIndex}/href`,
path: `/_links/bitstreams/${event.toIndex}/href`,
} as Operation;
this.bundleService.patch(bundle, [moveOperation]).pipe(take(1)).subscribe((response: RemoteData<Bundle>) => {
this.zone.run(() => {
this.displayNotifications('item.edit.bitstreams.notifications.move', [response]);
// Remove all cached requests from this bundle and call the event's callback when the requests are cleared
this.requestService.removeByHrefSubstring(bundle.self).pipe(
filter((isCached) => isCached),
take(1),
).subscribe(() => event.finish());
});
});
}
});
}
/**
* Display notifications
* - Error notification for each failed response with their message
* - Success notification in case there's at least one successful response
* @param key The i18n key for the notification messages
* @param responses The returned responses to display notifications for
*/
displayNotifications(key: string, responses: RemoteData<any>[]) {
if (isNotEmpty(responses)) {
const failedResponses = responses.filter((response: RemoteData<Bundle>) => hasValue(response) && response.hasFailed);
const successfulResponses = responses.filter((response: RemoteData<Bundle>) => hasValue(response) && response.hasSucceeded);
failedResponses.forEach((response: RemoteData<Bundle>) => {
this.notificationsService.error(this.translateService.instant(`${key}.failed.title`), response.errorMessage);
});
if (successfulResponses.length > 0) {
this.notificationsService.success(this.translateService.instant(`${key}.saved.title`), this.translateService.instant(`${key}.saved.content`));
}
}
}
/**
* Request the object updates service to discard all current changes to this item
* Shows a notification to remind the user that they can undo this