# HG changeset patch -- Bitbucket.org # Project galaxy-dist # URL http://bitbucket.org/galaxy/galaxy-dist/overview # User rc # Date 1287000426 14400 # Node ID c0feb970e48de8b713a9a516cad61950ed0641b5 # Parent 77e13329ab8b9e69089400259eb70cda9525ec80 sample tracking bug fixes --- a/templates/admin/requests/rename_datasets.mako +++ b/templates/admin/requests/rename_datasets.mako @@ -3,15 +3,14 @@ <% from galaxy.web.controllers.requests_admin import build_rename_datasets_for_sample_select_field %> -<br/><br/> -<font color="red"><b><i>A dataset can be renamed only if its status is "Not Started"</i></b></font> +<h3>Rename datasets for Sample "${sample.name}"</h3><ul class="manage-table-actions"><li><a class="action-button" href="${h.url_for( controller='requests_admin', action='manage_datasets', sample_id=trans.security.encode_id( sample.id ) )}">Browse datasets</a></li><li> - <a class="action-button" href="${h.url_for( controller='requests_common', action='manage_request', cntrller=cntrller, id=trans.security.encode_id( sample.request.id ) )}">Browse this request</a> + <a class="action-button" href="${h.url_for( controller='requests_common', action='manage_request', cntrller='requests_admin', id=trans.security.encode_id( sample.request.id ) )}">Browse this request</a></li></ul> @@ -19,40 +18,39 @@ ${render_msg( message, status )} %endif +${render_msg( 'A dataset can be renamed only if it is in <b>Not Started</b> state.', 'warning' )} <div class="toolForm"> - <div class="toolFormTitle">Rename datasets for Sample "${sample.name}"</div> - <div class="toolFormBody"> - <form name="rename_datasets" id="rename_datasets" action="${h.url_for( controller='requests_admin', action='rename_datasets', id_list=id_list, sample_id=trans.security.encode_id( sample.id ) )}" method="post" > - <table class="grid"> - <thead> - <tr> - <th>Prepend directory name</th> - <th>Name</th> - <th>Path on sequencer</th> - </tr> - <thead> - <tbody> - %for sample_dataset in sample_datasets: - %if sample_dataset.status == trans.app.model.Sample.transfer_status.NOT_STARTED: - <tr> - <td> - <% rename_datasets_for_sample_select_field = build_rename_datasets_for_sample_select_field( trans, sample_dataset ) %> - ${rename_datasets_for_sample_select_field} - </td> - <td> - <input type="text" name="new_name_${trans.security.encode_id( sample_dataset.id} )" value="${sample_dataset.name}" size="100"/> - </td> - <td>${sample_dataset.file_path}</td> - </tr> - %endif - %endfor - </tbody> - </table> - <br/> - <div class="form-row"> - <input type="submit" name="rename_datasets_button" value="Save"/> - <input type="submit" name="cancel_rename_datasets_button" value="Close"/> - </div> - </form> - </div> + <form name="rename_datasets" id="rename_datasets" action="${h.url_for( controller='requests_admin', action='rename_datasets', id_list=id_list, sample_id=trans.security.encode_id( sample.id ) )}" method="post" > + <table class="grid"> + <thead> + <tr> + <th>Prepend directory name</th> + <th>Name</th> + <th>Path on sequencer</th> + </tr> + <thead> + <tbody> + %for id in id_list: + <% sample_dataset = trans.sa_session.query( trans.model.SampleDataset ).get( trans.security.decode_id( id ) ) %> + %if sample_dataset.status == trans.app.model.Sample.transfer_status.NOT_STARTED: + <tr> + <td> + <% rename_datasets_for_sample_select_field = build_rename_datasets_for_sample_select_field( trans, sample_dataset ) %> + ${rename_datasets_for_sample_select_field.get_html()} + </td> + <td> + <input type="text" name="new_name_${trans.security.encode_id( sample_dataset.id ) }" value="${sample_dataset.name}" size="100"/> + </td> + <td>${sample_dataset.file_path}</td> + </tr> + %endif + %endfor + </tbody> + </table> + <br/> + <div class="form-row"> + <input type="submit" name="rename_datasets_button" value="Save"/> + <input type="submit" name="cancel_rename_datasets_button" value="Close"/> + </div> + </form></div> --- a/lib/galaxy/web/controllers/requests_common.py +++ b/lib/galaxy/web/controllers/requests_common.py @@ -105,8 +105,7 @@ class RequestsGrid( grids.Grid ): class RequestsCommon( BaseController, UsesFormDefinitionWidgets ): @web.json - def sample_state_updates( self, trans, ids=None, states=None, cntrller=None ): - # TODO fix this mthod - cntrller is required in the signature. + def sample_state_updates( self, trans, cntrller, ids=None, states=None ): # Avoid caching trans.response.headers['Pragma'] = 'no-cache' trans.response.headers['Expires'] = '0' @@ -424,13 +423,19 @@ class RequestsCommon( BaseController, Us except: invalid_id_redirect( trans, cntrller, folder_id ) for sample_id in selected_samples: - sample = trans.sa_session.query( trans.model.Sample ).get( sample_id ) + sample = trans.sa_session.query( trans.model.Sample ).get( trans.security.decode_id( sample_id ) ) sample.library = library sample.folder = folder trans.sa_session.add( sample ) trans.sa_session.flush() trans.sa_session.refresh( request ) message = 'Changes made to the selected samples have been saved. ' + return trans.response.send_redirect( web.url_for( controller='requests_common', + action='manage_request', + cntrller=cntrller, + id=request_id, + status=status, + message=message ) ) elif params.get( 'cancel_change_lib_button', False ): return trans.response.send_redirect( web.url_for( controller='requests_common', action='manage_request', @@ -859,7 +864,7 @@ class RequestsCommon( BaseController, Us # The user has selected a sample to copy. library_id = current_samples[ copy_sample_index][ 'library_select_field' ].get_selected( return_value=True ) folder_id = current_samples[ copy_sample_index ][ 'folder_select_field' ].get_selected( return_value=True ) - name = current_samples[ copy_sample_index ][ 'name' ] + '_%i' % ( index+1 ) + name = current_samples[ copy_sample_index ][ 'name' ] + '_%i' % ( len( current_samples ) + 1 ) library_id = 'none' folder_id = 'none' field_values = [ val for val in current_samples[ copy_sample_index ][ 'field_values' ] ] @@ -867,7 +872,7 @@ class RequestsCommon( BaseController, Us # The user has not selected a sample to copy (may just be adding a sample). library_id = None folder_id = None - name = 'Sample_%i' % ( sample_index+1 ) + name = 'Sample_%i' % ( len( current_samples ) + 1 ) field_values = [ '' for field in request.type.sample_form.fields ] # Build the library_select_field and folder_select_field for the new sample being added. library_select_field, folder_select_field = self.__build_library_and_folder_select_fields( trans, --- a/lib/galaxy/web/controllers/requests_admin.py +++ b/lib/galaxy/web/controllers/requests_admin.py @@ -9,11 +9,13 @@ import logging, os, pexpect, ConfigParse log = logging.getLogger( __name__ ) -class UserColumn( grids.TextColumn ): - def get_value( self, trans, grid, request ): - return request.user.email + class AdminRequestsGrid( RequestsGrid ): + class UserColumn( grids.TextColumn ): + def get_value( self, trans, grid, request ): + return request.user.email + # Grid definition columns = [ col for col in RequestsGrid.columns ] columns.append( UserColumn( "User", model_class=model.User, @@ -180,7 +182,7 @@ class RequestsAdmin( BaseController, Use @web.json def get_file_details( self, trans, id, folder_path ): def print_ticks( d ): - # TODO: why is this method here? Add comments! + # pexpect timeout method pass # Avoid caching trans.response.headers['Pragma'] = 'no-cache' @@ -243,16 +245,20 @@ class RequestsAdmin( BaseController, Use if not sample_dataset_id: return invalid_id_redirect( trans, 'requests_admin', sample_dataset_id ) id_list = util.listify( sample_dataset_id ) + selected_sample_datasets = [] + for sample_dataset_id in id_list: + try: + selected_sample_datasets.append( trans.sa_session.query( trans.model.SampleDataset ).get( trans.security.decode_id( sample_dataset_id ) ) ) + except: + return invalid_id_redirect( trans, 'requests_admin', sample_dataset_id ) if operation == "view": - sample_dataset = trans.sa_session.query( trans.model.SampleDataset ).get( trans.security.decode_id( sample_dataset_id ) ) return trans.fill_template( '/admin/requests/dataset.mako', - sample_dataset=sample_dataset ) + sample_dataset=selected_sample_datasets[0] ) elif operation == "delete": not_deleted = [] - for sample_dataset_id in id_list: - sample_dataset = trans.sa_session.query( trans.model.SampleDataset ).get( trans.security.decode_id( sample_dataset_id ) ) - sample_id = sample_dataset.sample_id - if sample_dataset.status == sample_dataset.sample.transfer_status.NOT_STARTED: + for sample_dataset in selected_sample_datasets: + sample_id = sample_dataset.sample.id + if sample_dataset.status == trans.app.model.Sample.transfer_status.NOT_STARTED: trans.sa_session.delete( sample_dataset ) trans.sa_session.flush() else: @@ -267,13 +273,26 @@ class RequestsAdmin( BaseController, Use status=status, message=message ) ) elif operation == "rename": - sample_dataset = trans.sa_session.query( trans.model.SampleDataset ).get( trans.security.decode_id( sample_dataset_id ) ) + # if none of the selected sample datasets are in the NOT_STARTED state, + # then display error message + flag = True + for sd in selected_sample_datasets: + if sd.status == trans.app.model.Sample.transfer_status.NOT_STARTED: + flag = False + break + if flag: + status = 'error' + message = 'A dataset can be renamed only if it is in the <b>Not Started</b> state.' + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='manage_datasets', + sample_id=trans.security.encode_id( selected_sample_datasets[0].sample.id ), + status=status, + message=message ) ) return trans.fill_template( '/admin/requests/rename_datasets.mako', - sample=sample_dataset.sample, + sample=selected_sample_datasets[0].sample, id_list=id_list ) elif operation == "start transfer": - sample_dataset = trans.sa_session.query( trans.model.SampleDataset ).get( trans.security.decode_id( sample_dataset_id ) ) - self.__start_datatx( trans, sample_dataset.sample, id_list ) + self.__start_datatx( trans, selected_sample_datasets[0].sample, selected_sample_datasets ) # Render the grid view sample_id = params.get( 'sample_id', None ) try: @@ -340,7 +359,7 @@ class RequestsAdmin( BaseController, Use message = 'Changes saved successfully.' return trans.fill_template( '/admin/requests/rename_datasets.mako', sample=sample, - sample_datasets=sample_datasets, + id_list=id_list, message=message, status=status ) return trans.response.send_redirect( web.url_for( controller='requests_admin', @@ -353,38 +372,48 @@ class RequestsAdmin( BaseController, Use message = util.restore_text( params.get( 'message', '' ) ) status = params.get( 'status', 'done' ) request_id = kwd.get( 'request_id', None ) + files = [] try: request = trans.sa_session.query( trans.model.Request ).get( trans.security.decode_id( request_id ) ) except: return invalid_id_redirect( trans, 'requests_admin', request_id ) - files_list = util.listify( params.get( 'files_list', [] ) ) + selected_files = util.listify( params.get( 'files_list', [] ) ) folder_path = util.restore_text( params.get( 'folder_path', request.type.datatx_info[ 'data_dir' ] ) ) - selected_value = kwd.get( 'sample_id', 'none' ) - sample_id_select_field = self.__build_sample_id_select_field( request, selected_value ) + selected_sample_id = kwd.get( 'sample_id', 'none' ) + sample_id_select_field = self.__build_sample_id_select_field( trans, request, selected_sample_id ) # The __get_files() method redirects here with a status of 'error' and a message if there # was a problem retrieving the files. if folder_path and status != 'error': folder_path = self.__check_path( folder_path ) - sample_id = params.get( 'sample_id', None ) - try: - sample = trans.sa_session.query( trans.model.Sample ).get( trans.security.decode_id( sample_id ) ) - except: - return invalid_id_redirect( trans, 'requests_admin', sample_id ) - # Get the filenames from the remote host - files = self.__get_files( trans, request, folder_path ) - if params.get( 'open_folder', False ): - if len( files_list ) == 1: - folder_path = os.path.join( folder_path, files_list[0] ) - folder_path = self.__check_path( folder_path ) + if params.get( 'folder_up', False ): + if folder_path[-1] == os.sep: + folder_path = os.path.dirname(folder_path[:-1]) + folder_path = self.__check_path( folder_path ) elif params.get( 'select_show_datasets_button', False ) or params.get( 'select_more_button', False ): - sample_dataset_file_names = self.__save_sample_datasets( trans, sample, files_list, folder_path ) + # get the sample these datasets are associated with + try: + sample = trans.sa_session.query( trans.model.Sample ).get( trans.security.decode_id( selected_sample_id ) ) + sample.library.id and sample.folder.id + except: + # if no sample (with associated library & folder) has been selected + status = 'error' + message = 'Select a sample with associated data library and folder before selecting the dataset(s).' + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='get_data', + request_id=trans.security.encode_id( request.id ), + folder_path=folder_path, + status=status, + message=message ) ) + # save the sample datasets + sample_dataset_file_names = self.__save_sample_datasets( trans, sample, selected_files, folder_path ) if sample_dataset_file_names: message = 'Datasets (%s) have been selected for sample (%s)' % \ ( str( sample_dataset_file_names )[1:-1].replace( "'", "" ), sample.name ) if params.get( 'select_show_datasets_button', False ): return trans.response.send_redirect( web.url_for( controller='requests_admin', action='manage_datasets', - sample_id=sample_id, + request_id=request_id, + sample_id=trans.security.encode_id( sample.id ), message=message, status=status ) ) else: # 'select_more_button' was clicked @@ -392,11 +421,13 @@ class RequestsAdmin( BaseController, Use action='get_data', request_id=request_id, folder_path=folder_path, - sample_id=sample_id, + sample_id=sample.id, open_folder=True, message=message, status=status ) ) - return trans.fill_template( '/admin/requests/dataset_transfer.mako', + # Get the filenames from the remote host + files = self.__get_files( trans, request, folder_path ) + return trans.fill_template( '/admin/requests/get_data.mako', cntrller='requests_admin', request=request, sample_id_select_field=sample_id_select_field, @@ -434,20 +465,20 @@ class RequestsAdmin( BaseController, Use if ok: return output.splitlines() return trans.response.send_redirect( web.url_for( controller='requests_admin', - action='get_data', - request_id=trans.security.encode_id( request.id ), - folder_path=folder_path, - status=status, - message=message ) ) + action='get_data', + request_id=trans.security.encode_id( request.id ), + folder_path=folder_path, + status=status, + message=message ) ) def __check_path( self, a_path ): # Return a valid folder_path if a_path and not a_path.endswith( os.sep ): a_path += os.sep return a_path - def __save_sample_datasets( self, trans, sample, files_list, folder_path ): + def __save_sample_datasets( self, trans, sample, selected_files, folder_path ): sample_dataset_file_names = [] - if files_list: - for f in files_list: + if selected_files: + for f in selected_files: filepath = os.path.join( folder_path, f ) if f[-1] == os.sep: # FIXME: The selected item is a folder so transfer all the folder contents @@ -522,7 +553,7 @@ class RequestsAdmin( BaseController, Use trans.sa_session.add( lfp ) trans.sa_session.flush() return datatx_user - def __send_message( self, trans, datatx_info, sample, id_list ): + def __send_message( self, trans, datatx_info, sample, selected_sample_datasets ): """Ceates an xml message and sends it to the rabbitmq server""" # Create the xml message based on the following template xml = \ @@ -542,8 +573,7 @@ class RequestsAdmin( BaseController, Use <file>%(FILE)s</file></dataset>''' datasets = '' - for id in id_list: - sample_dataset = trans.sa_session.query( trans.model.SampleDataset ).get( trans.security.decode_id( id ) ) + for sample_dataset in selected_sample_datasets: if sample_dataset.status == sample.transfer_status.NOT_STARTED: datasets = datasets + dataset_xml % dict( ID=str( sample_dataset.id ), NAME=sample_dataset.name, @@ -574,7 +604,7 @@ class RequestsAdmin( BaseController, Use routing_key=trans.app.config.amqp['routing_key'] ) chan.close() conn.close() - def __start_datatx( self, trans, sample, id_list ): + def __start_datatx( self, trans, sample, selected_sample_datasets ): datatx_user = self.__setup_datatx_user( trans, sample.library, sample.folder ) # Validate sequencer information datatx_info = sample.request.type.datatx_info @@ -582,8 +612,8 @@ class RequestsAdmin( BaseController, Use message = "Error in sequencer login information." status = "error" else: - self.__send_message( trans, datatx_info, sample, id_list ) - message = "%i datasets have been queued for transfer from the sequencer. Click the Refresh button above to see the latest transfer status." % len( id_list ) + self.__send_message( trans, datatx_info, sample, selected_sample_datasets ) + message = "%i datasets have been queued for transfer from the sequencer. Click the Refresh button above to see the latest transfer status." % len( selected_sample_datasets ) status = "done" return trans.response.send_redirect( web.url_for( controller='requests_admin', action='manage_datasets', @@ -599,6 +629,14 @@ class RequestsAdmin( BaseController, Use obj_id = kwd.get( 'id', None ) if operation == "view_form_definition": return self.view_form_definition( trans, **kwd ) + elif operation == "view": + return self.view_request_type( trans, **kwd ) + elif operation == "delete": + return self.delete_request_type( trans, **kwd ) + elif operation == "undelete": + return self.undelete_request_type( trans, **kwd ) + elif operation == "permissions": + return self.request_type_permissions( trans, **kwd ) # Render the grid view return self.requesttype_grid( trans, **kwd ) @web.expose @@ -655,26 +693,26 @@ class RequestsAdmin( BaseController, Use message=message, status=status ) def __create_request_type_form( self, trans, **kwd ): - request_form_definitionss = self.get_all_forms( trans, + request_form_definitions = self.get_all_forms( trans, filter=dict( deleted=False ), form_type=trans.model.FormDefinition.types.REQUEST ) sample_form_definitions = self.get_all_forms( trans, filter=dict( deleted=False ), form_type=trans.model.FormDefinition.types.SAMPLE ) - if not request_form_definitionss or not sample_form_definitions: + if not request_form_definitions or not sample_form_definitions: return [],[] params = util.Params( kwd ) request_form_id = params.get( 'request_form_id', 'none' ) sample_form_id = params.get( 'sample_form_id', 'none' ) request_form_id_select_field = build_select_field( trans, - objs=request_form_definitionss, - label_attr='id', + objs=request_form_definitions, + label_attr='name', select_field_name='request_form_id', selected_value=request_form_id, refresh_on_change=False ) sample_form_id_select_field = build_select_field( trans, objs=sample_form_definitions, - label_attr='id', + label_attr='name', select_field_name='sample_form_id', selected_value=sample_form_id, refresh_on_change=False ) @@ -826,7 +864,7 @@ class RequestsAdmin( BaseController, Use status=status, message=message ) # ===== Methods for building SelectFields used on various admin_requests forms - def __build_sample_id_select_field( self, request, selected_value ): + def __build_sample_id_select_field( self, trans, request, selected_value ): return build_select_field( trans, request.samples, 'name', 'sample_id', selected_value=selected_value, refresh_on_change=False ) def __build_rename_dataset_select_field( self, trans, request_type=None ): if request_type: --- a/templates/admin/requests/get_data.mako +++ b/templates/admin/requests/get_data.mako @@ -68,13 +68,6 @@ } </script> -<style type="text/css"> -.msg_head { - padding: 0px 0px; - cursor: pointer; -} -</style> - <br/><br/><ul class="manage-table-actions"> @@ -92,7 +85,7 @@ <div class="toolForm"><div class="toolFormTitle">Select files for transfer</div> - <form name="get_data" id="get_data" action="${h.url_for( controller='requests_admin', action='get_data', cntrller=cntrller, request_id=trans.security.encode_id( request.id )}" method="post" > + <form name="get_data" id="get_data" action="${h.url_for( controller='requests_admin', action='get_data', cntrller=cntrller, request_id=trans.security.encode_id( request.id ))}" method="post" ><div class="form-row"><label>Sample:</label> ${sample_id_select_field.get_html()} --- a/templates/requests/common/manage_request.mako +++ b/templates/requests/common/manage_request.mako @@ -62,7 +62,7 @@ // Build request data var ids = [] var states = [] - $.each( sample_states, function ( id, state ) { + $.each( sample_states, function ( id, state, cntrller ) { ids.push( id ); states.push( state ); }); @@ -73,7 +73,7 @@ dataType: "json", data: { ids: ids.join( "," ), states: states.join( "," ) }, success : function ( data ) { - $.each( data, function(id, val, cntrller ) { + $.each( data, function( cntrller, id, val ) { // Replace HTML var cell1 = $("#sampleState-" + id); cell1.html( val.html_state ); @@ -146,8 +146,6 @@ </div><br/><br/> -<font color="red"><b><i>A dataset can be renamed only if its status is "Not Started"</i></b></font> - <ul class="manage-table-actions"><li><a class="action-button" id="seqreq-${request.id}-popup" class="menubutton">Sequencing Request Actions</a></li><div popupmenu="seqreq-${request.id}-popup">