From: Thierry Parmentelat <thierry.parmentelat@inria.fr> Date: Thu, 14 Mar 2013 15:19:50 +0000 (+0100) Subject: a pass on quickfilter, at least it displays something related to the input 'criterias' X-Git-Tag: myslice-django-0.1-1~3 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=433a5d301336bc9d402af49b2aceb257f57514bb;p=unfold.git a pass on quickfilter, at least it displays something related to the input 'criterias' the javascript has probably never been tested at that point I would think also it would make sense to read the metadata info --- diff --git a/README b/README index f1680239..92724d1f 100644 --- a/README +++ b/README @@ -162,14 +162,10 @@ I've tried to keep track of the version I picked and to have an easy upgrade pat we chose to have all static files (images, but also javascript and stylesheets) in the various proj or app where they belong, under a static/ subdir that has this structure: where-it-belongs/ - static/ img/ css/ js/ -NOTE. in essence any of these files can be moved around (from e.g. one templates/ dir to another) -at any time without any change needed in the code - * filenames / locations you can run the following make targets to have a summary of where things are @@ -178,27 +174,13 @@ at any time without any change needed in the code -- or -- $ make list-all - as far as possible it's great to have things named the same after e.g. say a plugin name - like e.g. - plugins/quickfilter.py - plugins/templates/quickfilter.html - plugins/static/js/quickfilter.js - plugins/static/css/quickfilter.css - - it's sometimes not working though, so here are a few additional conventions - the global layout (for now I needed only one) is named layout-myslice.html - it provides the global layout with one menu stuck on top and 2 divs 3/4 1/4 - - the views that I currently have are all named in templates/view-<>.html - they all extend a layout - they should/could admittedly move where they belong (in auth/slice/engine) - so that they would go with their views.py code, but for now it's impler this way +* plugins + use a naming scheme as simple as possible + like e.g. + plugins/quickfilter/quickfilter.py + plugins/quickfilter/quickfilter.html + plugins/quickfilter/quickfilter.js + plugins/quickfilter/quickfilter.css - and there are 3 'widgets' (login, logout, and topmenu) - these could maybe be best implemented as a plugin now that I have the right model for that - however esp. for the login/logout I'm not quite sure this will remain over time - so for now it's good enough like this -So in summary there's still room for a lot of improvement on this particular topic.. -At the very least topmenu should be made a plugin, and maybe also login/logout diff --git a/engine/plugin.py b/engine/plugin.py index 36d60dfc..8f817a5b 100644 --- a/engine/plugin.py +++ b/engine/plugin.py @@ -16,7 +16,7 @@ from engine.prelude import Prelude # . True : to debug all plugin DEBUG= False -#DEBUG= [ 'SliceList' ] +DEBUG= [ 'QuickFilter' ] # decorator to deflect calls on Plugin to its Prelude through self.page.prelude def to_prelude (method): diff --git a/plugins/lists/simplelist.js b/plugins/lists/simplelist.js index 6fdb4c3f..6ea2a77d 100644 --- a/plugins/lists/simplelist.js +++ b/plugins/lists/simplelist.js @@ -34,7 +34,7 @@ /* passing $this as 2nd arg: callbacks will retrieve $this as e.data */ $.subscribe(channel, $this, update_plugin); if (debug) window.console.log('subscribing to ' + channel); - $this.data('SimpleList', {options: options}); + $this.data('SimpleList', options); } }); }, @@ -82,7 +82,7 @@ else regular_set_message (error); return; } - var options = $plugindiv.data().SimpleList.options; + var options = $plugindiv.data().SimpleList; if (use_datatables) datatables_update_table ($table,$tbody,rows,options.key); else regular_update_table ($table,$tbody,rows,options.key); diff --git a/plugins/lists/simplelist.py b/plugins/lists/simplelist.py index a86d73c2..50cd573d 100644 --- a/plugins/lists/simplelist.py +++ b/plugins/lists/simplelist.py @@ -27,7 +27,7 @@ class SimpleList (Plugin) : 'css_files': [ "css/simplelist.css" ], } if self.with_datatables: - reqs['js_files'].append ("datatables/js/dataTables.js") + reqs['js_files'].append ("js/dataTables.js") reqs['js_files'].append ("js/with-datatables.js") return reqs diff --git a/plugins/lists/staticlist.py b/plugins/lists/staticlist.py index b9c644b6..134917a8 100644 --- a/plugins/lists/staticlist.py +++ b/plugins/lists/staticlist.py @@ -24,6 +24,6 @@ class StaticList (Plugin) : 'css_files': [ "css/staticlist.css" ], } if self.with_datatables: - reqs['js_files'].append ("datatables/js/dataTables.js") + reqs['js_files'].append ("js/dataTables.js") reqs['js_files'].append ("js/with-datatables.js") return reqs diff --git a/plugins/querycode/querycode.py b/plugins/querycode/querycode.py index fc5c163f..4b84548a 100644 --- a/plugins/querycode/querycode.py +++ b/plugins/querycode/querycode.py @@ -31,4 +31,5 @@ class QueryCode (Plugin): def json_settings_list (self): return ['plugin_uuid', 'query','query_uuid'] + # because we have a link to a query it looks like we need a spin, let's make this right def start_with_spin (self): return False diff --git a/plugins/quickfilter/quickfilter.html b/plugins/quickfilter/quickfilter.html index 491cdcb8..e9e8330c 100644 --- a/plugins/quickfilter/quickfilter.html +++ b/plugins/quickfilter/quickfilter.html @@ -1,14 +1,14 @@ <div id='quick-filters-{{ domid }}' class='quick-filters'> -<table class='filters'> + <table class='filters'> <tr> - {% for criteria in list %} - <th class='top'>{{criteria.key}}</th> - {% endfor %} - <th class="top">Extra fields</th> + {% for criteria in criterias %} + <th class='top'>{{criteria.key}}</th> + {% endfor %} + <th class="top">Extra fields</th> </tr> <tr> - {% for criteria in list %} - <td class='top'> + {% for criteria in criterias %} + <td class='top'> <select id='{{uid}}-select_{{criteria.key}}' class='topselect QuickFilter_select'> <option value=''>All</option> {% for item in criteria.values%} diff --git a/plugins/quickfilter/quickfilter.js b/plugins/quickfilter/quickfilter.js index 7402b7b7..5be5426f 100644 --- a/plugins/quickfilter/quickfilter.js +++ b/plugins/quickfilter/quickfilter.js @@ -1,73 +1,82 @@ - /** * MySlice QuickFilter plugin - * Version: 0.1.0 - * URL: http://www.myslice.info - * Description: A simple Plugin that prints some important variables, to be used as a template - * Requires: + * URL: http://trac.myslice.info + * Description: editing search filters * Author: The MySlice Team - * Copyright: Copyright 2012 UPMC Sorbonne Universités + * Copyright (c) 2012 UPMC Sorbonne Universite - INRIA * License: GPLv3 */ -(function( $ ){ - - var methods = { - init : function( options ) { - - return this.each(function(){ - - var $this = jQuery(this), - data = $this.data('QuickFilter'), QuickFilter = jQuery('<div />', {text : $this.attr('title')}); - - // If the plugin hasn't been initialized yet - if ( ! data ) { - - /* Plugin initialization */ - - data = jQuery(this).data(); - - /* Subscribe to selection updates published by the resource display plugins*/ - //jQuery.subscribe('selected', {instance: $this}, resource_selected); - jQuery.subscribe('/query/' + options.query_uuid + '/changed', {instance: $this}, query_changed); +( function($){ + var debug=false; + //debug=true; - /* End of plugin initialization */ - - jQuery(this).data('QuickFilter', { - plugin_uuid: options.plugin_uuid, - query_uuid: options.query_uuid, - target : $this, - QuickFilter : QuickFilter - }); + $.fn.QuickFilter = function( method ) { + /* Method calling logic */ + if ( methods[method] ) { + return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); + } else if ( typeof method === 'object' || ! method ) { + return methods.init.apply( this, arguments ); + } else { + $.error( 'Method ' + method + ' does not exist on $.QuickFilter' ); + } + }; - jQuery(this).data('current_query', null); - initialize_plugin(jQuery(this).data()); - - function update_options(e, rows){ - var d = data; - var availableTags={}; - jQuery.each (rows, function(index, obj) { - jQuery.each(obj,function(key,value){ - value = get_value(value); - if(!availableTags.hasOwnProperty(key)){availableTags[key]=new Array();} - //availableTags[key].push(value); - var currentArray=availableTags[key]; - if(value!=null){ - if(jQuery.inArray(value,currentArray)==-1){availableTags[key].push(value);} - } - }); - }); - jQuery.each(availableTags, function(key, value){ - value.sort(); - if(jQuery("#"+options.plugin_uuid+"-select_"+key).length>0){ - jQuery.each(value, function(k, optValue){ - jQuery("#"+options.plugin_uuid+"-select_"+key).append('<option>'+optValue+'</option>'); - }); - } - if(jQuery("#QuickFilter-string-"+key).length>0){ - jQuery("#QuickFilter-string-"+key).autocomplete({ + var methods = { + + init : function( options ) { + return this.each(function(){ + + var $this = $(this), + data = $this.data('QuickFilter'), QuickFilter = $('<div />', {text : $this.attr('title')}); + + if ( ! data ) { + + data = $(this).data(); + + /* Subscribe to selection updates published by the resource display plugins */ + //$.subscribe('selected', {instance: $this}, resource_selected); + $.subscribe('/query/' + options.query_uuid + '/changed', {instance: $this}, query_changed); + + + /* End of plugin initialization */ + + $(this).data('QuickFilter', { + plugin_uuid: options.plugin_uuid, + query_uuid: options.query_uuid, + target : $this, + QuickFilter : QuickFilter + }); + + $(this).data('current_query', null); + + initialize_plugin($(this).data()); + + function update_options(e, rows){ + var d = data; + var availableTags={}; + $.each (rows, function(index, obj) { + $.each(obj,function(key,value){ + value = get_value(value); + if(!availableTags.hasOwnProperty(key)){availableTags[key]=new Array();} + //availableTags[key].push(value); + var currentArray=availableTags[key]; + if(value!=null){ + if($.inArray(value,currentArray)==-1){availableTags[key].push(value);} + } + }); + }); + $.each(availableTags, function(key, value){ + value.sort(); + if($("#"+options.plugin_uuid+"-select_"+key).length>0){ + $.each(value, function(k, optValue){ + $("#"+options.plugin_uuid+"-select_"+key).append('<option>'+optValue+'</option>'); + }); + } + if($("#QuickFilter-string-"+key).length>0){ + $("#QuickFilter-string-"+key).autocomplete({ source: value, minLength: 0, // allows to browse items with no value typed in select: function(event, ui) { @@ -78,57 +87,39 @@ query=d.current_query; query.update_filter(key,op,val); // Publish the query changed, the other plugins with subscribe will get the changes - jQuery.publish('/query/' + query.uuid + '/changed', query); + $.publish('/query/' + query.uuid + '/changed', query); //add_ActiveFilter("#QuickFilter-string-"+key,ui.item.value,d); } - }); - } - }); - - - } - - /* Subscribe to results in order to redraw the table when updates arrive */ - jQuery.subscribe('/results/' + options.query_uuid + '/changed', {instance: $this}, update_options); - } - - }); - }, - destroy : function( ) { - - return this.each(function(){ - var $this = jQuery(this), data = $this.data('QuickFilter'); - jQuery(window).unbind('QuickFilter'); - data.QuickFilter.remove(); - $this.removeData('QuickFilter'); - }) - - }, -/* - reposition : function( ) { // ... }, - show : function( ) { // ... }, - hide : function( ) { // ... }, -*/ - update : function( content ) { } - }; - - jQuery.fn.QuickFilter = function( method ) { - /* Method calling logic */ - if ( methods[method] ) { - return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); - } else if ( typeof method === 'object' || ! method ) { - return methods.init.apply( this, arguments ); - } else { - jQuery.error( 'Method ' + method + ' does not exist on jQuery.QuickFilter' ); - } - + }); + } + }); + + + } + + /* Subscribe to results in order to redraw the table when updates arrive */ + $.subscribe('/results/' + options.query_uuid + '/changed', {instance: $this}, update_options); + } + + }); + }, + destroy : function( ) { + + return this.each(function(){ + var $this = $(this), data = $this.data('QuickFilter'); + $(window).unbind('QuickFilter'); + data.QuickFilter.remove(); + $this.removeData('QuickFilter'); + }) + + }, + update : function( content ) { + }, }; - /* Private methods */ - function query_changed(e, query) - { + function query_changed(e, query) { //panos: this takes a lot of time! data = e.data.instance.data(); var plugin_uuid=data.QuickFilter.plugin_uuid; @@ -139,7 +130,7 @@ data.current_query=query; // XXX can we modify data directly ? - //jQuery(data.QuickFilter.target).data('current_query', query); + //$(data.QuickFilter.target).data('current_query', query); if(previous_query!=null){ // If query has changed in another plugin @@ -148,119 +139,119 @@ var tmp=previous_query.diff_filter(query); // Remove first to clean up select boxes var removed_filters = tmp.removed; - jQuery.each(removed_filters, function(i,filter){ + $.each(removed_filters, function(i,filter){ console.log(filter[0]); allowedValues=getMetadata_property('resource', filter[0], 'allowed_values'); if (allowedValues!='' && allowedValues!="N/A") { - //if(MANIFOLD_METADATA[filter[0]]['allowed_values']!=''){ - jQuery('#QuickFilter_select_field').val("#"); - jQuery('#QuickFilter_select_value').children().remove().end(); - jQuery('#QuickFilter_select_value_container').hide(); + //if(MANIFOLD_METADATA[filter[0]]['allowed_values']!=''){ + $('#QuickFilter_select_field').val("#"); + $('#QuickFilter_select_value').children().remove().end(); + $('#QuickFilter_select_value_container').hide(); } - if(jQuery('#'+plugin_uuid+'-select_'+filter[0]).length>0 && filter[1]=="="){ - jQuery('#'+plugin_uuid+'-select_'+filter[0]).val(null); + if($('#'+plugin_uuid+'-select_'+filter[0]).length>0 && filter[1]=="="){ + $('#'+plugin_uuid+'-select_'+filter[0]).val(null); } - if(jQuery("#QuickFilter-string-"+filter[0]).length>0 && filter[1]=="="){ - jQuery("#QuickFilter-string-"+filter[0]).val(null); + if($("#QuickFilter-string-"+filter[0]).length>0 && filter[1]=="="){ + $("#QuickFilter-string-"+filter[0]).val(null); } }); // Then Add filters var added_filters = tmp.added; - jQuery.each(added_filters, function(i,filter){ - if(jQuery('#'+plugin_uuid+'-select_'+filter[0]).length>0 && filter[1]=="="){ - jQuery('#'+plugin_uuid+'-select_'+filter[0]).val(filter[2]); + $.each(added_filters, function(i,filter){ + if($('#'+plugin_uuid+'-select_'+filter[0]).length>0 && filter[1]=="="){ + $('#'+plugin_uuid+'-select_'+filter[0]).val(filter[2]); } - if(jQuery("#QuickFilter-string-"+filter[0]).length>0 && filter[1]=="="){ - jQuery("#QuickFilter-string-"+filter[0]).val(filter[2]); + if($("#QuickFilter-string-"+filter[0]).length>0 && filter[1]=="="){ + $("#QuickFilter-string-"+filter[0]).val(filter[2]); } }); } - jQuery.publish('debug', "Quick Filter received fields: " + query.fields+" - filter = "+query.filter); + $.publish('debug', "Quick Filter received fields: " + query.fields+" - filter = "+query.filter); } } function initialize_plugin(data) { - jQuery('#QuickFilter_select_value_div').hide(); - jQuery('#QuickFilter_string_value_div').hide(); - jQuery('#QuickFilter_int_value_div').hide(); + $('#QuickFilter_select_value_div').hide(); + $('#QuickFilter_string_value_div').hide(); + $('#QuickFilter_int_value_div').hide(); - jQuery('#QuickFilter_only_visible').click( function () { + $('#QuickFilter_only_visible').click( function () { var only_visible = this.checked; // Clear all options in the select box, Then add None option - jQuery('#QuickFilter_select_field').children().remove().end().append("<option value='#'>None</option>"); + $('#QuickFilter_select_field').children().remove().end().append("<option value='#'>None</option>"); // Get the current query (ONLY AFTER THE PLUGIN HAS BEEN INITIALIZED) var query = data.current_query; // iterate to remove each active filter if (only_visible) { if (typeof(query.fields) != 'undefined') { - jQuery.each (query.fields, function(index, value) { - jQuery('#QuickFilter_select_field').append("<option>"+value+"</option>"); + $.each (query.fields, function(index, value) { + $('#QuickFilter_select_field').append("<option>"+value+"</option>"); }); } }else{ headers=getMetadata_fields('resource'); - jQuery.each (headers, function (key, value) { - jQuery('#QuickFilter_select_field').append("<option>"+value['column']+"</option>"); + $.each (headers, function (key, value) { + $('#QuickFilter_select_field').append("<option>"+value['column']+"</option>"); }); } }); - jQuery('#QuickFilter_select_field').change( function () { - var field = jQuery(this).val(); + $('#QuickFilter_select_field').change( function () { + var field = $(this).val(); console.log(field); - jQuery('input[id^="QuickFilter-string-"]').hide(); - jQuery('#QuickFilter_int_value_div').hide(); + $('input[id^="QuickFilter-string-"]').hide(); + $('#QuickFilter_int_value_div').hide(); if(field=="#"){ - jQuery('#QuickFilter_select_value_container').hide(); + $('#QuickFilter_select_value_container').hide(); }else{ - jQuery('#QuickFilter_select_value_container').show(); - jQuery.publish('debug','field selected = '+field); + $('#QuickFilter_select_value_container').show(); + $.publish('debug','field selected = '+field); valType=getMetadata_property('resource', field, 'value_type'); if (valType == 'string' || valType=="N/A") { // If this key has predefined values, build a select with each allowed values as options allowedValues=getMetadata_property('resource', field, 'allowed_values'); if (allowedValues!='' && allowedValues!="N/A") { - jQuery('#QuickFilter_string_value_div').hide(); - jQuery('#QuickFilter_int_value_div').hide(); - jQuery('#QuickFilter_select_value_div').show(); - jQuery('#QuickFilter_select_value').show(); - jQuery('#QuickFilter_select_value').children().remove().end().append("<option value=''>all</option>"); -// @TODO: define seperator as ; + $('#QuickFilter_string_value_div').hide(); + $('#QuickFilter_int_value_div').hide(); + $('#QuickFilter_select_value_div').show(); + $('#QuickFilter_select_value').show(); + $('#QuickFilter_select_value').children().remove().end().append("<option value=''>all</option>"); + // @TODO: define seperator as ; allowed_values = allowedValues.split(","); - jQuery.each (allowed_values, function (key, value) { - jQuery('#QuickFilter_select_value').append("<option>"+value+"</option>"); + $.each (allowed_values, function (key, value) { + $('#QuickFilter_select_value').append("<option>"+value+"</option>"); }); - // Else build an autocomplete based on the values of result query + // Else build an autocomplete based on the values of result query }else{ - jQuery('#QuickFilter_select_value_div').hide(); - jQuery('#QuickFilter_string_value_div').show(); - jQuery('.QuickFilter-filter-value').hide(); - jQuery('#QuickFilter-string-'+field).show(); - jQuery('#QuickFilter_int_value_div').hide(); + $('#QuickFilter_select_value_div').hide(); + $('#QuickFilter_string_value_div').show(); + $('.QuickFilter-filter-value').hide(); + $('#QuickFilter-string-'+field).show(); + $('#QuickFilter_int_value_div').hide(); } } else if (valType == 'int') { - jQuery('#QuickFilter_select_value_div').hide(); - jQuery('#QuickFilter_string_value_div').hide(); - jQuery('#QuickFilter_int_value_div').show(); + $('#QuickFilter_select_value_div').hide(); + $('#QuickFilter_string_value_div').hide(); + $('#QuickFilter_int_value_div').show(); } } }); - jQuery('.QuickFilter-filter-value').change( function () { + $('.QuickFilter-filter-value').change( function () { var query = data.current_query; - var filter_value = jQuery(this).val(); - var filter_field = jQuery('#QuickFilter_select_field').val(); + var filter_value = $(this).val(); + var filter_field = $('#QuickFilter_select_field').val(); query.update_filter(filter_field, '=', filter_value); - jQuery.publish('/query/' + query.uuid + '/changed', query); + $.publish('/query/' + query.uuid + '/changed', query); }); - jQuery('.QuickFilter_select').change( function() { + $('.QuickFilter_select').change( function() { console.log(this.id); var query = data.current_query; var f_value = $(this).val(); @@ -268,10 +259,10 @@ var key = this.id.split("_"); // jordan ??? -/* - if (f_value == "Network") - f_value = ""; -*/ + /* + if (f_value == "Network") + f_value = ""; + */ if(typeof(key[1])!="undefined"){ console.log(key[1]+'='+f_value); if(f_value==""){ @@ -280,12 +271,9 @@ query.update_filter(key[1], '=', f_value); } } - jQuery.publish('/query/' + query.uuid + '/changed', query); + $.publish('/query/' + query.uuid + '/changed', query); }); } })( jQuery ); - - - diff --git a/plugins/quickfilter/quickfilter.py b/plugins/quickfilter/quickfilter.py index b7777e42..a49a0e50 100644 --- a/plugins/quickfilter/quickfilter.py +++ b/plugins/quickfilter/quickfilter.py @@ -2,22 +2,20 @@ from engine.plugin import Plugin class QuickFilter (Plugin) : - def __init__ (self, list=[], with_datatables=False, **settings): + def __init__ (self, criterias, **settings): Plugin.__init__ (self, **settings) - self.list=list - self.with_datatables = with_datatables + self.criterias=criterias self.page.expose_js_metadata() - def title (self) : return "Title for Quick " - def template_file (self): return "quickfilter.html" def requirements (self): - reqs = { 'js_files' : [ "js/quickfilter.js" ], - 'css_files': [ "css/quickfilter.css" ], + return { 'js_files' : "js/quickfilter.js", + 'css_files': "css/quickfilter.css", } - return reqs - def exclude_from_json (self): - return ['list'] - + def json_settings_list (self): + return ['criterias','plugin_uuid'] + + def template_env (self,request): + return {'criterias':self.criterias} diff --git a/trash/dashboard.py b/trash/dashboard.py index 76b72ec8..15f374f4 100644 --- a/trash/dashboard.py +++ b/trash/dashboard.py @@ -15,7 +15,7 @@ from plugins.lists.slicelist import SliceList from plugins.querycode.querycode import QueryCode from plugins.quickfilter.quickfilter import QuickFilter -from myslice.viewutils import, quickfilter_criterias +from myslice.viewutils import quickfilter_criterias # from myslice.viewutils import topmenu_items, the_user @@ -49,7 +49,7 @@ def dashboard_view (request): QuickFilter ( page=page, title='play with filters', - list=quickfilter_criterias, + criterias=quickfilter_criterias, ), SliceList ( # setting visible attributes first page=page, diff --git a/trash/pluginview.py b/trash/pluginview.py index b6d67665..9c9c6a70 100644 --- a/trash/pluginview.py +++ b/trash/pluginview.py @@ -58,7 +58,7 @@ def test_plugin_view (request): ), QuickFilter (page=page, title='QuickFilter in main content', - list=quickfilter_criterias, + criterias=quickfilter_criterias, ) ] ) # define 'content_main' to the template engine template_env [ 'content_main' ] = main_plugin.render(request)