From e3588e71e687167cf9d120c8879a9a87606c1dcb Mon Sep 17 00:00:00 2001 From: lowercasedonkey <lowercasedonkey@gmail.com> Date: Thu, 29 Apr 2021 14:05:55 -0400 Subject: [PATCH] begin moving all to js and better css --- css/rulesAssistant/raSummary.css | 9 ++ src/js/rulesAssistant.js | 105 ------------------ src/js/rulesAssistantSummary.js | 117 +++++++++++++++++++++ src/uncategorized/rulesAssistantSummary.tw | 21 ---- 4 files changed, 126 insertions(+), 126 deletions(-) create mode 100644 src/js/rulesAssistantSummary.js delete mode 100644 src/uncategorized/rulesAssistantSummary.tw diff --git a/css/rulesAssistant/raSummary.css b/css/rulesAssistant/raSummary.css index b9734d8fc01..62dbc9ad8a9 100644 --- a/css/rulesAssistant/raSummary.css +++ b/css/rulesAssistant/raSummary.css @@ -1,3 +1,12 @@ .scroll { overflow: auto; + height: 90vh +} + +table.finances { + text-align: left; + border-collapse: separate; + border-style: hidden; + empty-cells: hide; + border: "1" } diff --git a/src/js/rulesAssistant.js b/src/js/rulesAssistant.js index 826982329b3..c524403210c 100644 --- a/src/js/rulesAssistant.js +++ b/src/js/rulesAssistant.js @@ -411,111 +411,6 @@ globalThis.RulesDeconfliction = function(slave) { slave = before; }; -/** - * Creates a table to summarize RA - * @returns {string} - */ -globalThis.RASummaryCell = function() { - /** - * @param {object[]} objects - * @param {string[]} member - */ - function collectMemberFromObjects(objects, member) { - let r = []; - for (const o of objects) { - let to = o; - for (const m of member) { - to = to[m]; - } - r.push(to); - } - return r; - } - - /** - * @callback objectWalker - * @param {object} obj - * @param {string[]} memberPath - */ - - /** - * @param {object} obj - * @param {objectWalker} walker - * @param {string[]} path - */ - function walkObject(obj, walker, path) { - for (const prop in obj) { - const v = obj[prop]; - const vp = path.concat([prop]); - if (v !== null && typeof v === 'object') { - walkObject(v, walker, vp); - } else { - walker(obj, vp); - } - } - } - - /** - * @param {string[]} path - * @param {Array} cells - * @param {string[]} table - */ - function addRow(path, cells, table) { - if (!cells.some(v => v !== null)) { // skip empty rows - return; - } - - function ruleSetValueToString(v) { - if (typeof v === 'object') { - if (v.hasOwnProperty('cond') && v.hasOwnProperty('val')) { - return `<nowiki>${v.cond}</nowiki> ${v.val}`; - } else if (v.hasOwnProperty('min') && v.hasOwnProperty('max')) { - return `${v.min} to ${v.max}`; - } else { - return JSON.stringify(v); - } - } - return `${v}`; - } - - let r = `<td>${path.join('.')}</td>`; - for (const cell of cells) { - r += cell !== null ? `<td>${ruleSetValueToString(cell)}</td>` : '<td></td>'; - } - table.push(r); - } - /** @type {FC.RA.Rule[]} */ - const rules = V.defaultRules; - let r = ""; - - if (rules.length === 0) { - return ''; - } - - /* start row title */ - r += `<tr><th style="position:sticky; top:0px; background:#111"></th>`; - - /* make rest of row title */ - for (const rule of rules) { - r += `<th style="position:sticky; top:0px; background:#111">${rule.name}</th>`; - } - r += `</tr>`; - - const setters = rules.map(r => r.set); - /* A row for every condition the RA can set. */ - /* start loop for row*/ - - let tableRows = []; - walkObject(emptyDefaultRule().set, (obj, path) => { - addRow(path, collectMemberFromObjects(setters, path), tableRows); - }, []); - - for (const row of tableRows) { - r += `<tr>${row}</tr>`; - } - return r; -}; - /** * Creates RA target object used in rules for body properties * @param {string} condition comparison condition. One of '==', '>=', '<=', '>', '<' diff --git a/src/js/rulesAssistantSummary.js b/src/js/rulesAssistantSummary.js new file mode 100644 index 00000000000..aff44441ffc --- /dev/null +++ b/src/js/rulesAssistantSummary.js @@ -0,0 +1,117 @@ +new App.DomPassage("Rules Assistant Summary", () => { + V.nextButton = "Back"; + V.nextLink = "Rules Assistant"; + V.returnTo = "Rules Assistant"; + + const el = App.UI.DOM.makeElement("div", null, "scroll"); + App.UI.DOM.appendNewElement("div", el, `Here you can see an overview of all of your rules at the same time.`, "scene-intro"); + App.UI.DOM.appendNewElement("div", el, `Rules further to the right will always take priority, but some rules may not apply to all slaves.`, "scene-intro"); + + const table = App.UI.DOM.appendNewElement("table", el); + table.append(RASummaryCell()); + return el; + /** + * Creates a table to summarize RA + * @returns {string} + */ + function RASummaryCell() { + /** + * @param {object[]} objects + * @param {string[]} member + */ + function collectMemberFromObjects(objects, member) { + let r = []; + for (const o of objects) { + let to = o; + for (const m of member) { + to = to[m]; + } + r.push(to); + } + return r; + } + + /** + * @callback objectWalker + * @param {object} obj + * @param {string[]} memberPath + */ + + /** + * @param {object} obj + * @param {objectWalker} walker + * @param {string[]} path + */ + function walkObject(obj, walker, path) { + for (const prop in obj) { + const v = obj[prop]; + const vp = path.concat([prop]); + if (v !== null && typeof v === 'object') { + walkObject(v, walker, vp); + } else { + walker(obj, vp); + } + } + } + + /** + * @param {string[]} path + * @param {Array} cells + * @param {string[]} table + */ + function addRow(path, cells, table) { + if (!cells.some(v => v !== null)) { // skip empty rows + return; + } + + function ruleSetValueToString(v) { + if (typeof v === 'object') { + if (v.hasOwnProperty('cond') && v.hasOwnProperty('val')) { + return `<nowiki>${v.cond}</nowiki> ${v.val}`; + } else if (v.hasOwnProperty('min') && v.hasOwnProperty('max')) { + return `${v.min} to ${v.max}`; + } else { + return JSON.stringify(v); + } + } + return `${v}`; + } + + let r = `<td style="position:sticky; left: 0px; background:#111; z-index:1;">${path.join('.')}</td>`; + for (const cell of cells) { + r += cell !== null ? `<td>${ruleSetValueToString(cell)}</td>` : '<td></td>'; + } + table.push(r); + } + /** @type {FC.RA.Rule[]} */ + const rules = V.defaultRules; + let r = ""; + + if (rules.length === 0) { + return ''; + } + + /* start row title */ + r += `<tr style="z-index:2; position:sticky; top:0px; background:#111;"><th style="empty-cells: show"></th>`; + + /* make rest of row title */ + for (const rule of rules) { + r += `<th>${rule.name}</th>`; + } + r += `</tr>`; + + const setters = rules.map(r => r.set); + /* A row for every condition the RA can set. */ + /* start loop for row*/ + + let tableRows = []; + walkObject(emptyDefaultRule().set, (obj, path) => { + addRow(path, collectMemberFromObjects(setters, path), tableRows); + }, []); + + for (const row of tableRows) { + r += `<tr>${row}</tr>`; + } + return r; + }; +}); diff --git a/src/uncategorized/rulesAssistantSummary.tw b/src/uncategorized/rulesAssistantSummary.tw deleted file mode 100644 index 5e9b219c01d..00000000000 --- a/src/uncategorized/rulesAssistantSummary.tw +++ /dev/null @@ -1,21 +0,0 @@ -:: Rules Assistant Summary [nobr] - -<<set $nextButton = "Back", $nextLink = "Rules Assistant", $returnTo = "Rules Assistant">> -<div class="scroll" style="height:90vh"> -<i>Here you can see an overview of all of your rules at the same time. -<br>Rules further to the right will always take priority, but some rules may not apply to all slaves.</i> - -<style> - table.finances { - text-align: left; - border-collapse: separate; - border-spacing: 5px; - border-style: hidden; - empty-cells: hide; - } -</style> - -<table class= "finances" border= "1"> -<<print RASummaryCell()>> -</table> -</div> \ No newline at end of file -- GitLab