Commit 0501e23c authored by Christoffer Ackelman's avatar Christoffer Ackelman

Web: Changed Gdh to use Promises

parent 115edd49
This diff is collapsed.
...@@ -95,7 +95,7 @@ class Ev { ...@@ -95,7 +95,7 @@ class Ev {
console.log("toolitem2", o.userdata.e.supObject.vid, console.log("toolitem2", o.userdata.e.supObject.vid,
o.userdata.e.supObject.oix); o.userdata.e.supObject.oix);
this.ctx.gdh.getObjectFromAref(o.userdata.e.supObject, this.ctx.gdh.getObjectFromAref(o.userdata.e.supObject,
GdhOp.GET_OP_SELF, this.open_navigator_cb, null); GdhOp.GET_OP_SELF).then(this.open_navigator_cb);
console.log("toolitem2 event"); console.log("toolitem2 event");
}); });
// Trace sup object // Trace sup object
...@@ -106,18 +106,16 @@ class Ev { ...@@ -106,18 +106,16 @@ class Ev {
if (o === null) { if (o === null) {
return; return;
} }
let newwindow = window.open("", "_blank");
this.ctx.gdh.getObjectFromAref(o.userdata.e.supObject, this.ctx.gdh.getObjectFromAref(o.userdata.e.supObject,
GdhOp.GET_OP_METHOD_PLC, this.open_plc_cb, newwindow); GdhOp.GET_OP_METHOD_PLC).then(this.open_plc_cb);
}); });
// Graph event name // Graph event name
document.getElementById("toolitem4") document.getElementById("toolitem4")
.addEventListener("click", function (event) { .addEventListener("click", function (event) {
let o = this.ctx.get_select(); let o = this.ctx.get_select();
if (o.userdata instanceof EvItemAlarm) { if (o.userdata instanceof EvItemAlarm) {
let newwindow = window.open("", "_blank");
this.ctx.gdh.getObjectFromName(o.userdata.e.eventName, this.ctx.gdh.getObjectFromName(o.userdata.e.eventName,
GdhOp.GET_OP_METHOD_GRAPH, this.open_graph_cb, newwindow); GdhOp.GET_OP_METHOD_GRAPH).then(this.open_graph_cb);
} }
}); });
// Object raph event name // Object raph event name
...@@ -125,9 +123,8 @@ class Ev { ...@@ -125,9 +123,8 @@ class Ev {
.addEventListener("click", function (event) { .addEventListener("click", function (event) {
let o = this.ctx.get_select(); let o = this.ctx.get_select();
if (o.userdata instanceof EvItemAlarm) { if (o.userdata instanceof EvItemAlarm) {
let newwindow = window.open("", "_blank");
this.ctx.gdh.getObjectFromName(o.userdata.e.eventName, this.ctx.gdh.getObjectFromName(o.userdata.e.eventName,
GdhOp.GET_OP_METHOD_OBJECTGRAPH, this.open_graph_cb, newwindow); GdhOp.GET_OP_METHOD_OBJECTGRAPH).then(this.open_graph_cb);
} }
}); });
// Navigator event name // Navigator event name
...@@ -147,9 +144,8 @@ class Ev { ...@@ -147,9 +144,8 @@ class Ev {
if (o === null) { if (o === null) {
return; return;
} }
let newwindow = window.open("", "_blank");
this.ctx.gdh.getObjectFromName(o.userdata.e.eventName, this.ctx.gdh.getObjectFromName(o.userdata.e.eventName,
GdhOp.GET_OP_METHOD_PLC, this.open_plc_cb, newwindow); GdhOp.GET_OP_METHOD_PLC).then(this.open_plc_cb);
console.log("toolitem7 event"); console.log("toolitem7 event");
}); });
// History event name // History event name
...@@ -175,7 +171,7 @@ class Ev { ...@@ -175,7 +171,7 @@ class Ev {
if (o === null) { if (o === null) {
return; return;
} }
this.ctx.gdh.crrSignal(o.userdata.e.eventName, this.open_crr_cb, o); this.ctx.gdh.crrSignal(o.userdata.e.eventName).then(this.open_crr_cb(o));
console.log("toolitem10 event"); console.log("toolitem10 event");
}); });
// Help event name // Help event name
...@@ -192,12 +188,10 @@ class Ev { ...@@ -192,12 +188,10 @@ class Ev {
return; return;
} }
if (o.userdata instanceof EvItemAlarm) { if (o.userdata instanceof EvItemAlarm) {
let newwindow = window.open("", "_blank");
this.ctx.gdh.getObjectFromName(o.userdata.e.eventName, this.ctx.gdh.getObjectFromName(o.userdata.e.eventName,
GdhOp.GET_OP_METHOD_HELPCLASS, this.open_helpclass_cb, newwindow); GdhOp.GET_OP_METHOD_HELPCLASS).then(this.open_helpclass_cb);
} }
}); });
} }
is_authorized(access) { is_authorized(access) {
...@@ -206,25 +200,26 @@ class Ev { ...@@ -206,25 +200,26 @@ class Ev {
gdh_init_cb() { gdh_init_cb() {
if (!this.priv) { if (!this.priv) {
this.ctx.gdh.login("", "", this.login_cb, this); this.ctx.gdh.login("", "").then(this.login_cb);
} }
//this.ctx.gdh.mhSync( this.mhSyncIdx, this.sync_cb, this); //this.ctx.gdh.mhSync(this.mhSyncIdx).then(this.sync_cb);
this.ctx.gdh.listSent = true; this.ctx.gdh.listSent = true;
this.trace_cyclic(); this.trace_cyclic();
} }
login_cb(id, data, sts, result) { login_cb(res) {
console.log("Login:", sts, result); console.log("Login:", res.sts, res.value);
this.priv = (sts & 1) ? result : 0; this.priv = (res.sts & 1) ? res.value : 0;
} }
sync_cb(id, data, sts, result) { sync_cb(res) {
if (!(sts & 1)) { if (!(res.sts & 1)) {
return; return;
} }
let result = res.value;
if (result.length === 0) { if (result.length === 0) {
return; return;
} }
...@@ -326,7 +321,7 @@ class Ev { ...@@ -326,7 +321,7 @@ class Ev {
let item = node.get_userdata(); let item = node.get_userdata();
console.log("Ack", item.e.eventText); console.log("Ack", item.e.eventText);
this.ctx.gdh.mhAcknowledge(item.e.eventId, this.ack_cb, this); this.ctx.gdh.mhAcknowledge(item.e.eventId).then(this.ack_cb);
if (item.e.eventStatus & EventStatus.NotRet) { if (item.e.eventStatus & EventStatus.NotRet) {
item.e.eventStatus &= ~EventStatus.NotAck; item.e.eventStatus &= ~EventStatus.NotAck;
...@@ -338,24 +333,28 @@ class Ev { ...@@ -338,24 +333,28 @@ class Ev {
this.ctx.draw(); this.ctx.draw();
} }
ack_cb(id, data, sts) { ack_cb(res) {
console.log("ack sts", sts); console.log("ack sts", res.sts);
} }
open_objectgraph_cb(id, data, sts, result) { open_objectgraph_cb(res) {
if ((sts & 1) === 0) { let w = window.open("", "_blank");
data.document.write("Error status " + sts); if ((res.sts & 1) === 0) {
w.document.write("Error status " + res.sts);
} else { } else {
data.location.href = let result = res.value;
w.location.href =
"ge.html?graph=" + result.param1 + "&instance=" + result.fullname; "ge.html?graph=" + result.param1 + "&instance=" + result.fullname;
data.document.title = result.fullname; w.document.title = result.fullname;
} }
} }
open_graph_cb(id, data, sts, result) { open_graph_cb(res) {
if ((sts & 1) === 0) { let w = window.open("", "_blank");
data.document.write("Error status " + sts); if ((res.sts & 1) === 0) {
w.document.write("Error status " + res.sts);
} else { } else {
let result = res.value;
let idx = result.param1.indexOf('.'); let idx = result.param1.indexOf('.');
if (idx !== -1) { if (idx !== -1) {
result.param1 = result.param1.substring(0, idx); result.param1 = result.param1.substring(0, idx);
...@@ -366,62 +365,61 @@ class Ev { ...@@ -366,62 +365,61 @@ class Ev {
instancestr = "&instance=" + result.fullname; instancestr = "&instance=" + result.fullname;
} }
data.location.href = "ge.html?graph=" + result.param1 + instancestr; w.location.href = "ge.html?graph=" + result.param1 + instancestr;
data.document.title = result.param1; w.document.title = result.param1;
} }
} }
open_plc_cb(id, data, sts, result) { open_plc_cb(res) {
if ((sts & 1) === 0) { let w = window.open("", "_blank");
data.document.write("Error status " + sts); if ((res.sts & 1) === 0) {
w.document.write("Error status " + res.sts);
} else { } else {
let param1; let result = res.value;
if (result.param1 === "") { let param1 = result.param1 ? ("&obj=" + result.param1) : "";
param1 = "";
} else {
param1 = "&obj=" + result.param1;
}
console.log("flow.html?vid=" + result.objid.vid + "&oix=" + console.log("flow.html?vid=" + result.objid.vid + "&oix=" +
result.objid.oix + param1); result.objid.oix + param1);
data.location.href = w.location.href =
"flow.html?vid=" + result.objid.vid + "&oix=" + result.objid.oix + "flow.html?vid=" + result.objid.vid + "&oix=" + result.objid.oix +
param1; param1;
data.document.title = "Trace " + result.fullname; w.document.title = "Trace " + result.fullname;
} }
} }
open_navigator_cb(id, data, sts, result) { open_navigator_cb(res) {
console.log("Open navigator", sts); console.log("Open navigator", res.sts);
if ((sts & 1) === 0) { if ((res.sts & 1) === 0) {
console.log("Error status " + sts); console.log("Error status " + res.sts);
} else { } else {
localStorage.setItem("XttMethodNavigator", result.fullname); localStorage.setItem("XttMethodNavigator", res.value.fullname);
console.log("storage", localStorage.getItem("XttMethodNavigator")); console.log("storage", localStorage.getItem("XttMethodNavigator"));
} }
} }
open_objectgraph_cb(id, data, sts, result) { open_objectgraph_cb(res) {
if ((sts & 1) === 0) { let w = window.open("", "_blank");
data.document.write("Error status " + sts); if ((res.sts & 1) === 0) {
w.document.write("Error status " + res.sts);
} else { } else {
let classname = result.classname.toLowerCase(); let classname = res.value.classname.toLowerCase();
if (classname.substring(0, 1) === "$") { if (classname.substring(0, 1) === "$") {
classname = classname.substring(1); classname = classname.substring(1);
} }
let graphname = "pwr_c_" + classname; let graphname = "pwr_c_" + classname;
data.location.href = w.location.href =
"ge.html?graph=" + graphname + "&instance=" + result.fullname; "ge.html?graph=" + graphname + "&instance=" + res.value.fullname;
data.document.title = graphname + " " + result.fullname; w.document.title = graphname + " " + res.value.fullname;
} }
} }
open_helpclass_cb(id, data, sts, result) { open_helpclass_cb(res) {
if ((sts & 1) === 0) { let w = window.open("", "_blank");
data.document.write("Error status " + sts); if ((res.sts & 1) === 0) {
w.document.write("Error status " + res.sts);
} else { } else {
console.log("open_helpclass", result.param1); console.log("open_helpclass", res.value.param1);
data.location.href = w.location.href =
location.protocol + "//" + location.host + result.param1; location.protocol + "//" + location.host + res.value.param1;
} }
} }
...@@ -442,12 +440,12 @@ class Ev { ...@@ -442,12 +440,12 @@ class Ev {
} }
trace_cyclic() { trace_cyclic() {
this.ctx.gdh.mhSync(this.mhSyncIdx, this.sync_cb, this); this.ctx.gdh.mhSync(this.mhSyncIdx).then(this.sync_cb);
this.timer = setTimeout(this.trace_cyclic, 1000); this.timer = setTimeout(this.trace_cyclic, 1000);
} }
trace_scan(id, sts) { trace_scan(res) {
this.scan_update = false; this.scan_update = false;
if (this.scan_update) { if (this.scan_update) {
this.ctx.draw(); this.ctx.draw();
...@@ -581,17 +579,13 @@ class Ev { ...@@ -581,17 +579,13 @@ class Ev {
case Event.Key_CtrlL: case Event.Key_CtrlL:
let o = this.ctx.get_select(); let o = this.ctx.get_select();
if (o.userdata instanceof EvItemAlarm) { if (o.userdata instanceof EvItemAlarm) {
let newwindow = window.open("", "_blank"); this.ctx.gdh.getObject(o.userdata.objid, GdhOp.GET_OP_METHOD_PLC).then(this.open_plc_cb);
this.ctx.gdh.getObject(o.userdata.objid, GdhOp.GET_OP_METHOD_PLC,
this.open_plc_cb, newwindow);
} }
break; break;
case Event.Key_CtrlG: case Event.Key_CtrlG:
let o = this.ctx.get_select(); let o = this.ctx.get_select();
if (o.userdata instanceof EvItemAlarm) { if (o.userdata instanceof EvItemAlarm) {
let newwindow = window.open("", "_blank"); this.ctx.gdh.getObject(o.userdata.objid, GdhOp.GET_OP_METHOD_PLC).then(this.open_objectgraph_cb);
this.ctx.gdh.getObject(o.userdata.objid, GdhOp.GET_OP_METHOD_PLC,
this.open_objectgraph_cb, newwindow);
} }
break; break;
default: default:
......
...@@ -1775,10 +1775,8 @@ class FlowFrame { ...@@ -1775,10 +1775,8 @@ class FlowFrame {
} }
flow_open() { flow_open() {
console.log("flow_open");
console.log("ctx.gdh", this.ctx.gdh);
this.ctx.connect(); this.ctx.connect();
this.ctx.gdh.refObjectInfoList(this.ctx.gdh.refObjectInfoListReply); this.ctx.gdh.refObjectInfoList();
this.timer = setTimeout(this.flow_cyclic, 1000); this.timer = setTimeout(this.flow_cyclic, 1000);
} }
...@@ -1793,7 +1791,6 @@ class FlowFrame { ...@@ -1793,7 +1791,6 @@ class FlowFrame {
} }
flow_close() { flow_close() {
console.log("Close function", this.timer);
clearTimeout(this.timer); clearTimeout(this.timer);
for (let i in this.ctx.gdh.pending) { for (let i in this.ctx.gdh.pending) {
delete this.ctx.gdh.pending[i]; delete this.ctx.gdh.pending[i];
......
...@@ -74,10 +74,8 @@ class Appl { ...@@ -74,10 +74,8 @@ class Appl {
} }
if (classGraph) { if (classGraph) {
console.log("Cmd classGraph"); console.log("Cmd classGraph");
let newwindow = window.open("", "_blank");
this.graph.gdh.getObjectFromName(instanceValue, this.graph.gdh.getObjectFromName(instanceValue,
GdhOp.GET_OP_METHOD_OBJECTGRAPH, this.open_objectgraph_cb, GdhOp.GET_OP_METHOD_OBJECTGRAPH).then(this.open_objectgraph_cb);
newwindow);
} else { } else {
let graphName = cli.getQualValue("cli_arg2").toLowerCase(); let graphName = cli.getQualValue("cli_arg2").toLowerCase();
if (!graphName) { if (!graphName) {
...@@ -266,14 +264,16 @@ class Appl { ...@@ -266,14 +264,16 @@ class Appl {
} }
} }
open_objectgraph_cb(id, data, sts, result) { open_objectgraph_cb(res) {
if ((sts & 1) === 0) { let w = window.open("", "_blank");
data.document.write("Error status " + sts); if ((res.sts & 1) === 0) {
w.document.write("Error status " + res.sts);
} else { } else {
let result = res.value;
console.log("param1", result.param1); console.log("param1", result.param1);
data.location.href = w.location.href =
"ge.html?graph=" + result.param1 + "&instance=" + result.fullname; "ge.html?graph=" + result.param1 + "&instance=" + result.fullname;
data.document.title = result.param1 + " " + result.fullname; w.document.title = result.param1 + " " + result.fullname;
} }
} }
} }
......
This diff is collapsed.
...@@ -249,31 +249,27 @@ class Graph { ...@@ -249,31 +249,27 @@ class Graph {
gdh_init_cb() { gdh_init_cb() {
if (this.priv === null) { if (this.priv === null) {
this.gdh.login("", "", this.login_cb, this); this.gdh.login("", "").then(this.login_cb);
} }
this.ctx.traceConnect(); this.ctx.traceConnect();
this.gdh.refObjectInfoList(this.trace_connected); this.gdh.refObjectInfoList().then(e => this.trace_cyclic());
} }
login_cb(id, data, sts, result) { login_cb(res) {
console.log("Login:", sts, result); console.log("Login:", res.sts, res.value);
this.priv = (sts & 1) ? result : 0; this.priv = (res.sts & 1) ? res.value : 0;
}
trace_connected(id, sts) {
this.trace_cyclic();
} }
trace_cyclic() { trace_cyclic() {
if (this.frame.nogdh) { if (this.frame.nogdh) {
this.trace_scan(0, 0); this.trace_scan();
} else { } else {
this.gdh.getRefObjectInfoAll(this.trace_scan); this.gdh.getRefObjectInfoAll(this.trace_scan);
} }
} }
trace_scan(id, sts) { trace_scan() {
this.scan_time = this.ctx.scantime; this.scan_time = this.ctx.scantime;
this.fast_scan_time = this.ctx.fast_scantime; this.fast_scan_time = this.ctx.fast_scantime;
this.animation_scan_time = this.ctx.animation_scantime; this.animation_scan_time = this.ctx.animation_scantime;
......
...@@ -32,8 +32,8 @@ class OpWindMenu { ...@@ -32,8 +32,8 @@ class OpWindMenu {
gdh_init_cb() { gdh_init_cb() {
let oid = new PwrtObjid(0, 0); let oid = new PwrtObjid(0, 0);
this.user = "Default"; this.user = "Default";
this.gdh.login("", "", this.login_cb, this); this.gdh.login("", "").then(this.login_cb);
this.gdh.getOpwindMenu(this.get_opplace(), this.get_menu_cb, 999); this.gdh.getOpwindMenu(this.get_opplace()).then(this.get_menu_cb);
} }
add_menu_button(context, text) { add_menu_button(context, text) {
...@@ -49,9 +49,9 @@ class OpWindMenu { ...@@ -49,9 +49,9 @@ class OpWindMenu {
return button; return button;
} }
get_menu_cb(id, data, sts, result) { get_menu_cb(res) {
let result = res.value;
this.info = result; this.info = result;
console.log("Menu received", sts, data, result.buttons.length);
let context = document.getElementById("opwindmenu"); let context = document.getElementById("opwindmenu");
document.getElementById("opwind_title").innerHTML = result.title; document.getElementById("opwind_title").innerHTML = result.title;
...@@ -89,7 +89,7 @@ class OpWindMenu { ...@@ -89,7 +89,7 @@ class OpWindMenu {
passwd = c.crypt("aa", passwd); passwd = c.crypt("aa", passwd);
this.user = user; this.user = user;
this.gdh.login(user, passwd, this.login_cb, this); this.gdh.login(user, passwd).then(this.login_cb);
}); });
document.getElementById("cancel_button") document.getElementById("cancel_button")
.addEventListener("click", function (event) { .addEventListener("click", function (event) {
...@@ -102,7 +102,7 @@ class OpWindMenu { ...@@ -102,7 +102,7 @@ class OpWindMenu {
document.getElementById("login_frame").style.height = '0px'; document.getElementById("login_frame").style.height = '0px';
this.priv = 0; this.priv = 0;
this.user = "Default"; this.user = "Default";
this.gdh.login("", "", this.login_cb, this); this.gdh.login("", "").then(this.login_cb);
}); });
document.getElementById("login_user").innerHTML = ""; document.getElementById("login_user").innerHTML = "";
...@@ -200,10 +200,9 @@ class OpWindMenu { ...@@ -200,10 +200,9 @@ class OpWindMenu {
} }
} }
login_cb(id, data, sts, result) { login_cb(res) {
console.log("Login:", sts, result); if (res.sts & 1) {
if (sts & 1) { this.priv = res.value;
this.priv = result;
sessionStorage.setItem("pwr_privilege", String(this.priv)); sessionStorage.setItem("pwr_privilege", String(this.priv));
if (this.user_text !== null) { if (this.user_text !== null) {
this.user_text.textContent = this.user + " on " + this.host; this.user_text.textContent = this.user + " on " + this.host;
......
This diff is collapsed.
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