commit/galaxy-central: guerler: Grids: Refactoring and fixes
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/44b0d21b4c77/ Changeset: 44b0d21b4c77 User: guerler Date: 2013-12-05 00:51:44 Summary: Grids: Refactoring and fixes iG: removed templates/grid_common.mako Affected #: 8 files diff -r 60128a7ab160f23cf4fe4cb4231729cfa56369fb -r 44b0d21b4c7744d27d97241375b953abc1da7830 lib/galaxy/web/framework/helpers/grids.py --- a/lib/galaxy/web/framework/helpers/grids.py +++ b/lib/galaxy/web/framework/helpers/grids.py @@ -264,6 +264,7 @@ return url_for( **new_kwargs) self.use_panels = ( kwargs.get( 'use_panels', False ) in [ True, 'True', 'true' ] ) + self.advanced_search = ( kwargs.get( 'advanced_search', False ) in [ True, 'True', 'true' ] ) async_request = ( ( self.use_async ) and ( kwargs.get( 'async', False ) in [ True, 'True', 'true'] ) ) # Currently, filling the template returns a str object; this requires decoding the string into a # unicode object within mako templates. What probably should be done is to return the template as @@ -285,6 +286,7 @@ status = status, message = message, use_panels=self.use_panels, + advanced_search=self.advanced_search, show_item_checkboxes = ( self.show_item_checkboxes or kwargs.get( 'show_item_checkboxes', '' ) in [ 'True', 'true' ] ), # Pass back kwargs so that grid template can set and use args without diff -r 60128a7ab160f23cf4fe4cb4231729cfa56369fb -r 44b0d21b4c7744d27d97241375b953abc1da7830 static/scripts/galaxy.grids.js --- a/static/scripts/galaxy.grids.js +++ b/static/scripts/galaxy.grids.js @@ -19,6 +19,7 @@ filters: {}, sort_key: null, show_item_checkboxes: false, + advanced_search: false, cur_page: 1, num_pages: 1, operation: undefined, @@ -110,7 +111,8 @@ async: this.attributes.async, sort: this.attributes.sort_key, page: this.attributes.cur_page, - show_item_checkboxes: this.attributes.show_item_checkboxes + show_item_checkboxes: this.attributes.show_item_checkboxes, + advanced_search: this.attributes.advanced_search }; // Add operation, item_ids only if they have values. @@ -343,7 +345,7 @@ this.grid.add_filter(name, value, append); // Add button that displays filter and provides a button to delete it. - var t = $("<span>" + value + "<a href='javascript:void(0);'><span class='delete-search-icon' /></a></span>"); + var t = $("<span>" + value + "<a href='javascript:void(0);'><span class='delete-search-icon' /></span></a>"); t.addClass('text-filter-val'); var self = this; t.click(function() { @@ -579,15 +581,19 @@ // go to url go_to: function (inbound, href) { - + // get aysnc status var async = this.grid.get('async'); this.grid.set('async', false); + // get slide status + advanced_search = $('#advanced-search').is(":visible"); + this.grid.set('advanced_search', advanced_search); + // get default url if(!href) href = this.grid.get('url_base') + "?" + $.param(this.grid.get_url_data()); - // Clear grid of transient request attributes. + // clear grid of transient request attributes. this.grid.set({ operation: undefined, item_ids: undefined, diff -r 60128a7ab160f23cf4fe4cb4231729cfa56369fb -r 44b0d21b4c7744d27d97241375b953abc1da7830 static/scripts/packed/galaxy.grids.js --- a/static/scripts/packed/galaxy.grids.js +++ b/static/scripts/packed/galaxy.grids.js @@ -1,1 +1,1 @@ -jQuery.ajaxSettings.traditional=true;define(["mvc/ui"],function(){var a=Backbone.Model.extend({defaults:{url_base:"",async:false,async_ops:[],categorical_filters:[],filters:{},sort_key:null,show_item_checkboxes:false,cur_page:1,num_pages:1,operation:undefined,item_ids:undefined},can_async_op:function(c){return _.indexOf(this.attributes.async_ops,c)!==-1},add_filter:function(g,h,d){if(d){var e=this.attributes.filters[g],c;if(e===null||e===undefined){c=h}else{if(typeof(e)=="string"){if(e=="All"){c=h}else{var f=[];f[0]=e;f[1]=h;c=f}}else{c=e;c.push(h)}}this.attributes.filters[g]=c}else{this.attributes.filters[g]=h}},remove_filter:function(d,g){var c=this.attributes.filters[d];if(c===null||c===undefined){return false}var f=true;if(typeof(c)==="string"){if(c=="All"){f=false}else{delete this.attributes.filters[d]}}else{var e=_.indexOf(c,g);if(e!==-1){c.splice(e,1)}else{f=false}}return f},get_url_data:function(){var c={async:this.attributes.async,sort:this.attributes.sort_key,page:this.attributes.cur_page,show_item_checkboxes:this.attributes.show_item_checkboxes};if(this.attributes.operation){c.operation=this.attributes.operation}if(this.attributes.item_ids){c.id=this.attributes.item_ids}var d=this;_.each(_.pairs(d.attributes.filters),function(e){c["f-"+e[0]]=e[1]});return c}});var b=Backbone.View.extend({grid:null,initialize:function(c){this.init_grid(c);this.init_grid_controls();$("input[type=text]").each(function(){$(this).click(function(){$(this).select()}).keyup(function(){$(this).css("font-style","normal")})})},init_grid:function(c){this.grid=c;this.init_grid_elements()},init_grid_controls:function(){$(".submit-image").each(function(){$(this).mousedown(function(){$(this).addClass("gray-background")});$(this).mouseup(function(){$(this).removeClass("gray-background")})});var c=this;$(".sort-link").each(function(){$(this).click(function(){c.set_sort_condition($(this).attr("sort_key"));return false})});$(".categorical-filter > a").each(function(){$(this).click(function(){c.set_categorical_filter($(this).attr("filter_key"),$(this).attr("filter_val"));return false})});$(".text-filter-form").each(function(){$(this).submit(function(){var g=$(this).attr("column_key");var f=$("#input-"+g+"-filter");var h=f.val();f.val("");c.add_filter_condition(g,h,true);return false})});var d=$("#input-tags-filter");if(d.length){d.autocomplete(this.grid.history_tag_autocomplete_url,{selectFirst:false,autoFill:false,highlight:false,mustMatch:false})}var e=$("#input-name-filter");if(e.length){e.autocomplete(this.grid.history_name_autocomplete_url,{selectFirst:false,autoFill:false,highlight:false,mustMatch:false})}$(".advanced-search-toggle").each(function(){$(this).click(function(){$("#standard-search").slideToggle("fast");$("#advanced-search").slideToggle("fast");return false})})},init_grid_elements:function(){$(".grid").each(function(){var j=$(this).find("input.grid-row-select-checkbox");var i=$(this).find("span.grid-selected-count");var q=function(){i.text($(j).filter(":checked").length)};$(j).each(function(){$(this).change(q)});q()});if($(".community_rating_star").length!==0){$(".community_rating_star").rating({})}var p=this.grid.attributes;var o=this;$(".page-link > a").each(function(){$(this).click(function(){o.set_page($(this).attr("page_num"));return false})});$(".use-inbound").each(function(){$(this).click(function(i){o.execute({href:$(this).attr("href"),inbound:true});return false})});$(".use-outbound").each(function(){$(this).click(function(i){o.execute({href:$(this).attr("href")});return false})});for(var h in p.items){var k=$("#grid-"+h+"-popup");k.off();var d=new PopupMenu(k);var n=p.items[h];for(var g in p.operations){var e=p.operations[g];var l=e.label;var c=n.operation_config[l];var f=n.encode_id;if(c.allowed&&e.allow_popup){var m={html:e.label,href:c.url_args,target:c.target,confirmation_text:e.confirm,inbound:e.inbound};m.func=function(q){q.preventDefault();var j=$(q.target).html();var i=this.findItemByHtml(j);o.execute(i)};d.addItem(m)}}}},add_filter_condition:function(f,h,c){if(h===""){return false}this.grid.add_filter(f,h,c);var g=$("<span>"+h+"<a href='javascript:void(0);'><span class='delete-search-icon' /></a></span>");g.addClass("text-filter-val");var e=this;g.click(function(){e.grid.remove_filter(f,h);$(this).remove();e.go_page_one();e.execute()});var d=$("#"+f+"-filtering-criteria");d.append(g);this.go_page_one();this.execute()},set_sort_condition:function(h){var g=this.grid.get("sort_key");var f=h;if(g.indexOf(h)!==-1){if(g.substring(0,1)!=="-"){f="-"+h}else{}}$(".sort-arrow").remove();var e=(f.substring(0,1)=="-")?"↑":"↓";var c=$("<span>"+e+"</span>").addClass("sort-arrow");var d=$("#"+h+"-header");d.append(c);this.grid.set("sort_key",f);this.go_page_one();this.execute()},set_categorical_filter:function(e,g){var d=this.grid.get("categorical_filters")[e],f=this.grid.get("filters")[e];var c=this;$("."+e+"-filter").each(function(){var k=$.trim($(this).text());var i=d[k];var j=i[e];if(j==g){$(this).empty();$(this).addClass("current-filter");$(this).append(k)}else{if(j==f){$(this).empty();var h=$("<a href='#'>"+k+"</a>");h.click(function(){c.set_categorical_filter(e,j)});$(this).removeClass("current-filter");$(this).append(h)}}});this.grid.add_filter(e,g);this.go_page_one();this.execute()},set_page:function(c){var d=this;$(".page-link").each(function(){var i=$(this).attr("id"),g=parseInt(i.split("-")[2],10),e=d.grid.get("cur_page"),h;if(g===c){h=$(this).children().text();$(this).empty();$(this).addClass("inactive-link");$(this).text(h)}else{if(g===e){h=$(this).text();$(this).empty();$(this).removeClass("inactive-link");var f=$("<a href='#'>"+h+"</a>");f.click(function(){d.set_page(g)});$(this).append(f)}}});if(c==="all"){this.grid.set("cur_page",c)}else{this.grid.set("cur_page",parseInt(c,10))}this.execute()},submit_operation:function(f,g){var e=$('input[name="id"]:checked').length;if(!e>0){return false}var d=$(f).val();var c=[];$("input[name=id]:checked").each(function(){c.push($(this).val())});this.execute({operation:d,id:c,confirmation_text:g});return true},execute:function(l){var f=null;var e=null;var g=null;var c=null;var k=null;if(l){e=l.href;g=l.operation;f=l.id;c=l.confirmation_text;k=l.inbound;if(e!==undefined&&e.indexOf("operation=")!=-1){var j=e.split("?");if(j.length>1){var i=j[1];var d=i.split("&");for(var h=0;h<d.length;h++){if(d[h].indexOf("operation")!=-1){g=d[h].split("=")[1];g=g.replace(/\+/g," ")}else{if(d[h].indexOf("id")!=-1){f=d[h].split("=")[1]}}}}}}if(g&&f){if(c&&c!=""&&c!="None"){if(!confirm(c)){return false}}g=g.toLowerCase();this.grid.set({operation:g,item_ids:f});if(this.grid.can_async_op(g)){this.update_grid()}else{this.go_to(k,"")}return false}if(e){this.go_to(k,e);return false}if(this.grid.get("async")){this.update_grid()}else{this.go_to(k,"")}return false},go_to:function(f,d){var e=this.grid.get("async");this.grid.set("async",false);if(!d){d=this.grid.get("url_base")+"?"+$.param(this.grid.get_url_data())}this.grid.set({operation:undefined,item_ids:undefined,async:e});if(f){var c=$(".grid-header").closest(".inbound");if(c.length!==0){c.load(d);return}}window.location=d},update_grid:function(){var d=(this.grid.get("operation")?"POST":"GET");$(".loading-elt-overlay").show();var c=this;$.ajax({type:d,url:c.grid.get("url_base"),data:c.grid.get_url_data(),error:function(e){alert("Grid refresh failed")},success:function(f){var e=f.split("*****");$("#grid-table-body").html(e[0]);$("#grid-table-footer").html(e[1]);$("#grid-table-body").trigger("update");$(".loading-elt-overlay").hide();var g=$.trim(e[2]);if(g!==""){$("#grid-message").html(g).show();setTimeout(function(){$("#grid-message").hide()},5000)}},complete:function(){c.grid.set({operation:undefined,item_ids:undefined})}})},check_all_items:function(){var c=document.getElementById("check_all"),d=document.getElementsByTagName("input"),f=0,e;if(c.checked===true){for(e=0;e<d.length;e++){if(d[e].name.indexOf("id")!==-1){d[e].checked=true;f++}}}else{for(e=0;e<d.length;e++){if(d[e].name.indexOf("id")!==-1){d[e].checked=false}}}this.init_grid_elements()},go_page_one:function(){var c=this.grid.get("cur_page");if(c!==null&&c!==undefined&&c!=="all"){this.grid.set("cur_page",1)}}});return{Grid:a,GridView:b}}); \ No newline at end of file +jQuery.ajaxSettings.traditional=true;define(["mvc/ui"],function(){var a=Backbone.Model.extend({defaults:{url_base:"",async:false,async_ops:[],categorical_filters:[],filters:{},sort_key:null,show_item_checkboxes:false,advanced_search:false,cur_page:1,num_pages:1,operation:undefined,item_ids:undefined},can_async_op:function(c){return _.indexOf(this.attributes.async_ops,c)!==-1},add_filter:function(g,h,d){if(d){var e=this.attributes.filters[g],c;if(e===null||e===undefined){c=h}else{if(typeof(e)=="string"){if(e=="All"){c=h}else{var f=[];f[0]=e;f[1]=h;c=f}}else{c=e;c.push(h)}}this.attributes.filters[g]=c}else{this.attributes.filters[g]=h}},remove_filter:function(d,g){var c=this.attributes.filters[d];if(c===null||c===undefined){return false}var f=true;if(typeof(c)==="string"){if(c=="All"){f=false}else{delete this.attributes.filters[d]}}else{var e=_.indexOf(c,g);if(e!==-1){c.splice(e,1)}else{f=false}}return f},get_url_data:function(){var c={async:this.attributes.async,sort:this.attributes.sort_key,page:this.attributes.cur_page,show_item_checkboxes:this.attributes.show_item_checkboxes,advanced_search:this.attributes.advanced_search};if(this.attributes.operation){c.operation=this.attributes.operation}if(this.attributes.item_ids){c.id=this.attributes.item_ids}var d=this;_.each(_.pairs(d.attributes.filters),function(e){c["f-"+e[0]]=e[1]});return c}});var b=Backbone.View.extend({grid:null,initialize:function(c){this.init_grid(c);this.init_grid_controls();$("input[type=text]").each(function(){$(this).click(function(){$(this).select()}).keyup(function(){$(this).css("font-style","normal")})})},init_grid:function(c){this.grid=c;this.init_grid_elements()},init_grid_controls:function(){$(".submit-image").each(function(){$(this).mousedown(function(){$(this).addClass("gray-background")});$(this).mouseup(function(){$(this).removeClass("gray-background")})});var c=this;$(".sort-link").each(function(){$(this).click(function(){c.set_sort_condition($(this).attr("sort_key"));return false})});$(".categorical-filter > a").each(function(){$(this).click(function(){c.set_categorical_filter($(this).attr("filter_key"),$(this).attr("filter_val"));return false})});$(".text-filter-form").each(function(){$(this).submit(function(){var g=$(this).attr("column_key");var f=$("#input-"+g+"-filter");var h=f.val();f.val("");c.add_filter_condition(g,h,true);return false})});var d=$("#input-tags-filter");if(d.length){d.autocomplete(this.grid.history_tag_autocomplete_url,{selectFirst:false,autoFill:false,highlight:false,mustMatch:false})}var e=$("#input-name-filter");if(e.length){e.autocomplete(this.grid.history_name_autocomplete_url,{selectFirst:false,autoFill:false,highlight:false,mustMatch:false})}$(".advanced-search-toggle").each(function(){$(this).click(function(){$("#standard-search").slideToggle("fast");$("#advanced-search").slideToggle("fast");return false})})},init_grid_elements:function(){$(".grid").each(function(){var j=$(this).find("input.grid-row-select-checkbox");var i=$(this).find("span.grid-selected-count");var q=function(){i.text($(j).filter(":checked").length)};$(j).each(function(){$(this).change(q)});q()});if($(".community_rating_star").length!==0){$(".community_rating_star").rating({})}var p=this.grid.attributes;var o=this;$(".page-link > a").each(function(){$(this).click(function(){o.set_page($(this).attr("page_num"));return false})});$(".use-inbound").each(function(){$(this).click(function(i){o.execute({href:$(this).attr("href"),inbound:true});return false})});$(".use-outbound").each(function(){$(this).click(function(i){o.execute({href:$(this).attr("href")});return false})});for(var h in p.items){var k=$("#grid-"+h+"-popup");k.off();var d=new PopupMenu(k);var n=p.items[h];for(var g in p.operations){var e=p.operations[g];var l=e.label;var c=n.operation_config[l];var f=n.encode_id;if(c.allowed&&e.allow_popup){var m={html:e.label,href:c.url_args,target:c.target,confirmation_text:e.confirm,inbound:e.inbound};m.func=function(q){q.preventDefault();var j=$(q.target).html();var i=this.findItemByHtml(j);o.execute(i)};d.addItem(m)}}}},add_filter_condition:function(f,h,c){if(h===""){return false}this.grid.add_filter(f,h,c);var g=$("<span>"+h+"<a href='javascript:void(0);'><span class='delete-search-icon' /></span></a>");g.addClass("text-filter-val");var e=this;g.click(function(){e.grid.remove_filter(f,h);$(this).remove();e.go_page_one();e.execute()});var d=$("#"+f+"-filtering-criteria");d.append(g);this.go_page_one();this.execute()},set_sort_condition:function(h){var g=this.grid.get("sort_key");var f=h;if(g.indexOf(h)!==-1){if(g.substring(0,1)!=="-"){f="-"+h}else{}}$(".sort-arrow").remove();var e=(f.substring(0,1)=="-")?"↑":"↓";var c=$("<span>"+e+"</span>").addClass("sort-arrow");var d=$("#"+h+"-header");d.append(c);this.grid.set("sort_key",f);this.go_page_one();this.execute()},set_categorical_filter:function(e,g){var d=this.grid.get("categorical_filters")[e],f=this.grid.get("filters")[e];var c=this;$("."+e+"-filter").each(function(){var k=$.trim($(this).text());var i=d[k];var j=i[e];if(j==g){$(this).empty();$(this).addClass("current-filter");$(this).append(k)}else{if(j==f){$(this).empty();var h=$("<a href='#'>"+k+"</a>");h.click(function(){c.set_categorical_filter(e,j)});$(this).removeClass("current-filter");$(this).append(h)}}});this.grid.add_filter(e,g);this.go_page_one();this.execute()},set_page:function(c){var d=this;$(".page-link").each(function(){var i=$(this).attr("id"),g=parseInt(i.split("-")[2],10),e=d.grid.get("cur_page"),h;if(g===c){h=$(this).children().text();$(this).empty();$(this).addClass("inactive-link");$(this).text(h)}else{if(g===e){h=$(this).text();$(this).empty();$(this).removeClass("inactive-link");var f=$("<a href='#'>"+h+"</a>");f.click(function(){d.set_page(g)});$(this).append(f)}}});if(c==="all"){this.grid.set("cur_page",c)}else{this.grid.set("cur_page",parseInt(c,10))}this.execute()},submit_operation:function(f,g){var e=$('input[name="id"]:checked').length;if(!e>0){return false}var d=$(f).val();var c=[];$("input[name=id]:checked").each(function(){c.push($(this).val())});this.execute({operation:d,id:c,confirmation_text:g});return true},execute:function(l){var f=null;var e=null;var g=null;var c=null;var k=null;if(l){e=l.href;g=l.operation;f=l.id;c=l.confirmation_text;k=l.inbound;if(e!==undefined&&e.indexOf("operation=")!=-1){var j=e.split("?");if(j.length>1){var i=j[1];var d=i.split("&");for(var h=0;h<d.length;h++){if(d[h].indexOf("operation")!=-1){g=d[h].split("=")[1];g=g.replace(/\+/g," ")}else{if(d[h].indexOf("id")!=-1){f=d[h].split("=")[1]}}}}}}if(g&&f){if(c&&c!=""&&c!="None"){if(!confirm(c)){return false}}g=g.toLowerCase();this.grid.set({operation:g,item_ids:f});if(this.grid.can_async_op(g)){this.update_grid()}else{this.go_to(k,"")}return false}if(e){this.go_to(k,e);return false}if(this.grid.get("async")){this.update_grid()}else{this.go_to(k,"")}return false},go_to:function(f,d){var e=this.grid.get("async");this.grid.set("async",false);advanced_search=$("#advanced-search").is(":visible");this.grid.set("advanced_search",advanced_search);if(!d){d=this.grid.get("url_base")+"?"+$.param(this.grid.get_url_data())}this.grid.set({operation:undefined,item_ids:undefined,async:e});if(f){var c=$(".grid-header").closest(".inbound");if(c.length!==0){c.load(d);return}}window.location=d},update_grid:function(){var d=(this.grid.get("operation")?"POST":"GET");$(".loading-elt-overlay").show();var c=this;$.ajax({type:d,url:c.grid.get("url_base"),data:c.grid.get_url_data(),error:function(e){alert("Grid refresh failed")},success:function(f){var e=f.split("*****");$("#grid-table-body").html(e[0]);$("#grid-table-footer").html(e[1]);$("#grid-table-body").trigger("update");$(".loading-elt-overlay").hide();var g=$.trim(e[2]);if(g!==""){$("#grid-message").html(g).show();setTimeout(function(){$("#grid-message").hide()},5000)}},complete:function(){c.grid.set({operation:undefined,item_ids:undefined})}})},check_all_items:function(){var c=document.getElementById("check_all"),d=document.getElementsByTagName("input"),f=0,e;if(c.checked===true){for(e=0;e<d.length;e++){if(d[e].name.indexOf("id")!==-1){d[e].checked=true;f++}}}else{for(e=0;e<d.length;e++){if(d[e].name.indexOf("id")!==-1){d[e].checked=false}}}this.init_grid_elements()},go_page_one:function(){var c=this.grid.get("cur_page");if(c!==null&&c!==undefined&&c!=="all"){this.grid.set("cur_page",1)}}});return{Grid:a,GridView:b}}); \ No newline at end of file diff -r 60128a7ab160f23cf4fe4cb4231729cfa56369fb -r 44b0d21b4c7744d27d97241375b953abc1da7830 templates/grid_base.mako --- a/templates/grid_base.mako +++ b/templates/grid_base.mako @@ -1,5 +1,7 @@ <%! - from galaxy.web.framework.helpers.grids import TextColumn + from galaxy.web.framework.helpers.grids import TextColumn, StateColumn, GridColumnFilter + from galaxy.web.framework.helpers import iff + import galaxy.util def inherit(context): if context.get('use_panels'): @@ -12,16 +14,16 @@ return '/base.mako' %><%inherit file="${inherit(context)}"/> -<%namespace file="./grid_common.mako" import="*" /><%namespace file="/refresh_frames.mako" import="handle_refresh_frames" /><%namespace file="/display_common.mako" import="get_class_plural" /> -<%def name="load(embedded = False)"> +<%def name="load(embedded = False, insert = None)"><% + self.init(insert) + self.stylesheets() + self.javascripts() self.grid_javascripts() if embedded: - self.init() - self.stylesheets() self.render_grid_header( grid, False ) self.render_grid_table( grid, show_item_checkboxes=show_item_checkboxes ) else: @@ -30,7 +32,7 @@ %></%def> -<%def name="init()"> +<%def name="init(insert=None)"><% self.has_left_panel = False self.has_right_panel = False @@ -62,9 +64,12 @@ 'use_paging' : grid.use_paging, 'legend' : grid.legend, 'current_item_id' : False, - 'use_panels' : context.get('use_panels') + 'use_panels' : context.get('use_panels'), + 'insert' : insert, + 'default_filter_dict' : default_filter_dict, + 'advanced_search' : advanced_search } - + ## add current item if exists if current_item: self.grid_config['current_item_id'] = current_item.id @@ -96,6 +101,8 @@ 'label_id_prefix' : column.label_id_prefix, 'sortable' : column.sortable, 'label' : column.label, + 'filterable' : column.filterable, + 'is_text' : isinstance(column, TextColumn), 'href' : href, 'extra' : extra }) @@ -309,7 +316,9 @@ %endif </ul> %endif - + %if self.grid_config['insert']: + ${self.grid_config['insert']} + %endif ${render_grid_filters( grid )} </div></%def> @@ -583,3 +592,191 @@ %endif </%def> +## Print grid search/filtering UI. +<%def name="render_grid_filters( grid, render_advanced_search=True )"> + <% + default_filter_dict = self.grid_config['default_filter_dict'] + filters = self.grid_config['filters'] + + # Show advanced search if flag set or if there are filters for advanced search fields. + advanced_search_display = "none" + + if self.grid_config['advanced_search']: + advanced_search_display = "block" + + for column in self.grid_config['columns']: + if column['filterable'] == "advanced": + ## Show div if current filter has value that is different from the default filter. + column_key = column['key'] + if column_key in filters and column_key in default_filter_dict and \ + filters[column_key] != default_filter_dict[column_key]: + advanced_search_display = "block" + + # do not show standard search if showing adv. + standard_search_display = "block" + if advanced_search_display == "block": + standard_search_display = "none" + %> + ## Standard search. + <div id="standard-search" style="display: ${standard_search_display};"> + <table> + <tr><td style="padding: 0;"> + <table> + %for column in self.grid_config['columns']: + %if column['filterable'] == "standard": + ${render_grid_column_filter( grid, column )} + %endif + %endfor + </table> + </td></tr> + <tr><td> + ## Only show advanced search if there are filterable columns. + <% + show_advanced_search_link = False + if render_advanced_search: + for column in self.grid_config['columns']: + if column['filterable'] == "advanced": + show_advanced_search_link = True + break + endif + %> + %if show_advanced_search_link: + <a href="" class="advanced-search-toggle">Advanced Search</a> + %endif + </td></tr> + </table> + </div> + + ## Advanced search. + <div id="advanced-search" style="display: ${advanced_search_display}; margin-top: 5px; border: 1px solid #ccc;"> + <table> + <tr><td style="text-align: left" colspan="100"> + <a href="" class="advanced-search-toggle">Close Advanced Search</a> + </td></tr> + %for column in self.grid_config['columns']: + %if column['filterable'] == "advanced": + ## Show div if current filter has value that is different from the default filter. + <% + column_key = column['key'] + %> + % if column_key in filters and column_key in default_filter_dict and \ + filters[column_key] != default_filter_dict[column_key]: + <script type="text/javascript"> + $('#advanced-search').css("display", "block"); + </script> + % endif + + ${render_grid_column_filter( grid, column )} + %endif + %endfor + </table> + </div> +</%def> + +## Render a filter UI for a grid column. Filter is rendered as a table row. +<%def name="render_grid_column_filter( grid, column )"> + <tr> + <% + default_filter_dict = self.grid_config['default_filter_dict'] + filters = self.grid_config['filters'] + column_label = column['label'] + column_key = column['key'] + if column['filterable'] == "advanced": + column_label = column_label.lower() + %> + %if column['filterable'] == "advanced": + <td align="left" style="padding-left: 10px">${column_label}:</td> + %endif + <td style="padding: 0;"> + %if column['is_text']: + <form class="text-filter-form" column_key="${column_key}" action="${url(dict())}" method="get" > + ## Carry forward filtering criteria with hidden inputs. + %for temp_column in self.grid_config['columns']: + %if temp_column['key'] in filters: + <% value = filters[ temp_column['key'] ] %> + %if value != "All": + <% + if temp_column['is_text']: + value = h.to_json_string( value ) + %> + <input type="hidden" id="${temp_column['key']}" name="f-${temp_column['key']}" value='${value}'/> + %endif + %endif + %endfor + ## Print current filtering criteria and links to delete. + <span id="${column_key}-filtering-criteria"> + %if column_key in filters: + <% column_filter = filters[column_key] %> + %if isinstance( column_filter, basestring ): + %if column_filter != "All": + <span class='text-filter-val'> + ${filters[column_key]} + <% filter_all = GridColumnFilter( "", { column_key : "All" } ) %> + <a href="${url(filter_all.get_url_args())}"><span class="delete-search-icon" /></a> + </span> + %endif + %elif isinstance( column_filter, list ): + %for i, filter in enumerate( column_filter ): + <span class='text-filter-val'>${filter} + <% + new_filter = list( column_filter ) + del new_filter[ i ] + new_column_filter = GridColumnFilter( "", { column_key : h.to_json_string( new_filter ) } ) + %> + <a href="${url(new_column_filter.get_url_args())}"><span class="delete-search-icon" /></a> + </span> + %endfor + %endif + %endif + </span> + ## Print input field for column. + <span class="search-box"> + <% + # Set value, size of search input field. Minimum size is 20 characters. + value = iff( column['filterable'] == "standard", column['label'].lower(), "") + size = len( value ) + if size < 20: + size = 20 + # +4 to account for search icon/button. + size = size + 4 + %> + <input class="search-box-input" id="input-${column_key}-filter" name="f-${column_key}" type="text" value="${value}" size="${size}"/> + <button class="submit-image" type="submit" title='Search'><span style="display: none;"></button> + </span> + </form> + %else: + <span id="${column_key}-filtering-criteria"> + <% + seperator = False + %> + %for filter_label in self.grid_config['categorical_filters'][column_key]: + <% + # get filter + filter = self.grid_config['categorical_filters'][column_key][filter_label] + + # each filter will have only a single argument, so get that single argument + for key in filter: + filter_key = key + filter_arg = filter[key] + %> + %if seperator: + | + %endif + + <% + seperator = True + %> + %if column_key in cur_filter_dict and column_key in filter and cur_filter_dict[column_key] == filter_arg: + <span class="categorical-filter ${column_key}-filter current-filter">${filter_label}</span> + %else: + <span class="categorical-filter ${column_key}-filter"> + <a href="" filter_key="${filter_key}" filter_val="${filter_arg}">${filter_label}</a> + </span> + %endif + %endfor + </span> + %endif + </td> + </tr> +</%def> + diff -r 60128a7ab160f23cf4fe4cb4231729cfa56369fb -r 44b0d21b4c7744d27d97241375b953abc1da7830 templates/grid_common.mako --- a/templates/grid_common.mako +++ /dev/null @@ -1,187 +0,0 @@ -<%! - from galaxy.web.framework.helpers.grids import TextColumn, StateColumn, GridColumnFilter - from galaxy.web.framework.helpers import iff -%> - -## Render a filter UI for a grid column. Filter is rendered as a table row. -<%def name="render_grid_column_filter( grid, column )"> - <tr> - <% - column_label = column.label - if column.filterable == "advanced": - column_label = column_label.lower() - %> - %if column.filterable == "advanced": - <td align="left" style="padding-left: 10px">${column_label}:</td> - %endif - <td style="padding: 0;"> - %if isinstance(column, TextColumn): - <form class="text-filter-form" column_key="${column.key}" action="${url(dict())}" method="get" > - ## Carry forward filtering criteria with hidden inputs. - %for temp_column in grid.columns: - %if temp_column.key in cur_filter_dict: - <% value = cur_filter_dict[ temp_column.key ] %> - %if value != "All": - <% - if isinstance( temp_column, TextColumn ): - value = h.to_json_string( value ) - %> - <input type="hidden" id="${temp_column.key}" name="f-${temp_column.key}" value='${value}'/> - %endif - %endif - %endfor - ## Print current filtering criteria and links to delete. - <span id="${column.key}-filtering-criteria"> - %if column.key in cur_filter_dict: - <% column_filter = cur_filter_dict[column.key] %> - %if isinstance( column_filter, basestring ): - %if column_filter != "All": - <span class='text-filter-val'> - ${cur_filter_dict[column.key]} - <% filter_all = GridColumnFilter( "", { column.key : "All" } ) %> - <a href="${url(filter_all.get_url_args())}"><span class="delete-search-icon" /></a> - </span> - %endif - %elif isinstance( column_filter, list ): - %for i, filter in enumerate( column_filter ): - %if i > 0: - , - %endif - <span class='text-filter-val'>${filter} - <% - new_filter = list( column_filter ) - del new_filter[ i ] - new_column_filter = GridColumnFilter( "", { column.key : h.to_json_string( new_filter ) } ) - %> - <a href="${url(new_column_filter.get_url_args())}"><span class="delete-search-icon" /></a> - </span> - %endfor - %endif - %endif - </span> - ## Print input field for column. - <span class="search-box"> - <% - # Set value, size of search input field. Minimum size is 20 characters. - value = iff( column.filterable == "standard", column.label.lower(), "") - size = len( value ) - if size < 20: - size = 20 - # +4 to account for search icon/button. - size = size + 4 - %> - <input class="search-box-input" id="input-${column.key}-filter" name="f-${column.key}" type="text" value="${value}" size="${size}"/> - <button class="submit-image" type="submit" title='Search'><span style="display: none;"></button> - </span> - </form> - %else: - <span id="${column.key}-filtering-criteria"> - %for i, filter in enumerate( column.get_accepted_filters() ): - <% - # HACK: we know that each filter will have only a single argument, so get that single argument. - for key, arg in filter.args.items(): - filter_key = key - filter_arg = arg - %> - %if i > 0: - | - %endif - %if column.key in cur_filter_dict and column.key in filter.args and cur_filter_dict[column.key] == filter.args[column.key]: - <span class="categorical-filter ${column.key}-filter current-filter">${filter.label}</span> - %else: - <span class="categorical-filter ${column.key}-filter"> - <a href="${url(filter.get_url_args())}" filter_key="${filter_key}" filter_val="${filter_arg}">${filter.label}</a> - </span> - %endif - %endfor - </span> - %endif - </td> - </tr> -</%def> - -## Print grid search/filtering UI. -<%def name="render_grid_filters( grid, render_advanced_search=True )"> - <% - # Show advanced search if flag set or if there are filters for advanced search fields. - advanced_search_display = "none" - if 'advanced-search' in kwargs and kwargs['advanced-search'] in ['True', 'true']: - advanced_search_display = "block" - - for column in grid.columns: - if column.filterable == "advanced": - ## Show div if current filter has value that is different from the default filter. - if column.key in cur_filter_dict and column.key in default_filter_dict and \ - cur_filter_dict[column.key] != default_filter_dict[column.key]: - advanced_search_display = "block" - - # do not show standard search if showing adv. - standard_search_display = "block" - if advanced_search_display == "block": - standard_search_display = "none" - %> - ## Standard search. - <div id="standard-search" style="display: ${standard_search_display};"> - <table> - <tr><td style="padding: 0;"> - <table> - %for column in grid.columns: - %if column.filterable == "standard": - ${render_grid_column_filter( grid, column )} - %endif - %endfor - </table> - </td></tr> - <tr><td> - ## Clear the standard search. - ##| - ##<% filter_all = GridColumnFilter( "", { column.key : "All" } ) %> - ##<a href="${url(filter_all.get_url_args())}">Clear All</a> - - ## Only show advanced search if there are filterable columns. - <% - show_advanced_search_link = False - if render_advanced_search: - for column in grid.columns: - if column.filterable == "advanced": - show_advanced_search_link = True - break - endif - %> - %if show_advanced_search_link: - <% args = { "advanced-search" : True } %> - <a href="${url(args)}" class="advanced-search-toggle">Advanced Search</a> - %endif - </td></tr> - </table> - </div> - - ## Advanced search. - <div id="advanced-search" style="display: ${advanced_search_display}; margin-top: 5px; border: 1px solid #ccc;"> - <table> - <tr><td style="text-align: left" colspan="100"> - <% args = { "advanced-search" : False } %> - <a href="${url(args)}" class="advanced-search-toggle">Close Advanced Search</a> - ## Link to clear all filters. - ##| - ##<% - ## no_filter = GridColumnFilter("Clear All", default_filter_dict) - ##%> - ##<a href="${url(no_filter.get_url_args())}">${no_filter.label}</a> - </td></tr> - %for column in grid.columns: - %if column.filterable == "advanced": - ## Show div if current filter has value that is different from the default filter. - %if column.key in cur_filter_dict and column.key in default_filter_dict and \ - cur_filter_dict[column.key] != default_filter_dict[column.key]: - <script type="text/javascript"> - $('#advanced-search').css("display", "block"); - </script> - %endif - - ${render_grid_column_filter( grid, column )} - %endif - %endfor - </table> - </div> -</%def> diff -r 60128a7ab160f23cf4fe4cb4231729cfa56369fb -r 44b0d21b4c7744d27d97241375b953abc1da7830 templates/webapps/tool_shed/category/grid.mako --- a/templates/webapps/tool_shed/category/grid.mako +++ b/templates/webapps/tool_shed/category/grid.mako @@ -1,66 +1,13 @@ -<%namespace file="/display_common.mako" import="render_message" /> -<%namespace file="/grid_base.mako" import="*" /> -<%namespace file="/grid_common.mako" import="*" /> -<%inherit file="/grid_base.mako" /> +<%namespace name="grid_base" file="/grid_base.mako" import="*" /> +<%namespace name="grid_common" file="../common/grid_common.mako" import="*" /> -## Render grid header. -## TODO: This is very similar to this directory's valid_grid.mako, so see if we can re-use this code in a better way. -<%def name="render_grid_header( grid, repo_grid, render_title=True)"> - ${init()} - ${grid_javascripts()} - <div class="grid-header"> - %if render_title: - ${grid_title()} - %endif - %if grid.global_actions: - <ul class="manage-table-actions"> - %if len( grid.global_actions ) < 4: - %for action in grid.global_actions: - <li><a class="action-button" href="${h.url_for( **action.url_args )}">${action.label | h}</a></li> - %endfor - %else: - <li><a class="action-button" id="action-8675309-popup" class="menubutton">Actions</a></li> - <div popupmenu="action-8675309-popup"> - %for action in grid.global_actions: - <a class="action-button" href="${h.url_for( **action.url_args )}">${action.label | h}</a> - %endfor - </div> - %endif - </ul> - %endif - ${render_grid_filters( repo_grid, render_advanced_search=False )} - </div> +<%def name="insert()"> +<% + from tool_shed.grids.repository_grids import RepositoryGrid + repo_grid = RepositoryGrid() + grid_common.render_grid_filters(repo_grid) +%></%def> -<%def name="make_grid( grid, repo_grid )"> - <div class="loading-elt-overlay"></div> - <table> - <tr> - <td width="75%">${self.render_grid_header( grid, repo_grid )}</td> - <td></td> - <td></td> - </tr> - <tr> - <td width="100%" id="grid-message" valign="top">${render_message( message, status )}</td> - <td></td> - <td></td> - </tr> - </table> - ${render_grid_table( grid, show_item_checkboxes )} -</%def> - -<%def name="grid_body()"> - <% - from tool_shed.grids.repository_grids import RepositoryGrid - repo_grid = RepositoryGrid() - %> - ${self.make_grid( grid, repo_grid )} -</%def> - -<%def name="center_panel()"> - <div style="overflow: auto; height: 100%"> - <div class="page-container" style="padding: 10px;"> - ${self.grid_body( grid )} - </div> - </div> -</%def> +<!DOCTYPE HTML> +${grid_base.load(False, capture(self.insert))} \ No newline at end of file diff -r 60128a7ab160f23cf4fe4cb4231729cfa56369fb -r 44b0d21b4c7744d27d97241375b953abc1da7830 templates/webapps/tool_shed/category/valid_grid.mako --- a/templates/webapps/tool_shed/category/valid_grid.mako +++ b/templates/webapps/tool_shed/category/valid_grid.mako @@ -1,65 +1,13 @@ -<%namespace file="/display_common.mako" import="render_message" /> -<%namespace file="/grid_base.mako" import="*" /> -<%namespace file="/grid_common.mako" import="*" /> -<%inherit file="/grid_base.mako" /> +<%namespace name="grid_base" file="/grid_base.mako" import="*" /> +<%namespace name="grid_common" file="../common/grid_common.mako" import="*" /> -## Render grid header. -<%def name="render_grid_header( grid, repo_grid, render_title=True)"> - ${init()} - ${grid_javascripts()} - <div class="grid-header"> - %if render_title: - ${grid_title()} - %endif - %if grid.global_actions: - <ul class="manage-table-actions"> - %if len( grid.global_actions ) < 4: - %for action in grid.global_actions: - <li><a class="action-button" href="${h.url_for( **action.url_args )}">${action.label | h}</a></li> - %endfor - %else: - <li><a class="action-button" id="action-8675309-popup" class="menubutton">Actions</a></li> - <div popupmenu="action-8675309-popup"> - %for action in grid.global_actions: - <a class="action-button" href="${h.url_for( **action.url_args )}">${action.label | h}</a> - %endfor - </div> - %endif - </ul> - %endif - ${render_grid_filters( repo_grid, render_advanced_search=False )} - </div> +<%def name="insert()"> +<% + from tool_shed.grids.repository_grids import ValidRepositoryGrid + repo_grid = ValidRepositoryGrid() + grid_common.render_grid_filters(repo_grid) +%></%def> -<%def name="make_grid( grid, repo_grid )"> - <div class="loading-elt-overlay"></div> - <table> - <tr> - <td width="75%">${self.render_grid_header( grid, repo_grid )}</td> - <td></td> - <td></td> - </tr> - <tr> - <td width="100%" id="grid-message" valign="top">${render_message( message, status )}</td> - <td></td> - <td></td> - </tr> - </table> - ${render_grid_table( grid, show_item_checkboxes )} -</%def> - -<%def name="grid_body()"> - <% - from tool_shed.grids.repository_grids import ValidRepositoryGrid - repo_grid = ValidRepositoryGrid() - %> - ${self.make_grid( grid, repo_grid )} -</%def> - -<%def name="center_panel()"> - <div style="overflow: auto; height: 100%"> - <div class="page-container" style="padding: 10px;"> - ${self.grid_body( grid )} - </div> - </div> -</%def> +<!DOCTYPE HTML> +${grid_base.load(False, capture(self.insert))} \ No newline at end of file diff -r 60128a7ab160f23cf4fe4cb4231729cfa56369fb -r 44b0d21b4c7744d27d97241375b953abc1da7830 templates/webapps/tool_shed/common/grid_common.mako --- /dev/null +++ b/templates/webapps/tool_shed/common/grid_common.mako @@ -0,0 +1,187 @@ +<%! + from galaxy.web.framework.helpers.grids import TextColumn, StateColumn, GridColumnFilter + from galaxy.web.framework.helpers import iff +%> + +## Render a filter UI for a grid column. Filter is rendered as a table row. +<%def name="render_grid_column_filter( grid, column )"> + <tr> + <% + column_label = column.label + if column.filterable == "advanced": + column_label = column_label.lower() + %> + %if column.filterable == "advanced": + <td align="left" style="padding-left: 10px">${column_label}:</td> + %endif + <td style="padding: 0;"> + %if isinstance(column, TextColumn): + <form class="text-filter-form" column_key="${column.key}" action="${url(dict())}" method="get" > + ## Carry forward filtering criteria with hidden inputs. + %for temp_column in grid.columns: + %if temp_column.key in cur_filter_dict: + <% value = cur_filter_dict[ temp_column.key ] %> + %if value != "All": + <% + if isinstance( temp_column, TextColumn ): + value = h.to_json_string( value ) + %> + <input type="hidden" id="${temp_column.key}" name="f-${temp_column.key}" value='${value}'/> + %endif + %endif + %endfor + ## Print current filtering criteria and links to delete. + <span id="${column.key}-filtering-criteria"> + %if column.key in cur_filter_dict: + <% column_filter = cur_filter_dict[column.key] %> + %if isinstance( column_filter, basestring ): + %if column_filter != "All": + <span class='text-filter-val'> + ${cur_filter_dict[column.key]} + <% filter_all = GridColumnFilter( "", { column.key : "All" } ) %> + <a href="${url(filter_all.get_url_args())}"><span class="delete-search-icon" /></a> + </span> + %endif + %elif isinstance( column_filter, list ): + %for i, filter in enumerate( column_filter ): + %if i > 0: + , + %endif + <span class='text-filter-val'>${filter} + <% + new_filter = list( column_filter ) + del new_filter[ i ] + new_column_filter = GridColumnFilter( "", { column.key : h.to_json_string( new_filter ) } ) + %> + <a href="${url(new_column_filter.get_url_args())}"><span class="delete-search-icon" /></a> + </span> + %endfor + %endif + %endif + </span> + ## Print input field for column. + <span class="search-box"> + <% + # Set value, size of search input field. Minimum size is 20 characters. + value = iff( column.filterable == "standard", column.label.lower(), "") + size = len( value ) + if size < 20: + size = 20 + # +4 to account for search icon/button. + size = size + 4 + %> + <input class="search-box-input" id="input-${column.key}-filter" name="f-${column.key}" type="text" value="${value}" size="${size}"/> + <button class="submit-image" type="submit" title='Search'><span style="display: none;"></button> + </span> + </form> + %else: + <span id="${column.key}-filtering-criteria"> + %for i, filter in enumerate( column.get_accepted_filters() ): + <% + # HACK: we know that each filter will have only a single argument, so get that single argument. + for key, arg in filter.args.items(): + filter_key = key + filter_arg = arg + %> + %if i > 0: + | + %endif + %if column.key in cur_filter_dict and column.key in filter.args and cur_filter_dict[column.key] == filter.args[column.key]: + <span class="categorical-filter ${column.key}-filter current-filter">${filter.label}</span> + %else: + <span class="categorical-filter ${column.key}-filter"> + <a href="${url(filter.get_url_args())}" filter_key="${filter_key}" filter_val="${filter_arg}">${filter.label}</a> + </span> + %endif + %endfor + </span> + %endif + </td> + </tr> +</%def> + +## Print grid search/filtering UI. +<%def name="render_grid_filters( grid, render_advanced_search=True )"> + <% + # Show advanced search if flag set or if there are filters for advanced search fields. + advanced_search_display = "none" + if 'advanced-search' in kwargs and kwargs['advanced-search'] in ['True', 'true']: + advanced_search_display = "block" + + for column in grid.columns: + if column.filterable == "advanced": + ## Show div if current filter has value that is different from the default filter. + if column.key in cur_filter_dict and column.key in default_filter_dict and \ + cur_filter_dict[column.key] != default_filter_dict[column.key]: + advanced_search_display = "block" + + # do not show standard search if showing adv. + standard_search_display = "block" + if advanced_search_display == "block": + standard_search_display = "none" + %> + ## Standard search. + <div id="standard-search" style="display: ${standard_search_display};"> + <table> + <tr><td style="padding: 0;"> + <table> + %for column in grid.columns: + %if column.filterable == "standard": + ${render_grid_column_filter( grid, column )} + %endif + %endfor + </table> + </td></tr> + <tr><td> + ## Clear the standard search. + ##| + ##<% filter_all = GridColumnFilter( "", { column.key : "All" } ) %> + ##<a href="${url(filter_all.get_url_args())}">Clear All</a> + + ## Only show advanced search if there are filterable columns. + <% + show_advanced_search_link = False + if render_advanced_search: + for column in grid.columns: + if column.filterable == "advanced": + show_advanced_search_link = True + break + endif + %> + %if show_advanced_search_link: + <% args = { "advanced-search" : True } %> + <a href="${url(args)}" class="advanced-search-toggle">Advanced Search</a> + %endif + </td></tr> + </table> + </div> + + ## Advanced search. + <div id="advanced-search" style="display: ${advanced_search_display}; margin-top: 5px; border: 1px solid #ccc;"> + <table> + <tr><td style="text-align: left" colspan="100"> + <% args = { "advanced-search" : False } %> + <a href="${url(args)}" class="advanced-search-toggle">Close Advanced Search</a> + ## Link to clear all filters. + ##| + ##<% + ## no_filter = GridColumnFilter("Clear All", default_filter_dict) + ##%> + ##<a href="${url(no_filter.get_url_args())}">${no_filter.label}</a> + </td></tr> + %for column in grid.columns: + %if column.filterable == "advanced": + ## Show div if current filter has value that is different from the default filter. + %if column.key in cur_filter_dict and column.key in default_filter_dict and \ + cur_filter_dict[column.key] != default_filter_dict[column.key]: + <script type="text/javascript"> + $('#advanced-search').css("display", "block"); + </script> + %endif + + ${render_grid_column_filter( grid, column )} + %endif + %endfor + </table> + </div> +</%def> Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org