[hg] galaxy 1543: Add the ability to undelete deleted datasets f...

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[hg] galaxy 1543: Add the ability to undelete deleted datasets f...

Greg Von Kuster
details:   http://www.bx.psu.edu/hg/galaxy/rev/45033114f82d
changeset: 1543:45033114f82d
user:      Dan Blankenberg <[hidden email]>
date:      Thu Oct 02 16:37:32 2008 -0400
description:
Add the ability to undelete deleted datasets from a history.

A new selection under History Options allows users to select a history view containing deleted (and undeletable) datasets.

Known Issues:
1. When adding a new dataset to a history (tool execution), the history is always refreshed to show only non-deleted datasets.
2. When doing an ajax delete of a dataset while viewing deleted datasets, the newly deleted dataset is still removed from the current view of the history (instead of appearing with the deleted message), a refresh will bring it back.

8 file(s) affected in this change:

lib/galaxy/model/__init__.py
lib/galaxy/model/mapping.py
lib/galaxy/util/__init__.py
lib/galaxy/web/controllers/dataset.py
lib/galaxy/web/controllers/root.py
templates/history/options.mako
templates/root/history.mako
templates/root/history_common.mako

diffs (190 lines):

diff -r 20591fa0d05d -r 45033114f82d lib/galaxy/model/__init__.py
--- a/lib/galaxy/model/__init__.py Thu Oct 02 15:51:17 2008 -0400
+++ b/lib/galaxy/model/__init__.py Thu Oct 02 16:37:32 2008 -0400
@@ -281,7 +281,15 @@
             for child in self.children:
                 child.mark_deleted()
 
-
+    def mark_undeleted( self, include_children=True ):
+        self.deleted = False
+        if include_children:
+            for child in self.children:
+                child.mark_undeleted()
+    def undeletable( self ):
+        if self.purged:
+            return False
+        return True
 
 class History( object ):
     def __init__( self, id=None, name=None, user=None ):
diff -r 20591fa0d05d -r 45033114f82d lib/galaxy/model/mapping.py
--- a/lib/galaxy/model/mapping.py Thu Oct 02 15:51:17 2008 -0400
+++ b/lib/galaxy/model/mapping.py Thu Oct 02 16:37:32 2008 -0400
@@ -288,7 +288,9 @@
 assign_mapper( context, History, History.table,
     properties=dict( galaxy_sessions=relation( GalaxySessionToHistoryAssociation ),
                      datasets=relation( HistoryDatasetAssociation, backref="history", order_by=asc(HistoryDatasetAssociation.table.c.hid) ),
-                     active_datasets=relation( HistoryDatasetAssociation, primaryjoin=( ( HistoryDatasetAssociation.table.c.history_id == History.table.c.id ) & ( not_( HistoryDatasetAssociation.table.c.deleted ) ) ), order_by=asc( HistoryDatasetAssociation.table.c.hid ), lazy=False, viewonly=True ) ) )
+                     active_datasets=relation( HistoryDatasetAssociation, primaryjoin=( ( HistoryDatasetAssociation.table.c.history_id == History.table.c.id ) & ( not_( HistoryDatasetAssociation.table.c.deleted ) ) ), order_by=asc( HistoryDatasetAssociation.table.c.hid ), lazy=False, viewonly=True ),
+                     activatable_datasets=relation( HistoryDatasetAssociation, primaryjoin=( ( HistoryDatasetAssociation.table.c.history_id == History.table.c.id ) & ( not_( Dataset.table.c.purged ) ) ), order_by=asc( HistoryDatasetAssociation.table.c.hid ), lazy=False, viewonly=True )
+                      ) )
 
 assign_mapper( context, User, User.table,
     properties=dict( histories=relation( History, backref="user",
diff -r 20591fa0d05d -r 45033114f82d lib/galaxy/util/__init__.py
--- a/lib/galaxy/util/__init__.py Thu Oct 02 15:51:17 2008 -0400
+++ b/lib/galaxy/util/__init__.py Thu Oct 02 16:37:32 2008 -0400
@@ -206,7 +206,7 @@
     return ''
     
 def string_as_bool( string ):
-    if string.lower() in ( 'true', 'yes', 'on' ):
+    if str( string ).lower() in ( 'true', 'yes', 'on' ):
         return True
     else:
         return False
diff -r 20591fa0d05d -r 45033114f82d lib/galaxy/web/controllers/dataset.py
--- a/lib/galaxy/web/controllers/dataset.py Thu Oct 02 15:51:17 2008 -0400
+++ b/lib/galaxy/web/controllers/dataset.py Thu Oct 02 16:37:32 2008 -0400
@@ -128,3 +128,19 @@
                 return open(file_path)
             except:
                 raise paste.httpexceptions.HTTPNotFound( "File Not Found (%s)." % (filename) )
+    
+    @web.expose
+    def undelete( self, trans, id ):
+        history = trans.get_history()
+        data = self.app.model.HistoryDatasetAssociation.get( id )
+        if data and data.undeletable:
+            # Walk up parent datasets to find the containing history
+            topmost_parent = data
+            while topmost_parent.parent:
+                topmost_parent = topmost_parent.parent
+            assert topmost_parent in history.datasets, "Data does not belong to current history"
+            # Mark undeleted
+            data.mark_undeleted()
+            self.app.model.flush()
+            trans.log_event( "Dataset id %s has been undeleted" % str(id) )
+        return trans.response.send_redirect( web.url_for( controller='root', action='history', show_deleted = True ) )
diff -r 20591fa0d05d -r 45033114f82d lib/galaxy/web/controllers/root.py
--- a/lib/galaxy/web/controllers/root.py Thu Oct 02 15:51:17 2008 -0400
+++ b/lib/galaxy/web/controllers/root.py Thu Oct 02 16:37:32 2008 -0400
@@ -48,7 +48,7 @@
     ## ---- Root history display ---------------------------------------------
 
     @web.expose
-    def history( self, trans, as_xml=False ):
+    def history( self, trans, as_xml=False, show_deleted=False ):
         """
         Display the current history, creating a new history if neccesary.
         
@@ -63,7 +63,7 @@
             return trans.fill_template_mako( "root/history_as_xml.mako", history=history )
         else:
             template = "root/history.mako"
-            return trans.fill_template( "root/history.mako", history=history )
+            return trans.fill_template( "root/history.mako", history = history, show_deleted = util.string_as_bool( show_deleted ) )
 
     @web.expose
     def dataset_state ( self, trans, id=None, stamp=None ):
@@ -271,7 +271,7 @@
                                     datatypes=ldatatypes, err=None )
 
     @web.expose
-    def delete( self, trans, id = None, **kwd):
+    def delete( self, trans, id = None, show_deleted_on_refresh = False, **kwd):
         if id:
             if isinstance( id, list ):
                 dataset_ids = id
@@ -300,7 +300,7 @@
                             self.app.job_stop_queue.put( data.creating_job_associations[0].job )
                         except IndexError:
                             pass    # upload tool will cause this since it doesn't have a job
-        return self.history( trans )
+        return self.history( trans, show_deleted = show_deleted_on_refresh )
         
     @web.expose
     def delete_async( self, trans, id = None, **kwd):
diff -r 20591fa0d05d -r 45033114f82d templates/history/options.mako
--- a/templates/history/options.mako Thu Oct 02 15:51:17 2008 -0400
+++ b/templates/history/options.mako Thu Oct 02 16:37:32 2008 -0400
@@ -19,6 +19,7 @@
     <li><a href="${h.url_for( controller='workflow', action='build_from_current_history' )}">Construct workflow</a> from the current history</li>
     <li><a href="${h.url_for( action='history_share' )}" target="galaxy_main">Share</a> current history</div>
 %endif
+    <li><a href="${h.url_for( action='history', show_deleted=True)}" target="galaxy_history">Show deleted</a> datasets in history</li>
     <li><a href="${h.url_for( action='history_delete', id=history.id )}" confirm="Are you sure you want to delete the current history?">Delete</a> current history</div>
 </ul>
 
diff -r 20591fa0d05d -r 45033114f82d templates/root/history.mako
--- a/templates/root/history.mako Thu Oct 02 15:51:17 2008 -0400
+++ b/templates/root/history.mako Thu Oct 02 16:37:32 2008 -0400
@@ -209,7 +209,10 @@
 <body class="historyPage">
 
 <div id="top-links" class="historyLinks">
-    <a href="${h.url_for('history')}">refresh</a>
+    <a href="${h.url_for('history', show_deleted=show_deleted)}">refresh</a>
+    %if show_deleted:
+    | <a href="${h.url_for('history', show_deleted=False)}">hide deleted</a>
+    %endif
 </div>
 
 %if history.deleted:
@@ -221,11 +224,19 @@
 
 <%namespace file="history_common.mako" import="render_dataset" />
 
-%if len(history.active_datasets) < 1:
+%if ( show_deleted and len( history.datasets ) < 1 ) or len( history.active_datasets ) < 1:
     <div class="infomessagesmall" id="emptyHistoryMessage">
 %else:    
-    ## Render all active (not deleted) datasets, ordered from newest to oldest
-    %for data in reversed( history.active_datasets ):
+    <%
+    if show_deleted:
+        #all datasets
+        datasets_to_show = history.activatable_datasets
+    else:
+        #active (not deleted)
+        datasets_to_show = history.active_datasets
+    %>
+    ## Render requested datasets, ordered from newest to oldest
+    %for data in reversed( datasets_to_show ):
         %if data.visible:
             <div class="historyItemContainer" id="historyItemContainer-${data.id}">
                 ${render_dataset( data, data.hid )}
diff -r 20591fa0d05d -r 45033114f82d templates/root/history_common.mako
--- a/templates/root/history_common.mako Thu Oct 02 15:51:17 2008 -0400
+++ b/templates/root/history_common.mako Thu Oct 02 16:37:32 2008 -0400
@@ -8,8 +8,12 @@
     %>
     <div class="historyItemWrapper historyItem historyItem-${data_state}" id="historyItem-${data.id}">
         
+    %if data.deleted:
+        <div class="warningmessagesmall">
+            <strong>This dataset has been deleted. Click <a href="${h.url_for( controller='dataset', action='undelete', id=data.id )}" target="galaxy_history">here</a> to undelete.</strong>
+        </div>
+    %endif
         ## Header row for history items (name, state, action buttons)
-        
  <div style="overflow: hidden;" class="historyItemTitleBar">
     <div style="float: left; padding-right: 3px;">
  <div style='display: none;' id="progress-${data.id}">
@@ -24,7 +28,7 @@
     <div style="float: right;">
     <a href="${h.url_for( controller='dataset', dataset_id=data.id, action='display', filename='index')}" target="galaxy_main"><img src="${h.url_for('/static/images/eye_icon.png')}" rollover="${h.url_for('/static/images/eye_icon_dark.png')}" width='16' height='16' alt='display data' title='display data' class='displayButton' border='0'></a>
     <a href="${h.url_for( action='edit', id=data.id )}" target="galaxy_main"><img src="${h.url_for('/static/images/pencil_icon.png')}" rollover="${h.url_for('/static/images/pencil_icon_dark.png')}" width='16' height='16' alt='edit attributes' title='edit attributes' class='editButton' border='0'></a>
-    <a href="${h.url_for( action='delete', id=data.id )}" class="historyItemDelete" id="historyItemDelter-${data.id}"><img src="${h.url_for('/static/images/delete_icon.png')}" rollover="${h.url_for('/static/images/delete_icon_dark.png')}" width='16' height='16' alt='delete' class='deleteButton' border='0'></a>
+    <a href="${h.url_for( action='delete', id=data.id, show_deleted_on_refresh=show_deleted )}" class="historyItemDelete" id="historyItemDelter-${data.id}"><img src="${h.url_for('/static/images/delete_icon.png')}" rollover="${h.url_for('/static/images/delete_icon_dark.png')}" width='16' height='16' alt='delete' class='deleteButton' border='0'></a>
     </div>
     <span class="historyItemTitle"><b>${hid}: ${data.display_name()}</b></span>
  </div>
@@ -100,4 +104,4 @@
         </div>
     </div>
 
-</%def>
\ No newline at end of file
+</%def>