all files / grid/actions/ aggregate.js

96.43% Statements 81/84
88.89% Branches 24/27
100% Functions 18/18
96.43% Lines 81/84
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   20× 20× 20×   7981×   20× 20× 20× 20× 60×   20× 20× 20× 20× 20× 15× 15×   20× 20×   29× 29× 73× 73× 73× 73× 73×     73× 66×                 15×   14×   14× 14× 14× 14× 14×     20×     20× 20× 20×   20× 18×     20× 20×         29× 55× 73×          
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../base/enum", "../base/constant", "../renderer/footer-renderer", "../renderer/summary-cell-renderer", "../services/summary-model-generator"], function (require, exports, ej2_base_1, ej2_base_2, enum_1, constant_1, footer_renderer_1, summary_cell_renderer_1, summary_model_generator_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Aggregate = (function () {
        function Aggregate(parent, locator) {
            this.parent = parent;
            this.locator = locator;
            this.addEventListener();
        }
        Aggregate.prototype.getModuleName = function () {
            return 'aggregate';
        };
        Aggregate.prototype.initiateRender = function () {
            var _this = this;
            var cellFac = this.locator.getService('cellRendererFactory');
            var instance = new summary_cell_renderer_1.SummaryCellRenderer(this.parent, this.locator);
            [enum_1.CellType.Summary, enum_1.CellType.CaptionSummary, enum_1.CellType.GroupSummary].forEach(function (type) {
                return cellFac.addCellRenderer(type, instance);
            });
            this.footerRenderer = new footer_renderer_1.FooterRenderer(this.parent, this.locator);
            this.footerRenderer.renderPanel();
            this.footerRenderer.renderTable();
            this.locator.register('footerRenderer', this.footerRenderer);
            var fn = function () {
                _this.prepareSummaryInfo();
                _this.parent.off(constant_1.dataReady, fn);
            };
            this.parent.on(constant_1.dataReady, fn, this);
            this.parent.on(constant_1.dataReady, this.footerRenderer.refresh, this.footerRenderer);
        };
        Aggregate.prototype.prepareSummaryInfo = function () {
            var _this = this;
            summaryIterator(this.parent.aggregates, function (column) {
                var dataColumn = _this.parent.getColumnByField(column.field) || {};
                var type = dataColumn.type;
                column.setPropertiesSilent({ format: _this.getFormatFromType(column.format, type) });
                column.setFormatter(_this.parent.locale);
                column.setPropertiesSilent({ columnName: column.columnName || column.field });
            });
        };
        Aggregate.prototype.getFormatFromType = function (format, type) {
            if (ej2_base_2.isNullOrUndefined(type) || typeof format !== 'string') {
                return format;
            }
            var obj;
            switch (type) {
                case 'number':
                    obj = { format: format };
                    break;
                case 'date':
                    obj = { type: type, skeleton: format };
                    break;
                case 'datetime':
                    obj = { type: 'dateTime', skeleton: format };
                    break;
            }
            return obj;
        };
        Aggregate.prototype.onPropertyChanged = function (e) {
            if (e.module !== this.getModuleName()) {
                return;
            }
            if (ej2_base_2.isNullOrUndefined(this.footerRenderer)) {
                this.initiateRender();
            }
            this.prepareSummaryInfo();
            this.footerRenderer.refresh();
            var cModel = new summary_model_generator_1.CaptionSummaryModelGenerator(this.parent);
            var gModel = new summary_model_generator_1.GroupSummaryModelGenerator(this.parent);
            if (gModel.getData().length !== 0 || !cModel.isEmpty()) {
                this.parent.notify(constant_1.modelChanged, {});
            }
        };
        Aggregate.prototype.addEventListener = function () {
            Iif (this.parent.isDestroyed) {
                return;
            }
            this.parent.on(constant_1.initialEnd, this.initiateRender, this);
            this.parent.on(constant_1.uiUpdate, this.onPropertyChanged, this);
            this.parent.on(constant_1.refreshAggregates, this.refresh, this);
        };
        Aggregate.prototype.removeEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.footerRenderer.removeEventListener();
            this.parent.off(constant_1.initialEnd, this.initiateRender);
            this.parent.off(constant_1.dataReady, this.footerRenderer.refresh);
            this.parent.off(constant_1.uiUpdate, this.onPropertyChanged);
            this.parent.off(constant_1.refreshAggregates, this.refresh);
        };
        Aggregate.prototype.destroy = function () {
            this.removeEventListener();
            ej2_base_1.remove(this.parent.element.querySelector('.e-gridfooter'));
        };
        Aggregate.prototype.refresh = function (data) {
            var editedData = data instanceof Array ? data : [data];
            this.parent.notify(constant_1.refreshFooterRenderer, editedData);
            Eif (this.parent.groupSettings.columns.length > 0) {
                this.parent.notify(constant_1.groupAggregates, editedData);
            }
        };
        return Aggregate;
    }());
    exports.Aggregate = Aggregate;
    function summaryIterator(aggregates, callback) {
        aggregates.forEach(function (row) {
            row.columns.forEach(function (column) {
                callback(column, row);
            });
        });
    }
    exports.summaryIterator = summaryIterator;
});