plugins.resources_selected: now supporting update queries
authorJordan Augé <jordan.auge@lip6.fr>
Wed, 14 Aug 2013 14:45:09 +0000 (16:45 +0200)
committerJordan Augé <jordan.auge@lip6.fr>
Wed, 14 Aug 2013 14:45:09 +0000 (16:45 +0200)
manifold/js/manifold.js
plugins/resources_selected/static/css/resources_selected.css
plugins/resources_selected/static/js/resources_selected.js
plugins/resources_selected/static/resources_selected.html
trash/sliceview.py

index a59fa10..94e4469 100644 (file)
@@ -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': <query_uuid>, 'id': <possibly null>}
     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:
index 9431426..a9a0bda 100644 (file)
@@ -25,3 +25,10 @@ input.myslice_action {
    height:30px;
    background-color:#FF9933;
 }
+
+.ResourcesSelected .added {
+    background-color: #E3F6CE;
+}
+.ResourcesSelected .removed {
+    background-color: #F6CECE;
+}
index 18b61fd..5659670 100644 (file)
                 }
              });
             
+            // 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';
             switch(data.status) {
                 case FIELD_REQUEST_PENDING:
                     msg   = 'PENDING';
-                    color = 'white';
                     button = "<span class='ui-icon ui-icon-close ResourceSelectedClose' id='" + data.key + "'/>";
                     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 ****************************/
index a4450eb..aa5e485 100644 (file)
@@ -9,3 +9,7 @@
     </tr>
   </thead>
 </table>
+<input id="{{domid}}__update" type=button value="Update" />
+<input id="{{domid}}__refresh" type=button value="Refresh" />
+<input id="{{domid}}__reset" type=button value="Reset" />
+<input id="{{domid}}__clear_annotations" type=button value="Clear annotations" />
index 4afd625..a966100 100644 (file)
@@ -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",
+#    ))