move and remove some redundant code

This commit is contained in:
Robin Scholtes 2023-08-15 13:51:12 +12:00
parent c110e5a59f
commit 6a11d14794
4 changed files with 13 additions and 24 deletions

View file

@ -154,7 +154,6 @@ class Manager {
this.addDynamicListener(".arg:not(select)", "input", this.recipe.ingChange, this.recipe);
this.addDynamicListener(".arg[type=checkbox], .arg[type=radio], select.arg", "change", this.recipe.ingChange, this.recipe);
this.addDynamicListener("#rec-list .dropdown-menu.toggle-dropdown a", "click", this.recipe.dropdownToggleClick, this.recipe);
this.addDynamicListener("#rec-list", "operationremove", this.recipe.clearRecipe.bind(this.recipe));
this.addDynamicListener("textarea.arg", "dragover", this.recipe.textArgDragover, this.recipe);
this.addDynamicListener("textarea.arg", "dragleave", this.recipe.textArgDragLeave, this.recipe);
this.addDynamicListener("textarea.arg", "drop", this.recipe.textArgDrop, this.recipe);

View file

@ -24,6 +24,9 @@ export class CRecipeLi extends HTMLElement {
this.name = name;
this.args = [];
this.flowControl = this.app.operations[this.name].flowControl;
this.manualBake = this.app.operations[this.name].manualBake;
for (let i = 0; i < args.length; i++) {
const ing = new HTMLIngredient(args[i], this.app, this.app.manager);
this.args.push(ing);
@ -132,10 +135,15 @@ export class CRecipeLi extends HTMLElement {
const clearfixDiv = document.createElement("div");
if (this.app.operations[this.name].flowControl) {
if (this.flowControl) {
li.classList.add("flow-control-op");
}
if (this.manualBake && this.app.autoBake_) {
this.manager.controls.setAutoBake(false);
this.app.alert("Auto-Bake is disabled by default when using this operation.", 5000);
}
li.appendChild(icons);
li.appendChild(clearfixDiv);

View file

@ -280,7 +280,6 @@ class OperationsWaiter {
* @param {string} className - the className to update
*/
updateListItemsClasses(srcListSelector, className) {
console.log("li update");
const listItems = document.querySelectorAll(`${srcListSelector} li`);
const ops = document.querySelectorAll("c-operation-li > li.operation");

View file

@ -234,25 +234,6 @@ class RecipeWaiter {
}
/**
* Given an operation stub element, this function converts it into a full recipe element with
* arguments.
*
* @param {string} name - The operation stub element from the operations pane
*/
buildRecipeOperation(name) {
const op = new CRecipeLi(this.app, name, this.app.operations[name].args);
// Disable auto-bake if this is a manual op
if (op.manualBake && this.app.autoBake_) {
this.manager.controls.setAutoBake(false);
this.app.alert("Auto-Bake is disabled by default when using this operation.", 5000);
}
return op;
}
/**
* Adds the specified operation to the recipe
*
@ -261,7 +242,8 @@ class RecipeWaiter {
* @param {string} name - The name of the operation to add
*/
addOperation(name) {
const item = this.buildRecipeOperation(name);
const item = new CRecipeLi(this.app, name, this.app.operations[name].args);
document.getElementById("rec-list").appendChild(item);
$(item).find("[data-toggle='tooltip']").tooltip();
@ -285,7 +267,9 @@ class RecipeWaiter {
recList.removeChild(recList.firstChild);
}
recList.dispatchEvent(this.manager.operationremove);
window.dispatchEvent(this.app.manager.statechange);
this.app.manager.ops.updateListItemsClasses("#rec-list", "selected");
}
@ -335,7 +319,6 @@ class RecipeWaiter {
opAdd(e) {
console.log(e);
log.debug(`'${e.target.querySelector("li").getAttribute("data-name")}' added to recipe`);
console.log(e.target.querySelector("li").getAttribute("data-name"));
this.triggerArgEvents(e.target);
window.dispatchEvent(this.manager.statechange);
}