on master help sign in
add dataframe support to websocket client and library
commit2c0102325065f5bed5d9bdc454b34688f1be1f09 authorAgentM <agentm@themactionfaction.com> dateTue 8 Jan 2019, 21:07 (8 years ago) parent51fdb18
2 files changed+52−7
src/bin/ProjectM36/Server/WebSocket/project-m36.js+45−6 src/bin/ProjectM36/Server/WebSocket/websocket-client.js+7−1
src/bin/ProjectM36/Server/WebSocket/project-m36.js+45−6
@@ -55,9 +55,10 @@ var ProjectM36Connection = function (protocol, host, port, path, dbname, openCal
5555* @param {Object} acknowledgementresult - The status update containing an acknowledgement that the query was executed or null.
5656* @param {Object} errorResult - The status update containing the error information or null.
5757*/
58−var ProjectM36Status = function (relationResult, acknowledgementResult, errorResult)
58+var ProjectM36Status = function (relationResult, dataFrameResult, acknowledgementResult, errorResult)
5959{
6060 this.relation = relationResult;
61+ this.dataframe = dataFrameResult;
6162 this.acknowledgement = acknowledgementResult;
6263 this.error = errorResult;
6364}
@@ -75,6 +76,7 @@ ProjectM36Connection.prototype.readyState = function()
7576ProjectM36Connection.prototype.handleResponse = function(message)
7677{
7778 var relation = message["displayrelation"];
79+ var dataframe = message["displaydataframe"];
7880 var acknowledged = message["acknowledged"];
7981 var error = message["displayerror"];
8082 var prompt = message["promptInfo"];
@@ -82,12 +84,17 @@ ProjectM36Connection.prototype.handleResponse = function(message)
8284
8385 if(relation)
8486 {
85− this.statuscallback(new ProjectM36Status(relation['json'], null, null));
87+ this.statuscallback(new ProjectM36Status(relation['json'], null, null, null));
88+ }
89+
90+ if(dataframe)
91+ {
92+ this.statuscallback(new ProjectM36Status(null, dataframe['json'], null, null));
8693 }
8794
8895 if(acknowledged)
8996 {
90− this.statuscallback(new ProjectM36Status(null, true, null));
97+ this.statuscallback(new ProjectM36Status(null, null, true, null));
9198 }
9299
93100 if(error)
@@ -96,7 +103,7 @@ ProjectM36Connection.prototype.handleResponse = function(message)
96103 {
97104 error=error.tag; // for error objects
98105 }
99− this.statuscallback(new ProjectM36Status(null, null, error['json']));
106+ this.statuscallback(new ProjectM36Status(null, null, null, error['json']));
100107 }
101108
102109 if(prompt)
@@ -161,6 +168,7 @@ ProjectM36Connection.prototype.generateAtomType = function(attr)
161168{
162169 var atomType = attr[1]["tag"];
163170 var attrName = attr[0];
171+ var accessory = attr[2];
164172 var element = document.createElement("span");
165173 element.textContent = attrName + "::";
166174 if (atomType == "RelationAtomType")
@@ -185,7 +193,11 @@ ProjectM36Connection.prototype.generateAtomType = function(attr)
185193 var readableType = atomType.slice(0,-8);
186194 element.textContent += readableType;
187195 }
188− return element
196+ if(accessory)
197+ {
198+ element.textContent += accessory;
199+ }
200+ return element;
189201}
190202
191203ProjectM36Connection.prototype.generateRelationBody = function (body)
@@ -230,6 +242,33 @@ ProjectM36Connection.prototype.generateAtom = function(atom)
230242 return element;
231243}
232244
245+ProjectM36Connection.prototype.generateDataFrame = function(dataframe)
246+{
247+ for(var attrIndex=0; attrIndex < dataframe.attributes.length; attrIndex++)
248+ {
249+ var attr = dataframe.attributes[attrIndex];
250+ var ordering = "↕";
251+ for(var orderIndex=0; orderIndex < dataframe.orders.length; orderIndex++)
252+ {
253+ var order = dataframe.orders[orderIndex];
254+ if(order[0] == attr[0])
255+ {
256+ if(order[1] == "AscendingOrder")
257+ {
258+ ordering = "⬆";
259+ }
260+ else if(order[1] == "DescendingOrder")
261+ {
262+ ordering = "⬇";
263+ }
264+ }
265+ }
266+ dataframe.attributes[attrIndex].push(ordering);
267+ }
268+ return this.generateRelation([dataframe.attributes,
269+ {asList:dataframe.tuples}]);
270+}
271+
233272//special case to make sure that a table appears for "true" and "false"
234273function mungeEmptyRows()
235274{
@@ -249,4 +288,4 @@ function mungeEmptyRows()
249288 empty.appendChild(dudHeader);
250289 }
251290 }
252−}
291+}
src/bin/ProjectM36/Server/WebSocket/websocket-client.js+7−1
@@ -30,6 +30,12 @@ function updateStatus(status)
3030 appendResult(tutd, relastable);
3131 mungeEmptyRows();
3232 }
33+ if(status.dataframe)
34+ {
35+ var dataframeastable = conn.generateDataFrame(status.dataframe);
36+ appendResult(tutd, dataframeastable);
37+ mungeEmptyRows();
38+ }
3339 if(status.acknowledgement)
3440 {
3541 var ok = document.createElement("span");
@@ -253,4 +259,4 @@ function pageload()
253259{
254260 installSampleHandlers();
255261 setupDefaultConfig();
256−}
262+}