Commit 2fce9529 authored by Christoffer Ackelman's avatar Christoffer Ackelman

Web: More cleanup.

parent 6623271c
......@@ -21,7 +21,6 @@ class Appl {
command(cmd) {
console.log("Command: " + cmd);
let local_cmd = false;
if (!this.graph.isAuthorized(Access.AllRt)) {
console.log("Not authorized");
......@@ -37,15 +36,17 @@ class Appl {
let cli = new Cli(cliTable);
let command = cli.parse(cmd);
if (odd(cli.status)) {
if (command === ("OPEN")) {
if (cli.qualifierFound("cli_arg1")) {
let getQualIfExists = (qual) => (cli.qualifierFound(qual)) ? cli.getQualValue(qual) : null;
if (command === ("OPEN")) {
let cli_arg1 = getQualIfExists("cli_arg1");
if (cli_arg1) {
let jgraph = "JGRAPH";
let graph = "GRAPH";
let url = "URL";
let trend = "TREND";
let fast = "FAST";
let cli_arg1 = cli.getQualValue("cli_arg1").toUpperCase();
cli_arg1 = cli_arg1.toUpperCase();
if (jgraph.length >= cli_arg1.length &&
jgraph.substring(0, cli_arg1.length) === cli_arg1) {
// Command is "OPEN JGRAPH"
......@@ -53,17 +54,14 @@ class Appl {
} else if (graph.length >= cli_arg1.length &&
graph.substring(0, cli_arg1.length) === cli_arg1) {
// Command is "OPEN GRAPH"
let graphName = null;
let instanceValue = null;
let classGraph = false;
let objectValue = null;
if (cli.qualifierFound("/OBJECT")) {
objectValue = cli.getQualValue("/OBJECT");
let objectValue = getQualIfExists("/OBJECT");
if (objectValue) {
return 1;
}
if (cli.qualifierFound("/INSTANCE")) {
instanceValue = cli.getQualValue("/INSTANCE");
let instanceValue = getQualIfExists("/INSTANCE");
let classGraph = false;
if (instanceValue) {
classGraph = cli.qualifierFound("/CLASSGRAPH");
let parent = cli.qualifierFound("/PARENT");
if (parent) {
......@@ -81,31 +79,23 @@ class Appl {
GdhOp.GET_OP_METHOD_OBJECTGRAPH, this.open_objectgraph_cb,
newwindow);
} else {
if (!cli.qualifierFound("cli_arg2")) {
let graphName = cli.getQualValue("cli_arg2").toLowerCase();
if (!graphName) {
console.log("Syntax error");
return 0;
}
graphName = cli.getQualValue("cli_arg2").toLowerCase();
graphName = graphName.toLowerCase();
if (graphName.charAt(".pwg") === -1) {
graphName += ".pwg";
}
let href;
if (this.graph.frame.nogdh) {
if (instanceValue === null) {
href = "ge.html?graph=" + graphName + "&instance=no&gdh=no";
} else {
href = "ge.html?graph=" + graphName + "&instance=" +
instanceValue + "&gdh=no";
}
} else {
if (instanceValue === null) {
href = "ge.html?graph=" + graphName;
} else {
href =
"ge.html?graph=" + graphName + "&instance=" + instanceValue;
let href = "ge.html?graph=" + graphName;
if (instanceValue) {
href += "&instance=" + instanceValue
}
if (this.graph.frame.nogdh) {
href += "&gdh=no";
}
console.log("Cmd found: open graph", graphName, instanceValue);
let newwindow = window.open(href, "_blank");
......@@ -117,18 +107,9 @@ class Appl {
let frameName = null;
let urlValue = cli.getQualValue("cli_arg2");
if (urlValue.substring(0, 5) === "pwrb_" ||
urlValue.substring(0, 5) === "pwrs_" ||
urlValue.substring(0, 5) === "nmps_" ||
urlValue.substring(0, 9) === "profibus_" ||
urlValue.substring(0, 8) === "otherio_" ||
urlValue.substring(0, 4) === "opc_" ||
urlValue.substring(0, 14) === "basecomponent_" ||
urlValue.substring(0, 4) === "abb_" ||
urlValue.substring(0, 8) === "siemens_" ||
urlValue.substring(0, 7) === "ssabox_")
// Object reference manual
{
let arrTmp = ["pwrb", "pwrs", "nmps", "profibus", "otherio", "opc",
"basecomponent", "abb", "siemens", "ssabox"];
if (arrTmp.some(e => urlValue.startsWith(e + "_"))) { // Object reference manual
urlValue = "$pwr_doc/" + getLang() + "/orm/" + urlValue;
}
......@@ -147,39 +128,27 @@ class Appl {
}
}
} else if (command === ("SET")) {
if (cli.qualifierFound("cli_arg1")) {
let cli_arg1 = cli.getQualValue("cli_arg1").toUpperCase();
let cli_arg1 = getQualIfExists("cli_arg1");
if (cli_arg1) {
let cli_arg1 = cli_arg1.toUpperCase();
let subwindow = "SUBWINDOW";
if (subwindow.length >= cli_arg1.length &&
subwindow.substring(0, cli_arg1.length) === (cli_arg1)) {
// Command is "SET SUBWINDOW"
let name;
let graphstr;
let source;
let object;
let sts;
local_cmd = true;
if (cli.qualifierFound("/NAME")) {
name = cli.getQualValue("/NAME");
} else {
console.log("Cmd: name is missing\n");
let name = getQualIfExists("/NAME");
if (!name) {
console.log("Cmd: Name is missing\n");
return 0;
}
if (cli.qualifierFound("/SOURCE")) {
source = cli.getQualValue("/SOURCE");
} else {
let source = getQualIfExists("/SOURCE");
if (!source) {
console.log("Cmd: source is missing\n");
return 0;
}
if (cli.qualifierFound("/OBJECT")) {
object = cli.getQualValue("/OBJECT");
} else {
object = null;
}
if (cli.qualifierFound("cli_arg2")) {
graphstr = cli.getQualValue("cli_arg2").toLowerCase();
let object = getQualIfExists("/OBJECT");
let graphstr = getQualIfExists("cli_arg2");
if (graphstr) {
graphstr = graphstr.toLowerCase();
} else {
console.log("Syntax error");
return 0;
......@@ -200,115 +169,76 @@ class Appl {
fileName = this.pwrHost + "xtt_version_help_version.html";
this.openURL(fileName, null);
} else {
if (cli.qualifierFound("/BASE"))
// Not language dependent !! TODO
{
if (cli.qualifierFound("/BASE")) { // Not language dependent !! TODO
fileName = this.pwrHost + "help/xtt_help_";
} else {
fileName = "xtt_help_";
}
if (cli.qualifierFound("cli_arg1")) {
fileName += cli.getQualValue("cli_arg1").toLowerCase();
}
if (cli.qualifierFound("cli_arg2")) {
fileName += "_" + cli.getQualValue("cli_arg2").toLowerCase();
}
if (cli.qualifierFound("cli_arg3")) {
fileName += "_" + cli.getQualValue("cli_arg3").toLowerCase();
}
if (cli.qualifierFound("cli_arg4")) {
fileName += "_" + cli.getQualValue("cli_arg4").toLowerCase();
for (let i = 0; i < 4; i++) {
let tmp = getQualIfExists("cli_arg" + String(i+1));
fileName += tmp ? tmp.toLowerCase() : "";
}
if (fileName.substring(0, 5) === "pwrb_" ||
fileName.substring(0, 5) === "pwrs_" ||
fileName.substring(0, 5) === "nmps_" ||
fileName.substring(0, 9) === "profibus_" ||
fileName.substring(0, 8) === "otherio_" ||
fileName.substring(0, 4) === "opc_" ||
fileName.substring(0, 14) === "basecomponent_" ||
fileName.substring(0, 4) === "abb_" ||
fileName.substring(0, 8) === "siemens_" ||
fileName.substring(0, 7) === "ssabox_")
// Object reference manual
{
let arrTmp = ["pwrb", "pwrs", "nmps", "profibus", "otherio", "opc",
"basecomponent", "abb", "siemens", "ssabox"];
if (arrTmp.some(e => fileName.startsWith(e + "_"))) { // Object reference manual
fileName = "$pwr_doc/orm/" + fileName;
}
if (cli.qualifierFound("/BOOKMARK")) {
bookmarkValue = cli.getQualValue("/BOOKMARK");
}
bookmarkValue = getQualIfExists("/BOOKMARK");
fileName += ".html";
console.log("Loading helpfile \"" + fileName + "\"");
this.openURL(fileName, bookmarkValue);
}
local_cmd = true;
} else if (command === ("CHECK")) {
if (cli.qualifierFound("cli_arg1")) {
let cli_arg1 = getQualIfExists("cli_arg1");
if (cli_arg1) {
let methodstr = "METHOD";
let isattributestr = "ISATTRIBUTE";
let cli_arg1 = cli.getQualValue("cli_arg1").toUpperCase();
cli_arg1 = cli_arg1.toUpperCase();
if (methodstr.length >= cli_arg1.length &&
methodstr.substring(0, cli_arg1.length) === (cli_arg1)) {
// Command is "CHECK METHOD"
let method;
let object;
if (cli.qualifierFound("/METHOD")) {
method = cli.getQualValue("/METHOD");
} else {
let method = getQualIfExists("/METHOD");
if (!method) {
console.log("Cmd: Method is missing\n");
return 0;
}
if (cli.qualifierFound("/OBJECT")) {
object = cli.getQualValue("/OBJECT");
} else {
let object = getQualIfExists("/OBJECT");
if (!object) {
console.log("Cmd: Object is missing\n");
return 0;
}
} else if (isattributestr.length >= cli_arg1.length &&
isattributestr.substring(0, cli_arg1.length) === (cli_arg1)) {
// Command is "CHECK ISATTRIBUTE"
let method;
let object;
if (cli.qualifierFound("/OBJECT")) {
object = cli.getQualValue("/OBJECT");
} else {
let object = getQualIfExists("/OBJECT");
if (!object) {
console.log("Cmd: Object is missing\n");
return 0;
}
}
} else if (command === ("CALL")) {
if (cli.qualifierFound("cli_arg1")) {
let cli_arg1 = getQualIfExists("cli_arg1");
if (cli_arg1) {
let parameter = "METHOD";
let cli_arg1 = cli.getQualValue("cli_arg1").toUpperCase();
cli_arg1 = cli_arg1.toUpperCase();
if (parameter.length >= cli_arg1.length &&
parameter.substring(0, cli_arg1.length) === (cli_arg1)) {
// Command is "CHECK METHOD"
let method;
let object;
if (cli.qualifierFound("/METHOD")) {
method = cli.getQualValue("/METHOD");
} else {
let method = getQualIfExists("/METHOD");
if (!method) {
console.log("Cmd: Method is missing\n");
return 0;
}
if (cli.qualifierFound("/OBJECT")) {
object = cli.getQualValue("/OBJECT");
} else {
let object = getQualIfExists("/OBJECT");
if (!object) {
console.log("Cmd: Object is missing\n");
return 0;
}
}
}
} else if (command === ("SET")) {
return 1;
......@@ -331,8 +261,7 @@ class Appl {
}
openConfirmDialog(dyn, text, object) {
let res = confirm(text);
if (res) {
if (confirm(text)) {
dyn.confirmedAction(Event.MB1Click, object);
}
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -37,6 +37,31 @@ class LocalSub {
}
}
const strToTypeId = {
"boolean": Type.Boolean,
"float32": Type.Float32,
"float64": Type.Float64,
"char": Type.Char,
"int8": Type.Int8,
"int16": Type.Int16,
"int32": Type.Int32,
"int64": Type.Int64,
"uint8": Type.UInt8,
"uint16": Type.UInt16,
"uint32": Type.UInt32,
"uint64": Type.UInt64,
"objid": Type.Objid,
"time": Type.Time,
"deltatime": Type.DeltaTime,
"attrref": Type.AttrRef,
"status": Type.Status,
"netstatus": Type.NetStatus,
"enum": Type.Enum,
"mask": Type.Mask,
"bit": Type.Bit,
"string": Type.String
};
class GraphLocalDb {
subscriptions = [];
subscriptionCount = 1;
......@@ -58,38 +83,32 @@ class GraphLocalDb {
if (id === -1) {
id = this.subscriptionCount;
sub = new LocalSub(owner, name, typeId, id);
sub.ref();
this.subscriptions[id] = sub;
this.subscriptionCount++;
return id;
} else {
sub = this.subscriptions[id];
}
sub.ref();
return id;
}
}
unrefObjectInfo(id) {
let sub = this.subscriptions[id];
if (sub === null) {
return;
}
if (sub) {
sub.unref();
if (sub.getRefCount() <= 0) {
this.subscriptions[id] = null;
}
}
}
getObjectRefInfo(id) {
let sub = this.subscriptions[id];
if (sub === null) {
return 0;
if (sub) {
return (sub.value || 0);
}
if (typeof sub.value === 'undefined') {
return 0;
}
return sub.value;
}
getObjectInfo(owner, attributeName) {
let name = this.getName(attributeName);
......@@ -97,10 +116,7 @@ class GraphLocalDb {
if (id === -1) {
return new CdhrNumber(0, 2);
}
if (typeof this.subscriptions[id].value === 'undefined') {
return new CdhrNumber(0, 1);
}
return new CdhrNumber(this.subscriptions[id].value, 1);
return new CdhrNumber(this.subscriptions[id].value || 0, 1);
}
setObjectInfo(owner, attributeName, value) {
......@@ -125,14 +141,10 @@ class GraphLocalDb {
}
nameToId(owner, name) {
for (let i = 0; i < this.subscriptions.length; i++) {
let sub = this.subscriptions[i];
if (sub !== null && owner === sub.owner &&
name.toUpperCase() === sub.name.toUpperCase()) {
return i;
}
}
return -1;
return this.subscriptions.findIndex(function (sub) {
return (sub !== null && owner === sub.owner &&
name.toUpperCase() === sub.name.toUpperCase());
});
}
getName(attrName) {
......@@ -166,52 +178,12 @@ class GraphLocalDb {
} else {
suffix = attrName.substring(idx1, idx2).toUpperCase();
}
if (suffix === "BOOLEAN") {
return Type.Boolean;
}
if (suffix === "FLOAT32") {
return Type.Float32;
}
if (suffix === "INT32") {
return Type.Int32;
}
if (suffix === "UINT32") {
return Type.UInt32;
}
if (suffix === "INT16") {
return Type.Int16;
}
if (suffix === "UINT16") {
return Type.UInt16;
}
if (suffix === "INT8") {
return Type.Int8;
}
if (suffix === "UINT8") {
return Type.UInt8;
}
if (suffix === "CHAR") {
return Type.Char;
}
if (suffix === "FLOAT64") {
return Type.Float64;
}
if (suffix === "OBJID") {
return Type.Objid;
}
if (suffix === "STRING") {
return Type.String;
}
if (suffix === "TIME") {
return Type.Time;
}
if (suffix === "DELTATIME") {
return Type.DeltaTime;
}
if (suffix === "ATTRREF") {
return Type.AttrRef;
suffix = suffix.toLowerCase();
if (strToTypeId.hasOwnProperty(suffix)) {
return strToTypeId[suffix];
}
if (suffix.substring(0, 6) === "STRING") {
if (suffix.startsWith("string")) {
return Type.String;
}
return 0;
......@@ -286,11 +258,7 @@ class Graph {
login_cb(id, data, sts, result) {
console.log("Login:", sts, result);
if (sts & 1) {
this.priv = result;
} else {
this.priv = 0;
}
this.priv = (sts & 1) ? result : 0;
}
trace_connected(id, sts) {
......@@ -329,34 +297,20 @@ class Graph {
}
growUserdataOpen(lines, row, ctx, type) {
let dyn;
let ret = new UserdataCbReturn();
switch (type) {
case UserdataCbType.Ctx:
if (lines[row] === "1") {
dyn = new Dyn(this);
dyn.userdata = this;
ret.userdata = dyn;
ret.row = dyn.open(lines, row);
} else {
if (type === UserdataCbType.Ctx || type === UserdataCbType.Node || type === UserdataCbType.NodeClass) {
if (type === UserdataCbType.Ctx && lines[row] !== "1") {
ret.row = row - 1;
ret.userdata = null;
return ret;
}
break;
case UserdataCbType.Node:
dyn = new Dyn(this);
let dyn = new Dyn(this);
if (type !== UserdataCbType.NodeClass) {
dyn.userdata = this;
}
ret.userdata = dyn;
ret.row = dyn.open(lines, row);
break;
case UserdataCbType.NodeClass:
dyn = new Dyn(this);
ret.row = dyn.open(lines, row);
ret.userdata = dyn;
break;
default:
break;
}
return ret;
}
......@@ -389,9 +343,7 @@ class Graph {
}
let old_size = list.size();
list = this.ctx.get_object_list();
if (old_size !== list.size())
// Something is deleted
{
if (old_size !== list.size()) { // Something is deleted
break;
}
}
......@@ -495,70 +447,12 @@ class Graph {
if ((idx = str.indexOf('#')) !== -1) {
str = str.substring(0, idx);
}
if (str.toLowerCase() === "boolean") {
return Type.Boolean;
}
if (str.toLowerCase() === "float32") {
return Type.Float32;
}
if (str.toLowerCase() === "float64") {
return Type.Float64;
}
if (str.toLowerCase() === "char") {
return Type.Char;
}
if (str.toLowerCase() === "int8") {
return Type.Int8;
}
if (str.toLowerCase() === "int16") {
return Type.Int16;
}
if (str.toLowerCase() === "int32") {
return Type.Int32;
}
if (str.toLowerCase() === "int64") {
return Type.Int64;
}
if (str.toLowerCase() === "uint8") {
return Type.UInt8;
}
if (str.toLowerCase() === "uint16") {
return Type.UInt16;
}
if (str.toLowerCase() === "uint32") {
return Type.UInt32;
}
if (str.toLowerCase() === "uint64") {
return Type.UInt64;
}
if (str.toLowerCase() === "objid") {
return Type.Objid;
}
if (str.toLowerCase() === "time") {
return Type.Time;
}
if (str.toLowerCase() === "deltatime") {
return Type.DeltaTime;
}
if (str.toLowerCase() === "attrref") {
return Type.AttrRef;
}
if (str.toLowerCase() === "status") {
return Type.Status;
}
if (str.toLowerCase() === "netstatus") {
return Type.NetStatus;
}
if (str.toLowerCase() === "enum") {
return Type.Enum;
}
if (str.toLowerCase() === "mask") {
return Type.Mask;
}
if (str.toLowerCase() === "bit") {
return Type.Bit;
str = str.toLowerCase();
if (strToTypeId.hasOwnProperty(str)) {
return strToTypeId[str];
}
if (str.length >= 6 && str.substring(0, 6).toLowerCase() === "string") {
if (str.startsWith("string")) {
return Type.String;
}
return 0;
......@@ -566,11 +460,9 @@ class Graph {
stringToIndex(str) {
let idx1, idx2;
let index;
if ((idx1 = str.indexOf('[')) !== -1 && (idx2 = str.indexOf(']')) !== -1 &&
idx2 > idx1) {
index = parseInt(str.substring(idx1 + 1, idx2), 10);
let index = parseInt(str.substring(idx1 + 1, idx2), 10);
if (isNaN(index)) {
console.log("Element syntax error, " + str);
return 1;
......@@ -797,13 +689,13 @@ class Graph {
openValueInputDialog(dyn, text, elem) {
let value = prompt(text, "");
if (value !== null) {
if (value) {
dyn.valueInputAction(elem, value);
}
}
openConfirmDialog(dyn, text, object) {
if (appl !== null) {
if (appl) {
appl.openConfirmDialog(dyn, text, object);
}
}
......@@ -817,21 +709,18 @@ class Graph {
}
getAnimationScanTime() {
if (this.scan_time < this.animation_scan_time) {
return this.scan_time;
}
return this.animation_scan_time;
return Math.min(this.scan_time, this.animation_scan_time);
}
command(cmd) {
if (this.appl !== null) {
if (this.appl) {
return this.appl.command(cmd);
}
return 0;
}
script(script) {
if (this.appl !== null) {
if (this.appl) {
return this.appl.script(script);
}
return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment