diff --git a/js/rulesAssistant/conditionEditorSimple.js b/js/rulesAssistant/conditionEditorSimple.js index 0dd064745d83a4d77e11f0c6ebbde7184a18acc2..e3c64a81518d93fc0feb9204178fc52235a8129b 100644 --- a/js/rulesAssistant/conditionEditorSimple.js +++ b/js/rulesAssistant/conditionEditorSimple.js @@ -15,6 +15,8 @@ App.RA.Activation.SimpleEditor = (function() { * @property {"lt"|"lte"|""} numberUpperComparator * @property {number} numberLowerValue * @property {"gt"|"gte"|""} numberLowerComparator + * @property {string[]} assignments + * @property {"include"|"exclude"|"ignore"} assignmentMode */ /** @@ -192,6 +194,35 @@ App.RA.Activation.SimpleEditor = (function() { })); } + // Assignments + outerDiv.append("Assignments: "); + outerDiv.append(App.UI.DOM.makeSelect( + [{key: "ignore", name: "Ignored"}, {key: "include", name: "Include"}, {key: "exclude", name: "Exclude"}], + currentRule.assignmentMode, key => { + currentRule.assignmentMode = key; + refreshEditor(); + } + )); + if (currentRule.assignmentMode !== "ignore") { + for (const [key, getter] of App.RA.Activation.getterManager.assignmentGetters) { + if (getter.enabled && !getter.enabled()) { + continue; + } + const checkbox = document.createElement("input"); + checkbox.setAttribute("type", "checkbox"); + checkbox.checked = currentRule.assignments.includes(key); + checkbox.onchange = () => { + if (!currentRule.assignments.includes(key)) { + currentRule.assignments.push(key); + } else { + const index = currentRule.assignments.indexOf(key); + currentRule.assignments.splice(index, 1); + } + }; + outerDiv.append(` ${getter.name}: `, checkbox); + } + } + return outerDiv; } @@ -217,9 +248,11 @@ App.RA.Activation.SimpleEditor = (function() { numberUpperValue: 100, numberUpperComparator: "", numberLowerValue: -100, - numberLowerComparator: "" + numberLowerComparator: "", + assignments: [], + assignmentMode: "ignore", }; - // we know there is only one rule. + // we know there is only main one rule. let i = 0; const rulePart = rule[i]; if (rulePart === true) { @@ -262,6 +295,23 @@ App.RA.Activation.SimpleEditor = (function() { } i++; + // check for assignment rules + let any = false; + while (App.RA.Activation.getterManager.isAssignment(rule[i])) { + any = true; + ruleState.assignments.push(rule[i]); + i++; + } + if (any) { + i += 2; + if (rule[i] === "not") { + ruleState.assignmentMode = "exclude"; + i++; + } else { + ruleState.assignmentMode = "include"; + } + } + return ruleState; } @@ -318,11 +368,18 @@ App.RA.Activation.SimpleEditor = (function() { break; case "string": rule.push(ruleState.stringGetter); - rule.push("!"+ruleState.stringValue); + rule.push("!" + ruleState.stringValue); rule.push(ruleState.stringComparator); counter++; break; } + + if (ruleState.assignmentMode !== "ignore" && ruleState.assignments.length > 0) { + rule.push(...ruleState.assignments); + rule.push(ruleState.assignments.length, "or"); + counter++; + } + rule.push(counter, "and"); return rule; }