details: http://www.bx.psu.edu/hg/galaxy/rev/d1624544bc55 changeset: 3819:d1624544bc55 user: rc date: Mon May 24 16:00:03 2010 -0400 description: lims: ui fixes in adding samples diffstat: lib/galaxy/web/controllers/requests.py | 63 +++++++++++++++---------- lib/galaxy/web/controllers/requests_admin.py | 63 +++++++++++++++---------- templates/admin/requests/show_request.mako | 52 ++++++++++++++------ templates/requests/show_request.mako | 69 +++++++++++++++++---------- test/base/twilltestcase.py | 6 +- 5 files changed, 159 insertions(+), 94 deletions(-) diffs (388 lines): diff -r f7525fb463e0 -r d1624544bc55 lib/galaxy/web/controllers/requests.py --- a/lib/galaxy/web/controllers/requests.py Mon May 24 15:33:55 2010 -0400 +++ b/lib/galaxy/web/controllers/requests.py Mon May 24 16:00:03 2010 -0400 @@ -288,7 +288,7 @@ sample_copy=self.__copy_sample(current_samples), details='hide', edit_mode=util.restore_text( params.get( 'edit_mode', 'False' ) ), message=message, status=status ) - def __library_widgets(self, trans, user, sample_index, libraries, sample=None, **kwd): + def __library_widgets(self, trans, user, sample_index, libraries, sample=None, lib_id=None, folder_id=None, **kwd): ''' This method creates the data library & folder selectbox for creating & editing samples. First we get a list of all the libraries accessible to @@ -298,7 +298,8 @@ ''' params = util.Params( kwd ) # data library selectbox - lib_id = params.get( "sample_%i_library_id" % sample_index, 'none' ) + if not lib_id: + lib_id = params.get( "sample_%i_library_id" % sample_index, 'none' ) selected_lib = None if sample and lib_id == 'none': if sample.library: @@ -317,7 +318,7 @@ lib_widget.add_option('Select one', 'none') # all the libraries available to the selected user for lib, hidden_folder_ids in libraries.items(): - if str(lib.id) == lib_id: + if str(lib.id) == str(lib_id): lib_widget.add_option(lib.name, lib.id, selected=True) selected_lib, selected_hidden_folder_ids = lib, hidden_folder_ids.split(',') else: @@ -338,7 +339,10 @@ else: current_fid = params.get( "sample_%i_folder_id" % sample_index, 'none' ) else: - current_fid = 'none' + if folder_id: + current_fid = folder_id + else: + current_fid = 'none' # first option if lib_id == 'none': folder_widget.add_option('Select one', 'none', selected=True) @@ -479,29 +483,38 @@ # if the user has selected a sample no. to copy then copy the contents # of the src sample to the new sample else an empty sample src_sample_index = int(params.get( 'copy_sample', -1 )) + # get the number of new copies of the src sample + num_sample_to_copy = int(params.get( 'num_sample_to_copy', 1 )) if src_sample_index == -1: - # empty sample - lib_widget, folder_widget = self.__library_widgets(trans, request.user, - len(current_samples), - libraries, None, **kwd) - current_samples.append(dict(name='Sample_%i' % (len(current_samples)+1), - barcode='', - library=None, - folder=None, - field_values=['' for field in request.type.sample_form.fields], - lib_widget=lib_widget, - folder_widget=folder_widget)) + for ns in range(num_sample_to_copy): + # empty sample + lib_widget, folder_widget = self.__library_widgets(trans, request.user, + len(current_samples), + libraries, None, **kwd) + current_samples.append(dict(name='Sample_%i' % (len(current_samples)+1), + barcode='', + library=None, + folder=None, + field_values=['' for field in request.type.sample_form.fields], + lib_widget=lib_widget, + folder_widget=folder_widget)) else: - lib_widget, folder_widget = self.__library_widgets(trans, request.user, - len(current_samples), - libraries, None, **kwd) - current_samples.append(dict(name=current_samples[src_sample_index]['name']+'_%i' % (len(current_samples)+1), - barcode='', - library_id='none', - folder_id='none', - field_values=[val for val in current_samples[src_sample_index]['field_values']], - lib_widget=lib_widget, - folder_widget=folder_widget)) + src_library_id = current_samples[src_sample_index]['lib_widget'].get_selected()[1] + src_folder_id = current_samples[src_sample_index]['folder_widget'].get_selected()[1] + for ns in range(num_sample_to_copy): + lib_widget, folder_widget = self.__library_widgets(trans, request.user, + len(current_samples), + libraries, sample=None, + lib_id=src_library_id, + folder_id=src_folder_id, + **kwd) + current_samples.append(dict(name=current_samples[src_sample_index]['name']+'_%i' % (len(current_samples)+1), + barcode='', + library_id='none', + folder_id='none', + field_values=[val for val in current_samples[src_sample_index]['field_values']], + lib_widget=lib_widget, + folder_widget=folder_widget)) return trans.fill_template( '/requests/show_request.mako', request=request, request_details=self.request_details(trans, request.id), diff -r f7525fb463e0 -r d1624544bc55 lib/galaxy/web/controllers/requests_admin.py --- a/lib/galaxy/web/controllers/requests_admin.py Mon May 24 15:33:55 2010 -0400 +++ b/lib/galaxy/web/controllers/requests_admin.py Mon May 24 16:00:03 2010 -0400 @@ -805,7 +805,7 @@ sample_copy=self.__copy_sample(current_samples), details='hide', edit_mode=util.restore_text( params.get( 'edit_mode', 'False' ) ), message=message, status=status ) - def __library_widgets(self, trans, user, sample_index, libraries, sample=None, **kwd): + def __library_widgets(self, trans, user, sample_index, libraries, sample=None, lib_id=None, folder_id=None, **kwd): ''' This method creates the data library & folder selectbox for creating & editing samples. First we get a list of all the libraries accessible to @@ -815,7 +815,8 @@ ''' params = util.Params( kwd ) # data library selectbox - lib_id = params.get( "sample_%i_library_id" % sample_index, 'none' ) + if not lib_id: + lib_id = params.get( "sample_%i_library_id" % sample_index, 'none' ) selected_lib = None if sample and lib_id == 'none': if sample.library: @@ -834,7 +835,7 @@ lib_widget.add_option('Select one', 'none') # all the libraries available to the selected user for lib, hidden_folder_ids in libraries.items(): - if str(lib.id) == lib_id: + if str(lib.id) == str(lib_id): lib_widget.add_option(lib.name, lib.id, selected=True) selected_lib, selected_hidden_folder_ids = lib, hidden_folder_ids.split(',') else: @@ -855,7 +856,10 @@ else: current_fid = params.get( "sample_%i_folder_id" % sample_index, 'none' ) else: - current_fid = 'none' + if folder_id: + current_fid = folder_id + else: + current_fid = 'none' # first option if lib_id == 'none': folder_widget.add_option('Select one', 'none', selected=True) @@ -995,29 +999,38 @@ # if the user has selected a sample no. to copy then copy the contents # of the src sample to the new sample else an empty sample src_sample_index = int(params.get( 'copy_sample', -1 )) + # get the number of new copies of the src sample + num_sample_to_copy = int(params.get( 'num_sample_to_copy', 1 )) if src_sample_index == -1: - # empty sample - lib_widget, folder_widget = self.__library_widgets(trans, request.user, - len(current_samples), - libraries, None, **kwd) - current_samples.append(dict(name='Sample_%i' % (len(current_samples)+1), - barcode='', - library=None, - folder=None, - field_values=['' for field in request.type.sample_form.fields], - lib_widget=lib_widget, - folder_widget=folder_widget)) + for ns in range(num_sample_to_copy): + # empty sample + lib_widget, folder_widget = self.__library_widgets(trans, request.user, + len(current_samples), + libraries, None, **kwd) + current_samples.append(dict(name='Sample_%i' % (len(current_samples)+1), + barcode='', + library=None, + folder=None, + field_values=['' for field in request.type.sample_form.fields], + lib_widget=lib_widget, + folder_widget=folder_widget)) else: - lib_widget, folder_widget = self.__library_widgets(trans, request.user, - len(current_samples), - libraries, None, **kwd) - current_samples.append(dict(name=current_samples[src_sample_index]['name']+'_%i' % (len(current_samples)+1), - barcode='', - library_id='none', - folder_id='none', - field_values=[val for val in current_samples[src_sample_index]['field_values']], - lib_widget=lib_widget, - folder_widget=folder_widget)) + src_library_id = current_samples[src_sample_index]['lib_widget'].get_selected()[1] + src_folder_id = current_samples[src_sample_index]['folder_widget'].get_selected()[1] + for ns in range(num_sample_to_copy): + lib_widget, folder_widget = self.__library_widgets(trans, request.user, + len(current_samples), + libraries, sample=None, + lib_id=src_library_id, + folder_id=src_folder_id, + **kwd) + current_samples.append(dict(name=current_samples[src_sample_index]['name']+'_%i' % (len(current_samples)+1), + barcode='', + library_id='none', + folder_id='none', + field_values=[val for val in current_samples[src_sample_index]['field_values']], + lib_widget=lib_widget, + folder_widget=folder_widget)) return trans.fill_template( '/admin/requests/show_request.mako', request=request, request_details=self.request_details(trans, request.id), diff -r f7525fb463e0 -r d1624544bc55 templates/admin/requests/show_request.mako --- a/templates/admin/requests/show_request.mako Mon May 24 15:33:55 2010 -0400 +++ b/templates/admin/requests/show_request.mako Mon May 24 16:00:03 2010 -0400 @@ -444,8 +444,7 @@ %else: <label>There are no samples.</label> %endif - </div> - + </div> %if request.samples and request.submitted(): <script type="text/javascript"> // Updater @@ -458,25 +457,23 @@ <tbody> <tr> <div class="form-row"> + + %if request.unsubmitted(): + <td> + %if current_samples: + <label>Copy </label> + <input type="integer" name="num_sample_to_copy" value="1" size="3"/> + <label>sample(s) from sample</label> + ${sample_copy.get_html()} + %endif + <input type="submit" name="add_sample_button" value="Add New"/> + </td> + %endif <td> %if current_samples: <input type="submit" name="edit_samples_button" value="Edit samples"/> %endif </td> - %if request.unsubmitted(): - <td> - <label>Import from csv file</label> - <input type="file" name="file_data" /> - <input type="submit" name="import_samples_button" value="Import samples"/> - </td> - <td> - %if current_samples: - <label>Copy from sample</label> - ${sample_copy.get_html()} - %endif - <input type="submit" name="add_sample_button" value="Add New"/> - </td> - %endif </div> </tr> </tbody> @@ -504,3 +501,26 @@ <input type="hidden" name="request_id" value="${request.id}" /> </form> </div> + +<br/> + +%if request.unsubmitted(): +<div class="toolForm"> + <div class="form-row"> + <div class="msg_list"> + <h4 class="msg_head"><u>Import Samples</u></h4> + <div class="msg_body"> + <label>Import from csv file</label> + <input type="file" name="file_data" /> + <input type="submit" name="import_samples_button" value="Import samples"/> + <br/> + <div class="toolParamHelp" style="clear: both;"> + The csv file must be in the following format:<br/> + SampleName,DataLibrary,DataLibraryFolder,FieldValue1,FieldValue2... + </div> + </div> + </div> + </div> +</div> +%endif + diff -r f7525fb463e0 -r d1624544bc55 templates/requests/show_request.mako --- a/templates/requests/show_request.mako Mon May 24 15:33:55 2010 -0400 +++ b/templates/requests/show_request.mako Mon May 24 16:00:03 2010 -0400 @@ -364,31 +364,28 @@ %endif </div> %if request.unsubmitted() and edit_mode == 'False': - <table class="grid"> - <tbody> - <tr> - <div class="form-row"> - <td> - %if current_samples: - <input type="submit" name="edit_samples_button" value="Edit samples"/> - %endif - </td> - <td> - <label>Import from csv file</label> - <input type="file" name="file_data" /> - <input type="submit" name="import_samples_button" value="Import samples"/> - </td> - <td> - %if current_samples: - <label>Copy from sample</label> - ${sample_copy.get_html()} - %endif - <input type="submit" name="add_sample_button" value="Add New"/> - </td> - </div> - </tr> - </tbody> - </table> + <table class="grid"> + <tbody> + <tr> + <div class="form-row"> + <td> + %if current_samples: + <label>Copy </label> + <input type="integer" name="num_sample_to_copy" value="1" size="3"/> + <label>sample(s) from sample</label> + ${sample_copy.get_html()} + %endif + <input type="submit" name="add_sample_button" value="Add New"/> + </td> + <td> + %if current_samples: + <input type="submit" name="edit_samples_button" value="Edit samples"/> + %endif + </td> + </div> + </tr> + </tbody> + </table> %endif %if request.unsubmitted() and (request.samples or current_samples): <div class="form-row"> @@ -407,3 +404,25 @@ <input type="hidden" name="request_id" value="${request.id}" /> </form> </div> + + +<br/> +%if request.unsubmitted(): +<div class="toolForm"> + <div class="form-row"> + <div class="msg_list"> + <h4 class="msg_head"><u>Import Samples</u></h4> + <div class="msg_body"> + <label>Import from csv file</label> + <input type="file" name="file_data" /> + <input type="submit" name="import_samples_button" value="Import samples"/> + <br/> + <div class="toolParamHelp" style="clear: both;"> + The csv file must be in the following format:<br/> + SampleName,DataLibrary,DataLibraryFolder,FieldValue1,FieldValue2... + </div> + </div> + </div> + </div> +</div> +%endif diff -r f7525fb463e0 -r d1624544bc55 test/base/twilltestcase.py --- a/test/base/twilltestcase.py Mon May 24 15:33:55 2010 -0400 +++ b/test/base/twilltestcase.py Mon May 24 16:00:03 2010 -0400 @@ -1572,14 +1572,14 @@ self.check_page_for_string( 'There are no samples.' ) # this redundant stmt below is add so that the second form in # the page gets selected - tc.fv( "2", "request_id", request_id ) + tc.fv( "3", "request_id", request_id ) for sample_index, sample in enumerate(samples): tc.submit( "add_sample_button" ) self.check_page_for_string( 'Sequencing Request "%s"' % request_name ) sample_name, fields = sample - tc.fv( "2", "sample_%i_name" % sample_index, sample_name ) + tc.fv( "3", "sample_%i_name" % sample_index, sample_name ) for field_index, field_value in enumerate(fields): - tc.fv( "2", "sample_%i_field_%i" % ( sample_index, field_index ), field_value ) + tc.fv( "3", "sample_%i_field_%i" % ( sample_index, field_index ), field_value ) tc.submit( "save_samples_button" ) for sample_name, fields in samples: self.check_page_for_string( sample_name )