mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-16 11:37:04 +02:00
* Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License. Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUS-1.1 * Fix test that expected exact offset on hcl file --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Sarah Thompson <sthompson@hashicorp.com> Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
63 lines
1.7 KiB
JavaScript
63 lines
1.7 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import Component from '@glimmer/component';
|
|
import { tracked } from '@glimmer/tracking';
|
|
import { action } from '@ember/object';
|
|
|
|
/**
|
|
* @module PaginationControls
|
|
* PaginationControls components are used to paginate through item lists
|
|
*
|
|
* @example
|
|
* ```js
|
|
* <PaginationControls @startPage={{1}} @total={{100}} @size={{15}} @onChange={{this.onPageChange}} />
|
|
* ```
|
|
* @param {number} total - total number of items
|
|
* @param {number} [startPage=1] - initial page number to select
|
|
* @param {number} [size=15] - number of items to display per page
|
|
* @param {function} onChange - callback fired on page change
|
|
*/
|
|
|
|
export default class PaginationControls extends Component {
|
|
@tracked page;
|
|
|
|
constructor() {
|
|
super(...arguments);
|
|
this.page = this.args.startPage || 1;
|
|
this.size = this.args.size || 15; // size selector may be added in future version
|
|
}
|
|
|
|
get totalPages() {
|
|
return Math.ceil(this.args.total / this.size);
|
|
}
|
|
get displayInfo() {
|
|
const { total } = this.args;
|
|
const end = this.page * this.size;
|
|
return `${end - this.size + 1}-${end > total ? total : end} of ${total}`;
|
|
}
|
|
get pages() {
|
|
// show 5 pages with 2 on either side of the current page
|
|
let start = this.page - 2 >= 1 ? this.page - 2 : 1;
|
|
const incrementer = start + 4;
|
|
const end = incrementer <= this.totalPages ? incrementer : this.totalPages;
|
|
const pageNumbers = [];
|
|
while (start <= end) {
|
|
pageNumbers.push(start);
|
|
start++;
|
|
}
|
|
return pageNumbers;
|
|
}
|
|
get hasMorePages() {
|
|
return this.pages.lastObject !== this.totalPages;
|
|
}
|
|
|
|
@action
|
|
changePage(page) {
|
|
this.page = page;
|
|
this.args.onChange(page);
|
|
}
|
|
}
|