all files / base/ utils.js

97.65% Statements 83/85
90.91% Branches 50/55
100% Functions 13/13
97.65% Lines 83/85
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   876× 876× 9564× 277×   9287×   876×   311247×   480×   310767×   1180×     309587×     69218×   60×   69158×   261× 261× 2215× 2215×   261×   710×         709×   1991× 271× 271× 271×   271×   271×     1720× 1720× 12219×   12219×   12219×   1720×                 18× 18×     720× 720× 901×     711× 711×     720×   107559×   465×   167×      
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-data", "@syncfusion/ej2-data"], function (require, exports, ej2_base_1, ej2_data_1, ej2_data_2) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    function parentsUntil(elem, selector, isID) {
        var parent = elem;
        while (parent) {
            if (isID ? parent.id === selector : parent.classList.contains(selector)) {
                break;
            }
            parent = parent.parentElement;
        }
        return parent;
    }
    exports.parentsUntil = parentsUntil;
    function isScheduledTask(ganttProp) {
        if (ej2_base_1.isNullOrUndefined(ganttProp.startDate) && ej2_base_1.isNullOrUndefined(ganttProp.endDate) &&
            ej2_base_1.isNullOrUndefined(ganttProp.duration)) {
            return null;
        }
        else if (ej2_base_1.isNullOrUndefined(ganttProp.startDate) || ej2_base_1.isNullOrUndefined(ganttProp.endDate) ||
            ej2_base_1.isNullOrUndefined(ganttProp.duration)) {
            return false;
        }
        else {
            return true;
        }
    }
    exports.isScheduledTask = isScheduledTask;
    function isCountRequired(parent) {
        if (parent.dataSource && !(parent.dataSource instanceof ej2_data_1.DataManager) &&
            'result' in parent.dataSource) {
            return true;
        }
        return false;
    }
    exports.isCountRequired = isCountRequired;
    function getSwapKey(obj) {
        var temp = {};
        for (var _i = 0, _a = Object.keys(obj); _i < _a.length; _i++) {
            var key = _a[_i];
            temp[obj[key]] = key;
        }
        return temp;
    }
    exports.getSwapKey = getSwapKey;
    function isRemoteData(dataSource) {
        if (dataSource instanceof ej2_data_1.DataManager) {
            var adaptor = dataSource.adaptor;
            return (adaptor instanceof ej2_data_1.ODataAdaptor || (adaptor instanceof ej2_data_2.ODataV4Adaptor) ||
                (adaptor instanceof ej2_data_1.WebApiAdaptor) || (adaptor instanceof ej2_data_2.WebMethodAdaptor) ||
                (adaptor instanceof ej2_data_2.CacheAdaptor) || (adaptor instanceof ej2_data_2.RemoteSaveAdaptor) ||
                adaptor instanceof ej2_data_1.UrlAdaptor);
        }
        return false;
    }
    exports.isRemoteData = isRemoteData;
    function getTaskData(records, isNotExtend, eventArgs, parent) {
        if (eventArgs) {
            var result = void 0;
            for (var i = 0; i < records.length; i++) {
                var data = isNotExtend ?
                    (records[parseInt(i.toString(), 10)].taskData) : ej2_base_1.extend({}, records[parseInt(i.toString(), 10)].taskData, {}, true);
                result = (data);
            }
            return result;
        }
        else {
            var result = [];
            for (var i = 0; i < records.length; i++) {
                if (!ej2_base_1.isNullOrUndefined(parent) && parent.timezone) {
                    updateDates(records[i], parent);
                }
                var data = isNotExtend ? (records[parseInt(i.toString(), 10)].taskData) :
                    ej2_base_1.extend({}, records[parseInt(i.toString(), 10)].taskData, {}, true);
                result.push(data);
            }
            return result;
        }
    }
    exports.getTaskData = getTaskData;
    function updateDates(record, parent) {
        Eif (record && !ej2_base_1.isNullOrUndefined(record.ganttProperties)) {
            record.taskData[parent.taskFields.startDate] = parent.dateValidationModule.remove(record.ganttProperties.startDate, parent.timezone);
            Eif (parent.taskFields.endDate !== null) {
                record.taskData[parent.taskFields.endDate] = parent.dateValidationModule.remove(record.ganttProperties.endDate, parent.timezone);
            }
            Iif (parent.taskFields.baselineEndDate || parent.taskFields.baselineStartDate) {
                record.taskData[parent.taskFields.baselineStartDate] = parent.dateValidationModule.remove(record.ganttProperties.baselineStartDate, parent.timezone);
                record.taskData[parent.taskFields.baselineEndDate] = parent.dateValidationModule.remove(record.ganttProperties.baselineEndDate, parent.timezone);
            }
        }
        return null;
    }
    exports.updateDates = updateDates;
    function formatString(str, args) {
        var regx;
        for (var i = 0; i < args.length; i++) {
            regx = new RegExp('\\{' + (i) + '\\}', 'gm');
            str = str.replace(regx, args[i].toString());
        }
        return str;
    }
    exports.formatString = formatString;
    function getIndex(value, key1, collection, key2) {
        var index = -1;
        for (var i = 0; i < collection.length; i++) {
            if (ej2_base_1.getValue(key1, collection[i]) === ej2_base_1.getValue(key1, value) && ej2_base_1.isNullOrUndefined(key2)
                || (!ej2_base_1.isNullOrUndefined(key2) && ej2_base_1.getValue(key1, collection[i]) === ej2_base_1.getValue(key1, value)
                    && ej2_base_1.getValue(key2, collection[i]) === ej2_base_1.getValue(key2, value))) {
                index = i;
                break;
            }
        }
        return index;
    }
    exports.getIndex = getIndex;
    function pixelToPoint(value) {
        return (value * 76) / 92;
    }
    exports.pixelToPoint = pixelToPoint;
    function pointToPixel(value) {
        return (value * 92) / 76;
    }
    exports.pointToPixel = pointToPixel;
    var uid = 0;
    function getUid() {
        return uid++;
    }
    exports.getUid = getUid;
});