@colijnit/corecomponents_v12 12.0.46 → 12.0.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10518,6 +10518,403 @@
10518
10518
  },] }
10519
10519
  ];
10520
10520
 
10521
+ var PaginationService = /** @class */ (function () {
10522
+ function PaginationService() {
10523
+ this.change = new rxjs.Subject();
10524
+ this.instances = {};
10525
+ }
10526
+ Object.defineProperty(PaginationService.prototype, "DEFAULT_ID", {
10527
+ get: function () {
10528
+ return PaginationService.DEFAULT_ID;
10529
+ },
10530
+ enumerable: false,
10531
+ configurable: true
10532
+ });
10533
+ PaginationService.prototype.register = function (instance) {
10534
+ if (!instance.id) {
10535
+ instance.id = PaginationService.DEFAULT_ID;
10536
+ }
10537
+ if (!this.instances[instance.id]) {
10538
+ this.instances[instance.id] = instance;
10539
+ this.change.next(instance.id);
10540
+ }
10541
+ else {
10542
+ var changed = this.updateInstance(instance);
10543
+ if (changed) {
10544
+ this.change.next(instance.id);
10545
+ }
10546
+ }
10547
+ };
10548
+ // Returns the current page number.
10549
+ PaginationService.prototype.getCurrentPage = function (id) {
10550
+ if (this.instances[id]) {
10551
+ return this.instances[id].currentPage;
10552
+ }
10553
+ };
10554
+ // Sets the current page number.
10555
+ PaginationService.prototype.setCurrentPage = function (id, page) {
10556
+ if (this.instances[id]) {
10557
+ var instance = this.instances[id];
10558
+ var maxPage = Math.ceil(instance.totalItems / instance.itemsPerPage);
10559
+ if (page <= maxPage && 1 <= page) {
10560
+ this.instances[id].currentPage = page;
10561
+ this.change.next(id);
10562
+ }
10563
+ }
10564
+ };
10565
+ // Sets the value of instance.totalItems
10566
+ PaginationService.prototype.setTotalItems = function (id, totalItems) {
10567
+ if (this.instances[id] && 0 <= totalItems) {
10568
+ this.instances[id].totalItems = totalItems;
10569
+ this.change.next(id);
10570
+ }
10571
+ };
10572
+ // Sets the value of instance.itemsPerPage.
10573
+ PaginationService.prototype.setItemsPerPage = function (id, itemsPerPage) {
10574
+ if (this.instances[id]) {
10575
+ this.instances[id].itemsPerPage = itemsPerPage;
10576
+ this.change.next(id);
10577
+ }
10578
+ };
10579
+ /**
10580
+ * Returns a clone of the pagination instance object matching the id. If no
10581
+ * id specified, returns the instance corresponding to the default id.
10582
+ */
10583
+ PaginationService.prototype.getInstance = function (id) {
10584
+ if (id === void 0) { id = PaginationService.DEFAULT_ID; }
10585
+ if (this.instances[id]) {
10586
+ return ObjectUtils.GetShallowClone(this.instances[id]);
10587
+ }
10588
+ return {};
10589
+ };
10590
+ /**
10591
+ * Check each property of the instance and update any that have changed. Return
10592
+ * true if any changes were made, else return false.
10593
+ */
10594
+ PaginationService.prototype.updateInstance = function (instance) {
10595
+ var changed = false;
10596
+ for (var prop in this.instances[instance.id]) {
10597
+ if (instance[prop] !== this.instances[instance.id][prop]) {
10598
+ this.instances[instance.id][prop] = instance[prop];
10599
+ changed = true;
10600
+ }
10601
+ }
10602
+ return changed;
10603
+ };
10604
+ return PaginationService;
10605
+ }());
10606
+ PaginationService.DEFAULT_ID = "DEFAULT_PAGINATION_ID";
10607
+ PaginationService.decorators = [
10608
+ { type: core.Injectable }
10609
+ ];
10610
+ PaginationService.ctorParameters = function () { return []; };
10611
+
10612
+ var PaginationComponent = /** @class */ (function () {
10613
+ function PaginationComponent(_paginationService) {
10614
+ var _this = this;
10615
+ this._paginationService = _paginationService;
10616
+ this.maxSize = 7;
10617
+ this.directionLinks = true;
10618
+ this.previousLabel = 'Vorige pagina';
10619
+ this.nextLabel = 'Volgende pagina';
10620
+ this.autoHide = false;
10621
+ // Emits the new page number.
10622
+ this.pageChange = new core.EventEmitter();
10623
+ this.showClass = true;
10624
+ this.pages = [];
10625
+ this.changeSub = this._paginationService.change.subscribe(function (id) {
10626
+ if (_this.id === id) {
10627
+ _this._updatePageLinks();
10628
+ }
10629
+ });
10630
+ }
10631
+ PaginationComponent.prototype.ngOnInit = function () {
10632
+ if (!this.id) {
10633
+ this.id = this._paginationService.DEFAULT_ID;
10634
+ }
10635
+ this._updatePageLinks();
10636
+ };
10637
+ PaginationComponent.prototype.ngOnChanges = function () {
10638
+ this._updatePageLinks();
10639
+ };
10640
+ PaginationComponent.prototype.ngOnDestroy = function () {
10641
+ this.changeSub.unsubscribe();
10642
+ };
10643
+ PaginationComponent.prototype.goToFirstPage = function () {
10644
+ if (!this.isOnFirstPage()) {
10645
+ this.setCurrentPage(1);
10646
+ }
10647
+ };
10648
+ PaginationComponent.prototype.goToPreviousPage = function () {
10649
+ if (!this.isOnFirstPage()) {
10650
+ this.setCurrentPage(this.getCurrentPage() - 1);
10651
+ }
10652
+ };
10653
+ PaginationComponent.prototype.goToNextPage = function () {
10654
+ if (!this.isOnLastPage()) {
10655
+ this.setCurrentPage(this.getCurrentPage() + 1);
10656
+ }
10657
+ };
10658
+ PaginationComponent.prototype.setCurrentPage = function (page) {
10659
+ this.pageChange.emit(page);
10660
+ };
10661
+ PaginationComponent.prototype.isOnFirstPage = function () {
10662
+ return this.getCurrentPage() === 1;
10663
+ };
10664
+ PaginationComponent.prototype.isOnLastPage = function () {
10665
+ return this.getLastPage() === this.getCurrentPage();
10666
+ };
10667
+ PaginationComponent.prototype.shouldBeHidden = function () {
10668
+ if (!this.autoHide) {
10669
+ return false;
10670
+ }
10671
+ else {
10672
+ var instance = this._paginationService.getInstance();
10673
+ return (instance.totalItems <= instance.itemsPerPage);
10674
+ }
10675
+ };
10676
+ /**
10677
+ * Updates the page links and checks that the current page is valid. Should run whenever the
10678
+ * PaginationService.change stream emits a value matching the current ID, or when any of the
10679
+ * input values changes.
10680
+ */
10681
+ PaginationComponent.prototype._updatePageLinks = function () {
10682
+ var paginationInstance = this._paginationService.getInstance(this.id);
10683
+ this.pages = this.createPageArray(paginationInstance.currentPage, paginationInstance.itemsPerPage, paginationInstance.totalItems, this.maxSize);
10684
+ var correctedCurrentPage = this.outOfBoundCorrection(paginationInstance);
10685
+ if (correctedCurrentPage !== paginationInstance.currentPage) {
10686
+ this.setCurrentPage(correctedCurrentPage);
10687
+ }
10688
+ };
10689
+ PaginationComponent.prototype.getCurrentPage = function () {
10690
+ return this._paginationService.getCurrentPage(this.id);
10691
+ };
10692
+ PaginationComponent.prototype.getLastPage = function () {
10693
+ var instance = this._paginationService.getInstance(this.id);
10694
+ return Math.ceil(instance.totalItems / instance.itemsPerPage);
10695
+ };
10696
+ /**
10697
+ * Checks that the instance.currentPage property is within bounds for the current page range.
10698
+ * If not, return a correct value for currentPage, or the current value if OK.
10699
+ */
10700
+ PaginationComponent.prototype.outOfBoundCorrection = function (instance) {
10701
+ var totalPages = Math.ceil(instance.totalItems / instance.itemsPerPage);
10702
+ if (totalPages < instance.currentPage && 0 < totalPages) {
10703
+ return totalPages;
10704
+ }
10705
+ else if (instance.currentPage < 1) {
10706
+ return 1;
10707
+ }
10708
+ return instance.currentPage;
10709
+ };
10710
+ // Returns an array of IPage objects to use in the pagination controls.
10711
+ PaginationComponent.prototype.createPageArray = function (currentPage, itemsPerPage, totalItems, paginationRange) {
10712
+ // paginationRange could be a string if passed from attribute, so cast to number.
10713
+ paginationRange = +paginationRange;
10714
+ var pages = [];
10715
+ var totalPages = Math.ceil(totalItems / itemsPerPage);
10716
+ var halfWay = Math.ceil(paginationRange / 2);
10717
+ var isStart = currentPage <= halfWay;
10718
+ var isEnd = totalPages - halfWay < currentPage;
10719
+ var isMiddle = !isStart && !isEnd;
10720
+ var ellipsesNeeded = paginationRange < totalPages;
10721
+ var i = 1;
10722
+ while (i <= totalPages && i <= paginationRange) {
10723
+ var label = void 0;
10724
+ var pageNumber = this.calculatePageNumber(i, currentPage, paginationRange, totalPages);
10725
+ var openingEllipsesNeeded = (i === 2 && (isMiddle || isEnd));
10726
+ var closingEllipsesNeeded = (i === paginationRange - 1 && (isMiddle || isStart));
10727
+ if (ellipsesNeeded && (openingEllipsesNeeded || closingEllipsesNeeded)) {
10728
+ label = '...';
10729
+ }
10730
+ else {
10731
+ label = '' + pageNumber;
10732
+ }
10733
+ pages.push({
10734
+ label: label,
10735
+ value: pageNumber
10736
+ });
10737
+ i++;
10738
+ }
10739
+ return pages;
10740
+ };
10741
+ // Given the position in the sequence of pagination links [i], figure out what page number corresponds to that position.
10742
+ PaginationComponent.prototype.calculatePageNumber = function (i, currentPage, paginationRange, totalPages) {
10743
+ var halfWay = Math.ceil(paginationRange / 2);
10744
+ if (i === paginationRange) {
10745
+ return totalPages;
10746
+ }
10747
+ else if (i === 1) {
10748
+ return i;
10749
+ }
10750
+ else if (paginationRange < totalPages) {
10751
+ if (totalPages - halfWay < currentPage) {
10752
+ return totalPages - paginationRange + i;
10753
+ }
10754
+ else if (halfWay < currentPage) {
10755
+ return currentPage - halfWay + i;
10756
+ }
10757
+ else {
10758
+ return i;
10759
+ }
10760
+ }
10761
+ else {
10762
+ return i;
10763
+ }
10764
+ };
10765
+ return PaginationComponent;
10766
+ }());
10767
+ PaginationComponent.decorators = [
10768
+ { type: core.Component, args: [{
10769
+ selector: 'co-pagination',
10770
+ template: "\n <div class=\"pagination-component-main-wrapper\" *ngIf=\"!shouldBeHidden()\">\n <div>\n <ng-content></ng-content>\n </div>\n <ul class=\"pagination\">\n <li *ngIf=\"directionLinks\" class=\"pagination-previous\">\n <a (click)=\"goToPreviousPage()\" [class.disabled]=\"isOnFirstPage()\">{{ previousLabel }}</a>\n </li>\n <li *ngFor=\"let page of pages\" [class.current]=\"getCurrentPage() === page.value\" (click)=\"setCurrentPage(page.value)\">\n <span>{{page.label}}</span>\n </li>\n <li *ngIf=\"directionLinks\" class=\"pagination-next\">\n <a (click)=\"goToNextPage()\" [class.disabled]=\"isOnLastPage()\">{{ nextLabel }}</a>\n </li>\n </ul>\n </div>\n ",
10771
+ encapsulation: core.ViewEncapsulation.None
10772
+ },] }
10773
+ ];
10774
+ PaginationComponent.ctorParameters = function () { return [
10775
+ { type: PaginationService }
10776
+ ]; };
10777
+ PaginationComponent.propDecorators = {
10778
+ template: [{ type: core.ViewChild, args: ['template',] }],
10779
+ id: [{ type: core.Input }],
10780
+ maxSize: [{ type: core.Input }],
10781
+ directionLinks: [{ type: core.Input }],
10782
+ previousLabel: [{ type: core.Input }],
10783
+ nextLabel: [{ type: core.Input }],
10784
+ autoHide: [{ type: core.Input }],
10785
+ pageChange: [{ type: core.Output }],
10786
+ showClass: [{ type: core.HostBinding, args: ['class.co-pagination',] }]
10787
+ };
10788
+
10789
+ var LARGE_NUMBER = 999999999;
10790
+ var PaginatePipe = /** @class */ (function () {
10791
+ function PaginatePipe(paginateService) {
10792
+ this.paginateService = paginateService;
10793
+ // store the values from the last time the pipe
10794
+ this.state = {};
10795
+ }
10796
+ PaginatePipe.prototype.transform = function (collection, args) {
10797
+ // When an observable is passed through the AsyncPipe, it will output
10798
+ // `null` until the subscription resolves. In this case, we want to
10799
+ // use the cached data from the `state` object to prevent the NgFor
10800
+ // from flashing empty until the real values arrive.
10801
+ if (!(collection instanceof Array)) {
10802
+ var _id = args.id || this.paginateService.DEFAULT_ID;
10803
+ if (this.state[_id]) {
10804
+ return this.state[_id].slice;
10805
+ }
10806
+ else {
10807
+ return collection;
10808
+ }
10809
+ }
10810
+ var serverSideMode = args.totalItems !== undefined;
10811
+ var instance = this._createInstance(collection, args);
10812
+ var id = instance.id;
10813
+ var start;
10814
+ var end;
10815
+ var perPage = instance.itemsPerPage;
10816
+ this.paginateService.register(instance);
10817
+ if (!serverSideMode && collection instanceof Array) {
10818
+ perPage = perPage || LARGE_NUMBER;
10819
+ start = (instance.currentPage - 1) * perPage;
10820
+ end = start + perPage;
10821
+ var isIdentical = this._stateIsIdentical(id, collection, start, end);
10822
+ if (isIdentical) {
10823
+ return this.state[id].slice;
10824
+ }
10825
+ else {
10826
+ var slice = collection.slice(start, end);
10827
+ this._saveState(id, collection, slice, start, end);
10828
+ this.paginateService.change.next(id);
10829
+ return slice;
10830
+ }
10831
+ }
10832
+ // save the state for server-side collection to avoid null
10833
+ // flash as new data loads.
10834
+ this._saveState(id, collection, collection, start, end);
10835
+ return collection;
10836
+ };
10837
+ // Create an IPaginationInstance object, using defaults for any optional properties not supplied.
10838
+ PaginatePipe.prototype._createInstance = function (collection, args) {
10839
+ var config = args;
10840
+ this._checkConfig(config);
10841
+ return {
10842
+ id: config.id || this.paginateService.DEFAULT_ID,
10843
+ itemsPerPage: config.itemsPerPage || 0,
10844
+ currentPage: config.currentPage || 1,
10845
+ totalItems: config.totalItems || collection.length
10846
+ };
10847
+ };
10848
+ // Ensure the argument passed to the filter contains the required properties.
10849
+ PaginatePipe.prototype._checkConfig = function (config) {
10850
+ var required = ["itemsPerPage", "currentPage"];
10851
+ var missing = required.filter(function (prop) { return !config.hasOwnProperty(prop); });
10852
+ if (0 < missing.length) {
10853
+ throw new Error("PaginatePipe: Argument is missing the following required properties: " + missing.join(", "));
10854
+ }
10855
+ };
10856
+ /**
10857
+ * To avoid returning a brand new array each time the pipe is run, we store the state of the sliced
10858
+ * array for a given id. This means that the next time the pipe is run on this collection & id, we just
10859
+ * need to check that the collection, start and end points are all identical, and if so, return the
10860
+ * last sliced array.
10861
+ */
10862
+ PaginatePipe.prototype._saveState = function (id, collection, slice, start, end) {
10863
+ this.state[id] = {
10864
+ collection: collection,
10865
+ size: collection.length,
10866
+ slice: slice,
10867
+ start: start,
10868
+ end: end
10869
+ };
10870
+ };
10871
+ // For a given id, returns true if the collection, size, start and end values are identical.
10872
+ PaginatePipe.prototype._stateIsIdentical = function (id, collection, start, end) {
10873
+ var state = this.state[id];
10874
+ if (!state) {
10875
+ return false;
10876
+ }
10877
+ return state.collection === collection &&
10878
+ state.size === collection.length &&
10879
+ state.start === start &&
10880
+ state.end === end;
10881
+ };
10882
+ return PaginatePipe;
10883
+ }());
10884
+ PaginatePipe.decorators = [
10885
+ { type: core.Pipe, args: [{
10886
+ name: 'paginate',
10887
+ pure: false
10888
+ },] }
10889
+ ];
10890
+ PaginatePipe.ctorParameters = function () { return [
10891
+ { type: PaginationService }
10892
+ ]; };
10893
+
10894
+ var PaginationModule = /** @class */ (function () {
10895
+ function PaginationModule() {
10896
+ }
10897
+ return PaginationModule;
10898
+ }());
10899
+ PaginationModule.decorators = [
10900
+ { type: core.NgModule, args: [{
10901
+ imports: [
10902
+ common.CommonModule
10903
+ ],
10904
+ providers: [
10905
+ PaginationService
10906
+ ],
10907
+ declarations: [
10908
+ PaginationComponent,
10909
+ PaginatePipe
10910
+ ],
10911
+ exports: [
10912
+ PaginationComponent,
10913
+ PaginatePipe
10914
+ ]
10915
+ },] }
10916
+ ];
10917
+
10521
10918
  /*
10522
10919
  * Public API Surface of corecomponents
10523
10920
  */
@@ -10603,6 +11000,8 @@
10603
11000
  exports.MultiSelectListComponent = MultiSelectListComponent;
10604
11001
  exports.MultiSelectListModule = MultiSelectListModule;
10605
11002
  exports.ObserveVisibilityModule = ObserveVisibilityModule;
11003
+ exports.PaginationComponent = PaginationComponent;
11004
+ exports.PaginationModule = PaginationModule;
10606
11005
  exports.PopupButtonsComponent = PopupButtonsComponent;
10607
11006
  exports.PopupMessageDisplayComponent = PopupMessageDisplayComponent;
10608
11007
  exports.PopupModule = PopupModule;
@@ -10623,6 +11022,8 @@
10623
11022
  exports["ɵbc"] = PrependPipe;
10624
11023
  exports["ɵbd"] = ClickOutsideDirective;
10625
11024
  exports["ɵbe"] = ClickOutsideMasterService;
11025
+ exports["ɵbf"] = PaginationService;
11026
+ exports["ɵbg"] = PaginatePipe;
10626
11027
  exports["ɵc"] = CoRippleDirective;
10627
11028
  exports["ɵd"] = CoViewportRulerService;
10628
11029
  exports["ɵe"] = CoScrollDispatcherService;