summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2015-05-12 12:23:50 +0300
committerAlon Levy <alon@pobox.com>2015-05-12 12:30:24 +0300
commit675dbf4f5ddb9f5b01d06c21d5a75dd798af9005 (patch)
tree808527fccd697f560e63e4a8481a67a408e9b1e9
parent5bc73cd5701f1a5a9d214d8b680ea8d8948298d2 (diff)
client/view/activity: clickable to select changed nodes, description
-rw-r--r--src/client/rz_core.js2
-rw-r--r--src/client/view/activity.js107
2 files changed, 99 insertions, 10 deletions
diff --git a/src/client/rz_core.js b/src/client/rz_core.js
index 3a680374..8255486e 100644
--- a/src/client/rz_core.js
+++ b/src/client/rz_core.js
@@ -207,7 +207,7 @@ function init() {
init_graphs();
init_graph_views();
init_ws_connection();
- activity.init($('.graph-view'));
+ activity.init(main_graph, $('.graph-view'));
if (rz_config.backend_enabled) {
var cur_rzdoc_name = rzdoc__current__get_name();
diff --git a/src/client/view/activity.js b/src/client/view/activity.js
index 44d3632a..53706c06 100644
--- a/src/client/view/activity.js
+++ b/src/client/view/activity.js
@@ -1,21 +1,110 @@
-define(['jquery', 'Bacon'],
-function($, Bacon) {
+define(['jquery', 'underscore', 'Bacon', 'view/selection'],
+function($, _, Bacon, selection) {
var incomingActivityBus = new Bacon.Bus(),
- activity_element;
+ activity_element,
+ graph_view_element,
+ graph;
-function init(graph_view)
+function init(_graph, _graph_view_element)
{
activity_element = $('<div class="activity-root-div"></div>');
- graph_view.append(activity_element);
+ graph_view_element = _graph_view_element;
+ graph_view_element.append(activity_element);
+ graph = _graph;
}
-function appendActivity(topo_diff_spec)
+function is_topo(diff)
{
- var new_div = $('<div></div>');
+ return diff['link_id_set_rm'] !== undefined && diff['node_set_add'] !== undefined,
+ diff['node_id_set_rm'] !== undefined && diff['link_set_add'] !== undefined;
+}
+
+function is_attr(diff)
+{
+ return diff['__type_node'] !== undefined && diff['__type_link'] !== undefined;
+}
+
+function node_ids_from_diff(diff)
+{
+ return is_attr(diff) ? _.keys(diff['__type_node']) : _.pluck(diff.node_set_add, 'id');
+}
+
+function link_ids_from_diff(diff)
+{
+ return is_attr(diff) ? _.keys(diff['__type_link']) : _.pluck(diff.link_set_add, 'id');
+}
+
+function topo_explanation(diff)
+{
+ var nodes_added = _.pluck(diff.node_set_add, 'name'),
+ links_added = _.pluck(diff.link_set_add, 'name');
+
+ return (nodes_added.length > 0 ? 'added ' + nodes_added.join(' ') + ' nodes' : '') +
+ (nodes_added.length > 0 && links_added.length > 0 ? ', ' : '') +
+ (links_added.length > 0 ? 'added ' + links_added.join(' ') + ' links' : '');
+}
+
+function attr_explanation(diff)
+{
+ //var nodes_changed = _.map(diff.__type_node0
+ return '' + diff;
+}
+
+function explanation_from_diff(diff)
+{
+ if (is_topo(diff)) {
+ return topo_explanation(diff);
+ }
+ if (is_attr(diff)) {
+ return attr_explanation(diff);
+ }
+
+}
+
+function time_diff(d1, d2)
+{
+ var delta = Math.floor((d2 - d1) / 1000.0),
+ seconds = delta % 60,
+ minutes = (delta / 60) % 60,
+ hours = (delta / 3600) % 24,
+ days = Math.floor((delta / 86400));
+
+ if (delta < 60) {
+ return '' + delta + ' seconds ago';
+ }
+ if (delta < 3600) {
+ return '' + minutes + 'minutes and ' + seconds + ' seconds ago';
+ }
+ return '' + days + ' days, ' + minutes + ' minutes and ' + seconds + ' seconds ago';
+}
+
+/**
+ * appendActivity(activity)
+ *
+ * [!] should be diff?
+ *
+ */
+function appendActivity(diff)
+{
+ var new_div = $('<div class="activity-div"></div>'),
+ meta = diff.meta || {},
+ creation_date = meta.ts_created !== undefined ? new Date(meta.ts_created) : new Date(),
+ commit = meta.commit, // [!] unused, should link to permanent url
+ author = meta.author || 'Anonymous',
+ sentence = meta.sentence,
+ affected_node_ids = node_ids_from_diff(diff),
+ affected_link_ids = link_ids_from_diff(diff),
+ affected_nodes = _.filter(_.map(affected_node_ids, graph.find_node__by_id), null),
+ affected_links = _.filter(_.map(affected_link_ids, graph.find_link__by_id), null);
+ explanation = (sentence !== undefined && sentence.length > 0) ? sentence : explanation_from_diff(diff);
- new_div.text('' + topo_diff_spec);
- activity_element.append(new_div);
+ new_div.text(creation_date + ' ' + author + ': ' + explanation);
+ activity_element.prepend(new_div);
+ new_div.on('click', function (event) {
+ (event.shiftKey ? selection.invert_both : selection.select_both)
+ (affected_nodes, affected_links);
+ });
// TODO - x button
// TODO - format of text per activity (topo/attr)
// TODO - user data (requires protocol update?)