all files / treegrid/ utils.js

99.07% Statements 107/108
98.59% Branches 70/71
100% Functions 14/14
99.07% Lines 106/107
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   60385× 1561× 1561×       58824×   84895× 270×   84625×   386× 1999× 24×     362×   23105×       195×   22910×   41× 41× 41× 1140× 1140× 287×     41×   196713×   196713× 196713× 153287×     153281× 50460×   102821× 31655× 31655×     31647× 2766×   28881× 28881×         71166×       43426×     52005× 52005×   435×   51570× 15235× 4186× 4186× 14861× 14861×     2661×       51570×   372× 319× 319×   53×   306× 306× 306× 306× 3503× 3503× 3503× 56333×   3503×   306×   205× 205× 205× 205× 205× 205× 205× 205×   203165× 4319× 4319×     198846× 198846×     957× 957×      
define(["require", "exports", "@syncfusion/ej2-grids", "@syncfusion/ej2-data", "@syncfusion/ej2-data", "@syncfusion/ej2-base"], function (require, exports, ej2_grids_1, ej2_data_1, ej2_data_2, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    function isRemoteData(parent) {
        if (parent.dataSource instanceof ej2_data_1.DataManager) {
            var adaptor = parent.dataSource.adaptor;
            return (adaptor instanceof ej2_data_1.ODataAdaptor ||
                (adaptor instanceof ej2_data_2.WebApiAdaptor) || (adaptor instanceof ej2_data_2.WebMethodAdaptor) ||
                (adaptor instanceof ej2_data_2.CacheAdaptor) || adaptor instanceof ej2_data_1.UrlAdaptor);
        }
        return false;
    }
    exports.isRemoteData = isRemoteData;
    function isCountRequired(parent) {
        if (parent.dataSource && 'result' in parent.dataSource) {
            return true;
        }
        return false;
    }
    exports.isCountRequired = isCountRequired;
    function isCheckboxcolumn(parent) {
        for (var i = 0; i < parent.columns.length; i++) {
            if (parent.columns[parseInt(i.toString(), 10)].showCheckbox) {
                return true;
            }
        }
        return false;
    }
    exports.isCheckboxcolumn = isCheckboxcolumn;
    function isFilterChildHierarchy(parent) {
        if ((!ej2_base_1.isNullOrUndefined(parent.grid.searchSettings.key) && parent.grid.searchSettings.key !== '' &&
            (parent.searchSettings.hierarchyMode === 'Child' || parent.searchSettings.hierarchyMode === 'None')) ||
            (parent.allowFiltering && parent.grid.filterSettings.columns.length &&
                (parent.filterSettings.hierarchyMode === 'Child' || parent.filterSettings.hierarchyMode === 'None'))) {
            return true;
        }
        return false;
    }
    exports.isFilterChildHierarchy = isFilterChildHierarchy;
    function findParentRecords(records) {
        var datas = [];
        var recordsLength = Object.keys(records).length;
        for (var i = 0, len = recordsLength; i < len; i++) {
            var hasChild = ej2_grids_1.getObject('hasChildRecords', records[parseInt(i.toString(), 10)]);
            if (hasChild) {
                datas.push(records[parseInt(i.toString(), 10)]);
            }
        }
        return datas;
    }
    exports.findParentRecords = findParentRecords;
    function getExpandStatus(parent, record, parents) {
        var parentRecord = ej2_base_1.isNullOrUndefined(record.parentItem) ? null :
            getParentData(parent, record.parentItem.uniqueID);
        var childParent;
        if (parentRecord != null) {
            if (parent.initialRender && !ej2_base_1.isNullOrUndefined(parentRecord[parent.expandStateMapping])
                && !parentRecord[parent.expandStateMapping]) {
                parentRecord.expanded = false;
                return false;
            }
            else if (parentRecord.expanded === false) {
                return false;
            }
            else if (parentRecord.parentItem) {
                childParent = getParentData(parent, parentRecord.parentItem.uniqueID);
                if (childParent && parent.initialRender && !ej2_base_1.isNullOrUndefined(childParent[parent.expandStateMapping])
                    && !childParent[parent.expandStateMapping]) {
                    childParent.expanded = false;
                    return false;
                }
                if (childParent && childParent.expanded === false) {
                    return false;
                }
                else Eif (childParent) {
                    return getExpandStatus(parent, childParent, parents);
                }
                return true;
            }
            else {
                return true;
            }
        }
        else {
            return true;
        }
    }
    exports.getExpandStatus = getExpandStatus;
    function findChildrenRecords(records) {
        var datas = [];
        if (ej2_base_1.isNullOrUndefined(records) || (!records.hasChildRecords && !ej2_base_1.isNullOrUndefined(records.childRecords)
            && !records.childRecords.length)) {
            return [];
        }
        if (!ej2_base_1.isNullOrUndefined(records.childRecords)) {
            var childRecords = records.childRecords.filter(function (item) { return !item.isSummaryRow; });
            var keys = Object.keys(childRecords);
            for (var i = 0, len = keys.length; i < len; i++) {
                datas.push(childRecords[parseInt(i.toString(), 10)]);
                if (childRecords[parseInt(i.toString(), 10)].hasChildRecords ||
                    (!ej2_base_1.isNullOrUndefined(childRecords[parseInt(i.toString(), 10)].childRecords) &&
                        childRecords[parseInt(i.toString(), 10)].childRecords.length)) {
                    datas = datas.concat(findChildrenRecords(childRecords[parseInt(i.toString(), 10)]));
                }
            }
        }
        return datas;
    }
    exports.findChildrenRecords = findChildrenRecords;
    function isOffline(parent) {
        if (isRemoteData(parent)) {
            var dm = parent.dataSource;
            return !ej2_base_1.isNullOrUndefined(dm.ready);
        }
        return true;
    }
    exports.isOffline = isOffline;
    function extendArray(array) {
        var objArr = [];
        var obj;
        var keys;
        for (var i = 0; array && i < array.length; i++) {
            keys = Object.keys(array[parseInt(i.toString(), 10)]);
            obj = {};
            for (var j = 0; j < keys.length; j++) {
                obj[keys[parseInt(j.toString(), 10)]] = array[parseInt(i.toString(), 10)][keys[parseInt(j.toString(), 10)]];
            }
            objArr.push(obj);
        }
        return objArr;
    }
    exports.extendArray = extendArray;
    function getPlainData(value) {
        delete value.hasChildRecords;
        delete value.childRecords;
        delete value.index;
        delete value.parentItem;
        delete value.level;
        delete value.taskData;
        delete value.uniqueID;
        return value;
    }
    exports.getPlainData = getPlainData;
    function getParentData(parent, value, requireFilter) {
        if (requireFilter) {
            var idFilter = 'uniqueIDFilterCollection';
            return parent["" + idFilter]["" + value];
        }
        else {
            var id = 'uniqueIDCollection';
            return parent["" + id]["" + value];
        }
    }
    exports.getParentData = getParentData;
    function isHidden(el) {
        var style = window.getComputedStyle(el);
        return ((style.display === 'none') || (style.visibility === 'hidden'));
    }
    exports.isHidden = isHidden;
});