blob: 520a19eaea31bff1a15431931bb35b919c227192 [file] [log] [blame]
{"version":3,"file":"covalent-core-paging.umd.js.map","sources":["ng://@covalent/core/paging/paging-bar.component.ts","ng://@covalent/core/paging/paging.module.ts"],"sourcesContent":["import { Component, Input, Output, EventEmitter, OnInit, Optional, ChangeDetectorRef, ChangeDetectionStrategy } from '@angular/core';\nimport { coerceNumberProperty } from '@angular/cdk/coercion';\nimport { Dir } from '@angular/cdk/bidi';\n\nexport interface IPageChangeEvent {\n page: number;\n maxPage: number;\n pageSize: number;\n total: number;\n fromRow: number;\n toRow: number;\n}\n\n@Component({\n changeDetection: ChangeDetectionStrategy.OnPush,\n selector: 'td-paging-bar',\n templateUrl: './paging-bar.component.html',\n styleUrls: ['./paging-bar.component.scss' ],\n})\nexport class TdPagingBarComponent implements OnInit {\n\n private _pageSize: number = 50;\n private _total: number = 0;\n private _page: number = 1;\n private _fromRow: number = 1;\n private _toRow: number = 1;\n private _initialized: boolean = false;\n private _pageLinks: number[] = [];\n private _pageLinkCount: number = 0;\n // special case when 2 pageLinks, detect when hit end of pages so can lead in correct direction\n private _hitEnd: boolean = false;\n // special case when 2 pageLinks, detect when hit start of pages so can lead in correct direction\n private _hitStart: boolean = false;\n\n /**\n * firstLast?: boolean\n * Shows or hides the first and last page buttons of the paging bar. Defaults to 'false'\n */\n @Input('firstLast') firstLast: boolean = true;\n\n /**\n * initialPage?: number\n * Sets starting page for the paging bar. Defaults to '1'\n */\n @Input('initialPage') initialPage: number = 1;\n\n /**\n * pageLinkCount?: number\n * Amount of page navigation links for the paging bar. Defaults to '0'\n */\n @Input('pageLinkCount')\n set pageLinkCount(pageLinkCount: number) {\n this._pageLinkCount = coerceNumberProperty(pageLinkCount);\n this._calculatePageLinks();\n this._changeDetectorRef.markForCheck();\n }\n get pageLinkCount(): number {\n return this._pageLinkCount;\n }\n\n /**\n * pageSize?: number\n * Selected page size for the pagination. Defaults 50.\n */\n @Input('pageSize')\n set pageSize(pageSize: number) {\n this._pageSize = coerceNumberProperty(pageSize);\n this._page = 1;\n if (this._initialized) {\n this._handleOnChange();\n }\n this._changeDetectorRef.markForCheck();\n }\n get pageSize(): number {\n return this._pageSize;\n }\n\n /**\n * total: number\n * Total rows for the pagination.\n */\n @Input('total')\n set total(total: number) {\n this._total = coerceNumberProperty(total);\n this._calculateRows();\n this._calculatePageLinks();\n this._changeDetectorRef.markForCheck();\n }\n get total(): number {\n return this._total;\n }\n\n /**\n * pageLinks: number[]\n * Returns the pageLinks in an array\n */\n get pageLinks(): number[] {\n return this._pageLinks;\n }\n\n /**\n * range: string\n * Returns the range of the rows.\n */\n get range(): string {\n return `${!this._toRow ? 0 : this._fromRow}-${this._toRow}`;\n }\n\n /**\n * page: number\n * Returns the current page.\n */\n get page(): number {\n return this._page;\n }\n\n /**\n * page: number\n * Returns the max page for the current pageSize and total.\n */\n get maxPage(): number {\n return Math.ceil(this._total / this._pageSize);\n }\n\n /**\n * change?: function\n * Method to be executed when page size changes or any button is clicked in the paging bar.\n * Emits an [IPageChangeEvent] implemented object.\n */\n @Output('change') onChange: EventEmitter<IPageChangeEvent> = new EventEmitter<IPageChangeEvent>();\n\n get isRTL(): boolean {\n if (this._dir) {\n return this._dir.dir === 'rtl';\n }\n return false;\n }\n\n constructor(@Optional() private _dir: Dir,\n private _changeDetectorRef: ChangeDetectorRef) {}\n\n ngOnInit(): void {\n this._page = coerceNumberProperty(this.initialPage);\n this._calculateRows();\n this._calculatePageLinks();\n this._initialized = true;\n this._changeDetectorRef.markForCheck();\n }\n\n /**\n * navigateToPage?: function\n * Navigates to a specific valid page. Returns 'true' if page is valid, else 'false'.\n */\n navigateToPage(page: number): boolean {\n if (page === 1 || (page >= 1 && page <= this.maxPage)) {\n this._page = coerceNumberProperty(Math.floor(page));\n this._handleOnChange();\n return true;\n }\n return false;\n }\n\n /**\n * firstPage?: function\n * Navigates to the first page. Returns 'true' if page is valid, else 'false'.\n */\n firstPage(): boolean {\n return this.navigateToPage(1);\n }\n\n /**\n * prevPage?: function\n * Navigates to the previous page. Returns 'true' if page is valid, else 'false'.\n */\n prevPage(): boolean {\n return this.navigateToPage(this._page - 1);\n }\n\n /**\n * nextPage?: function\n * Navigates to the next page. Returns 'true' if page is valid, else 'false'.\n */\n nextPage(): boolean {\n return this.navigateToPage(this._page + 1);\n }\n\n /**\n * lastPage?: function\n * Navigates to the last page. Returns 'true' if page is valid, else 'false'.\n */\n lastPage(): boolean {\n return this.navigateToPage(this.maxPage);\n }\n\n isMinPage(): boolean {\n return this._page <= 1;\n }\n\n isMaxPage(): boolean {\n return this._page >= this.maxPage;\n }\n\n private _calculateRows(): void {\n let top: number = (this._pageSize * this._page);\n this._fromRow = (this._pageSize * (this._page - 1)) + 1;\n this._toRow = this._total > top ? top : this._total;\n }\n\n /**\n * _calculatePageLinks?: function\n * Calculates the page links that should be shown to the user based on the current state of the paginator\n */\n private _calculatePageLinks(): void {\n // special case when 2 pageLinks, detect when hit end of pages so can lead in correct direction\n if (this.isMaxPage()) {\n this._hitEnd = true;\n this._hitStart = false;\n }\n // special case when 2 pageLinks, detect when hit start of pages so can lead in correct direction\n if (this.isMinPage()) {\n this._hitEnd = false;\n this._hitStart = true;\n }\n // If the pageLinkCount goes above max possible pages based on perpage setting then reset it to maxPage\n let actualPageLinkCount: number = this.pageLinkCount;\n if (this.pageLinkCount > this.maxPage) {\n actualPageLinkCount = this.maxPage;\n }\n // reset the pageLinks array\n this._pageLinks = [];\n // fill in the array with the pageLinks based on the current selected page\n let middlePageLinks: number = Math.floor(actualPageLinkCount / 2);\n for (let x: number = 0; x < actualPageLinkCount; x++) {\n // don't go past the maxPage in the pageLinks\n // have to handle even and odd pageLinkCounts differently so can still lead to the next numbers\n if ((actualPageLinkCount % 2 === 0 && (this.page + middlePageLinks > this.maxPage)) ||\n (actualPageLinkCount % 2 !== 0 && (this.page + middlePageLinks >= this.maxPage))) {\n this._pageLinks[x] = this.maxPage - (actualPageLinkCount - (x + 1));\n // if the selected page is after the middle then set that page as middle and get the correct balance on left and right\n // special handling when there are only 2 pageLinks to just drop to next if block so can lead to next numbers when moving to right\n // when moving to the left then go into this block\n } else if ((actualPageLinkCount > 2 || actualPageLinkCount <= 2 && this._hitEnd) && (this.page - middlePageLinks) > 0) {\n this._pageLinks[x] = (this.page - middlePageLinks) + x;\n // if the selected page is before the middle then set the pages based on the x index leading up to and after selected page\n } else if ((this.page - middlePageLinks) <= 0) {\n this._pageLinks[x] = x + 1;\n // other wise just set the array in order starting from the selected page\n } else {\n this._pageLinks[x] = this.page + x;\n }\n }\n }\n\n private _handleOnChange(): void {\n this._calculateRows();\n this._calculatePageLinks();\n let event: IPageChangeEvent = {\n page: this._page,\n maxPage: this.maxPage,\n pageSize: this._pageSize,\n total: this._total,\n fromRow: this._fromRow,\n toRow: this._toRow,\n };\n this._changeDetectorRef.markForCheck();\n this.onChange.emit(event);\n }\n\n}\n","import { NgModule } from '@angular/core';\n\nimport { CommonModule } from '@angular/common';\n\nimport { MatIconModule } from '@angular/material/icon';\nimport { MatButtonModule } from '@angular/material/button';\n\nimport { TdPagingBarComponent } from './paging-bar.component';\n\n@NgModule({\n imports: [\n CommonModule,\n MatIconModule,\n MatButtonModule,\n ],\n declarations: [\n TdPagingBarComponent,\n ],\n exports: [\n TdPagingBarComponent,\n ],\n})\nexport class CovalentPagingModule {\n\n}\n"],"names":["EventEmitter","coerceNumberProperty","Component","ChangeDetectionStrategy","Dir","Optional","ChangeDetectorRef","Input","Output","NgModule","CommonModule","MatIconModule","MatButtonModule"],"mappings":";;;;;;;;;;AAAA;QA0IE,8BAAgC,IAAS,EACrB,kBAAqC;YADzB,SAAI,GAAJ,IAAI,CAAK;YACrB,uBAAkB,GAAlB,kBAAkB,CAAmB;YAtHjD,cAAS,GAAW,EAAE,CAAC;YACvB,WAAM,GAAW,CAAC,CAAC;YACnB,UAAK,GAAW,CAAC,CAAC;YAClB,aAAQ,GAAW,CAAC,CAAC;YACrB,WAAM,GAAW,CAAC,CAAC;YACnB,iBAAY,GAAY,KAA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