Added status message mechanism for the Worker to report to the app

This commit is contained in:
n1474335 2017-08-25 01:24:12 +01:00
parent 6af82680f1
commit d68523a54e
6 changed files with 73 additions and 23 deletions

View File

@ -112,7 +112,21 @@ function loadRequiredModules(recipeConfig) {
if (!OpModules.hasOwnProperty(module)) { if (!OpModules.hasOwnProperty(module)) {
console.log("Loading module " + module); console.log("Loading module " + module);
sendStatusMessage("Loading module " + module);
self.importScripts(self.docURL + "/" + module + ".js"); self.importScripts(self.docURL + "/" + module + ".js");
} }
}); });
} }
/**
* Send status update to the app.
*
* @param {string} msg
*/
function sendStatusMessage(msg) {
self.postMessage({
action: "statusMessage",
data: msg
});
}

View File

@ -118,24 +118,7 @@ App.prototype.handleError = function(err) {
App.prototype.setBakingStatus = function(bakingStatus) { App.prototype.setBakingStatus = function(bakingStatus) {
this.baking = bakingStatus; this.baking = bakingStatus;
let outputLoader = document.getElementById("output-loader"), this.manager.output.toggleLoader(bakingStatus);
outputElement = document.getElementById("output-text");
if (bakingStatus) {
this.manager.controls.hideStaleIndicator();
this.bakingStatusTimeout = setTimeout(function() {
outputElement.disabled = true;
outputLoader.style.visibility = "visible";
outputLoader.style.opacity = 1;
this.manager.controls.toggleBakeButtonFunction(true);
}.bind(this), 200);
} else {
clearTimeout(this.bakingStatusTimeout);
outputElement.disabled = false;
outputLoader.style.opacity = 0;
outputLoader.style.visibility = "hidden";
this.manager.controls.toggleBakeButtonFunction(false);
}
}; };
@ -194,6 +177,9 @@ App.prototype.handleChefMessage = function(e) {
this.workerLoaded = true; this.workerLoaded = true;
this.loaded(); this.loaded();
break; break;
case "statusMessage":
this.manager.output.setStatusMsg(e.data.data);
break;
default: default:
console.error("Unrecognised message from ChefWorker", e); console.error("Unrecognised message from ChefWorker", e);
break; break;

View File

@ -201,4 +201,44 @@ OutputWaiter.prototype.maximiseOutputClick = function(e) {
} }
}; };
/**
* Shows or hides the loading icon.
*
* @param {boolean} value
*/
OutputWaiter.prototype.toggleLoader = function(value) {
const outputLoader = document.getElementById("output-loader"),
outputElement = document.getElementById("output-text");
if (value) {
this.manager.controls.hideStaleIndicator();
this.bakingStatusTimeout = setTimeout(function() {
outputElement.disabled = true;
outputLoader.style.visibility = "visible";
outputLoader.style.opacity = 1;
this.manager.controls.toggleBakeButtonFunction(true);
}.bind(this), 200);
} else {
clearTimeout(this.bakingStatusTimeout);
outputElement.disabled = false;
outputLoader.style.opacity = 0;
outputLoader.style.visibility = "hidden";
this.manager.controls.toggleBakeButtonFunction(false);
this.setStatusMsg("");
}
};
/**
* Sets the baking status message value.
*
* @param {string} msg
*/
OutputWaiter.prototype.setStatusMsg = function(msg) {
const el = document.querySelector("#output-loader .loading-msg");
el.textContent = msg;
};
export default OutputWaiter; export default OutputWaiter;

View File

@ -65,7 +65,8 @@
const msg = loadingMsgs.shift(); const msg = loadingMsgs.shift();
try { try {
const el = document.getElementById("preloader-msg"); const el = document.getElementById("preloader-msg");
el.className = "loading"; // Causes CSS transition on first message if (!el.classList.contains("loading"))
el.classList.add("loading"); // Causes CSS transition on first message
el.innerHTML = msg; el.innerHTML = msg;
} catch (err) {} // Ignore errors if DOM not yet ready } catch (err) {} // Ignore errors if DOM not yet ready
loadingMsgs.push(msg); loadingMsgs.push(msg);
@ -84,7 +85,7 @@
<!-- Preloader overlay --> <!-- Preloader overlay -->
<div id="loader-wrapper"> <div id="loader-wrapper">
<div id="preloader" class="loader"></div> <div id="preloader" class="loader"></div>
<div id="preloader-msg"></div> <div id="preloader-msg" class="loading-msg"></div>
</div> </div>
<!-- End preloader overlay --> <!-- End preloader overlay -->
<span id="edit-favourites" class="btn btn-default btn-sm"><img aria-hidden="true" src="<%- require('../static/images/favourite-16x16.png') %>" alt="Star Icon"/> Edit</span> <span id="edit-favourites" class="btn btn-default btn-sm"><img aria-hidden="true" src="<%- require('../static/images/favourite-16x16.png') %>" alt="Star Icon"/> Edit</span>
@ -193,6 +194,7 @@
<textarea id="output-text" readonly="readonly"></textarea> <textarea id="output-text" readonly="readonly"></textarea>
<div id="output-loader"> <div id="output-loader">
<div class="loader"></div> <div class="loader"></div>
<div class="loading-msg"></div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -110,3 +110,11 @@
font-weight: normal; font-weight: normal;
cursor: help; cursor: help;
} }
#output-loader .loading-msg {
opacity: 1;
font-family: var(--primary-font-family);
line-height: var(--primary-line-height);
color: var(--primary-font-colour);
top: 50%;
}

View File

@ -58,7 +58,7 @@
animation: spin 1.5s linear infinite; animation: spin 1.5s linear infinite;
} }
#preloader-msg { .loading-msg {
display: block; display: block;
position: relative; position: relative;
width: 300px; width: 300px;
@ -69,14 +69,14 @@
opacity: 0; opacity: 0;
} }
#preloader-msg.loading { .loading-msg.loading {
opacity: 1; opacity: 1;
transition: all 0.1s ease-in; transition: all 0.1s ease-in;
} }
/* Loaded */ /* Loaded */
.loaded #preloader-msg { .loaded .loading-msg {
opacity: 0; opacity: 0;
transition: all 0.3s ease-out; transition: all 0.3s ease-out;
} }