mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-10 11:33:04 +00:00
[CST-9636] WIP improve bulk access page
This commit is contained in:
@@ -22,7 +22,7 @@
|
|||||||
<a ngbNavLink>{{'admin.access-control.bulk-access-browse.search.header' | translate}}</a>
|
<a ngbNavLink>{{'admin.access-control.bulk-access-browse.search.header' | translate}}</a>
|
||||||
<ng-template ngbNavContent>
|
<ng-template ngbNavContent>
|
||||||
<div class="mx-n3">
|
<div class="mx-n3">
|
||||||
<ds-themed-search [configuration]="'default'"
|
<ds-themed-search [configuration]="'administrativeBulkAccess'"
|
||||||
[selectable]="true"
|
[selectable]="true"
|
||||||
[selectionConfig]="{ repeatable: true, listId: listId }"
|
[selectionConfig]="{ repeatable: true, listId: listId }"
|
||||||
[showThumbnails]="false"></ds-themed-search>
|
[showThumbnails]="false"></ds-themed-search>
|
||||||
@@ -30,15 +30,20 @@
|
|||||||
</ng-template>
|
</ng-template>
|
||||||
</li>
|
</li>
|
||||||
<li [ngbNavItem]="'selected'">
|
<li [ngbNavItem]="'selected'">
|
||||||
<a
|
<a ngbNavLink>
|
||||||
ngbNavLink>{{'admin.access-control.bulk-access-browse.selected.header' | translate: {number: ((objectsSelected$ | async)?.payload?.totalElements) ? (objectsSelected$ | async)?.payload?.totalElements : '0'} }}</a>
|
{{'admin.access-control.bulk-access-browse.selected.header' | translate: {number: ((objectsSelected$ | async)?.payload?.totalElements) ? (objectsSelected$ | async)?.payload?.totalElements : '0'} }}
|
||||||
|
</a>
|
||||||
<ng-template ngbNavContent>
|
<ng-template ngbNavContent>
|
||||||
<ds-viewable-collection [config]="paginationOptions"
|
<ds-themed-object-list [config]="paginationOptions$ | async"
|
||||||
[hideGear]="true"
|
[hideGear]="true"
|
||||||
[objects]="objectsSelected$ | async"
|
[listToPaginate]="true"
|
||||||
[selectable]="true"
|
[objects]="objectsSelected$ | async"
|
||||||
[selectionConfig]="{ repeatable: true, listId: listId }"
|
[selectable]="true"
|
||||||
[showThumbnails]="false"></ds-viewable-collection>
|
[selectionConfig]="{ repeatable: true, listId: listId }"
|
||||||
|
[showThumbnails]="false"
|
||||||
|
[showPaginator]="false"
|
||||||
|
(next)="pageNext()"
|
||||||
|
(prev)="pagePrev()"></ds-themed-object-list>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
|
||||||
|
|
||||||
import { BehaviorSubject, Subscription } from 'rxjs';
|
import { BehaviorSubject, Subscription } from 'rxjs';
|
||||||
import { distinctUntilChanged, map } from 'rxjs/operators';
|
import { distinctUntilChanged, map } from 'rxjs/operators';
|
||||||
@@ -13,6 +13,7 @@ import { ListableObject } from '../../../shared/object-collection/shared/listabl
|
|||||||
import { createSuccessfulRemoteDataObject } from '../../../shared/remote-data.utils';
|
import { createSuccessfulRemoteDataObject } from '../../../shared/remote-data.utils';
|
||||||
import { PageInfo } from '../../../core/shared/page-info.model';
|
import { PageInfo } from '../../../core/shared/page-info.model';
|
||||||
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
|
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
|
||||||
|
import { hasValue } from '../../../shared/empty.util';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-bulk-access-browse',
|
selector: 'ds-bulk-access-browse',
|
||||||
@@ -25,43 +26,97 @@ import { PaginationComponentOptions } from '../../../shared/pagination/paginatio
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class BulkAccessBrowseComponent implements OnInit {
|
export class BulkAccessBrowseComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The selection list id
|
||||||
|
*/
|
||||||
|
@Input() listId!: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The active nav id
|
* The active nav id
|
||||||
*/
|
*/
|
||||||
activateId = 'search';
|
activateId = 'search';
|
||||||
|
|
||||||
/**
|
|
||||||
* The selection list id
|
|
||||||
*/
|
|
||||||
listId: string = 'bulk-access-list';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of the objects already selected
|
* The list of the objects already selected
|
||||||
*/
|
*/
|
||||||
objectsSelected$: BehaviorSubject<RemoteData<PaginatedList<ListableObject>>> = new BehaviorSubject<RemoteData<PaginatedList<ListableObject>>>(null);
|
objectsSelected$: BehaviorSubject<RemoteData<PaginatedList<ListableObject>>> = new BehaviorSubject<RemoteData<PaginatedList<ListableObject>>>(null);
|
||||||
|
|
||||||
paginationOptions: PaginationComponentOptions;
|
/**
|
||||||
|
* The pagination options object used for the list of selected elements
|
||||||
|
*/
|
||||||
|
paginationOptions$: BehaviorSubject<PaginationComponentOptions> = new BehaviorSubject<PaginationComponentOptions>(Object.assign(new PaginationComponentOptions(), {
|
||||||
|
id: 'bas',
|
||||||
|
pageSize: 5,
|
||||||
|
currentPage: 1
|
||||||
|
}));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array to track all subscriptions and unsubscribe them onDestroy
|
||||||
|
*/
|
||||||
private subs: Subscription[] = [];
|
private subs: Subscription[] = [];
|
||||||
|
|
||||||
constructor(private selectableListService: SelectableListService) {
|
constructor(private selectableListService: SelectableListService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subscribe to selectable list updates
|
||||||
|
*/
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.paginationOptions = Object.assign(new PaginationComponentOptions(), {
|
|
||||||
id: 'elp',
|
|
||||||
pageSize: 10,
|
|
||||||
currentPage: 1
|
|
||||||
});
|
|
||||||
this.subs.push(
|
this.subs.push(
|
||||||
this.selectableListService.getSelectableList(this.listId).pipe(
|
this.selectableListService.getSelectableList(this.listId).pipe(
|
||||||
distinctUntilChanged(),
|
distinctUntilChanged(),
|
||||||
map((list: SelectableListState) => {
|
map((list: SelectableListState) => this.generatePaginatedListBySelectedElements(list))
|
||||||
console.log(list);
|
|
||||||
return createSuccessfulRemoteDataObject(buildPaginatedList(new PageInfo(), list?.selection || []))
|
|
||||||
})
|
|
||||||
).subscribe(this.objectsSelected$)
|
).subscribe(this.objectsSelected$)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pageNext() {
|
||||||
|
this.paginationOptions$.next(Object.assign(new PaginationComponentOptions(), this.paginationOptions$.value, {
|
||||||
|
currentPage: this.paginationOptions$.value.currentPage + 1
|
||||||
|
}));
|
||||||
|
console.log(this.paginationOptions$.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
pagePrev() {
|
||||||
|
this.paginationOptions$.next(Object.assign(new PaginationComponentOptions(), this.paginationOptions$.value, {
|
||||||
|
currentPage: this.paginationOptions$.value.currentPage - 1
|
||||||
|
}));
|
||||||
|
console.log(this.paginationOptions$.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private calculatePageCount(pageSize, totalCount = 0) {
|
||||||
|
// we suppose that if we have 0 items we want 1 empty page
|
||||||
|
return totalCount < pageSize ? 1 : Math.ceil(totalCount / pageSize);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate The RemoteData object containing the list of the selected elements
|
||||||
|
* @param list
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
private generatePaginatedListBySelectedElements(list: SelectableListState): RemoteData<PaginatedList<ListableObject>> {
|
||||||
|
const pageInfo = new PageInfo({
|
||||||
|
elementsPerPage: this.paginationOptions$.value.pageSize,
|
||||||
|
totalElements: list?.selection.length,
|
||||||
|
totalPages: this.calculatePageCount(this.paginationOptions$.value.pageSize, list?.selection.length),
|
||||||
|
currentPage: this.paginationOptions$.value.currentPage
|
||||||
|
});
|
||||||
|
if (pageInfo.currentPage > pageInfo.totalPages) {
|
||||||
|
pageInfo.currentPage = pageInfo.totalPages;
|
||||||
|
this.paginationOptions$.next(Object.assign(new PaginationComponentOptions(), this.paginationOptions$.value, {
|
||||||
|
currentPage: pageInfo.currentPage
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
return createSuccessfulRemoteDataObject(buildPaginatedList(pageInfo, list?.selection || []));
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.subs
|
||||||
|
.filter((sub) => hasValue(sub))
|
||||||
|
.forEach((sub) => sub.unsubscribe());
|
||||||
|
this.selectableListService.deselectAll(this.listId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<ds-bulk-access-browse></ds-bulk-access-browse>
|
<ds-bulk-access-browse [listId]="listId"></ds-bulk-access-browse>
|
||||||
<div class="clearfix mb-3"></div>
|
<div class="clearfix mb-3"></div>
|
||||||
<ds-bulk-access-settings></ds-bulk-access-settings>
|
<ds-bulk-access-settings [listId]="listId"></ds-bulk-access-settings>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
@@ -7,6 +7,12 @@ import { Component, OnInit } from '@angular/core';
|
|||||||
})
|
})
|
||||||
export class BulkAccessComponent implements OnInit {
|
export class BulkAccessComponent implements OnInit {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The selection list id
|
||||||
|
*/
|
||||||
|
listId: string = 'bulk-access-list';
|
||||||
|
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, Input, OnInit } from '@angular/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-bulk-access-settings',
|
selector: 'ds-bulk-access-settings',
|
||||||
@@ -7,6 +7,11 @@ import { Component, OnInit } from '@angular/core';
|
|||||||
})
|
})
|
||||||
export class BulkAccessSettingsComponent implements OnInit {
|
export class BulkAccessSettingsComponent implements OnInit {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The selection list id
|
||||||
|
*/
|
||||||
|
@Input() listId!: string;
|
||||||
|
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
Reference in New Issue
Block a user