[hg] galaxy 3531: lims: automatic update of sample state when th...
details: http://www.bx.psu.edu/hg/galaxy/rev/3c124a19ae94 changeset: 3531:3c124a19ae94 user: rc date: Mon Mar 15 12:40:30 2010 -0400 description: lims: automatic update of sample state when the state is changed in th db (using scanner etc) diffstat: lib/galaxy/web/controllers/requests_admin.py | 21 ++++++ templates/admin/requests/show_request.mako | 87 ++++++++++++++++++++++++--- templates/requests/sample_datasets.mako | 7 ++ templates/requests/sample_state.mako | 5 + 4 files changed, 109 insertions(+), 11 deletions(-) diffs (175 lines): diff -r 6d079d53f9db -r 3c124a19ae94 lib/galaxy/web/controllers/requests_admin.py --- a/lib/galaxy/web/controllers/requests_admin.py Mon Mar 15 11:31:14 2010 -0400 +++ b/lib/galaxy/web/controllers/requests_admin.py Mon Mar 15 12:40:30 2010 -0400 @@ -231,6 +231,27 @@ def index( self, trans ): return trans.fill_template( "/admin/requests/index.mako" ) + @web.json + def sample_state_updates( self, trans, ids=None, states=None ): + # Avoid caching + trans.response.headers['Pragma'] = 'no-cache' + trans.response.headers['Expires'] = '0' + # Create new HTML for any that have changed + rval = {} + if ids is not None and states is not None: + ids = map( int, ids.split( "," ) ) + states = states.split( "," ) + for id, state in zip( ids, states ): + sample = trans.sa_session.query( self.app.model.Sample ).get( id ) + if sample.current_state().name != state: + rval[id] = { + "state": sample.current_state().name, + "datasets": len(sample.dataset_files), + "html_state": unicode( trans.fill_template( "requests/sample_state.mako", sample=sample ), 'utf-8' ), + "html_datasets": unicode( trans.fill_template( "requests/sample_datasets.mako", trans=trans, sample=sample ), 'utf-8' ) + } + return rval + @web.expose @web.require_admin def list( self, trans, **kwd ): diff -r 6d079d53f9db -r 3c124a19ae94 templates/admin/requests/show_request.mako --- a/templates/admin/requests/show_request.mako Mon Mar 15 11:31:14 2010 -0400 +++ b/templates/admin/requests/show_request.mako Mon Mar 15 12:40:30 2010 -0400 @@ -1,5 +1,7 @@ <%inherit file="/base.mako"/> <%namespace file="/message.mako" import="render_msg" /> +<%namespace file="/requests/sample_state.mako" import="render_sample_state" /> +<%namespace file="/requests/sample_datasets.mako" import="render_sample_datasets" /> %if msg: ${render_msg( msg, messagetype )} @@ -42,6 +44,54 @@ }); </script> +<script type="text/javascript"> + // Looks for changes in sample states using an async request. Keeps + // calling itself (via setTimeout) until all samples are in a terminal + // state. + var updater = function ( sample_states ) { + // Check if there are any items left to track + var empty = true; + for ( i in sample_states ) { + empty = false; + break; + } + if ( ! empty ) { + setTimeout( function() { updater_callback( sample_states ) }, 1000 ); + } + }; + var updater_callback = function ( sample_states ) { + // Build request data + var ids = [] + var states = [] + $.each( sample_states, function ( id, state ) { + ids.push( id ); + states.push( state ); + }); + // Make ajax call + $.ajax( { + type: "POST", + url: "${h.url_for( controller='requests_admin', action='sample_state_updates' )}", + dataType: "json", + data: { ids: ids.join( "," ), states: states.join( "," ) }, + success : function ( data ) { + $.each( data, function( id, val ) { + // Replace HTML + var cell1 = $("#sampleState-" + id); + cell1.html( val.html_state ); + var cell2 = $("#sampleDatasets-" + id); + cell2.html( val.html_datasets ); + sample_states[ parseInt(id) ] = val.state; + }); + updater( sample_states ); + }, + error: function() { + // Just retry, like the old method, should try to be smarter + updater( sample_states ); + } + }); + }; +</script> + <style type="text/css"> .msg_head { padding: 0px 0px; @@ -162,15 +212,21 @@ %if sample_index in range(len(request.samples)): <td>${info['name']}</td> <td>${info['barcode']}</td> - <td> - %if sample: - %if sample.request.unsubmitted(): - Unsubmitted - %else: - <a href="${h.url_for( controller='requests_admin', action='show_events', sample_id=sample.id)}">${sample.current_state().name}</a> - %endif - %endif - </td> + %if sample.request.unsubmitted(): + <td>Unsubmitted</td> + %else: + <td id="sampleState-${sample.id}">${render_sample_state( sample )}</td> + %endif + +## <td> +## %if sample: +## %if sample.request.unsubmitted(): +## Unsubmitted +## %else: +## <a href="${h.url_for( controller='requests_admin', action='show_events', sample_id=sample.id)}">${sample.current_state().name}</a> +## %endif +## %endif +## </td> %if info['library']: <td><a href="${h.url_for( controller='library_common', action='browse_library', cntrller='library', id=trans.security.encode_id( info['library'].id ) )}">${info['library'].name}</a></td> %else: @@ -182,8 +238,9 @@ <td></td> %endif %if request.submitted() or request.complete(): - <td> - <a href="${h.url_for( controller='requests_admin', action='show_datatx_page', sample_id=trans.security.encode_id(sample.id) )}">${len(sample.dataset_files)}</a> + <td id="sampleDatasets-${sample.id}"> + ${render_sample_datasets( sample )} +## <a href="${h.url_for( controller='requests_admin', action='show_datatx_page', sample_id=trans.security.encode_id(sample.id) )}">${len(sample.dataset_files)}</a> </td> %endif @@ -358,6 +415,14 @@ <label>There are no samples.</label> %endif </div> + + %if request.samples and request.submitted(): + <script type="text/javascript"> + // Updater + updater({${ ",".join( [ '"%s" : "%s"' % ( s.id, s.current_state().name ) for s in request.samples ] ) }}); + </script> + %endif + %if edit_mode == 'False': <table class="grid"> <tbody> diff -r 6d079d53f9db -r 3c124a19ae94 templates/requests/sample_datasets.mako --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/requests/sample_datasets.mako Mon Mar 15 12:40:30 2010 -0400 @@ -0,0 +1,7 @@ +<%def name="render_sample_datasets( sample )"> + <a href="${h.url_for(controller='requests_admin', action='show_datatx_page', sample_id=trans.security.encode_id(sample.id))}">${sample.transferred_dataset_files()}</a> +</%def> + + + +${render_sample_datasets( sample )} diff -r 6d079d53f9db -r 3c124a19ae94 templates/requests/sample_state.mako --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/requests/sample_state.mako Mon Mar 15 12:40:30 2010 -0400 @@ -0,0 +1,5 @@ +<%def name="render_sample_state( sample )"> + <a href="${h.url_for( controller='requests_admin', action='show_events', sample_id=sample.id)}">${sample.current_state().name}</a> +</%def> + +${render_sample_state( sample )}
participants (1)
-
Greg Von Kuster