Permalink
Browse files

results from Rserve come in javascript-friendly. No more .value[0].va…

…lue[0] madness
  • Loading branch information...
1 parent bc6a268 commit d1862cfe4e4454bd980741836cac076ad28e9431 Carlos Scheidegger committed Mar 15, 2013
View
@@ -31,17 +31,16 @@ var editor = {
populate_file_list: function() {
var that = this;
rcloud.get_all_user_filenames(function(data) {
- data = data.value;
var this_user = rcloud.username();
var result = [];
that.file_tree_model = {};
for (var i=0; i<data.length; ++i) {
- var dirname = data[i].value[0].value[0];
- var files_data = data[i].value[1].value;
+ var dirname = data[i][0];
+ var files_data = data[i][1];
var file_nodes = _.map(files_data, function(file_data) {
- var name = file_data.value[0].value[0];
- var mtime = file_data.value[1].value[0];
+ var name = file_data[0];
+ var mtime = file_data[1];
var result = {
label: name,
mtime: mtime,
@@ -138,8 +137,8 @@ var editor = {
function update_source_search(result) {
d3.select("#input-text-source-results-title")
- .style("display", (result.value !== null && result.value.length >= 1)?null:"none");
- var data = _.map(result.value, split_source_search_lines);
+ .style("display", (result !== null && result.length >= 1)?null:"none");
+ var data = _.map(result, split_source_search_lines);
d3.select("#input-text-source-results-table")
.selectAll("tr").remove();
var td_classes = ["user", "filename", "linenumber", "loc"];
@@ -181,8 +180,8 @@ var editor = {
};
function update_history_search(result) {
d3.select("#input-text-history-results-title")
- .style("display", (result.value !== null && result.value.length >= 1)?null:"none");
- var data = _.map(result.value, split_history_search_lines);
+ .style("display", (result !== null && result.length >= 1)?null:"none");
+ var data = _.map(result, split_history_search_lines);
d3.select("#input-text-history-results-table")
.selectAll("tr").remove();
var td_classes = ["date", "user", "loc"];
@@ -214,8 +213,8 @@ var editor = {
;
};
rcloud.search(search_string, function(result) {
- update_source_search(result.value[0]);
- update_history_search(result.value[1]);
+ update_source_search(result[0]);
+ update_history_search(result[1]);
});
}
};
@@ -21,9 +21,9 @@ FacetChart.facet_tour_plot = function(array_list)
{
var result = {};
var columns = [];
- for (var i=0; i<array_list.value.length; ++i) {
+ for (var i=0; i<array_list.length; ++i) {
result["dim_" + i] = Facet.attribute_buffer({
- vertex_array: array_list.value[i].value,
+ vertex_array: array_list[i],
item_size: 1,
keep_array: true
});
@@ -147,7 +147,7 @@ function create_markdown_cell_html_view(cell_model)
},
result_updated: function(r) {
r_result_div.hide();
- r_result_div.html(r.value[0]);
+ r_result_div.html(r);
r_result_div.slideDown(150);
// There's a list of things that we need to do to the output:
@@ -164,7 +164,7 @@ function create_markdown_cell_html_view(cell_model)
var that = this;
rcloud.resolve_deferred_result(uuids[1], function(data) {
$(that).replaceWith(function() {
- return shell.handle(data.value[0].value[0], data);
+ return shell.handle(data[0], data);
});
});
});
@@ -376,7 +376,7 @@ function create_interactive_cell_html_view(cell_model)
},
result_updated: function(r) {
r_result_div.hide();
- r_result_div.html(r.value[0]);
+ r_result_div.html(r);
r_result_div.slideDown(150);
// There's a list of things that we need to do to the output:
@@ -393,7 +393,7 @@ function create_interactive_cell_html_view(cell_model)
var that = this;
rcloud.resolve_deferred_result(uuids[1], function(data) {
$(that).replaceWith(function() {
- return shell.handle(data.value[0].value[0], data);
+ return shell.handle(data[0], data);
});
});
});
@@ -24,7 +24,7 @@ Notebook.create_controller = function(model)
load_from_file: function(user, filename, k) {
var that = this;
rcloud.load_user_file(user, filename, function(contents) {
- var json_contents = JSON.parse(contents.value.join("\n"));
+ var json_contents = JSON.parse(contents.join("\n"));
that.clear();
_.each(json_contents, function (json_cell) {
var cell_model = that.append_cell(
@@ -37,7 +37,7 @@ Notebook.create_controller = function(model)
var that = this;
var json_rep = JSON.stringify(model.json());
rcloud.load_user_file(user, filename, function(old_contents) {
- old_contents = old_contents.value.join("\n");
+ old_contents = old_contents.join("\n");
if (json_rep !== old_contents) {
rcloud.save_to_user_file(user, filename, json_rep, function() {
k && k();
View
@@ -1,11 +1,3 @@
-/*
-
- RClient is a low-level communication layer between Javascript and a
- running R process on the other side.
-
- */
-
-//////////////////////////////////////////////////////////////////////////////
(function() {
// takes a string and returns the appropriate r literal string with escapes.
@@ -61,35 +53,29 @@ RClient = {
var _capturing_callback = undefined;
var result;
- var command_counter = 0;
result = {
handlers: {
"eval": function(v) {
- if (v.value.length === 3) {
- var command_id = v.value[2].value[0];
- result.display_response(v.value[1]);
- }
- return v.value[1];
+ debugger;
+ result.post_response(v);
+ return v;
},
"markdown.eval": function(v) {
- if (v.value.length === 3) {
- var command_id = v.value[2].value[0];
- result.display_markdown_response(v.value[1]);
- }
- return v.value[1];
+ result.display_markdown_response(v);
+ return v;
},
"browsePath": function(v) {
- $.ajax({ url: "http://127.0.0.1:8080" + v.value[1].value }).done(function(result) {
+ $.ajax({ url: "http://127.0.0.1:8080" + v }).done(function(result) {
// horrible hack: we strip the content down to its main div via regexp
// cue jwz here.
var inside_body = /[\s\S]*<body>([\s\S]*)<\/body>/g.exec(result)[1];
$("#help-output").html(inside_body);
});
},
// FIXME: I couldn't get this.post_* to work from here so this is just to avoid the error ... it's nonsensical, obviously
- "img.url.update": function(v) { return v.value[1]; },
- "img.url.final": function(v) { return v.value[1]; },
+ "img.url.update": function(v) { return v; },
+ "img.url.final": function(v) { return v; },
"dev.new": function(v) { return ""; },
"dev.close": function(v) { return ""; },
"internal_cmd": function(v) { return ""; },
@@ -98,7 +84,6 @@ RClient = {
}
},
running: false,
- result_handlers: {},
eval: function(data) {
var that = this;
@@ -127,17 +112,18 @@ RClient = {
return this.post_error("Unknown command " + cmd);
}
if (cmd == "img.url.update" || cmd == "img.url.final") {
+ throw "Who's doing this?";
// FIXME: this is a bad hack storing in the window - do something more reasonable ;)
- var ix = window.devImgIndex;
- if (!ix) window.devImgIndex = ix = 1;
- if (cmd == "img.url.final") window.devImgIndex++;
- var div = document.getElementById("dimg"+ix);
- if (div) // FIXME: we may want to move the div down as well -- maybe just remove the old one and add a new one?
- div.innerHTML = "<img src="+data.value[1].value[0]+">";
- else
- this.post_div("<div id=dimg"+ix+"><img src="+data.value[1].value[0]+"></div>");
+ // var ix = window.devImgIndex;
+ // if (!ix) window.devImgIndex = ix = 1;
+ // if (cmd == "img.url.final") window.devImgIndex++;
+ // var div = document.getElementById("dimg"+ix);
+ // if (div) // FIXME: we may want to move the div down as well -- maybe just remove the old one and add a new one?
+ // div.innerHTML = "<img src="+data.value[1].value[0]+">";
+ // else
+ // this.post_div("<div id=dimg"+ix+"><img src="+data.value[1].value[0]+"></div>");
}
- return cmds[cmd].call(this, data);
+ return cmds[cmd].call(this, data.json()[1]);
},
register_handler: function(cmd, callback) {
@@ -163,24 +149,6 @@ RClient = {
return shell.post_div(msg);
},
- post_binary_response: function(msg) {
- if (_debug) {
- this.post_debug_message(msg);
- this.display_response(parse(msg));
- } else {
- try {
- this.display_response(parse(msg));
- } catch (e) {
- this.post_error("Uncaught exception: " + e.message + " - " + e.status_code);
- }
- }
- },
-
- display_response: function (result) {
- if (result) $("#output").append(result.html_element());
- window.scrollTo(0, document.body.scrollHeight);
- },
-
display_markdown_response: function(result) {
if (result) {
$("#output")
@@ -197,7 +165,6 @@ RClient = {
//////////////////////////////////////////////////////////////////
post_error: function (msg) {
- debugger;
var d = $("<div class='error-message'></div>").html(msg);
$("#output").append(d);
window.scrollTo(0, document.body.scrollHeight);
@@ -230,22 +197,16 @@ RClient = {
wrap_command: function(command, silent) {
// FIXME code injection? notice that this is already eval, so
// what _additional_ harm would exist?
- var this_command = command_counter++;
if (silent === undefined) {
silent = false;
}
- return [ "rcloud.support::session.eval({" + command + "}, "
- + this_command + ", "
- + (silent?"TRUE":"FALSE") + ")",
- this_command ];
+ return "rcloud.support::session.eval({" + command + "}, "
+ + (silent?"TRUE":"FALSE") + ")";
},
markdown_wrap_command: function(command, silent) {
- var this_command = command_counter++;
- return [ "rcloud.support::session.markdown.eval({markdownToHTML(text=paste(knit(text=" + escape_r_literal_string(command+'\n') + "), collapse=\"\\n\"), fragment=TRUE)}, "
- + this_command + ", "
- + (silent?"TRUE":"FALSE") + ")",
- this_command ];
+ return "rcloud.support::session.markdown.eval({markdownToHTML(text=paste(knit(text=" + escape_r_literal_string(command+'\n') + "), collapse=\"\\n\"), fragment=TRUE)}, "
+ + (silent?"TRUE":"FALSE") + ")";
},
log: function(command) {
@@ -272,24 +233,23 @@ RClient = {
callback = no_callback;
var t;
if (wrap) {
- t = wrap(command);
+ command = wrap(command);
} else {
- t = this.wrap_command(command, true);
+ command = this.wrap_command(command, true);
}
- command = t[0];
if (_debug)
console.log(command);
function unwrap(v) {
+ v = v.value.json();
if (_debug) {
debugger;
console.log(v);
}
try {
- callback(v.value.value[1]);
+ callback(v[1]);
} catch (e) {
if (e.constructor === NoCallbackError) {
- debugger;
- that.handlers[v.value.value[0].value[0]](v.value);
+ that.handlers[v[0]](v[1]);
}
}
}
View
@@ -4,11 +4,11 @@ rcloud.init_client_side_data = function()
{
var that = this;
rcloud.get_user_filenames(function(data) {
- that.user_filenames = data.value;
+ that.user_filenames = data;
//////////////////////////////////////////////////////////////////
// debugging info
- var filenames = data.value;
+ var filenames = data;
var userfiles_float = d3.select("#internals-user-files");
userfiles_float.append("h3").text("User files");
userfiles_float.append("ul")
@@ -18,7 +18,7 @@ rcloud.init_client_side_data = function()
.append("li").text(function(i) { return i; });
});
rclient.send_and_callback("rcloud.prefix.uuid()", function(data) {
- that.wplot_uuid = data.value[0];
+ that.wplot_uuid = data;
});
};
Oops, something went wrong.

0 comments on commit d1862cf

Please sign in to comment.