From be0e12589d23eb6fee27f615c4c874b147aa47d3 Mon Sep 17 00:00:00 2001 From: j433866 Date: Mon, 10 Jun 2019 12:47:27 +0100 Subject: [PATCH] Display preview of output in output tab headers. Remove unused argument from setLogLevel() --- src/web/waiters/OutputWaiter.mjs | 48 ++++++++++++++++++++++++++++---- src/web/waiters/WorkerWaiter.mjs | 6 +--- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/web/waiters/OutputWaiter.mjs b/src/web/waiters/OutputWaiter.mjs index 29e49118..84a7c268 100755 --- a/src/web/waiters/OutputWaiter.mjs +++ b/src/web/waiters/OutputWaiter.mjs @@ -74,6 +74,21 @@ class OutputWaiter { } } + /** + * Gets the dish object for an output. + * + * @param inputNum - The inputNum of the output to get the dish of + * @returns {Dish} + */ + getOutputDish(inputNum) { + if (this.outputExists(inputNum) && + this.outputs[inputNum].data && + this.outputs[inputNum].data.dish) { + return this.outputs[inputNum].data.dish; + } + return null; + } + /** * Checks if an output exists in the output dictionary * @@ -189,6 +204,7 @@ class OutputWaiter { delete this.outputs[inputNum].error; } + this.displayTabInfo(inputNum); this.set(inputNum); } @@ -293,7 +309,6 @@ class OutputWaiter { outputHtml.innerHTML = ""; } else if (output.status === "baked" || output.status === "inactive") { document.querySelector("#output-loader .loading-msg").textContent = `Loading output ${inputNum}`; - this.displayTabInfo(inputNum); this.closeFile(); let scriptElements, lines, length; @@ -642,6 +657,8 @@ class OutputWaiter { document.getElementById("output-tabs").lastElementChild.style.boxShadow = "-15px 0px 15px -15px var(--primary-border-colour) inset"; } + this.displayTabInfo(inputNum); + if (changeTab) { this.changeTab(inputNum, false); } @@ -673,6 +690,10 @@ class OutputWaiter { const tabsRight = (newOutputs[newOutputs.length - 1] !== this.getLargestInputNum()); this.manager.tabs.refreshOutputTabs(newOutputs, inputNum, tabsLeft, tabsRight); + + for (let i = 0; i < newOutputs.length; i++) { + this.displayTabInfo(newOutputs[i]); + } } this.app.debounce(this.set, 50, "setOutput", this, [inputNum])(); @@ -919,6 +940,11 @@ class OutputWaiter { tabsRight = (newNums[newNums.length - 1] !== this.getLargestInputNum()); this.manager.tabs.refreshOutputTabs(newNums, activeTab, tabsLeft, tabsRight); + + for (let i = 0; i < newNums.length; i++) { + this.displayTabInfo(newNums[i]); + } + } /** @@ -926,14 +952,26 @@ class OutputWaiter { * * @param {number} inputNum */ - displayTabInfo(inputNum) { + async displayTabInfo(inputNum) { const tabItem = this.manager.tabs.getOutputTabItem(inputNum); - if (!tabItem) return; - const tabContent = tabItem.firstElementChild; + const tabContent = tabItem.firstElementChild, + dish = this.getOutputDish(inputNum); + let tabStr = ""; - tabContent.innerText = `Tab ${inputNum}`; + if (dish !== null) { + tabStr = await this.getDishStr(this.getOutputDish(inputNum)); + tabStr = tabStr.replace(/[\n\r]/g, ""); + } + + tabStr = tabStr.slice(0, 200); + if (tabStr === "") { + tabStr = `Tab ${inputNum}`; + } else { + tabStr = `${inputNum}: ${tabStr}`; + } + tabContent.innerText = tabStr; } diff --git a/src/web/waiters/WorkerWaiter.mjs b/src/web/waiters/WorkerWaiter.mjs index b5e7d76e..8fa015ef 100644 --- a/src/web/waiters/WorkerWaiter.mjs +++ b/src/web/waiters/WorkerWaiter.mjs @@ -207,8 +207,6 @@ class WorkerWaiter { break; case "dishReturned": this.callbacks[r.data.id](r.data); - this.dishWorker.terminate(); - this.dishWorker = null; break; case "silentBakeComplete": break; @@ -623,10 +621,8 @@ class WorkerWaiter { /** * Sets the console log level in the workers. - * - * @param {string} level */ - setLogLevel(level) { + setLogLevel() { for (let i = 0; i < this.chefWorkers.length; i++) { this.chefWorkers[i].worker.postMessage({ action: "setLogLevel",