on master help sign in
display notifications in sample websocket html client
commitc99084f80f68e0af3f38f5c5f3a5b18bd5ec7aa6 authorAgentM <agentm@themactionfaction.com> dateWed 27 Sep 2017, 11:38 (9 years ago) parent02e6eec
2 files changed+52−1
src/bin/ProjectM36/Server/WebSocket/project-m36.js+9−1 src/bin/ProjectM36/Server/WebSocket/websocket-client.js+43
src/bin/ProjectM36/Server/WebSocket/project-m36.js+9−1
@@ -10,7 +10,7 @@
1010* @param {promptCallback} promptCallback - A function called whenever prompt information such as the current schema name and current branch name (if any).
1111* @param {closeCallback} closeCallback - A function called once the connection is closed.
1212*/
13−var ProjectM36Connection = function (protocol, host, port, path, dbname, openCallback, errorCallback, statusCallback, promptCallback, closeCallback) {
13+var ProjectM36Connection = function (protocol, host, port, path, dbname, openCallback, errorCallback, statusCallback, promptCallback, notificationCallback, closeCallback) {
1414 this.protocol = protocol;
1515 this.host = host;
1616 this.port = port;
@@ -44,6 +44,7 @@ var ProjectM36Connection = function (protocol, host, port, path, dbname, openCal
4444 };
4545 this.statuscallback = statusCallback;
4646 this.promptcallback = promptCallback;
47+ this.notificationcallback = notificationCallback;
4748 this.socket = socket;
4849}
4950
@@ -77,6 +78,7 @@ ProjectM36Connection.prototype.handleResponse = function(message)
7778 var acknowledged = message["acknowledged"];
7879 var error = message["displayerror"];
7980 var prompt = message["promptInfo"];
81+ var notification = message["notificationname"]
8082
8183 if(relation)
8284 {
@@ -101,6 +103,12 @@ ProjectM36Connection.prototype.handleResponse = function(message)
101103 {
102104 this.promptcallback(prompt["headname"], prompt["schemaname"]);
103105 }
106+
107+ if(notification)
108+ {
109+ var evaldnotif = message.evaldnotification;
110+ this.notificationcallback(message.notificationname, evaldnotif);
111+ }
104112}
105113
106114/**
src/bin/ProjectM36/Server/WebSocket/websocket-client.js+43
@@ -49,6 +49,48 @@ function promptUpdate(headName, schemaName)
4949 document.getElementById("promptinfo").textContent = "Current Branch: (" + headName + ") Schema: (" + schemaName + ")";
5050}
5151
52+function relationErrorAsString(errObj)
53+{
54+ return errObj.tag + " " + errObj.contents;
55+}
56+
57+function notificationUpdate(notificationName, evaldNotif)
58+{
59+ //generate two tables for display
60+ var notifDiv = document.createElement('div');
61+ var oldInfo = document.createElement('div');
62+ oldInfo.textContent = "Pre-change info: ";
63+ var newInfo = document.createElement('div');
64+ newInfo.textContent = "Post-change info: ";
65+ var status = "Notification received: " + notificationName;
66+
67+ if(evaldNotif.reportOldRelation.Left)
68+ {
69+ var errOld = evaldNotif.reportOldRelation.Left;
70+ oldInfo.textContent += relationErrorAsString(errOld);
71+ }
72+ else if(evaldNotif.reportOldRelation.Right)
73+ {
74+ oldInfo.appendChild(conn.generateRelation(evaldNotif.reportOldRelation.Right));
75+ }
76+
77+ if(evaldNotif.reportNewRelation.Left)
78+ {
79+ var errNew = evaldNotif.reportNewRelation.Left;
80+ newInfo.textContent += relationErrorAsString(errNew);
81+ }
82+ else if(evaldNotif.reportNewRelation.Right)
83+ {
84+ newInfo.appendChild(conn.generateRelation(evaldNotif.reportNewRelation.Right));
85+ }
86+
87+ notifDiv.appendChild(oldInfo);
88+ notifDiv.appendChild(document.createElement('br'));
89+ notifDiv.appendChild(newInfo);
90+ appendResult(status,notifDiv);
91+ mungeEmptyRows();
92+}
93+
5294var conn;
5395
5496function connectOrDisconnect(form)
@@ -82,6 +124,7 @@ function connectOrDisconnect(form)
82124 connectionError,
83125 updateStatus,
84126 promptUpdate,
127+ notificationUpdate,
85128 connectionClosed);
86129 toggleConnectionFields(form, false, "Connecting...");
87130 }