all files / grid/services/ summary-model-generator.js

99.36% Statements 156/157
96.49% Branches 110/114
100% Functions 38/38
99.32% Lines 146/147
11 statements, 6 functions, 9 branches Ignored     
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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215          1627×   6527× 6527× 6527× 6527× 8132× 10617×     8132× 3451×     6527×   1043×   1550× 1550× 38×   1550× 1304× 1447×     1550× 56×   1550× 1550×   2374× 12×     2366× 2366× 2366× 2366× 1272×   2366×   1272× 1272× 1272× 1272× 1272× 54×   1218×     1272× 1272× 8224×     1272× 1272× 1272× 1272× 1272× 4870× 1272×   10092× 8224×       8224× 790×   8224×   8224×                 8224× 8224×   2366× 2366× 2366× 2366× 1272× 1272× 1272× 1531×   1272×   2366×   739×   1531× 1531× 1531× 1531× 1531× 1520×   1531× 1535× 1535× 1535×   1535×     1535× 1535× 1535× 1535× 1294× 1294×     1531× 1531× 1531×   1036×     719×   4255×   533× 533× 27×   629×   2843×     719×   4334×   2695× 2695× 1805× 1805×     1599×   2952×        
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
define(["require", "exports", "../models/row", "../models/column", "@syncfusion/ej2-base", "../base/util", "../base/enum", "../models/cell"], function (require, exports, row_1, column_1, ej2_base_1, util_1, enum_1, cell_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var SummaryModelGenerator = (function () {
        function SummaryModelGenerator(parent) {
            this.parent = parent;
        }
        SummaryModelGenerator.prototype.getData = function () {
            var _this = this;
            var rows = [];
            var row = this.parent.aggregates.slice();
            for (var i = 0; i < row.length; i++) {
                var columns = row[parseInt(i.toString(), 10)].columns.filter(function (column) {
                    return !(column.footerTemplate || column.groupFooterTemplate || column.groupCaptionTemplate)
                        || _this.columnSelector(column);
                });
                if (columns.length) {
                    rows.push({ columns: columns });
                }
            }
            return rows;
        };
        SummaryModelGenerator.prototype.columnSelector = function (column) {
            return column.footerTemplate !== undefined;
        };
        SummaryModelGenerator.prototype.getColumns = function (start) {
            var columns = [];
            if (this.parent.detailTemplate || !ej2_base_1.isNullOrUndefined(this.parent.childGrid)) {
                columns.push(new column_1.Column({}));
            }
            if (this.parent.allowGrouping) {
                for (var i = 0; i < this.parent.groupSettings.columns.length; i++) {
                    columns.push(new column_1.Column({}));
                }
            }
            if (this.parent.isRowDragable() && !start) {
                columns.push(new column_1.Column({}));
            }
            columns.push.apply(columns, this.parent.getColumns());
            return columns;
        };
        SummaryModelGenerator.prototype.generateRows = function (input, args, start, end, columns) {
            if (input.length === 0) {
                if (args === undefined || !(args.count || args.loadSummaryOnEmpty)) {
                    return [];
                }
            }
            var data = this.buildSummaryData(input, args);
            var rows = [];
            var row = this.getData();
            for (var i = 0; i < row.length; i++) {
                rows.push(this.getGeneratedRow(row[parseInt(i.toString(), 10)], data[parseInt(i.toString(), 10)], args ? args.level : undefined, start, end, args ? args.parentUid : undefined, columns));
            }
            return rows;
        };
        SummaryModelGenerator.prototype.getGeneratedRow = function (summaryRow, data, raw, start, end, parentUid, columns) {
            var tmp = [];
            var indents = this.getIndentByLevel();
            var isDetailGridAlone = !ej2_base_1.isNullOrUndefined(this.parent.childGrid);
            var indentLength = this.parent.getIndentCount();
            if (this.parent.groupSettings.columns.length && this.parent.allowRowDragAndDrop) {
                indents.push('e-indentcelltop');
            }
            else Iif (this.parent.isRowDragable() && !start) {
                indents = ['e-indentcelltop'];
            }
            var values = columns ? columns : this.getColumns(start);
            for (var i = 0; i < values.length; i++) {
                tmp.push(this.getGeneratedCell(values[parseInt(i.toString(), 10)], summaryRow, i >= indentLength ? this.getCellType() :
                    i === 0 && this.parent.childGrid ? enum_1.CellType.DetailFooterIntent : enum_1.CellType.Indent, indents[parseInt(i.toString(), 10)], isDetailGridAlone));
            }
            var row = new row_1.Row({ data: data, attributes: { class: 'e-summaryrow' } });
            row.cells = tmp;
            row.uid = util_1.getUid('grid-row');
            row.parentUid = parentUid;
            row.isAggregateRow = true;
            row.visible = tmp.some(function (cell) { return cell.isDataCell && cell.visible; });
            return row;
        };
        SummaryModelGenerator.prototype.getGeneratedCell = function (column, summaryRow, cellType, indent, isDetailGridAlone) {
            var sColumn = summaryRow.columns.filter(function (scolumn) { return scolumn.columnName === column.field; })[0];
            var attrs = {
                'style': { 'textAlign': column.textAlign },
                'e-mappinguid': column.uid, index: column.index
            };
            if (indent) {
                attrs.class = indent;
            }
            if (ej2_base_1.isNullOrUndefined(indent) && isDetailGridAlone) {
                attrs.class = 'e-detailindentcelltop';
            }
            var opt = {
                'visible': column.visible,
                'isDataCell': !ej2_base_1.isNullOrUndefined(sColumn),
                'isTemplate': sColumn && !ej2_base_1.isNullOrUndefined(sColumn.footerTemplate
                    || sColumn.groupFooterTemplate || sColumn.groupCaptionTemplate),
                'column': sColumn || {},
                'attributes': attrs,
                'cellType': cellType
            };
            opt.column.headerText = column.headerText;
            return new cell_1.Cell(opt);
        };
        SummaryModelGenerator.prototype.buildSummaryData = function (data, args) {
            var dummy = [];
            var summaryRows = this.getData();
            var single = {};
            for (var i = 0; i < summaryRows.length; i++) {
                single = {};
                var column = summaryRows[parseInt(i.toString(), 10)].columns;
                for (var j = 0; j < column.length; j++) {
                    single = this.setTemplate(column[parseInt(j.toString(), 10)], (args && args.aggregates) ? args : data, single);
                }
                dummy.push(single);
            }
            return dummy;
        };
        SummaryModelGenerator.prototype.getIndentByLevel = function () {
            return this.parent.groupSettings.columns.map(function () { return 'e-indentcelltop'; });
        };
        SummaryModelGenerator.prototype.setTemplate = function (column, data, single) {
            var types = column.type;
            var helper = {};
            var formatFn = column.getFormatter() || (function () { return function (a) { return a; }; })();
            var group = data;
            if (!(types instanceof Array)) {
                types = [column.type];
            }
            for (var i = 0; i < types.length; i++) {
                var key = column.field + ' - ' + types[parseInt(i.toString(), 10)].toLowerCase();
                var disp = column.columnName;
                var disablePageWiseAggregatesGroup = this.parent.groupSettings.disablePageWiseAggregates
                    && this.parent.groupSettings.columns.length && group.items ? true : false;
                var val = (types[parseInt(i.toString(), 10)] !== 'Custom' || disablePageWiseAggregatesGroup) && group.aggregates
                    && key in group.aggregates ? group.aggregates["" + key] :
                    util_1.calculateAggregate(types[parseInt(i.toString(), 10)], group.aggregates ? group : data, column, this.parent);
                single["" + disp] = single["" + disp] || {};
                single["" + disp]["" + key] = val;
                single["" + disp][types[parseInt(i.toString(), 10)]] = !ej2_base_1.isNullOrUndefined(val) ? formatFn(val) : ' ';
                if (group.field) {
                    single["" + disp].field = group.field;
                    single["" + disp].key = group.key;
                }
            }
            helper.format = column.getFormatter();
            column.setTemplate(helper);
            return single;
        };
        SummaryModelGenerator.prototype.getCellType = function () {
            return enum_1.CellType.Summary;
        };
        return SummaryModelGenerator;
    }());
    exports.SummaryModelGenerator = SummaryModelGenerator;
    var GroupSummaryModelGenerator = (function (_super) {
        __extends(GroupSummaryModelGenerator, _super);
        function GroupSummaryModelGenerator() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        GroupSummaryModelGenerator.prototype.columnSelector = function (column) {
            return column.groupFooterTemplate !== undefined;
        };
        GroupSummaryModelGenerator.prototype.getIndentByLevel = function (level) {
            Eif (level === void 0) { level = this.parent.groupSettings.columns.length; }
            if (this.parent.allowRowDragAndDrop && this.parent.groupSettings.columns.length) {
                level -= 1;
            }
            return this.parent.groupSettings.columns.map(function (v, indx) { return indx <= level - 1 ? '' : 'e-indentcelltop'; });
        };
        GroupSummaryModelGenerator.prototype.getCellType = function () {
            return enum_1.CellType.GroupSummary;
        };
        return GroupSummaryModelGenerator;
    }(SummaryModelGenerator));
    exports.GroupSummaryModelGenerator = GroupSummaryModelGenerator;
    var CaptionSummaryModelGenerator = (function (_super) {
        __extends(CaptionSummaryModelGenerator, _super);
        function CaptionSummaryModelGenerator() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        CaptionSummaryModelGenerator.prototype.columnSelector = function (column) {
            return column.groupCaptionTemplate !== undefined;
        };
        CaptionSummaryModelGenerator.prototype.getData = function () {
            var initVal = { columns: [] };
            return [_super.prototype.getData.call(this).reduce(function (prev, cur) {
                    prev.columns = prev.columns.concat(cur.columns);
                    return prev;
                }, initVal)];
        };
        CaptionSummaryModelGenerator.prototype.isEmpty = function () {
            return (this.getData()[0].columns || []).length === 0;
        };
        CaptionSummaryModelGenerator.prototype.getCellType = function () {
            return enum_1.CellType.CaptionSummary;
        };
        return CaptionSummaryModelGenerator;
    }(SummaryModelGenerator));
    exports.CaptionSummaryModelGenerator = CaptionSummaryModelGenerator;
});