data libraries: initial take on showing libraries to anonyms and filter on deleted libraries

plus some newly packed script that wasn't packed in error
This commit is contained in:
Martin Cech
2014-03-13 16:50:27 -04:00
parent dca64eeb8b
commit 496d7d90d3
4 changed files with 42 additions and 23 deletions
+19 -15
View File
@@ -2,10 +2,10 @@
API operations on a data library.
"""
from galaxy import util
from galaxy.util import string_as_bool
from galaxy import web
from galaxy import exceptions
from galaxy.web import _future_expose_api as expose_api
from galaxy.web import _future_expose_api_anonymous as expose_api_anonymous
from galaxy.model.orm import and_, not_, or_
from galaxy.web.base.controller import BaseAPIController, url_for
@@ -15,17 +15,15 @@ log = logging.getLogger( __name__ )
class LibrariesController( BaseAPIController ):
@expose_api
def index( self, trans, deleted='False', **kwd ):
@expose_api_anonymous
def index( self, trans, **kwd ):
"""
index( self, trans, deleted='False', **kwd )
index( self, trans, **kwd )
* GET /api/libraries:
Returns a list of summary data for all libraries that are ``non-deleted``
* GET /api/libraries/deleted:
Returns a list of summary data for ``deleted`` libraries.
Returns a list of summary data for all libraries.
:param deleted: if True, show only ``deleted`` libraries, if False or nonpresent show only ``non-deleted``
:type deleted: boolean
:param deleted: if True, show only ``deleted`` libraries, if False show only ``non-deleted``
:type deleted: boolean (optional)
:returns: list of dictionaries containing library information
:rtype: list
@@ -33,11 +31,17 @@ class LibrariesController( BaseAPIController ):
.. seealso:: :attr:`galaxy.model.Library.dict_collection_visible_keys`
"""
query = trans.sa_session.query( trans.app.model.Library )
deleted = util.string_as_bool( deleted )
if deleted:
query = query.filter( trans.app.model.Library.table.c.deleted == True )
else:
query = query.filter( trans.app.model.Library.table.c.deleted == False )
deleted = kwd.get( 'deleted', 'missing' )
try:
deleted = util.asbool( deleted )
if deleted:
query = query.filter( trans.app.model.Library.table.c.deleted == True )
else:
query = query.filter( trans.app.model.Library.table.c.deleted == False )
except ValueError:
# given value wasn't true/false so we don't filter on this parameter at all
pass
current_user_role_ids = [ role.id for role in trans.get_current_user_roles() ]
library_access_action = trans.app.security_agent.permitted_actions.LIBRARY_ACCESS.action
restricted_library_ids = [ lp.library_id for lp in ( trans.sa_session.query( trans.model.LibraryPermissions )
@@ -196,7 +200,7 @@ class LibrariesController( BaseAPIController ):
.. seealso:: :attr:`galaxy.model.Library.dict_element_visible_keys`
"""
undelete = string_as_bool( kwd.get( 'undelete', False ) )
undelete = util.string_as_bool( kwd.get( 'undelete', False ) )
if not trans.user_is_admin():
raise exceptions.ItemAccessibilityException( 'Only administrators can delete and undelete libraries.' )
try:
+21 -6
View File
@@ -817,20 +817,31 @@ var GalaxyLibraryview = Backbone.View.extend({
$("#center").css('overflow','auto');
},
render: function (models) {
/** Renders the libraries table either from the object's own collection, or from a given array of library models,
or renders an empty list in case no data is present. */
render: function (options) {
var template = this.templateLibraryList();
var libraries_to_render = null;
var include_deleted = false;
var models = null
if (typeof options !== 'undefined'){
include_deleted = typeof options.with_deleted !== 'undefined' ? options.with_deleted : false;
models = typeof options.models !== 'undefined' ? options.models : null;
}
if (this.collection !== null && typeof models === 'undefined'){
libraries_to_render = this.collection.models;
if (this.collection !== null && models === null){
if (include_deleted){ // show all the libraries
libraries_to_render = this.collection.models;
} else{ // show only undeleted libraries
libraries_to_render = this.collection.where({deleted: false});;
}
} else if (models !== null){
libraries_to_render = models;
} else {
libraries_to_render = [];
}
this.$el.html(template({libraries: libraries_to_render, order: this.collection.sort_order}));
}
this.$el.html(template({libraries: libraries_to_render, order: this.collection.sort_order}));
},
/** Sorts the underlying collection according to the parameters received through URL.
@@ -867,6 +878,9 @@ var GalaxyLibraryview = Backbone.View.extend({
tmpl_array.push('');
tmpl_array.push('<h3>Data Libraries Beta Test. This is work in progress. Please report problems & ideas via <a href="mailto:galaxy-bugs@bx.psu.edu?Subject=DataLibrariesBeta_Feedback" target="_blank">email</a> and <a href="https://trello.com/c/nwYQNFPK/56-data-library-ui-progressive-display-of-folders" target="_blank">Trello</a>.</h3>');
tmpl_array.push('<a href="" id="create_new_library_btn" class="btn btn-primary file ">New Library</a>');
tmpl_array.push('<% if(libraries.length === 0) { %>');
tmpl_array.push("<div>I see no libraries. Why don't you create one?</div>");
tmpl_array.push('<% } else{ %>');
tmpl_array.push('<table class="library_table table table-condensed">');
tmpl_array.push(' <thead>');
tmpl_array.push(' <th><a title="Click to reverse order" href="#sort/name/<% if(order==="desc"||order===null){print("asc")}else{print("desc")} %>">name</a> <span title="Sorted alphabetically" class="fa fa-sort-alpha-<%- order %>"></span></th>');
@@ -883,6 +897,7 @@ var GalaxyLibraryview = Backbone.View.extend({
tmpl_array.push(' <% }); %>');
tmpl_array.push(' </tbody>');
tmpl_array.push('</table>');
tmpl_array.push('<% }%>');
tmpl_array.push('</div>');
return _.template(tmpl_array.join(''));
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1 +1 @@
define(["utils/utils"],function(a){var b=Backbone.View.extend({visible:false,optionsDefault:{title:"",icon:"",buttons:null,body:null,height:null,operations:null,placement:"bottom",overflow:"auto"},$title:null,$content:null,$buttons:null,$operations:null,initialize:function(d){this.options=a.merge(d,this.optionsDefault);this.setElement(this._template(this.options));this.$content=this.$el.find("#content");this.$title=this.$el.find("#title-text");if(this.options.height){this.$el.find("#body").css("height",this.options.height);this.$el.find("#content").css("overflow",this.options.overflow)}this.$buttons=$(this.el).find("#buttons");if(this.options.buttons){var c=this;$.each(this.options.buttons,function(e,f){f.$el.prop("id",e);c.$buttons.append(f.$el)})}else{this.$buttons.remove()}this.$operations=$(this.el).find("#operations");if(this.options.operations){var c=this;$.each(this.options.operations,function(e,f){f.$el.prop("id",e);c.$operations.append(f.$el)})}if(this.options.body){this.append(this.options.body)}},append:function(c){this.$content.append(a.wrap(c))},content:function(){return this.$content},show:function(){this.$el.fadeIn("fast");this.visible=true},hide:function(){this.$el.fadeOut("fast");this.visible=false},enableButton:function(c){this.$buttons.find("#"+c).prop("disabled",false)},disableButton:function(c){this.$buttons.find("#"+c).prop("disabled",true)},hideOperation:function(c){this.$operations.find("#"+c).hide()},showOperation:function(c){this.$operations.find("#"+c).show()},setOperation:function(e,d){var c=this.$operations.find("#"+e);c.off("click");c.on("click",d)},title:function(d){var c=this.$title;if(d){c.html(d)}return c.html()},_template:function(d){var c='<div class="toolForm">';if(d.title||d.icon){c+='<div id="title" class="toolFormTitle" style="overflow:hidden; padding-bottom: 1px;"><div id="operations" style="float: right;"></div><div style="overflow: hidden; margin-bottom: 4px;">';if(d.icon){c+='<i style="padding-top: 3px; float: left; font-size: 1.2em" class="icon fa '+d.icon+'">&nbsp;</i>'}c+='<div id="title-text" style="padding-top: 2px; float: left;">'+d.title+"</div>";c+="</div></div>"}c+='<div id="body" class="toolFormBody">';if(d.placement=="top"){c+='<div id="buttons" class="buttons" style="height: 50px; padding: 10px;"></div>'}c+='<div id="content" class="content" style="height: inherit; padding: 10px;"></div>';if(d.placement=="bottom"){c+='<div id="buttons" class="buttons" style="height: 50px; padding: 10px;"></div>'}c+="</div></div>";return c}});return{View:b}});
define(["utils/utils"],function(a){var b=Backbone.View.extend({visible:false,optionsDefault:{title:"",icon:"",buttons:null,body:null,height:null,operations:null,placement:"bottom",overflow:"auto"},$title:null,$content:null,$buttons:null,$operations:null,initialize:function(d){this.options=a.merge(d,this.optionsDefault);this.setElement(this._template(this.options));this.$content=this.$el.find("#content");this.$title=this.$el.find("#title-text");if(this.options.height){this.$el.find("#body").css("height",this.options.height);this.$el.find("#content").css("overflow",this.options.overflow)}this.$buttons=$(this.el).find("#buttons");if(this.options.buttons){var c=this;$.each(this.options.buttons,function(e,f){f.$el.prop("id",e);c.$buttons.append(f.$el)})}else{this.$buttons.remove()}this.$operations=$(this.el).find("#operations");if(this.options.operations){var c=this;$.each(this.options.operations,function(e,f){f.$el.prop("id",e);c.$operations.append(f.$el)})}if(this.options.body){this.append(this.options.body)}},append:function(c){this.$content.append(a.wrap(c))},content:function(){return this.$content},show:function(){this.$el.fadeIn("fast");this.visible=true},hide:function(){this.$el.fadeOut("fast");this.visible=false},enableButton:function(c){this.$buttons.find("#"+c).prop("disabled",false)},disableButton:function(c){this.$buttons.find("#"+c).prop("disabled",true)},hideOperation:function(c){this.$operations.find("#"+c).hide()},showOperation:function(c){this.$operations.find("#"+c).show()},setOperation:function(e,d){var c=this.$operations.find("#"+e);c.off("click");c.on("click",d)},title:function(d){var c=this.$title;if(d){c.html(d)}return c.html()},_template:function(d){var c='<div class="toolForm">';if(d.title||d.icon){c+='<div id="title" class="toolFormTitle" style="overflow:hidden; padding-bottom: 1px;"><div id="operations" style="float: right;"></div><div style="overflow: hidden; margin-bottom: 4px;">';if(d.icon){c+='<i style="padding-top: 3px; float: left; font-size: 1.2em" class="icon fa '+d.icon+'">&nbsp;</i>'}c+='<div id="title-text" style="padding-top: 1px; float: left;">'+d.title+"</div>";c+="</div></div>"}c+='<div id="body" class="toolFormBody">';if(d.placement=="top"){c+='<div id="buttons" class="buttons" style="height: 50px; padding: 10px;"></div>'}c+='<div id="content" class="content" style="height: inherit; padding: 10px;"></div>';if(d.placement=="bottom"){c+='<div id="buttons" class="buttons" style="height: 50px; padding: 10px;"></div>'}c+="</div></div>";return c}});return{View:b}});