More Node-related module tidying (but still doesn't solve ES6 browser issues with uncompiled code)

This commit is contained in:
Jeff Parsons 2017-01-02 16:51:09 -08:00 committed by Jeff Parsons
commit 67e1e66cb1
16 changed files with 1049 additions and 1050 deletions

View file

@ -49,9 +49,6 @@
"use strict";
var Usr = require("../../shared/es6/usrlib");
var Web = require("../../shared/es6/weblib");
/**
* Since the Closure Compiler treats ES6 classes as @struct rather than @dict by default,
* it deters us from defining named properties on our components; eg:
@ -210,6 +207,16 @@ class Component {
return Component.machines[idMachine];
}
/**
* Component.getTime()
*
* @return {number} the current time, in milliseconds
*/
static getTime()
{
return Date.now() || +new Date();
}
/**
* Component.log(s, type)
*
@ -225,9 +232,9 @@ class Component {
var sElapsed = "", sMsg = (type? (type + ": ") : "") + s;
if (typeof Usr != "undefined") {
if (Component.msStart === undefined) {
Component.msStart = Usr.getTime();
Component.msStart = Component.getTime();
}
sElapsed = (Usr.getTime() - Component.msStart) + "ms: ";
sElapsed = (Component.getTime() - Component.msStart) + "ms: ";
}
if (window && window.console) console.log(sElapsed + sMsg.replace(/\n/g, " "));
}
@ -290,7 +297,7 @@ class Component {
if (!COMPILED) {
Component.println(s, "notice", id);
}
if (!fPrintOnly && Web.alertUser) Web.alertUser((id? (id + ": ") : "") + s);
if (!fPrintOnly) Component.alertUser((id? (id + ": ") : "") + s);
}
/**
@ -303,7 +310,7 @@ class Component {
if (!COMPILED) {
Component.println(s, "warning");
}
if (Web.alertUser) Web.alertUser(s);
Component.alertUser(s);
}
/**
@ -316,7 +323,52 @@ class Component {
if (!COMPILED) {
Component.println(s, "error");
}
if (Web.alertUser) Web.alertUser(s);
Component.alertUser(s);
}
/**
* Component.alertUser(sMessage)
*
* @param {string} sMessage
*/
static alertUser(sMessage)
{
if (window) {
window.alert(sMessage);
} else {
Component.log(sMessage);
}
};
/**
* Component.confirmUser(sPrompt)
*
* @param {string} sPrompt
* @returns {boolean} true if the user clicked OK, false if Cancel/Close
*/
static confirmUser(sPrompt)
{
var fResponse = false;
if (window) {
fResponse = window.confirm(sPrompt);
}
return fResponse;
}
/**
* Component.promptUser()
*
* @param {string} sPrompt
* @param {string} [sDefault]
* @returns {string|null}
*/
static promptUser(sPrompt, sDefault)
{
var sResponse = null;
if (window) {
sResponse = window.prompt(sPrompt, sDefault === undefined? "" : sDefault);
}
return sResponse;
}
/**
@ -638,7 +690,7 @@ class Component {
};
}(control));
/**
* Override this.notice() with a replacement function that eliminates the Web.alertUser() call
* Override this.notice() with a replacement function that eliminates the Component.alertUser() call
*
* @this {Component}
* @param {string} s
@ -1062,4 +1114,4 @@ if (!Function.prototype.bind) {
};
}
module.exports = Component;
if (NODE) module.exports = Component;

View file

@ -62,7 +62,7 @@ function savePC(idMachine, sPCJSFile, callback)
});
return true;
}
Web.alertUser("Unable to identify machine '" + idMachine + "'");
Component.alertUser("Unable to identify machine '" + idMachine + "'");
return false;
}
@ -98,7 +98,7 @@ function downloadCSS(sURL, sPCJS, nErrorCode, aMachineInfo)
}
return;
}
Web.alertUser("Error (" + nErrorCode + ") requesting " + sURL);
Component.alertUser("Error (" + nErrorCode + ") requesting " + sURL);
}
/**
@ -208,10 +208,10 @@ function downloadPC(sURL, sCSS, nErrorCode, aMachineInfo)
sAlert += '<script type="text/javascript" src="' + sScript + '"></script>\n';
sAlert += '<script type="text/javascript">embedPC("' + idMachine + '","' + sXMLFile + '","' + sXSLFile + '");</script>\n\n';
sAlert += 'The machine should appear where the <div> is located.';
Web.alertUser(sAlert);
Component.alertUser(sAlert);
return;
}
Web.alertUser("Missing XML/XSL resources");
Component.alertUser("Missing XML/XSL resources");
}
/**

View file

@ -93,16 +93,6 @@ class Usr {
}
}
/**
* getTime()
*
* @return {number} the current time, in milliseconds
*/
static getTime()
{
return Date.now() || +new Date();
}
/**
* getTimestamp()
*
@ -245,7 +235,6 @@ class Usr {
bfs[f] = {mask: mask, shift: bit};
bit += width;
}
// Component.assert(bit <= 32);
return bfs;
}
@ -288,7 +277,6 @@ class Usr {
*/
static setBitField(bf, v, n)
{
// Component.assert(!(n & ~(bf.mask >>> bf.shift)));
return (v & ~bf.mask) | ((n << bf.shift) & bf.mask);
}

View file

@ -135,8 +135,6 @@ class Web {
/**
* notice(s, fPrintOnly, id)
*
* If Component.notice() calls Web.alertUser(), it will fall back to Web.log() if all else fails.
*
* @param {string} s is the message text
* @param {boolean} [fPrintOnly]
* @param {string} [id] is the caller's ID, if any
@ -201,7 +199,7 @@ class Web {
return Net.getResource(sURL, dataPost, fAsync, done);
}
var xmlHTTP = (window.XMLHttpRequest ? new window.XMLHttpRequest() : new window.ActiveXObject("Microsoft.XMLHTTP"));
var xmlHTTP = (window.XMLHttpRequest? new window.XMLHttpRequest() : new window.ActiveXObject("Microsoft.XMLHTTP"));
if (fAsync) {
xmlHTTP.onreadystatechange = function()
{
@ -413,7 +411,7 @@ class Web {
dataPost[ReportAPI.QUERY.USER] = sUser;
dataPost[ReportAPI.QUERY.TYPE] = sType;
dataPost[ReportAPI.QUERY.DATA] = sReport;
var sReportURL = (sHostName ? sHostName : "http://" + SITEHOST) + ReportAPI.ENDPOINT;
var sReportURL = (sHostName? sHostName : "http://" + SITEHOST) + ReportAPI.ENDPOINT;
Web.getResource(sReportURL, dataPost, true);
}
@ -424,7 +422,7 @@ class Web {
*/
static getHost()
{
return ("http://" + (window ? window.location.host : SITEHOST));
return ("http://" + (window? window.location.host : SITEHOST));
}
/**
@ -434,7 +432,7 @@ class Web {
*/
static getHostURL()
{
return (window ? window.location.href : null);
return (window? window.location.href : null);
}
/**
@ -444,7 +442,7 @@ class Web {
*/
static getHostProtocol()
{
return (window ? window.location.protocol : "file:");
return (window? window.location.protocol : "file:");
}
/**
@ -454,48 +452,7 @@ class Web {
*/
static getUserAgent()
{
return (window ? window.navigator.userAgent : "");
}
/**
* alertUser(sMessage)
*
* @param {string} sMessage
*/
static alertUser(sMessage)
{
if (window) window.alert(sMessage); else Web.log(sMessage);
};
/**
* confirmUser(sPrompt)
*
* @param {string} sPrompt
* @returns {boolean} true if the user clicked OK, false if Cancel/Close
*/
static confirmUser(sPrompt)
{
var fResponse = false;
if (window) {
fResponse = window.confirm(sPrompt);
}
return fResponse;
}
/**
* promptUser()
*
* @param {string} sPrompt
* @param {string} [sDefault]
* @returns {string|null}
*/
static promptUser(sPrompt, sDefault)
{
var sResponse = null;
if (window) {
sResponse = window.prompt(sPrompt, sDefault === undefined ? "" : sDefault);
}
return sResponse;
return (window? window.navigator.userAgent : "");
}
/**
@ -729,12 +686,12 @@ class Web {
static downloadFile(sData, sType, fBase64, sFileName)
{
var link = null, sAlert;
var sURI = "data:application/" + sType + (fBase64 ? ";base64" : "") + ",";
var sURI = "data:application/" + sType + (fBase64? ";base64" : "") + ",";
if (!Web.isUserAgent("Firefox")) {
sURI += (fBase64 ? sData : encodeURI(sData));
sURI += (fBase64? sData : encodeURI(sData));
} else {
sURI += (fBase64 ? sData : encodeURIComponent(sData));
sURI += (fBase64? sData : encodeURIComponent(sData));
}
if (sFileName) {
link = document.createElement('a');
@ -749,7 +706,7 @@ class Web {
sAlert = 'Check your Downloads folder for ' + sFileName + '.';
} else {
window.open(sURI);
sAlert = 'Check your browser for a new window/tab containing the requested data' + (sFileName ? (' (' + sFileName + ')') : '') + '.';
sAlert = 'Check your browser for a new window/tab containing the requested data' + (sFileName? (' (' + sFileName + ')') : '') + '.';
}
return sAlert;
}