blob: 2a998e8cf45b97e512dd83a1f39e704ef28c4f2f [file] [log] [blame]
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/common"),require("@angular/material/icon"),require("@angular/material/button"),require("@angular/cdk/coercion"),require("@angular/cdk/bidi")):"function"==typeof define&&define.amd?define("@covalent/core/paging",["exports","@angular/core","@angular/common","@angular/material/icon","@angular/material/button","@angular/cdk/coercion","@angular/cdk/bidi"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).covalent=t.covalent||{},t.covalent.core=t.covalent.core||{},t.covalent.core.paging={}),t.ng.core,t.ng.common,t.ng.material.icon,t.ng.material.button,t.ng.cdk.coercion,t.ng.cdk.bidi)}(this,(function(t,e,n,i,a,o,r){"use strict";var s=function(){function t(t,n){this._dir=t,this._changeDetectorRef=n,this._pageSize=50,this._total=0,this._page=1,this._fromRow=1,this._toRow=1,this._initialized=!1,this._pageLinks=[],this._pageLinkCount=0,this._hitEnd=!1,this._hitStart=!1,this.firstLast=!0,this.initialPage=1,this.change=new e.EventEmitter}return Object.defineProperty(t.prototype,"pageLinkCount",{get:function(){return this._pageLinkCount},set:function(t){this._pageLinkCount=o.coerceNumberProperty(t),this._calculatePageLinks(),this._changeDetectorRef.markForCheck()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"pageSize",{get:function(){return this._pageSize},set:function(t){this._pageSize=o.coerceNumberProperty(t),this._page=1,this._initialized&&this._handleOnChange(),this._changeDetectorRef.markForCheck()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"total",{get:function(){return this._total},set:function(t){this._total=o.coerceNumberProperty(t),this._calculateRows(),this._calculatePageLinks(),this._changeDetectorRef.markForCheck()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"pageLinks",{get:function(){return this._pageLinks},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"range",{get:function(){return(this._toRow?this._fromRow:0)+"-"+this._toRow},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"page",{get:function(){return this._page},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"maxPage",{get:function(){return Math.ceil(this._total/this._pageSize)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isRTL",{get:function(){return!!this._dir&&"rtl"===this._dir.dir},enumerable:!1,configurable:!0}),t.prototype.ngOnInit=function(){this._page=o.coerceNumberProperty(this.initialPage),this._calculateRows(),this._calculatePageLinks(),this._initialized=!0,this._changeDetectorRef.markForCheck()},t.prototype.navigateToPage=function(t){return(1===t||t>=1&&t<=this.maxPage)&&(this._page=o.coerceNumberProperty(Math.floor(t)),this._handleOnChange(),!0)},t.prototype.firstPage=function(){return this.navigateToPage(1)},t.prototype.prevPage=function(){return this.navigateToPage(this._page-1)},t.prototype.nextPage=function(){return this.navigateToPage(this._page+1)},t.prototype.lastPage=function(){return this.navigateToPage(this.maxPage)},t.prototype.isMinPage=function(){return this._page<=1},t.prototype.isMaxPage=function(){return this._page>=this.maxPage},t.prototype._calculateRows=function(){var t=this._pageSize*this._page;this._fromRow=this._pageSize*(this._page-1)+1,this._toRow=this._total>t?t:this._total},t.prototype._calculatePageLinks=function(){this.isMaxPage()&&(this._hitEnd=!0,this._hitStart=!1),this.isMinPage()&&(this._hitEnd=!1,this._hitStart=!0);var t=this.pageLinkCount;this.pageLinkCount>this.maxPage&&(t=this.maxPage),this._pageLinks=[];for(var e=Math.floor(t/2),n=0;n<t;n++)t%2==0&&this.page+e>this.maxPage||t%2!=0&&this.page+e>=this.maxPage?this._pageLinks[n]=this.maxPage-(t-(n+1)):(t>2||t<=2&&this._hitEnd)&&this.page-e>0?this._pageLinks[n]=this.page-e+n:this.page-e<=0?this._pageLinks[n]=n+1:this._pageLinks[n]=this.page+n},t.prototype._handleOnChange=function(){this._calculateRows(),this._calculatePageLinks();var t={page:this._page,maxPage:this.maxPage,pageSize:this._pageSize,total:this._total,fromRow:this._fromRow,toRow:this._toRow};this._changeDetectorRef.markForCheck(),this.change.emit(t)},t}();s.decorators=[{type:e.Component,args:[{changeDetection:e.ChangeDetectionStrategy.OnPush,selector:"td-paging-bar",template:'<div class="td-paging-bar" (change)="$event.stopPropagation()">\n <ng-content></ng-content>\n <div class="td-paging-bar-navigation">\n <button\n mat-icon-button\n class="td-paging-bar-first-page"\n type="button"\n *ngIf="firstLast"\n [disabled]="isMinPage()"\n (click)="firstPage()"\n >\n <mat-icon>{{ isRTL ? \'skip_next\' : \'skip_previous\' }}</mat-icon>\n </button>\n <button mat-icon-button class="td-paging-bar-prev-page" type="button" [disabled]="isMinPage()" (click)="prevPage()">\n <mat-icon>{{ isRTL ? \'navigate_next\' : \'navigate_before\' }}</mat-icon>\n </button>\n <ng-template *ngIf="pageLinkCount > 0" let-link let-index="index" ngFor [ngForOf]="pageLinks">\n <button\n class="td-paging-bar-link-page"\n mat-icon-button\n type="button"\n [color]="page === link ? \'accent\' : undefined"\n (click)="navigateToPage(link)"\n >\n {{ link }}\n </button>\n </ng-template>\n <button mat-icon-button class="td-paging-bar-next-page" type="button" [disabled]="isMaxPage()" (click)="nextPage()">\n <mat-icon>{{ isRTL ? \'navigate_before\' : \'navigate_next\' }}</mat-icon>\n </button>\n <button\n mat-icon-button\n class="td-paging-bar-last-page"\n type="button"\n *ngIf="firstLast"\n [disabled]="isMaxPage()"\n (click)="lastPage()"\n >\n <mat-icon>{{ isRTL ? \'skip_previous\' : \'skip_next\' }}</mat-icon>\n </button>\n </div>\n</div>\n',styles:[":host{display:block}:host .td-paging-bar{-ms-flex-align:center;-ms-flex-direction:row;-ms-flex-line-pack:center;-ms-flex-pack:end;align-content:center;align-items:center;box-sizing:border-box;display:-ms-flexbox;display:flex;flex-direction:row;height:48px;justify-content:flex-end;max-width:100%}:host .td-paging-bar ::ng-deep>*{margin:0 10px}:host .td-paging-bar [mat-icon-button]{font-size:12px;font-weight:400}"]}]}],s.ctorParameters=function(){return[{type:r.Dir,decorators:[{type:e.Optional}]},{type:e.ChangeDetectorRef}]},s.propDecorators={firstLast:[{type:e.Input}],initialPage:[{type:e.Input}],pageLinkCount:[{type:e.Input,args:["pageLinkCount"]}],pageSize:[{type:e.Input,args:["pageSize"]}],total:[{type:e.Input,args:["total"]}],change:[{type:e.Output}]};var g=function(){};g.decorators=[{type:e.NgModule,args:[{imports:[n.CommonModule,i.MatIconModule,a.MatButtonModule],declarations:[s],exports:[s]}]}],t.CovalentPagingModule=g,t.TdPagingBarComponent=s,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=covalent-core-paging.umd.min.js.map