From 08d7894cc080789686f4b6301626ce54c444d1ff Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jordan=20Aug=C3=A9?= Date: Wed, 14 Aug 2013 16:45:09 +0200 Subject: [PATCH] plugins.resources_selected: now supporting update queries --- manifold/js/manifold.js | 30 ++++-- .../static/css/resources_selected.css | 7 ++ .../static/js/resources_selected.js | 94 ++++++++++++++++--- .../static/resources_selected.html | 4 + trash/sliceview.py | 14 +-- 5 files changed, 123 insertions(+), 26 deletions(-) diff --git a/manifold/js/manifold.js b/manifold/js/manifold.js index a59fa101..94e4469f 100644 --- a/manifold/js/manifold.js +++ b/manifold/js/manifold.js @@ -33,15 +33,15 @@ var FIELD_STATE_CHANGED = 9; var IN_PROGRESS = 101; var DONE = 102; -/* Update requests from plugins */ +/* Update requests related to subqueries */ var SET_ADD = 201; var SET_REMOVED = 202; -var RUN_UPDATE = 203; // request var FIELD_REQUEST_CHANGE = 301; var FIELD_REQUEST_ADD = 302; var FIELD_REQUEST_REMOVE = 303; +var FIELD_REQUEST_RESET = 304; // status var FIELD_REQUEST_PENDING = 301; var FIELD_REQUEST_SUCCESS = 302; @@ -56,8 +56,9 @@ var STATUS_UPDATE_PENDING = 504; var STATUS_UPDATE_IN_PROGRESS = 505; var STATUS_UPDATE_RECEIVED = 506; var STATUS_UPDATE_ERROR = 507; -// outdated ? +/* Requests for query cycle */ +var RUN_UPDATE = 601; // A structure for storing queries @@ -301,6 +302,22 @@ var manifold = { } }, + run_query: function(query, callback) + { + // default value for callback = null + if (typeof callback === 'undefined') + callback = null; + + var query_json = JSON.stringify(query); + + /* Nothing related to pubsub here... for the moment at least. */ + //query.iter_subqueries(function (sq) { + // manifold.raise_record_event(sq.query_uuid, IN_PROGRESS); + //}); + + $.post(manifold.proxy_url, {'json': query_json} , manifold.success_closure(query, null, callback /*domid*/)); + }, + // Executes all async. queries // input queries are specified as a list of {'query_uuid': , 'id': } asynchroneous_exec : function (query_publish_dom_tuples) { @@ -428,7 +445,8 @@ var manifold = { if (data.code == 1) { // WARNING messages.error("Some errors have been received from the manifold backend at " + MANIFOLD_URL + " [" + data.description + "]"); // publish error code and text message on a separate channel for whoever is interested - jQuery.publish("/results/" + publish_uuid + "/failed", [data.code, data.description] ); + if (publish_uuid) + $.publish("/results/" + publish_uuid + "/failed", [data.code, data.description] ); $("#notifications").notify("create", "sticky", { title: 'Warning', @@ -617,9 +635,7 @@ var manifold = { break; case RUN_UPDATE: - update_query = query_ext.main_query_ext.update_query_ext.query; - - manifold.asynchroneous_exec ( [ {'query_uuid': update_query.query_uuid, 'publish_uuid' : query_uuid} ], false); + manifold.run_query(query_ext.main_query_ext.update_query_ext.query); break; case FILTER_ADDED: diff --git a/plugins/resources_selected/static/css/resources_selected.css b/plugins/resources_selected/static/css/resources_selected.css index 9431426f..a9a0bda0 100644 --- a/plugins/resources_selected/static/css/resources_selected.css +++ b/plugins/resources_selected/static/css/resources_selected.css @@ -25,3 +25,10 @@ input.myslice_action { height:30px; background-color:#FF9933; } + +.ResourcesSelected .added { + background-color: #E3F6CE; +} +.ResourcesSelected .removed { + background-color: #F6CECE; +} diff --git a/plugins/resources_selected/static/js/resources_selected.js b/plugins/resources_selected/static/js/resources_selected.js index 18b61fdb..5659670d 100644 --- a/plugins/resources_selected/static/js/resources_selected.js +++ b/plugins/resources_selected/static/js/resources_selected.js @@ -47,31 +47,84 @@ } }); + // XXX This should not be done at init... + this.el('update').click(this, this.do_update); + this.el('refresh').click(this, this.do_refresh); + this.el('reset').click(this, this.do_reset); + this.el('clear_annotations').click(this, this.do_clear_annotations); + this.listen_query(options.query_uuid); }, /*************************** PLUGIN EVENTS ****************************/ /***************************** GUI EVENTS *****************************/ - - // Move through the query cycle - // XXX 'update', 'refresh', 'reset' and 'remove annotation' button - // This is a query scheduler + do_update: function(e) + { + var self = e.data; + // XXX check that the query is not disabled + manifold.raise_event(self.options.query_uuid, RUN_UPDATE); + }, + + do_refresh: function(e) + { + throw 'Not implemented'; + }, + + do_reset: function(e) + { + throw 'Not implemented'; + }, + + do_clear_annotations: function(e) + { + throw 'Not implemented'; + }, + /************************** GUI MANIPULATION **************************/ + + set_button_state: function(name, state) + { + this.el(name).attr('disabled', state ? false : 'disabled'); + }, + clear: function() { }, + find_row: function(key) + { + // key in third position, column id = 2 + var KEY_POS = 2; + + var cols = $.grep(this.table.fnSettings().aoData, function(col) { + return (col._aData[KEY_POS] == key); + } ); + + if (cols.length == 0) + return null; + if (cols.length > 1) + throw "Too many same-key rows in ResourceSelected plugin"; + + return cols[0]; + }, + set_state: function(data) { var action; - var color; var msg; var button = ''; + var row; + + if (data.request == FIELD_REQUEST_RESET) { + // find line + // delete it + } + switch(data.request) { case FIELD_REQUEST_CHANGE: action = 'UPDATE'; @@ -87,29 +140,46 @@ switch(data.status) { case FIELD_REQUEST_PENDING: msg = 'PENDING'; - color = 'white'; button = ""; break; case FIELD_REQUEST_SUCCESS: msg = 'SUCCESS'; - color = 'green'; break; case FIELD_REQUEST_FAILURE: msg = 'FAILURE'; - color = 'red'; break; } - var status = msg + color; + var status = msg + status; - this.table.fnAddData([ + // find line + // if no, create it, else replace it + // XXX it's not just about adding lines, but sometimes removing some + // XXX how do we handle status reset ? + row = this.find_row(data.value); + newline = [ action, data.key, data.value, msg, button - ]); - // XXX change cell color according to status + ]; + if (!row) { + // XXX second parameter refresh = false can improve performance. todo in hazelnut also + this.table.fnAddData(newline); + row = this.find_row(data.value); + } else { + // Update row text... + this.table.fnUpdate(newline, row.nTr); + } + + // Change cell color according to status + if (row) { + $(row.nTr).removeClass('add remove') + var cls = action.toLowerCase(); + if (cls) + $(row.nTr).addClass(cls); + } }, /*************************** QUERY HANDLER ****************************/ diff --git a/plugins/resources_selected/static/resources_selected.html b/plugins/resources_selected/static/resources_selected.html index a4450eb5..aa5e4855 100644 --- a/plugins/resources_selected/static/resources_selected.html +++ b/plugins/resources_selected/static/resources_selected.html @@ -9,3 +9,7 @@ + + + + diff --git a/trash/sliceview.py b/trash/sliceview.py index 4afd6250..a9661005 100644 --- a/trash/sliceview.py +++ b/trash/sliceview.py @@ -24,7 +24,7 @@ from plugins.query_editor import QueryEditor from plugins.active_filters import ActiveFilters from plugins.quickfilter.quickfilter import QuickFilter from plugins.messages.messages import Messages -from plugins.updater import Updater +#from plugins.updater import Updater tmp_default_slice='ple.upmc.myslicedemo' debug = True @@ -258,12 +258,12 @@ def _slice_view (request, slicename): domid = "msgs-pre", levels = "ALL", )) - main_plugin.insert(Updater( - page = page, - title = "wont show up as non togglable by default", - query = main_query, - label = "Update slice", - )) +# main_plugin.insert(Updater( +# page = page, +# title = "wont show up as non togglable by default", +# query = main_query, +# label = "Update slice", +# )) -- 2.43.0