From 59370f16a20cc56aaa61ca8a9a2aa62d418af22b Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Mon, 18 Aug 2014 21:24:08 +0300 Subject: adding history, links & nodes only no atomicity - nodes/links recorded as separate additions We record both temp (state == 'temp') and not temp nodes, can be filtered during analysis. --- scripts/history.js | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 scripts/history.js (limited to 'scripts/history.js') diff --git a/scripts/history.js b/scripts/history.js new file mode 100644 index 00000000..396b3f3c --- /dev/null +++ b/scripts/history.js @@ -0,0 +1,79 @@ +// Once upon a time we shall have a versioned property graph from which history +// will be one extractable aspect, much like a git for graphs. Now we just have +// a plain list of events for a specific user. + +// Enums and chrome don't play along well. Object.freeze I guess? actually rhizi code cuases +// exceptions but that shouldn't break the console, as evidenced by the '__commandLineAPI is not defined' +// error below. +// +// Uncaught TypeError: Can't add property addednodes, object is not extensible rhizicore.js:4 +// Uncaught TypeError: Can't add property text, object is not extensible textanalysis.js:3 +// Uncaught TypeError: Can't add property key, object is not extensible buttons.js:5 +// Uncaught ReferenceError: sentence is not defined robot.js:11 +// Resource interpreted as Font but transferred with MIME type application/font-sfnt: "http://localhost:8000/external/Lato300.ttf". jquery.js:2 +// > document +// ReferenceError: __commandLineAPI is not defined +//var ActionEnum = Enum(); + +function History(user) { + this.records = []; + this.user = user; +} + +var ACTION_TYPE = 'ACTION_TYPE'; +var ACTION_MOUSE = 'ACTION_MOUSE'; +var ACTION_GRAPH_ADD = 'ACTION_GRAPH_ADD'; +var ACTION_GRAPH_DELETE = 'ACTION_GRAPH_DELETE'; + +History.prototype.record = function(d) +{ + if (d === undefined || d.action === undefined) { + throw "Invalid arguments"; + } + d['user'] = this.user; + d['timestamp'] = new Date(); + this.records.push(d); +}; + +History.prototype.save_to_file = function() +{ + // TODO: filename and chrome support (grep json;base64 for other locations) + // perhaps has to wait for FileWriter api? + location.href = 'data:text/json;base64,' + window.btoa(JSON.stringify(this.records)); +}; + +History.prototype.clear_history = function() +{ + this.records = []; +} + +History.prototype.record_nodes_removal = function(ids) +{ + this.record({ + 'action': ACTION_GRAPH_DELETE, + 'node_ids': ids + }); +} + +History.prototype.record_links = function(links) +{ + if (links === undefined || links.length === undefined || links.length <= 0) { + throw "Invalid arguments" + } + this.record({ + 'action': ACTION_GRAPH_ADD, + 'nodes': [], + 'links': links + }); +} + +History.prototype.record_nodes = function(nodes) +{ + if (nodes === undefined || nodes.length === undefined || nodes.length <= 0) { + throw "Invalid arguments" + } + this.record({'action': ACTION_GRAPH_ADD, + 'nodes': nodes, + 'linkes': [] + }); +} -- cgit v1.3.1