[hg] galaxy 1551: Add ability to undelete histories.
details: http://www.bx.psu.edu/hg/galaxy/rev/fdbf15ea1f8a changeset: 1551:fdbf15ea1f8a user: Dan Blankenberg <dan@bx.psu.edu> date: Wed Oct 08 12:00:16 2008 -0400 description: Add ability to undelete histories. 2 file(s) affected in this change: lib/galaxy/web/controllers/root.py templates/history/list.mako diffs (188 lines): diff -r 64c0734ff262 -r fdbf15ea1f8a lib/galaxy/web/controllers/root.py --- a/lib/galaxy/web/controllers/root.py Tue Oct 07 15:21:46 2008 -0400 +++ b/lib/galaxy/web/controllers/root.py Wed Oct 08 12:00:16 2008 -0400 @@ -371,6 +371,42 @@ refresh_frames=['history']) @web.expose + def history_undelete( self, trans, id=[], **kwd): + """Undeletes a list of histories, ensures that histories are owned by current user""" + history_names = [] + errors = [] + ok_msg = "" + if id: + if not isinstance( id, list ): + id = id.split( "," ) + user = trans.get_user() + for hid in id: + try: + int( hid ) + except: + errors.append( "Invalid history: %s" % str( hid ) ) + continue + history = self.app.model.History.get( hid ) + if history: + if history.user != user: + errors.append( "History does not belong to current user." ) + continue + if history.purged: + errors.append( "History has already been purged and can not be undeleted." ) + continue + history_names.append( history.name ) + history.deleted = False + else: + errors.append( "Not able to find history %s." % str( hid ) ) + trans.log_event( "History id %s marked as undeleted" % str(hid) ) + self.app.model.flush() + if history_names: + ok_msg = "Histories (%s) have been undeleted." % ", ".join( history_names ) + else: + errors.append( "You must select at least one history to undelete." ) + return self.history_available( trans, id=','.join( id ), show_deleted=True, ok_msg = ok_msg, error_msg = " ".join( errors ) ) + + @web.expose def clear_history( self, trans ): """Clears the history for a user""" history = trans.get_history() @@ -414,7 +450,7 @@ @web.expose @web.require_login( "work with multiple histories" ) - def history_available( self, trans, id=None, as_xml=False, **kwd ): + def history_available( self, trans, id=[], do_operation = "view", show_deleted = False, ok_msg = "", error_msg="", as_xml=False, **kwd ): """ List all available histories """ @@ -422,11 +458,21 @@ trans.response.set_content_type('text/xml') return trans.fill_template( "/history/list_as_xml.mako" ) if not isinstance( id, list ): - id = [ id ] + id = id.split( "," ) trans.log_event( "History id %s available" % str( id ) ) + + history_operations = dict( share=self.history_share, rename=self.history_rename, delete=self.history_delete, undelete=self.history_undelete ) + + if do_operation in history_operations: + return history_operations[do_operation]( trans, id=id, show_deleted=show_deleted, ok_msg=ok_msg, error_msg=error_msg, **kwd ) + return trans.fill_template( "/history/list.mako", ids=id, user=trans.get_user(), - current_history=trans.get_history() ) + current_history=trans.get_history(), + show_deleted=util.string_as_bool( show_deleted ), + ok_msg=ok_msg, error_msg=error_msg ) + + @web.expose def history_import( self, trans, id=None, confirm=False, **kwd ): diff -r 64c0734ff262 -r fdbf15ea1f8a templates/history/list.mako --- a/templates/history/list.mako Tue Oct 07 15:21:46 2008 -0400 +++ b/templates/history/list.mako Wed Oct 08 12:00:16 2008 -0400 @@ -1,67 +1,65 @@ <%inherit file="/base.mako"/> <%def name="title()">Your saved histories</%def> -<%def name="javascripts()"> -${parent.javascripts()} -<script type="text/javascript"> - ## FIXME: This depends on javascript, could be moved into controller - function OnSubmitForm() - { - if(document.history_actions.operation[0].checked == true) - { - document.history_actions.action = "${h.url_for( action="history_share") }"; - } - else if(document.history_actions.operation[1].checked == true) - { - - document.history_actions.action = "${h.url_for( action="history_rename") }"; - } - else if(document.history_actions.operation[2].checked == true) - { - if (confirm("Are you sure you want to delete these histories?")) - { - document.history_actions.action = "${h.url_for( action="history_delete" )}"; - } - } - - return true; - } -</script> -</%def> - +%if error_msg: +<p> +<div class="errormessage">${error_msg}</div> +<div style="clear: both"></div> +</p> +%endif +%if ok_msg: +<p> +<div class="donemessage">${ok_msg}</div> +<div style="clear: both"></div> +</p> +%endif + %if user.histories: - <h1>Stored Histories</h1> - <form name="history_actions" onSubmit="return OnSubmitForm();" method="post" > + <h1 style="margin-bottom:0px;">Stored Histories</h1> + %if show_deleted: + <div><a href="${h.url_for( action='history_available', id=','.join( ids ), show_deleted=False )}">hide deleted</a></div> + %else: + <div><a href="${h.url_for( action='history_available', id=','.join( ids ), show_deleted=True )}">show deleted</a></div> + %endif + <form name="history_actions" action="${h.url_for( action='history_available')}" method="post" > <table class="colored" border="0" cellspacing="0" cellpadding="0" width="100%"> - <tr class="header" align="center"><td></td><td>Name</td><td>Size</td><td>Last modified</td><td>Actions</td></tr> + <tr class="header" align="center"><td>Name</td><td>Size</td><td>Last modified</td><td>Actions</td></tr> %for history in user.histories: - %if not( history.deleted ): + %if ( show_deleted and not history.purged ) or not( history.deleted ): <tr> - <td><input type=checkbox name="id" value="${history.id}" + <td> + <input type=checkbox name="id" value="${history.id}" %if str(history.id) in ids: checked %endif - ></td><td>${history.name} - %if history.deleted: - (deleted) + >${history.name} + %if history == trans.get_history(): + (current history) %endif </td> <td>${len(history.active_datasets)}</td> <td>${str(history.update_time)[:19]}</td> <td> + %if not history.deleted: <a href="${h.url_for( action='history_rename', id=history.id )}">rename</a><br /> <a href="${h.url_for( action='history_switch', id=history.id )}">switch to</a><br /> - <a href="${h.url_for( action='history_delete', id=history.id )}" confirm="Are you sure you want to delete this history?">delete</a> + <a href="${h.url_for( action='history_delete', id=history.id )}" confirm="Are you sure you want to delete this history?">delete</a><br /> + %else: + <a href="${h.url_for( action='history_undelete', id=history.id )}">undelete</a><br /> + %endif </td> </tr> %endif %endfor <tr><th colspan="100%">Action</th></tr> - <tr><td colspan="100%" align="center"><input type="radio" name="operation" value="1" checked>Share <input type="radio" name="operation" value="2">Rename <input type="radio" name="operation" value="3">Delete </td></tr> + <tr><td colspan="100%" align="center"><input type="radio" name="do_operation" value="share" checked>Share <input type="radio" name="do_operation" value="rename">Rename <input type="radio" name="do_operation" value="delete">Delete + %if show_deleted: + <input type="radio" name="do_operation" value="undelete">Undelete + %endif + </td></tr> <tr><td colspan="100%" align="center"><input type="submit" name="submit" value="Perform Action"></td></tr> </table> </form> %else: You have no stored histories %endif - \ No newline at end of file
participants (1)
-
Nate Coraor