Browse Source

Display preview of output in output tab headers.
Remove unused argument from setLogLevel()

j433866 6 years ago
parent
commit
be0e12589d
2 changed files with 44 additions and 10 deletions
  1. 43 5
      src/web/waiters/OutputWaiter.mjs
  2. 1 5
      src/web/waiters/WorkerWaiter.mjs

+ 43 - 5
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;
 
     }
 

+ 1 - 5
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",