generalise adding of columns to table
This commit is contained in:
parent
d43ffbaefb
commit
11ad090132
|
@ -120,21 +120,28 @@ div>label {
|
||||||
return Number(number) >= Number(min) && Number(number) <= Number(max);
|
return Number(number) >= Number(min) && Number(number) <= Number(max);
|
||||||
}
|
}
|
||||||
|
|
||||||
function add_power(ext, row) {
|
function add_column(row, cols, header) {
|
||||||
for (const [key, value] of Object.entries(ext.power)) {
|
header.columns.forEach((col) => {
|
||||||
row["power_" + key] = value;
|
if (header.columns.includes(col)) {
|
||||||
}
|
if (typeof cols[col] === 'object') {
|
||||||
|
for (const [key, value] of Object.entries(cols[col])) {
|
||||||
|
row[col + '_' + key] = value;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
row[col] = cols[col];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_table(bases, extensions) {
|
function update_table(bases, extensions) {
|
||||||
let tdata = [];
|
let tdata = [];
|
||||||
let base_header = {};
|
let header = {};
|
||||||
let ext_header = {};
|
|
||||||
|
|
||||||
// first, fill base_header
|
// first, fill base_header
|
||||||
bases.forEach((base) => {
|
bases.forEach((base) => {
|
||||||
if ((typeof base.header !== "undefined") && base.header) {
|
if ((typeof base.header !== "undefined") && base.header) {
|
||||||
base_header = structuredClone(base);
|
header["base"] = structuredClone(base);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -146,7 +153,7 @@ div>label {
|
||||||
// first, fill ext_header
|
// first, fill ext_header
|
||||||
extensions.forEach((ext) => {
|
extensions.forEach((ext) => {
|
||||||
if ((typeof ext.header !== "undefined") && ext.header) {
|
if ((typeof ext.header !== "undefined") && ext.header) {
|
||||||
ext_header = structuredClone(ext);
|
header["extension"] = structuredClone(ext);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -154,17 +161,13 @@ div>label {
|
||||||
let already_added = false;
|
let already_added = false;
|
||||||
extensions.forEach((ext) => {
|
extensions.forEach((ext) => {
|
||||||
if ((typeof ext.header === "undefined") || (ext.header == false)) {
|
if ((typeof ext.header === "undefined") || (ext.header == false)) {
|
||||||
base_header.columns.forEach((col) => {
|
add_column(row, base, header["base"]);
|
||||||
if (base_header.columns.includes(col)) {
|
|
||||||
row[col] = base[col];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let [ext_start, ext_end] = ext.frequency.split('-');
|
let [ext_start, ext_end] = ext.frequency.split('-');
|
||||||
if (typeof base.frequency === "number") {
|
if (typeof base.frequency === "number") {
|
||||||
// at single frequency
|
// at single frequency
|
||||||
if (isInRange(base.frequency, ext_start, ext_end)) {
|
if (isInRange(base.frequency, ext_start, ext_end)) {
|
||||||
add_power(ext, row);
|
add_column(row, ext, header["extension"]);
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -173,7 +176,7 @@ div>label {
|
||||||
let [base_start, base_end] = base.frequency.split('-');
|
let [base_start, base_end] = base.frequency.split('-');
|
||||||
if (isInRange(base_start, ext_start, ext_end) && isInRange(base_end, ext_start, ext_end)) {
|
if (isInRange(base_start, ext_start, ext_end) && isInRange(base_end, ext_start, ext_end)) {
|
||||||
// base range is inside of ext range or the same
|
// base range is inside of ext range or the same
|
||||||
add_power(ext, row);
|
add_column(row, ext, header["extension"]);
|
||||||
} else {
|
} else {
|
||||||
// base range is split by ext range
|
// base range is split by ext range
|
||||||
if (isInRange(ext_start, base_start, base_end)) {
|
if (isInRange(ext_start, base_start, base_end)) {
|
||||||
|
@ -182,7 +185,7 @@ div>label {
|
||||||
let start = ext_start;
|
let start = ext_start;
|
||||||
let end = base_end < ext_end ? base_end : ext_end;
|
let end = base_end < ext_end ? base_end : ext_end;
|
||||||
r["frequency"] = start + '-' + end;
|
r["frequency"] = start + '-' + end;
|
||||||
add_power(ext, r);
|
add_column(r, ext, header["extension"]);
|
||||||
tdata.push(r);
|
tdata.push(r);
|
||||||
already_added = true;
|
already_added = true;
|
||||||
} else if (isInRange(ext_end, base_start, base_end)) {
|
} else if (isInRange(ext_end, base_start, base_end)) {
|
||||||
|
@ -191,7 +194,7 @@ div>label {
|
||||||
let start = base_start;
|
let start = base_start;
|
||||||
let end = ext_end;
|
let end = ext_end;
|
||||||
r["frequency"] = start + '-' + end;
|
r["frequency"] = start + '-' + end;
|
||||||
add_power(ext, r);
|
add_column(r, ext, header["extension"]);
|
||||||
tdata.push(r);
|
tdata.push(r);
|
||||||
already_added = true;
|
already_added = true;
|
||||||
}
|
}
|
||||||
|
@ -232,11 +235,11 @@ div>label {
|
||||||
|
|
||||||
column.headerFilter = "input";
|
column.headerFilter = "input";
|
||||||
column.headerFilterFunc = filter_with_not;
|
column.headerFilterFunc = filter_with_not;
|
||||||
if (typeof base_header.titles[column.field] !== "undefined") {
|
if (typeof header["base"].titles[column.field] !== "undefined") {
|
||||||
column.title = base_header.titles[column.field];
|
column.title = header["base"].titles[column.field];
|
||||||
}
|
}
|
||||||
if (typeof ext_header.titles[column.field] !== "undefined") {
|
if (typeof header["extension"].titles[column.field] !== "undefined") {
|
||||||
column.title = ext_header.titles[column.field];
|
column.title = header["extension"].titles[column.field];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue