details: http://www.bx.psu.edu/hg/galaxy/rev/49961332adb6 changeset: 3345:49961332adb6 user: Greg Von Kuster <greg@bx.psu.edu> date: Fri Feb 05 15:51:01 2010 -0500 description: Data library UI cleanup and improvements. Widgets are now displayed for the currently selected tempalte when adding one to a library item. diffstat: lib/galaxy/web/controllers/library_common.py | 41 +++++++++++- templates/library/common/browse_library.mako | 10 +- templates/library/common/common.mako | 36 +++++++--- templates/library/common/ldda_info.mako | 28 ++++---- templates/library/common/library_info.mako | 57 +++++++++++++++-- templates/library/common/select_info_template.mako | 70 +++++++++++++++++---- test/base/twilltestcase.py | 5 +- test/functional/test_security_and_libraries.py | 2 +- 8 files changed, 190 insertions(+), 59 deletions(-) diffs (435 lines): diff -r e3af9317e829 -r 49961332adb6 lib/galaxy/web/controllers/library_common.py --- a/lib/galaxy/web/controllers/library_common.py Fri Feb 05 15:29:22 2010 -0500 +++ b/lib/galaxy/web/controllers/library_common.py Fri Feb 05 15:51:01 2010 -0500 @@ -1,4 +1,4 @@ -import os, os.path, shutil, urllib, StringIO, re, gzip, tempfile, shutil, zipfile +import os, os.path, shutil, urllib, StringIO, re, gzip, tempfile, shutil, zipfile, copy from galaxy.web.base.controller import * from galaxy import util, jobs from galaxy.datatypes import sniff @@ -6,6 +6,7 @@ from galaxy.util.json import to_json_string from galaxy.tools.actions import upload_common from galaxy.web.controllers.forms import get_all_forms +from galaxy.web.form_builder import SelectField from galaxy.model.orm import * from galaxy.util.streamball import StreamBall import logging, tempfile, zipfile, tarfile, os, sys @@ -1314,7 +1315,7 @@ action = 'ldda_edit_info' id = ldda_id if params.get( 'add_info_template_button', False ): - form = trans.sa_session.query( trans.app.model.FormDefinition ).get( int( params.form_id ) ) + form = trans.sa_session.query( trans.app.model.FormDefinition ).get( trans.security.decode_id( params.form_id ) ) form_values = trans.app.model.FormValues( form, [] ) trans.sa_session.add( form_values ) trans.sa_session.flush() @@ -1326,7 +1327,7 @@ assoc = trans.app.model.LibraryDatasetDatasetInfoAssociation( item, form, form_values ) trans.sa_session.add( assoc ) trans.sa_session.flush() - msg = 'An information template based on the form "%s" has been added to this %s.' % ( form.name, library_item_desc ) + msg = 'A template based on the form "%s" has been added to this %s.' % ( form.name, library_item_desc ) trans.response.send_redirect( web.url_for( controller='library_common', action=action, cntrller=cntrller, @@ -1336,6 +1337,36 @@ show_deleted=show_deleted, msg=msg, messagetype='done' ) ) + def generate_template_stuff( trans, forms, form_id ): + # Returns the following: + # - a list of template ids + # - a list of dictionaries whose keys are template ids and whose values are templates widgets. + # The dictionary built using the received forms param + # - a select list whose options are templates + template_ids = [ 'none' ] + widgets = [] + for form in forms: + template_ids.append( trans.security.encode_id( form.id ) ) + template_select_list = SelectField( 'form_id', + refresh_on_change=True, + refresh_on_change_values=template_ids[1:] ) + if form_id == 'none': + template_select_list.add_option( 'Select one', 'none', selected=True ) + decoded_form_id = None + else: + template_select_list.add_option( 'Select one', 'none' ) + decoded_form_id = trans.security.decode_id( form_id ) + for form in forms: + if decoded_form_id and decoded_form_id == form.id: + template_select_list.add_option( form.name, trans.security.encode_id( form.id ), selected=True ) + widgets = form.get_widgets( trans.user ) + else: + template_select_list.add_option( form.name, trans.security.encode_id( form.id ) ) + return template_ids, widgets, template_select_list + if params.get( 'refresh', False ): + template_ids, widgets, template_select_list = generate_template_stuff( trans, forms, kwd.get( 'form_id' ) ) + else: + template_ids, widgets, template_select_list = generate_template_stuff( trans, forms, 'none' ) return trans.fill_template( '/library/common/select_info_template.mako', cntrller=cntrller, library_item_name=item.name, @@ -1344,7 +1375,9 @@ library_id=library_id, folder_id=folder_id, ldda_id=ldda_id, - forms=forms, + template_ids=template_ids, + widgets=widgets, + template_select_list=template_select_list, show_deleted=show_deleted, msg=msg, messagetype=messagetype ) diff -r e3af9317e829 -r 49961332adb6 templates/library/common/browse_library.mako --- a/templates/library/common/browse_library.mako Fri Feb 05 15:29:22 2010 -0500 +++ b/templates/library/common/browse_library.mako Fri Feb 05 15:51:01 2010 -0500 @@ -17,8 +17,6 @@ <% if cntrller in [ 'library', 'requests' ]: can_add = trans.app.security_agent.can_add_library_item( current_user_roles, library ) - if can_add: - info_association, inherited = library.get_info_association() can_modify = trans.app.security_agent.can_modify_library_item( current_user_roles, library ) can_manage = trans.app.security_agent.can_manage_library_item( current_user_roles, library ) info_association, inherited = library.get_info_association() @@ -277,7 +275,7 @@ %if folder.deleted: <span class="libraryItem-error"> %endif - ${folder.name} + <a href="${h.url_for( controller='library_common', action='folder_info', cntrller=cntrller, id=trans.security.encode_id( folder.id ), library_id=library_id, show_deleted=show_deleted )}">${folder.name}</a> %if folder.description: <i>- ${folder.description}</i> %endif @@ -372,7 +370,7 @@ <tr class="libraryTitle"> %if cntrller == 'library_admin' or can_add or can_modify or can_manage: <th style="padding-left: 42px;"> - ${library.name} + <a href="${h.url_for( controller='library_common', action='library_info', cntrller=cntrller, id=trans.security.encode_id( library.id ), show_deleted=show_deleted )}"><b>${library.name[:50]}</b></a> <a id="library-${library.id}-popup" class="popup-arrow" style="display: none;">▼</a> <div popupmenu="library-${library.id}-popup"> %if not library.deleted: @@ -406,7 +404,9 @@ </div> </th> %else: - <th style="padding-left: 42px;">${library.name}</th> + <th style="padding-left: 42px;"> + <a href="${h.url_for( controller='library_common', action='library_info', cntrller=cntrller, id=trans.security.encode_id( library.id ), show_deleted=show_deleted )}"><b>${library.name[:50]}</b></a> + </th> %endif <th>Information</th> <th>Uploaded By</th> diff -r e3af9317e829 -r 49961332adb6 templates/library/common/common.mako --- a/templates/library/common/common.mako Fri Feb 05 15:29:22 2010 -0500 +++ b/templates/library/common/common.mako Fri Feb 05 15:51:01 2010 -0500 @@ -1,23 +1,20 @@ <%def name="render_template_info( cntrller, item_type, library_id, widgets, folder_id=None, ldda_id=None, editable=True )"> <% if item_type == 'library': - item_desc = 'library' item = trans.sa_session.query( trans.app.model.Library ).get( trans.security.decode_id( library_id ) ) elif item_type == 'folder': - item_desc = 'folder' item = trans.sa_session.query( trans.app.model.LibraryFolder ).get( trans.security.decode_id( folder_id ) ) elif item_type == 'ldda': - item_desc = 'dataset' item = trans.sa_session.query( trans.app.model.LibraryDatasetDatasetAssociation ).get( trans.security.decode_id( ldda_id ) ) if cntrller == 'library': current_user_roles = trans.get_current_user_roles() %> %if widgets: - <p/> - <div class="toolForm"> - <div class="toolFormTitle">Other information about ${item_desc} ${item.name}</div> - <div class="toolFormBody"> - %if editable and ( cntrller=='library_admin' or trans.app.security_agent.can_modify_library_item( current_user_roles, item ) ): + %if editable and ( cntrller=='library_admin' or trans.app.security_agent.can_modify_library_item( current_user_roles, item ) ): + <p/> + <div class="toolForm"> + <div class="toolFormTitle">Other information about ${item.name}</div> + <div class="toolFormBody"> <form name="edit_info" action="${h.url_for( controller='library_common', action='edit_template_info', cntrller=cntrller, item_type=item_type, library_id=library_id, num_widgets=len( widgets ), folder_id=folder_id, ldda_id=ldda_id, show_deleted=show_deleted )}" method="post"> %for i, field in enumerate( widgets ): <div class="form-row"> @@ -33,7 +30,22 @@ <input type="submit" name="edit_info_button" value="Save"/> </div> </form> - %else: + </div> + </div> + %else: + <% contents = False %> + %for i, field in enumerate( widgets ): + %if field[ 'widget' ].value: + <% + contents = True + break + %> + %endif + %endfor + %if contents: + <div class="toolForm"> + <div class="toolFormTitle">Other information about ${item.name}</div> + <div class="toolFormBody"> %for i, field in enumerate( widgets ): %if field[ 'widget' ].value: <div class="form-row"> @@ -46,9 +58,9 @@ </div> %endif %endfor - %endif - </div> - </div> + </div> + %endif + %endif %endif </%def> diff -r e3af9317e829 -r 49961332adb6 templates/library/common/ldda_info.mako --- a/templates/library/common/ldda_info.mako Fri Feb 05 15:29:22 2010 -0500 +++ b/templates/library/common/ldda_info.mako Fri Feb 05 15:51:01 2010 -0500 @@ -98,18 +98,18 @@ </div> %endif </div> - %if widgets: - ${render_template_info( cntrller=cntrller, item_type='ldda', library_id=library_id, widgets=widgets, folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ), ldda_id=trans.security.encode_id( ldda.id ), editable=False )} +</div> +%if widgets: + ${render_template_info( cntrller=cntrller, item_type='ldda', library_id=library_id, widgets=widgets, folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ), ldda_id=trans.security.encode_id( ldda.id ), editable=False )} +%endif +%if current_version: + <% expired_lddas = [ e_ldda for e_ldda in ldda.library_dataset.expired_datasets ] %> + %if expired_lddas: + <div class="toolFormTitle">Expired versions of ${ldda.name}</div> + %for expired_ldda in expired_lddas: + <div class="form-row"> + <a href="${h.url_for( controller='library_common', action='ldda_display_info', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( expired_ldda.library_dataset.folder.id ), id=trans.security.encode_id( expired_ldda.id ), show_deleted=show_deleted )}">${expired_ldda.name}</a> + </div> + %endfor %endif - %if current_version: - <% expired_lddas = [ e_ldda for e_ldda in ldda.library_dataset.expired_datasets ] %> - %if expired_lddas: - <div class="toolFormTitle">Expired versions of ${ldda.name}</div> - %for expired_ldda in expired_lddas: - <div class="form-row"> - <a href="${h.url_for( controller='library_common', action='ldda_display_info', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( expired_ldda.library_dataset.folder.id ), id=trans.security.encode_id( expired_ldda.id ), show_deleted=show_deleted )}">${expired_ldda.name}</a> - </div> - %endfor - %endif - %endif -</div> +%endif diff -r e3af9317e829 -r 49961332adb6 templates/library/common/library_info.mako --- a/templates/library/common/library_info.mako Fri Feb 05 15:29:22 2010 -0500 +++ b/templates/library/common/library_info.mako Fri Feb 05 15:51:01 2010 -0500 @@ -2,6 +2,14 @@ <%namespace file="/message.mako" import="render_msg" /> <%namespace file="/library/common/common.mako" import="render_template_info" /> +<% + if cntrller in [ 'library', 'requests' ]: + can_add = trans.app.security_agent.can_add_library_item( current_user_roles, library ) + can_modify = trans.app.security_agent.can_modify_library_item( current_user_roles, library ) + can_manage = trans.app.security_agent.can_manage_library_item( current_user_roles, library ) + info_association, inherited = library.get_info_association() +%> + <br/><br/> <ul class="manage-table-actions"> <li> @@ -13,7 +21,7 @@ ${render_msg( msg, messagetype )} %endif -%if cntrller == 'library_admin' or trans.app.security_agent.can_modify_library_item( current_user_roles, library ): +%if cntrller == 'library_admin' or can_modify: <div class="toolForm"> <div class="toolFormTitle">Change library name and description</div> <div class="toolFormBody"> @@ -32,21 +40,56 @@ </div> <div style="clear: both"></div> </div> - <input type="submit" name="rename_library_button" value="Save"/> + <div class="form-row"> + <input type="submit" name="rename_library_button" value="Save"/> + </div> </form> </div> </div> <p/> %else: <div class="toolForm"> - <div class="toolFormTitle">View information about ${library.name}</div> + <div class="toolFormTitle"> + %if cntrller == 'library_admin' or can_add or can_manage: + <th style="padding-left: 42px;"> + <a href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=trans.security.encode_id( library.id ), show_deleted=show_deleted )}"><b>${library.name[:50]}</b></a> + <a id="library-${library.id}-popup" class="popup-arrow" style="display: none;">▼</a> + <div popupmenu="library-${library.id}-popup"> + %if not library.deleted: + %if ( cntrller == 'library_admin' or can_add ) and not library.info_association: + <a class="action-button" href="${h.url_for( controller='library_common', action='add_info_template', cntrller=cntrller, item_type='library', library_id=trans.security.encode_id( library.id ), show_deleted=show_deleted )}">Add template</a> + %endif + %if cntrller == 'library_admin' and info_association: + <a class="action-button" href="${h.url_for( controller='library_common', action='delete_info_template', cntrller=cntrller, item_type='library', library_id=trans.security.encode_id( library.id ), show_deleted=show_deleted )}">Delete template</a> + %endif + %if cntrller == 'library_admin' or can_manage: + <a class="action-button" href="${h.url_for( controller='library_common', action='library_permissions', cntrller=cntrller, id=trans.security.encode_id( library.id ), show_deleted=show_deleted )}">Edit permissions</a> + %endif + %if cntrller == 'library_admin': + <a class="action-button" confirm="Click OK to delete the library named '${library.name}'." href="${h.url_for( controller='library_admin', action='delete_library_item', library_id=trans.security.encode_id( library.id ), library_item_id=trans.security.encode_id( library.id ), library_item_type='library' )}">Delete this data library and its contents</a> + %endif + %elif cntrller == 'library_admin' and not library.purged: + <a class="action-button" href="${h.url_for( controller='library_admin', action='undelete_library_item', library_id=trans.security.encode_id( library.id ), library_item_id=trans.security.encode_id( library.id ), library_item_type='library' )}">Undelete this data library</a> + %endif + </div> + </th> + %else: + <th style="padding-left: 42px;"> + <a href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=trans.security.encode_id( library.id ), show_deleted=show_deleted )}"><b>${library.name[:50]}</b></a> + </th> + %endif + </div> <div class="toolFormBody"> <div class="form-row"> - <b>Name:</b> ${library.name} - <div style="clear: both"></div> - <b>Description:</b> ${library.description} - <div style="clear: both"></div> + <label>Name:</label> + ${library.name} </div> + <div style="clear: both"></div> + <div class="form-row"> + <label>Description:</label> + ${library.description} + </div> + <div style="clear: both"></div> </div> </div> %endif diff -r e3af9317e829 -r 49961332adb6 templates/library/common/select_info_template.mako --- a/templates/library/common/select_info_template.mako Fri Feb 05 15:29:22 2010 -0500 +++ b/templates/library/common/select_info_template.mako Fri Feb 05 15:51:01 2010 -0500 @@ -1,6 +1,31 @@ <%inherit file="/base.mako"/> <%namespace file="/message.mako" import="render_msg" /> +<script type="text/javascript"> +$( function() { + $( "select[refresh_on_change='true']").change( function() { + var refresh = false; + var refresh_on_change_values = $( this )[0].attributes.getNamedItem( 'refresh_on_change_values' ) + if ( refresh_on_change_values ) { + refresh_on_change_values = refresh_on_change_values.value.split( ',' ); + var last_selected_value = $( this )[0].attributes.getNamedItem( 'last_selected_value' ); + for( i= 0; i < refresh_on_change_values.length; i++ ) { + if ( $( this )[0].value == refresh_on_change_values[i] || ( last_selected_value && last_selected_value.value == refresh_on_change_values[i] ) ){ + refresh = true; + break; + } + } + } + else { + refresh = true; + } + if ( refresh ){ + $( "#select_info_template" ).submit(); + } + }); +}); +</script> + <br/><br/> <ul class="manage-table-actions"> <li> @@ -13,21 +38,38 @@ %endif <div class="toolForm"> - <div class="toolFormTitle">Select a form on which to base the template for the ${library_item_desc} '${library_item_name}'</div> - <form name="new_info_template" action="${h.url_for( controller='library_common', action='add_info_template', cntrller=cntrller, item_type=item_type, library_id=library_id, folder_id=folder_id, ldda_id=ldda_id, show_deleted=show_deleted )}" method="post" > + <div class="toolFormTitle">Select a template for the ${library_item_desc} '${library_item_name}'</div> + <form id="select_info_template" name="select_info_template" action="${h.url_for( controller='library_common', action='add_info_template', cntrller=cntrller, item_type=item_type, library_id=library_id, folder_id=folder_id, ldda_id=ldda_id, show_deleted=show_deleted )}" method="post" > <div class="toolFormBody"> - <div class="form-row"> - <label>Template:</label> - <select name="form_id"> - %for form in forms: - <option value="${form.id}">${form.name}</option> - %endfor - </select> - </div> - <div style="clear: both"></div> - <div class="form-row"> - <input type="submit" name="add_info_template_button" value="Add template to ${library_item_desc}"/> - </div> + <table class="grid"> + <tr> + <div class="form-row"> + <td> + <input type="hidden" name="refresh" value="true" size="40"/> + <label>Template:</label> + ${template_select_list.get_html()} + </td> + <td> + <input type="submit" name="add_info_template_button" value="Add template to ${library_item_desc}"/> + </td> + </div> + </tr> + </table> + %if template_select_list.get_selected() != ('Select one', 'none'): + <div style="clear: both"></div> + <div class="form-row"> + %for i, field in enumerate( widgets ): + <div class="form-row"> + <label>${field[ 'label' ]}</label> + ${field[ 'widget' ].get_html()} + <div class="toolParamHelp" style="clear: both;"> + ${field[ 'helptext' ]} + </div> + <div style="clear: both"></div> + </div> + %endfor + </div> + %endif </div> </form> </div> diff -r e3af9317e829 -r 49961332adb6 test/base/twilltestcase.py --- a/test/base/twilltestcase.py Fri Feb 05 15:29:22 2010 -0500 +++ b/test/base/twilltestcase.py Fri Feb 05 15:51:01 2010 -0500 @@ -1403,9 +1403,10 @@ elif item_type == 'ldda': url = "%s/library_common/add_info_template?cntrller=%s&item_type=%s&library_id=%s&folder_id=%s&ldda_id=%s" % ( self.url, cntrller, item_type, library_id, folder_id, ldda_id ) self.visit_url( url ) - self.check_page_for_string ( "Select a form on which to base the template" ) + self.check_page_for_string ( "Select a template for the" ) + tc.fv( '1', 'form_id', form_id ) tc.submit( 'add_info_template_button' ) - self.check_page_for_string = 'An information template based on the form "%s" has been added to this' % form_name + self.check_page_for_string = 'A template based on the form "%s" has been added to this' % form_name self.home() def library_info( self, library_id, library_name, ele_1_field_name, ele_1_contents, ele_2_field_name, ele_2_contents, controller='library_admin' ): """Add information to a library using an existing template with 2 elements""" diff -r e3af9317e829 -r 49961332adb6 test/functional/test_security_and_libraries.py --- a/test/functional/test_security_and_libraries.py Fri Feb 05 15:29:22 2010 -0500 +++ b/test/functional/test_security_and_libraries.py Fri Feb 05 15:51:01 2010 -0500 @@ -582,7 +582,7 @@ self.add_info_template( 'library_admin', 'library', self.security.encode_id( library_one.id ), - str( form_one.id ), + self.security.encode_id( form_one.id ), form_one.name ) # Make sure the template fields are displayed on the library information page field_dict = form_one.fields[ 0 ]