Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove legacy TreeColumns code - now unused #775

Merged
merged 2 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 0 additions & 173 deletions slick.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,178 +512,6 @@
};
}

/**
*
* @param {Array} treeColumns Array com levels of columns
* @returns {{hasDepth: 'hasDepth', getTreeColumns: 'getTreeColumns', extractColumns: 'extractColumns', getDepth: 'getDepth', getColumnsInDepth: 'getColumnsInDepth', getColumnsInGroup: 'getColumnsInGroup', visibleColumns: 'visibleColumns', filter: 'filter', reOrder: reOrder}}
* @constructor
*/
function TreeColumns(treeColumns) {
var columnsById = {};

function init() {
mapToId(treeColumns);
}

function mapToId(columns) {
columns
.forEach(function (column) {
columnsById[column.id] = column;

if (column.columns) {
mapToId(column.columns);
}
});
}

function filter(node, condition) {
return node.filter(function (column) {
var valid = condition.call(column);

if (valid && column.columns) {
column.columns = filter(column.columns, condition);
}

return valid && (!column.columns || column.columns.length);
});

}

function sort(columns, grid) {
columns
.sort(function (a, b) {
var indexA = getOrDefault(grid.getColumnIndex(a.id)),
indexB = getOrDefault(grid.getColumnIndex(b.id));

return indexA - indexB;
})
.forEach(function (column) {
if (column.columns) {
sort(column.columns, grid);
}
});
}

function getOrDefault(value) {
return typeof value === 'undefined' ? -1 : value;
}

function getDepth(node) {
if (node.length) {
for (var i in node) {
return getDepth(node[i]);
}
} else if (node.columns) {
return 1 + getDepth(node.columns);
} else {
return 1;
}
}

function getColumnsInDepth(node, depth, current) {
var columns = [];
current = current || 0;

if (depth == current) {
if (node.length) {
node.forEach(function(n) {
if (n.columns) {
n.extractColumns = function() {
return extractColumns(n);
};
}
});
}
return node;
} else {
for (var i in node) {
if (node[i].columns) {
columns = columns.concat(getColumnsInDepth(node[i].columns, depth, current + 1));
}
}
}

return columns;
}

function extractColumns(node) {
var result = [];

if (node.hasOwnProperty('length')) {
for (var i = 0; i < node.length; i++) {
result = result.concat(extractColumns(node[i]));
}
} else {
if (node.hasOwnProperty('columns')) {
result = result.concat(extractColumns(node.columns));
} else {
return node;
}
}

return result;
}

function cloneTreeColumns() {
return extend([], treeColumns);
}

init();

this.hasDepth = function () {
for (var i in treeColumns) {
if (treeColumns[i].hasOwnProperty('columns'))
return true;
}

return false;
};

this.getTreeColumns = function () {
return treeColumns;
};

this.extractColumns = function () {
return this.hasDepth()? extractColumns(treeColumns): treeColumns;
};

this.getDepth = function () {
return getDepth(treeColumns);
};

this.getColumnsInDepth = function (depth) {
return getColumnsInDepth(treeColumns, depth);
};

this.getColumnsInGroup = function (groups) {
return extractColumns(groups);
};

this.visibleColumns = function () {
return filter(cloneTreeColumns(), function () {
return this.visible;
});
};

this.filter = function (condition) {
return filter(cloneTreeColumns(), condition);
};

this.reOrder = function (grid) {
return sort(treeColumns, grid);
};

this.getById = function (id) {
return columnsById[id];
};

this.getInIds = function (ids) {
return ids.map(function (id) {
return columnsById[id];
});
};
}

function regexSanitizer(dirtyHtml) {
return dirtyHtml.replace(/(\b)(on[a-z]+)(\s*)=|javascript:([^>]*)[^>]*|(<\s*)(\/*)script([<>]*).*(<\s*)(\/*)script(>*)|(&lt;)(\/*)(script|script defer)(.*)(&gt;|&gt;">)/gi, '');
}
Expand Down Expand Up @@ -1138,7 +966,6 @@
* @constructor
*/
"GlobalEditorLock": new EditorLock(),
"TreeColumns": TreeColumns,

"keyCode": {
SPACE: 8,
Expand Down
Loading