Merge remote-tracking branch '4Science-bitbucket/main' into CST-5337

This commit is contained in:
Luca Giamminonni
2022-07-06 16:39:38 +02:00
1079 changed files with 41298 additions and 21673 deletions

View File

@@ -19,7 +19,11 @@ import { SortDirection, SortOptions } from '../../core/cache/models/sort-options
import { hasValue } from '../empty.util';
import { PageInfo } from '../../core/shared/page-info.model';
import { PaginationService } from '../../core/pagination/pagination.service';
import { map } from 'rxjs/operators';
import { map, take } from 'rxjs/operators';
import { RemoteData } from '../../core/data/remote-data';
import { PaginatedList } from '../../core/data/paginated-list.model';
import { ListableObject } from '../object-collection/shared/listable-object.model';
import { ViewMode } from '../../core/shared/view-mode.model';
/**
* The default pagination controls component.
@@ -33,6 +37,11 @@ import { map } from 'rxjs/operators';
encapsulation: ViewEncapsulation.Emulated
})
export class PaginationComponent implements OnDestroy, OnInit {
/**
* ViewMode that should be passed to {@link ListableObjectComponentLoaderComponent}.
*/
viewMode: ViewMode = ViewMode.ListElement;
/**
* Number of items in collection.
*/
@@ -53,6 +62,26 @@ export class PaginationComponent implements OnDestroy, OnInit {
*/
@Input() sortOptions: SortOptions;
/**
* Whether or not the pagination should be rendered as simple previous and next buttons instead of the normal pagination
*/
@Input() showPaginator = true;
/**
* The current pagination configuration
*/
@Input() config?: PaginationComponentOptions;
/**
* The list of listable objects to render in this component
*/
@Input() objects: RemoteData<PaginatedList<ListableObject>>;
/**
* The current sorting configuration
*/
@Input() sortConfig: SortOptions;
/**
* An event fired when the page is changed.
* Event's payload equals to the newly selected page.
@@ -168,6 +197,15 @@ export class PaginationComponent implements OnDestroy, OnInit {
*/
private subs: Subscription[] = [];
/**
* If showPaginator is set to true, emit when the previous button is clicked
*/
@Output() prev = new EventEmitter<boolean>();
/**
* If showPaginator is set to true, emit when the next button is clicked
*/
@Output() next = new EventEmitter<boolean>();
/**
* Method provided by Angular. Invoked after the constructor.
*/
@@ -352,4 +390,31 @@ export class PaginationComponent implements OnDestroy, OnInit {
map((hasMultiplePages) => hasMultiplePages || !this.hidePagerWhenSinglePage)
);
}
/**
* Go to the previous page
*/
goPrev() {
this.prev.emit(true);
this.updatePagination(-1);
}
/**
* Go to the next page
*/
goNext() {
this.next.emit(true);
this.updatePagination(1);
}
/**
* Update page when next or prev button is clicked
* @param value
*/
updatePagination(value: number) {
this.paginationService.getCurrentPagination(this.id, this.paginationOptions).pipe(take(1)).subscribe((currentPaginationOptions) => {
this.updateParams({page: (currentPaginationOptions.currentPage + value).toString()});
});
}
}