all files / treegrid/actions/ page.js

98.25% Statements 112/114
86% Branches 43/50
100% Functions 19/19
98.23% Lines 111/113
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163   148× 148× 148×   148× 148×   146× 145×     11395×     146×             41× 1333×   41× 72×       41×             41× 41×             19× 19× 61× 61× 61× 16× 422×   16×     19× 19× 61×   19×   263× 263× 263× 26×       266× 266× 266×         263× 263× 263× 263× 263×       259× 8818×     263× 263× 263× 263× 263× 263× 51× 51× 51×   263× 263× 263× 263×   266×        
define(["require", "exports", "@syncfusion/ej2-grids", "@syncfusion/ej2-grids", "../base/constant", "@syncfusion/ej2-data", "@syncfusion/ej2-base", "../utils"], function (require, exports, ej2_grids_1, ej2_grids_2, events, ej2_data_1, ej2_base_1, utils_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Page = (function () {
        function Page(parent) {
            ej2_grids_1.Grid.Inject(ej2_grids_2.Page);
            this.parent = parent;
            this.addEventListener();
        }
        Page.prototype.addEventListener = function () {
            this.parent.on(events.localPagedExpandCollapse, this.collapseExpandPagedchilds, this);
            this.parent.on(events.pagingActions, this.pageAction, this);
        };
        Page.prototype.removeEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.parent.off(events.localPagedExpandCollapse, this.collapseExpandPagedchilds);
            this.parent.off(events.pagingActions, this.pageAction);
        };
        Page.prototype.getModuleName = function () {
            return 'pager';
        };
        Page.prototype.refresh = function () {
            this.parent.grid.pagerModule.refresh();
        };
        Page.prototype.destroy = function () {
            this.removeEventListener();
        };
        Page.prototype.goToPage = function (pageNo) {
            this.parent.grid.pagerModule.goToPage(pageNo);
        };
        Page.prototype.updateExternalMessage = function (message) {
            Iif (ej2_base_1.isNullOrUndefined(message)) {
                var error = 'The provided value for the message is undefined. Please ensure the message contains string.';
                this.parent.trigger(events.actionFailure, { error: error });
            }
            this.parent.grid.pagerModule.updateExternalMessage(message);
        };
        Page.prototype.collapseExpandPagedchilds = function (rowDetails) {
            rowDetails.record.expanded = rowDetails.action === 'collapse' ? false : true;
            this.parent.flatData.map(function (e) { return e.expanded = e.uniqueID === rowDetails.record.uniqueID &&
                e.expanded !== rowDetails.record.expanded ? rowDetails.record.expanded : e.expanded; });
            if (this.parent.enableImmutableMode) {
                var primaryKeyField_1 = this.parent.getPrimaryKeyFieldNames()[0];
                var record = this.parent.flatData.filter(function (e) {
                    return e["" + primaryKeyField_1] === rowDetails.record["" + primaryKeyField_1];
                });
                Eif (record.length) {
                    record[0].expanded = rowDetails.record.expanded;
                }
            }
            var ret = {
                result: this.parent.flatData,
                row: rowDetails.row,
                action: rowDetails.action,
                record: rowDetails.record,
                count: this.parent.flatData.length
            };
            ej2_base_1.getValue('grid.renderModule', this.parent).dataManagerSuccess(ret);
            if (this.parent.enableImmutableMode) {
                var row = 'row';
                var action = 'action';
                var targetEle = void 0;
                if (ret["" + action] === 'collapse') {
                    targetEle = ret["" + row].getElementsByClassName('e-treegridexpand')[0];
                    Eif (!ej2_base_1.isNullOrUndefined(targetEle)) {
                        ej2_base_1.removeClass([targetEle], 'e-treegridexpand');
                        ej2_base_1.addClass([targetEle], 'e-treegridcollapse');
                    }
                }
                else Eif (ret["" + action] === 'expand') {
                    targetEle = ret["" + row].getElementsByClassName('e-treegridcollapse')[0];
                    Eif (!ej2_base_1.isNullOrUndefined(targetEle)) {
                        ej2_base_1.removeClass([targetEle], 'e-treegridcollapse');
                        ej2_base_1.addClass([targetEle], 'e-treegridexpand');
                    }
                }
            }
        };
        Page.prototype.pageRoot = function (pagedResults, temp, result) {
            var newResults = ej2_base_1.isNullOrUndefined(result) ? [] : result;
            var _loop_1 = function (t) {
                newResults.push(temp[parseInt(t.toString(), 10)]);
                var res = [];
                if (temp[parseInt(t.toString(), 10)].hasChildRecords) {
                    res = pagedResults.filter(function (e) {
                        return temp[parseInt(t.toString(), 10)].uniqueID === e.parentUniqueID;
                    });
                    newResults = this_1.pageRoot(pagedResults, res, newResults);
                }
            };
            var this_1 = this;
            for (var t = 0; t < temp.length; t++) {
                _loop_1(t);
            }
            return newResults;
        };
        Page.prototype.updatePageSize = function (pageingDetails) {
            var updateSize = pageingDetails.result.length;
            var gridPagerModule = this.parent.grid.pagerModule;
            if (this.parent.pageSettings.pageSizes === true) {
                if (gridPagerModule.pagerObj.pagerdropdownModule['dropDownListObject'].value === gridPagerModule.pagerObj.getLocalizedLabel('All')) {
                    gridPagerModule['pagerObj'].totalRecordsCount = updateSize;
                    this.parent.grid.pageSettings.pageSize = updateSize;
                }
            }
        };
        Page.prototype.pageAction = function (pageingDetails) {
            var _this = this;
            var dm = new ej2_data_1.DataManager(pageingDetails.result);
            if (this.parent.pageSettings.pageSizeMode === 'Root') {
                var temp = [];
                var propname = (this.parent.grid.filterSettings.columns.length > 0) &&
                    (this.parent.filterSettings.hierarchyMode === 'Child' || this.parent.filterSettings.hierarchyMode === 'None') ?
                    'filterLevel' : 'level';
                var query = new ej2_data_1.Query().where(propname, 'equal', 0);
                temp = dm.executeLocal(query);
                pageingDetails.count = temp.length;
                var size = this.parent.grid.pageSettings.pageSize;
                var current = this.parent.grid.pageSettings.currentPage;
                var skip = size * (current - 1);
                query = query.skip(skip).take(size);
                temp = dm.executeLocal(query);
                var newResults = this.pageRoot(pageingDetails.result, temp);
                pageingDetails.result = newResults;
            }
            else {
                var dm_1 = new ej2_data_1.DataManager(pageingDetails.result);
                var expanded = new ej2_data_1.Predicate('expanded', 'notequal', null).or('expanded', 'notequal', undefined);
                var parents_1 = dm_1.executeLocal(new ej2_data_1.Query().where(expanded));
                var visualData = void 0;
                if (utils_1.isFilterChildHierarchy(this.parent) && (pageingDetails.actionArgs.action !== 'collapse' &&
                    pageingDetails.actionArgs.action !== 'expand')) {
                    visualData = parents_1;
                }
                else {
                    visualData = parents_1.filter(function (e) {
                        return utils_1.getExpandStatus(_this.parent, e, parents_1);
                    });
                }
                pageingDetails.count = visualData.length;
                var query = new ej2_data_1.Query();
                var size = this.parent.grid.pageSettings.pageSize;
                this.updatePageSize(pageingDetails);
                var current = this.parent.grid.pageSettings.currentPage;
                if (visualData.length < (current * size)) {
                    current = (Math.floor(visualData.length / size)) + ((visualData.length % size) ? 1 : 0);
                    current = current ? current : 1;
                    this.parent.grid.setProperties({ pageSettings: { currentPage: current } }, true);
                }
                var skip = size * (current - 1);
                query = query.skip(skip).take(size);
                dm_1.dataSource.json = visualData;
                pageingDetails.result = dm_1.executeLocal(query);
            }
            this.parent.notify('updateAction', pageingDetails);
        };
        return Page;
    }());
    exports.Page = Page;
});