order-ui
Version:
order the UI base on id
69 lines (68 loc) • 2.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ComponentOrderUtil = void 0;
class ComponentOrderUtil {
static ORDER_COMPONENT(componentIdList, node) {
if (componentIdList.length < 1) {
// @ts-ignore
componentIdList = ComponentOrderUtil.DEFAULT_LIST;
}
componentIdList.sort((a, b) => {
if (b.alignNo > a.alignNo) {
return -1;
}
if (b.alignNo < a.alignNo) {
return 1;
}
return 0;
});
let d = null;
const list = [];
componentIdList.forEach(f => {
if (f.name.includes(',')) {
const ids = f.name.split(',');
ids.forEach((id) => {
d = document.getElementById(id.trim());
if (!ComponentOrderUtil.isEmpty(d)) {
if (f.isVisible) {
list.push(d);
}
d.remove();
}
});
}
else {
d = document.getElementById(f.name);
if (!ComponentOrderUtil.isEmpty(d)) {
if (f.isVisible) {
list.push(d);
}
d.remove();
}
}
});
list.forEach((l) => {
if (!ComponentOrderUtil.isEmpty(l)) {
let parentNode = document.getElementById(ComponentOrderUtil.PARENT_NODE);
if (ComponentOrderUtil.isEmpty(parentNode)) {
parentNode = document.getElementById(node);
}
if (l.tagName === ComponentOrderUtil.LIST_NODE) {
parentNode.appendChild(l);
}
else {
const childNode = document.createElement(ComponentOrderUtil.LIST_NODE.toLowerCase());
childNode.appendChild(l);
parentNode.appendChild(childNode);
}
}
});
}
static isEmpty(input) {
return input === undefined || input === null || input === '' || input === 'null' || input === 'undefined' || input === 'Infinity';
}
}
exports.ComponentOrderUtil = ComponentOrderUtil;
ComponentOrderUtil.PARENT_NODE = 'summary-list';
ComponentOrderUtil.LIST_NODE = 'LI';
ComponentOrderUtil.DEFAULT_LIST = [];