mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 10:34:15 +00:00
63945: Bitstream pagination and removal of listing per bundle
This commit is contained in:
@@ -303,7 +303,8 @@
|
||||
"failed": {
|
||||
"title": "Error deleting bitstream"
|
||||
}
|
||||
}
|
||||
},
|
||||
"empty": "This item doesn't contain any bitstreams. Click the upload button to create one."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@@ -20,23 +20,23 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table *ngIf="updatesMap && updatesMap.size > 0" class="table table-responsive table-striped table-bordered">
|
||||
<ds-pagination *ngIf="(updates$ | async) && ((updates$ | async) | dsObjectValues).length > 0"
|
||||
[paginationOptions]="(searchOptions$ | async)?.pagination"
|
||||
[pageInfoState]="(bitstreams$ | async)?.payload"
|
||||
[collectionSize]="(bitstreams$ | async)?.payload?.totalElements"
|
||||
[sortOptions]="(searchOptions$ | async)?.sort"
|
||||
[hideGear]="true"
|
||||
[hidePagerWhenSinglePage]="true">
|
||||
<table class="table table-responsive table-striped table-bordered">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>{{'item.edit.bitstreams.headers.name' | translate}}</th>
|
||||
<th>{{'item.edit.bitstreams.headers.bundle' | translate}}</th>
|
||||
<th>{{'item.edit.bitstreams.headers.description' | translate}}</th>
|
||||
<th class="text-center">{{'item.edit.bitstreams.headers.format' | translate}}</th>
|
||||
<th class="text-center">{{'item.edit.bitstreams.headers.actions' | translate}}</th>
|
||||
</tr>
|
||||
<ng-container *ngFor="let updatesItem of updatesMap | keyvalue">
|
||||
<tr>
|
||||
<th>{{'item.edit.bitstreams.headers.bundle' | translate}}: {{ updatesItem.key }}</th>
|
||||
<td class="w-100"></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<ng-container *ngIf="updatesItem.value">
|
||||
<ng-container *ngVar="((updatesItem.value | async) | dsObjectValues) as updateValues">
|
||||
<ng-container *ngVar="((updates$ | async) | dsObjectValues) as updateValues">
|
||||
<tr *ngFor="let updateValue of updateValues"
|
||||
ds-item-edit-bitstream
|
||||
[fieldUpdate]="updateValue"
|
||||
@@ -48,10 +48,13 @@
|
||||
}">
|
||||
</tr>
|
||||
</ng-container>
|
||||
</ng-container>
|
||||
</ng-container>
|
||||
</tbody>
|
||||
</table>
|
||||
</ds-pagination>
|
||||
<div *ngIf="!(updates$ | async) || (updates$ | async) && ((updates$ | async) | dsObjectValues).length === 0" class="alert alert-info w-100 d-inline-block" role="alert">
|
||||
{{'item.edit.bitstreams.empty' | translate}}
|
||||
</div>
|
||||
|
||||
<div class="button-row bottom">
|
||||
<div class="my-2 float-right">
|
||||
<button class="btn btn-danger" *ngIf="!(isReinstatable() | async)"
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { ChangeDetectorRef, Component, Inject, OnDestroy } from '@angular/core';
|
||||
import { AbstractItemUpdateComponent } from '../abstract-item-update/abstract-item-update.component';
|
||||
import { filter, map, switchMap, take } from 'rxjs/operators';
|
||||
import { filter, map, switchMap, take, tap } from 'rxjs/operators';
|
||||
import { Bitstream } from '../../../core/shared/bitstream.model';
|
||||
import { toBitstreamsArray, toBundleMap } from '../../../core/shared/item-bitstreams-utils';
|
||||
import { toBitstreamsArray } from '../../../core/shared/item-bitstreams-utils';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { FieldUpdate, FieldUpdates } from '../../../core/data/object-updates/object-updates.reducer';
|
||||
import { Subscription } from 'rxjs/internal/Subscription';
|
||||
@@ -22,8 +22,10 @@ import { RequestService } from '../../../core/data/request.service';
|
||||
import { getSucceededRemoteData } from '../../../core/shared/operators';
|
||||
import { Item } from '../../../core/shared/item.model';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
|
||||
export const ORIGINAL_BUNDLE = 'ORIGINAL';
|
||||
import { PaginatedList } from '../../../core/data/paginated-list';
|
||||
import { SearchConfigurationService } from '../../../+search-page/search-service/search-configuration.service';
|
||||
import { PaginatedSearchOptions } from '../../../+search-page/paginated-search-options.model';
|
||||
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-item-bitstreams',
|
||||
@@ -36,16 +38,14 @@ export const ORIGINAL_BUNDLE = 'ORIGINAL';
|
||||
export class ItemBitstreamsComponent extends AbstractItemUpdateComponent implements OnDestroy {
|
||||
|
||||
/**
|
||||
* A Map of the current item's bundles and respective FieldUpdates
|
||||
* key: Bundle Name
|
||||
* value: FieldUpdates about the bundle's bitstreams
|
||||
* The currently listed bitstreams
|
||||
*/
|
||||
updatesMap: Map<string, Observable<FieldUpdates>>;
|
||||
bitstreams$: BehaviorSubject<RemoteData<PaginatedList<Bitstream>>> = new BehaviorSubject<RemoteData<PaginatedList<Bitstream>>>(null);
|
||||
|
||||
/**
|
||||
* A subscription keeping the updatesMap up-to-date
|
||||
* The current paginated search options
|
||||
*/
|
||||
updatesMapSub: Subscription;
|
||||
searchOptions$: Observable<PaginatedSearchOptions>;
|
||||
|
||||
/**
|
||||
* A subscription that checks when the item is deleted in cache and reloads the item by sending a new request
|
||||
@@ -53,6 +53,11 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
|
||||
*/
|
||||
itemUpdateSubscription: Subscription;
|
||||
|
||||
/**
|
||||
* A subscription keeping track of the current search options and applying them to the bitstreams$ observable
|
||||
*/
|
||||
bitstreamsSubscription: Subscription;
|
||||
|
||||
constructor(
|
||||
public itemService: ItemDataService,
|
||||
public objectUpdatesService: ObjectUpdatesService,
|
||||
@@ -64,7 +69,8 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
|
||||
public bitstreamService: BitstreamDataService,
|
||||
public objectCache: ObjectCacheService,
|
||||
public requestService: RequestService,
|
||||
public cdRef: ChangeDetectorRef
|
||||
public cdRef: ChangeDetectorRef,
|
||||
public searchConfig: SearchConfigurationService
|
||||
) {
|
||||
super(itemService, objectUpdatesService, router, notificationsService, translateService, EnvConfig, route);
|
||||
}
|
||||
@@ -74,6 +80,8 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
super.ngOnInit();
|
||||
this.searchOptions$ = this.searchConfig.paginatedSearchOptions;
|
||||
this.initializeBitstreamsUpdate();
|
||||
this.initializeItemUpdate();
|
||||
}
|
||||
|
||||
@@ -88,35 +96,17 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
|
||||
* Initialize the original fields for the object-updates-service
|
||||
*/
|
||||
initializeOriginalFields(): void {
|
||||
this.item.bitstreams.pipe(
|
||||
toBitstreamsArray(),
|
||||
take(1)
|
||||
).subscribe((bitstreams: Bitstream[]) => {
|
||||
this.objectUpdatesService.initialize(this.url, bitstreams, this.item.lastModified);
|
||||
});
|
||||
this.objectUpdatesService.initialize(this.url, [], this.item.lastModified);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize field updates
|
||||
*/
|
||||
initializeUpdates(): void {
|
||||
this.updates$ = this.item.bitstreams.pipe(
|
||||
this.updates$ = this.bitstreams$.pipe(
|
||||
toBitstreamsArray(),
|
||||
switchMap((bitstreams: Bitstream[]) => this.objectUpdatesService.getFieldUpdates(this.url, bitstreams))
|
||||
switchMap((bitstreams: Bitstream[]) => this.objectUpdatesService.getFieldUpdatesExclusive(this.url, bitstreams))
|
||||
);
|
||||
this.updatesMapSub = this.item.bitstreams.pipe(
|
||||
toBundleMap()
|
||||
).subscribe((bundleMap: Map<string, Bitstream[]>) => {
|
||||
const updatesMap = new Map();
|
||||
bundleMap.forEach((bitstreams: Bitstream[], bundleName: string) => {
|
||||
updatesMap.set(bundleName, this.objectUpdatesService.getFieldUpdatesExclusive(this.url, bitstreams));
|
||||
});
|
||||
if (updatesMap.size === 0) {
|
||||
// Add an ORIGINAL bundle by default if the item doesn't contain any bitstreams
|
||||
updatesMap.set(ORIGINAL_BUNDLE, undefined);
|
||||
}
|
||||
this.updatesMap = updatesMap;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,17 +122,31 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
|
||||
this.item = itemRD.payload;
|
||||
this.initializeOriginalFields();
|
||||
this.initializeUpdates();
|
||||
// Navigate back to the first page to force a reload of the bitstream page
|
||||
this.router.navigate([this.url], { queryParamsHandling: 'merge', queryParams: { page: 0 } });
|
||||
this.cdRef.detectChanges();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the bitstream update subscription, which keeps track of the current search options and applies
|
||||
* them to the bitstreams$ observable by sending out a REST request
|
||||
*/
|
||||
initializeBitstreamsUpdate(): void {
|
||||
this.bitstreamsSubscription = this.searchOptions$.pipe(
|
||||
switchMap((searchOptions) => this.itemService.getBitstreams(this.item.id, searchOptions))
|
||||
).subscribe((bitsreams: RemoteData<PaginatedList<Bitstream>>) => {
|
||||
this.bitstreams$.next(bitsreams);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit the current changes
|
||||
* Bitstreams marked as deleted send out a delete request to the rest API
|
||||
* Display notifications and reset the current item/updates
|
||||
*/
|
||||
submit() {
|
||||
const removedBitstreams$ = this.item.bitstreams.pipe(
|
||||
const removedBitstreams$ = this.bitstreams$.pipe(
|
||||
toBitstreamsArray(),
|
||||
switchMap((bitstreams: Bitstream[]) => this.objectUpdatesService.getFieldUpdatesExclusive(this.url, bitstreams) as Observable<FieldUpdates>),
|
||||
map((fieldUpdates: FieldUpdates) => Object.values(fieldUpdates).filter((fieldUpdate: FieldUpdate) => fieldUpdate.changeType === FieldChangeType.REMOVE)),
|
||||
@@ -180,7 +184,6 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
|
||||
* De-cache the current item (it should automatically reload due to itemUpdateSubscription)
|
||||
*/
|
||||
reset() {
|
||||
this.updatesMap = undefined;
|
||||
this.refreshItemCache();
|
||||
this.initializeItemUpdate();
|
||||
}
|
||||
@@ -197,7 +200,7 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
|
||||
* Unsubscribe from open subscriptions whenever the component gets destroyed
|
||||
*/
|
||||
ngOnDestroy(): void {
|
||||
this.updatesMapSub.unsubscribe();
|
||||
this.itemUpdateSubscription.unsubscribe();
|
||||
this.bitstreamsSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,10 @@
|
||||
<td>
|
||||
<td class="w-100">
|
||||
{{ bitstream.name }}
|
||||
</td>
|
||||
<td class="w-100">
|
||||
<td>
|
||||
{{ bitstream.bundleName }}
|
||||
</td>
|
||||
<td>
|
||||
{{ bitstream.description }}
|
||||
</td>
|
||||
<td class="text-center">
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { distinctUntilChanged, filter, map } from 'rxjs/operators';
|
||||
import { distinctUntilChanged, filter, map, take } from 'rxjs/operators';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { Observable } from 'rxjs';
|
||||
@@ -12,7 +12,7 @@ import { URLCombiner } from '../url-combiner/url-combiner';
|
||||
import { DataService } from './data.service';
|
||||
import { RequestService } from './request.service';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { FindAllOptions, PatchRequest, RestRequest } from './request.models';
|
||||
import { FindAllOptions, GetRequest, PatchRequest, RestRequest } from './request.models';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
|
||||
@@ -20,6 +20,10 @@ import { HttpClient } from '@angular/common/http';
|
||||
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
|
||||
import { configureRequest, getRequestFromRequestHref } from '../shared/operators';
|
||||
import { RequestEntry } from './request.reducer';
|
||||
import { PaginatedSearchOptions } from '../../+search-page/paginated-search-options.model';
|
||||
import { RemoteData } from './remote-data';
|
||||
import { PaginatedList } from './paginated-list';
|
||||
import { Bitstream } from '../shared/bitstream.model';
|
||||
|
||||
@Injectable()
|
||||
export class ItemDataService extends DataService<Item> {
|
||||
@@ -118,4 +122,25 @@ export class ItemDataService extends DataService<Item> {
|
||||
map((requestEntry: RequestEntry) => requestEntry.response)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item's bitstreams using paginated search options
|
||||
* @param itemId The item's ID
|
||||
* @param searchOptions The search options to use
|
||||
*/
|
||||
public getBitstreams(itemId: string, searchOptions?: PaginatedSearchOptions): Observable<RemoteData<PaginatedList<Bitstream>>> {
|
||||
const hrefObs = this.getItemWithdrawEndpoint(itemId).pipe(
|
||||
map((href) => `${href}/bitstreams`),
|
||||
map((href) => searchOptions ? searchOptions.toRestUrl(href) : href)
|
||||
);
|
||||
hrefObs.pipe(
|
||||
take(1)
|
||||
).subscribe((href) => {
|
||||
const request = new GetRequest(this.requestService.generateRequestId(), href);
|
||||
this.requestService.configure(request);
|
||||
});
|
||||
|
||||
return this.rdbService.buildList<Bitstream>(hrefObs);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -3,48 +3,14 @@ import { RemoteData } from '../data/remote-data';
|
||||
import { PaginatedList } from '../data/paginated-list';
|
||||
import { Bitstream } from './bitstream.model';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { combineLatest as observableCombineLatest } from 'rxjs';
|
||||
import { getSucceededRemoteData } from './operators';
|
||||
import { hasValueOperator } from '../../shared/empty.util';
|
||||
|
||||
/**
|
||||
* Operator for turning the current page of bitstreams into an array
|
||||
*/
|
||||
export const toBitstreamsArray = () =>
|
||||
(source: Observable<RemoteData<PaginatedList<Bitstream>>>): Observable<Bitstream[]> =>
|
||||
source.pipe(
|
||||
getSucceededRemoteData(),
|
||||
hasValueOperator(),
|
||||
map((bitstreamRD: RemoteData<PaginatedList<Bitstream>>) => bitstreamRD.payload.page)
|
||||
);
|
||||
|
||||
export const getBundleNames = () =>
|
||||
(source: Observable<RemoteData<PaginatedList<Bitstream>>>): Observable<string[]> =>
|
||||
source.pipe(
|
||||
toBitstreamsArray(),
|
||||
map((bitstreams: Bitstream[]) => {
|
||||
const result = [];
|
||||
bitstreams.forEach((bitstream: Bitstream) => {
|
||||
if (result.indexOf(bitstream.bundleName) < 0) {
|
||||
result.push(bitstream.bundleName);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
})
|
||||
);
|
||||
|
||||
export const filterByBundleName = (bundleName: string) =>
|
||||
(source: Observable<RemoteData<PaginatedList<Bitstream>>>): Observable<Bitstream[]> =>
|
||||
source.pipe(
|
||||
toBitstreamsArray(),
|
||||
map((bitstreams: Bitstream[]) =>
|
||||
bitstreams.filter((bitstream: Bitstream) => bitstream.bundleName === bundleName)
|
||||
)
|
||||
);
|
||||
|
||||
export const toBundleMap = () =>
|
||||
(source: Observable<RemoteData<PaginatedList<Bitstream>>>): Observable<Map<string, Bitstream[]>> =>
|
||||
observableCombineLatest(source.pipe(toBitstreamsArray()), source.pipe(getBundleNames())).pipe(
|
||||
map(([bitstreams, bundleNames]) => {
|
||||
const bundleMap = new Map();
|
||||
bundleNames.forEach((bundleName: string) => {
|
||||
bundleMap.set(bundleName, bitstreams.filter((bitstream: Bitstream) => bitstream.bundleName === bundleName));
|
||||
});
|
||||
return bundleMap;
|
||||
})
|
||||
);
|
||||
|
Reference in New Issue
Block a user