From 11ad0901326197dadbe9dfea65ec1154cdfd194a Mon Sep 17 00:00:00 2001 From: dm5wk Date: Sun, 26 May 2024 20:49:21 +0200 Subject: [PATCH] generalise adding of columns to table --- band-plan.html | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/band-plan.html b/band-plan.html index 7c9e358..e32267b 100644 --- a/band-plan.html +++ b/band-plan.html @@ -120,21 +120,28 @@ div>label { return Number(number) >= Number(min) && Number(number) <= Number(max); } - function add_power(ext, row) { - for (const [key, value] of Object.entries(ext.power)) { - row["power_" + key] = value; - } + function add_column(row, cols, header) { + header.columns.forEach((col) => { + 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) { let tdata = []; - let base_header = {}; - let ext_header = {}; + let header = {}; // first, fill base_header bases.forEach((base) => { 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 extensions.forEach((ext) => { 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; extensions.forEach((ext) => { if ((typeof ext.header === "undefined") || (ext.header == false)) { - base_header.columns.forEach((col) => { - if (base_header.columns.includes(col)) { - row[col] = base[col]; - } - }); + add_column(row, base, header["base"]); let [ext_start, ext_end] = ext.frequency.split('-'); if (typeof base.frequency === "number") { // at single frequency if (isInRange(base.frequency, ext_start, ext_end)) { - add_power(ext, row); + add_column(row, ext, header["extension"]); } else { return; } @@ -173,7 +176,7 @@ div>label { let [base_start, base_end] = base.frequency.split('-'); 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 - add_power(ext, row); + add_column(row, ext, header["extension"]); } else { // base range is split by ext range if (isInRange(ext_start, base_start, base_end)) { @@ -182,7 +185,7 @@ div>label { let start = ext_start; let end = base_end < ext_end ? base_end : ext_end; r["frequency"] = start + '-' + end; - add_power(ext, r); + add_column(r, ext, header["extension"]); tdata.push(r); already_added = true; } else if (isInRange(ext_end, base_start, base_end)) { @@ -191,7 +194,7 @@ div>label { let start = base_start; let end = ext_end; r["frequency"] = start + '-' + end; - add_power(ext, r); + add_column(r, ext, header["extension"]); tdata.push(r); already_added = true; } @@ -232,11 +235,11 @@ div>label { column.headerFilter = "input"; column.headerFilterFunc = filter_with_not; - if (typeof base_header.titles[column.field] !== "undefined") { - column.title = base_header.titles[column.field]; + if (typeof header["base"].titles[column.field] !== "undefined") { + column.title = header["base"].titles[column.field]; } - if (typeof ext_header.titles[column.field] !== "undefined") { - column.title = ext_header.titles[column.field]; + if (typeof header["extension"].titles[column.field] !== "undefined") { + column.title = header["extension"].titles[column.field]; } });