all files / treegrid/actions/ logger.js

92.86% Statements 78/84
84.48% Branches 49/58
100% Functions 15/15
92.5% Lines 74/80
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          1259× 1259× 1259× 1259×   11279×   4763× 4084×   4763× 4763× 6716× 6716× 6716× 35× 35× 35×   35× 35× 35×     35×   30×     30×   29×     29×   35×           35×         622× 622×     622× 622×   622× 622× 622× 622×                 622× 622×         622×                          
/* 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", "@syncfusion/ej2-base", "@syncfusion/ej2-grids"], function (require, exports, ej2_base_1, ej2_grids_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var DOC_URL = 'https://ej2.syncfusion.com/documentation/treegrid';
    var BASE_DOC_URL = 'https://ej2.syncfusion.com/documentation';
    var WARNING = '[EJ2TreeGrid.Warning]';
    var ERROR = '[EJ2TreeGrid.Error]';
    var INFO = '[EJ2TreeGrid.Info]';
    var IsRowDDEnabled = false;
    var Logger = (function (_super) {
        __extends(Logger, _super);
        function Logger(parent) {
            var _this = this;
            ej2_grids_1.Grid.Inject(ej2_grids_1.Logger);
            _this = _super.call(this, parent) || this;
            return _this;
        }
        Logger.prototype.getModuleName = function () {
            return 'logger';
        };
        Logger.prototype.log = function (types, args) {
            if (!(types instanceof Array)) {
                types = [types];
            }
            var type = types;
            for (var i = 0; i < type.length; i++) {
                var item = ej2_grids_1.detailLists[type[parseInt(i.toString(), 10)]];
                var cOp = item.check(args, this.parent);
                if (cOp.success) {
                    var message = item.generateMessage(args, this.parent, cOp.options);
                    message = message.replace('EJ2Grid', 'EJ2TreeGrid').replace('* Hierarchy Grid', '').replace('* Grouping', '');
                    if (IsRowDDEnabled && type[parseInt(i.toString(), 10)] === 'primary_column_missing') {
                        message = message.replace('Editing', 'Row DragAndDrop');
                        IsRowDDEnabled = false;
                    }
                    var index = message.indexOf('https');
                    var gridurl = message.substring(index);
                    Iif (type[parseInt(i.toString(), 10)] === 'module_missing') {
                        message = message.replace(gridurl, DOC_URL + '/modules');
                    }
                    else if (type[parseInt(i.toString(), 10)] === 'primary_column_missing' || type[parseInt(i.toString(), 10)] === 'selection_key_missing') {
                        message = message.replace(gridurl, BASE_DOC_URL + '/api/treegrid/column/#isprimarykey');
                    }
                    else Iif (type[parseInt(i.toString(), 10)] === 'grid_remote_edit') {
                        message = message.replace(gridurl, DOC_URL + '/edit');
                    }
                    else if (type[parseInt(i.toString(), 10)] === 'virtual_height') {
                        message = message.replace(gridurl, DOC_URL + '/virtual');
                    }
                    else Iif (type[parseInt(i.toString(), 10)] === 'check_datasource_columns') {
                        message = message.replace(gridurl, DOC_URL + '/columns');
                    }
                    else if (type[parseInt(i.toString(), 10)] === 'locale_missing') {
                        message = message.replace(gridurl, DOC_URL + '/global-local/#localization');
                    }
                    Iif (type[parseInt(i.toString(), 10)] === 'datasource_syntax_mismatch') {
                        if (!ej2_base_1.isNullOrUndefined(this.treeGridObj) && !ej2_base_1.isNullOrUndefined(this.treeGridObj.dataStateChange)) {
                            console[item.logType](message);
                        }
                    }
                    else {
                        console[item.logType](message);
                    }
                }
            }
        };
        Logger.prototype.treeLog = function (types, args, treeGrid) {
            this.treeGridObj = treeGrid;
            Iif (!(types instanceof Array)) {
                types = [types];
            }
            var type = types;
            if (treeGrid.allowRowDragAndDrop && !treeGrid.columns.filter(function (column) { return column.isPrimaryKey; }).length) {
                IsRowDDEnabled = true;
                this.log('primary_column_missing', args);
            }
            for (var i = 0; i < type.length; i++) {
                var item = exports.treeGridDetails[type[parseInt(i.toString(), 10)]];
                var cOp = item.check(args, treeGrid);
                if (cOp.success) {
                    var message = item.generateMessage(args, treeGrid, cOp.options);
                    console[item.logType](message);
                }
            }
        };
        return Logger;
    }(ej2_grids_1.Logger));
    exports.Logger = Logger;
    exports.treeGridDetails = {
        mapping_fields_missing: {
            type: 'mapping_fields_missing',
            logType: 'error',
            check: function (args, parent) {
                var opt = { success: false };
                if ((ej2_base_1.isNullOrUndefined(parent.idMapping) && ej2_base_1.isNullOrUndefined(parent.childMapping)
                    && ej2_base_1.isNullOrUndefined(parent.parentIdMapping)) ||
                    (!ej2_base_1.isNullOrUndefined(parent.idMapping) && ej2_base_1.isNullOrUndefined(parent.parentIdMapping)) ||
                    (ej2_base_1.isNullOrUndefined(parent.idMapping) && !ej2_base_1.isNullOrUndefined(parent.parentIdMapping))) {
                    opt = { success: true };
                }
                return opt;
            },
            generateMessage: function () {
                return ERROR + ':' + ' MAPPING FIELDS MISSING \n' + 'One of the following fields is missing. It is ' +
                    'required for the hierarchical relationship of records in TreeGrid:\n' +
                    '* childMapping\n' + '* idMapping\n' + '* parentIdMapping\n' +
                    'Refer to the following documentation links for more details.\n' +
                    (BASE_DOC_URL + "/api/treegrid#childmapping") + '\n' +
                    (BASE_DOC_URL + "/api/treegrid#idmapping") + '\n' +
                    (BASE_DOC_URL + "/api/treegrid#$parentidmapping");
            }
        }
    };
});