Merge pull request #4681 from guerler/replace_analysis_forms

Remove history renaming mako
This commit is contained in:
John Chilton
2017-09-26 09:42:10 -04:00
committed by GitHub
14 changed files with 88 additions and 124 deletions
+6
View File
@@ -15,6 +15,7 @@ var jQuery = require( 'jquery' ),
Workflows = require( 'mvc/workflow/workflow' ),
HistoryList = require( 'mvc/history/history-list' ),
ToolFormComposite = require( 'mvc/tool/tool-form-composite' ),
QueryStringParsing = require( 'utils/query-string-parsing' ),
Utils = require( 'utils/utils' ),
Ui = require( 'mvc/ui/ui-misc' ),
DatasetError = require( 'mvc/dataset/dataset-error' ),
@@ -48,6 +49,7 @@ window.app = function app( options, bootstrapped ){
'(/)pages(/)(:action_id)' : 'show_pages',
'(/)visualizations/(:action_id)' : 'show_visualizations',
'(/)workflows/list_published(/)' : 'show_workflows_published',
'(/)histories(/)rename(/)' : 'show_histories_rename',
'(/)histories(/)(:action_id)' : 'show_histories',
'(/)datasets(/)list(/)' : 'show_datasets',
'(/)workflow/import_workflow' : 'show_import_workflow',
@@ -95,6 +97,10 @@ window.app = function app( options, bootstrapped ){
this.page.display( new HistoryList.View( { action_id: action_id } ) );
},
show_histories_rename : function() {
this.page.display( new FormWrapper.View ( { url : 'history/rename?id=' + QueryStringParsing.get( 'id' ), redirect: 'histories/list' } ) );
},
show_datasets : function() {
this.page.display( new GridView( { url_base: Galaxy.root + 'dataset/list', dict_format: true } ) );
},
@@ -8,7 +8,7 @@ define( [ 'utils/utils', 'mvc/grid/grid-view', 'mvc/history/history-model', 'mvc
this.setElement( $( '<div/>' ) );
this.model = new Backbone.Model();
Utils.get({
url : Galaxy.root + 'history/' + options.action_id,
url : Galaxy.root + 'history/' + options.action_id + '?' + $.param( Galaxy.params ),
success : function( response ) {
response[ 'dict_format' ] = true;
_.each( response[ 'operations' ], function( operation ) {
+1
View File
@@ -123,6 +123,7 @@ def paste_app_factory(global_conf, **kwargs):
webapp.add_client_route('/histories/list')
webapp.add_client_route('/histories/list_published')
webapp.add_client_route('/histories/list_shared')
webapp.add_client_route('/histories/rename')
webapp.add_client_route('/datasets/list')
webapp.add_client_route('/datasets/edit')
webapp.add_client_route('/datasets/error')
@@ -13,7 +13,7 @@ from galaxy import model
from galaxy import web
from galaxy.model.item_attrs import UsesAnnotations
from galaxy.model.item_attrs import UsesItemRatings
from galaxy.util import nice_size, Params, parse_int
from galaxy.util import listify, nice_size, Params, parse_int, sanitize_text
from galaxy.util.odict import odict
from galaxy.util.sanitize_html import sanitize_html
from galaxy.web import url_for
@@ -109,7 +109,7 @@ class HistoryListGrid(grids.Grid):
grids.GridOperation("View", allow_multiple=False, url_args=dict(action='view')),
grids.GridOperation("Share or Publish", allow_multiple=False, condition=(lambda item: not item.deleted), url_args=dict(action='sharing')),
grids.GridOperation("Copy", allow_multiple=False, condition=(lambda item: not item.deleted), async_compatible=False),
grids.GridOperation("Rename", condition=(lambda item: not item.deleted), url_args=dict(action='rename')),
grids.GridOperation("Rename", condition=(lambda item: not item.deleted), url_args=dict(controller="", action="histories/rename"), target="top"),
grids.GridOperation("Delete", condition=(lambda item: not item.deleted), async_compatible=True),
grids.GridOperation("Delete Permanently", condition=(lambda item: not item.purged), confirm="History contents will be removed from disk, this cannot be undone. Continue?", async_compatible=True),
grids.GridOperation("Undelete", condition=(lambda item: item.deleted and not item.purged), async_compatible=True),
@@ -240,16 +240,16 @@ class HistoryController(BaseUIController, SharableMixin, UsesAnnotations, UsesIt
kwargs['dict_format'] = True
return self.published_list_grid(trans, **kwargs)
@web.expose
@web.json
@web.expose_api
@web.require_login("work with multiple histories")
def list(self, trans, **kwargs):
"""List all available histories"""
current_history = trans.get_history()
status = message = None
message = kwargs.get('message')
status = kwargs.get('status')
if 'operation' in kwargs:
operation = kwargs['operation'].lower()
history_ids = galaxy.util.listify(kwargs.get('id', []))
history_ids = listify(kwargs.get('id', []))
# Display no message by default
status, message = None, None
# Load the histories and ensure they all belong to the current user
@@ -308,7 +308,10 @@ class HistoryController(BaseUIController, SharableMixin, UsesAnnotations, UsesIt
trans.sa_session.flush()
# Render the list view
kwargs['dict_format'] = True
return self.stored_list_grid(trans, status=status, message=message, **kwargs)
if message and status:
kwargs['message'] = sanitize_text(message)
kwargs['status'] = status
return self.stored_list_grid(trans, **kwargs)
def _list_delete(self, trans, histories, purge=False):
"""Delete histories"""
@@ -424,7 +427,7 @@ class HistoryController(BaseUIController, SharableMixin, UsesAnnotations, UsesIt
"""List histories shared with current user by others"""
status = message = None
if 'operation' in kwargs:
ids = galaxy.util.listify(kwargs.get('id', []))
ids = listify(kwargs.get('id', []))
operation = kwargs['operation'].lower()
if operation == 'unshare':
if not ids:
@@ -680,7 +683,7 @@ class HistoryController(BaseUIController, SharableMixin, UsesAnnotations, UsesIt
session = trans.sa_session
# Id values take precedence over histories passed in; last resort is current history.
if id:
ids = galaxy.util.listify(id)
ids = listify(id)
if ids:
histories = [self.history_manager.get_accessible(self.decode_id(history_id), trans.user, current_history=trans.history)
for history_id in ids]
@@ -747,7 +750,7 @@ class HistoryController(BaseUIController, SharableMixin, UsesAnnotations, UsesIt
if not id:
# Default to the current history
id = trans.security.encode_id(trans.history.id)
id = galaxy.util.listify(id)
id = listify(id)
send_to_err = err_msg
histories = []
for history_id in id:
@@ -887,7 +890,7 @@ class HistoryController(BaseUIController, SharableMixin, UsesAnnotations, UsesIt
if not ids:
# Default to the current history
ids = trans.security.encode_id(trans.history.id)
ids = galaxy.util.listify(ids)
ids = listify(ids)
histories = []
for history_id in ids:
history_id = self.decode_id(history_id)
@@ -898,7 +901,7 @@ class HistoryController(BaseUIController, SharableMixin, UsesAnnotations, UsesIt
def _get_users(self, trans, user, emails_or_ids):
send_to_users = []
send_to_err = ""
for string in galaxy.util.listify(emails_or_ids):
for string in listify(emails_or_ids):
string = string.strip()
if not string:
continue
@@ -1237,59 +1240,49 @@ class HistoryController(BaseUIController, SharableMixin, UsesAnnotations, UsesIt
return
# TODO: used in page/editor.mako
@web.expose
@web.expose_api
@web.require_login("rename histories")
def rename(self, trans, id=None, name=None, **kwd):
user = trans.get_user()
def rename(self, trans, payload=None, **kwd):
id = kwd.get('id')
if not id:
# Default to the current history
history = trans.get_history()
if not history.user:
return trans.show_error_message("You must save your history before renaming it.")
id = trans.security.encode_id(history.id)
id = galaxy.util.listify(id)
name = galaxy.util.listify(name)
return message_exception(trans, 'No history id received for renaming.')
user = trans.get_user()
id = listify(id)
histories = []
for history_id in id:
history = self.history_manager.get_owned(self.decode_id(history_id), trans.user, current_history=trans.history)
if history and history.user_id == user.id:
histories.append(history)
if not name or len(histories) != len(name):
return trans.fill_template("/history/rename.mako", histories=histories)
change_msgs = []
for i in range(len(histories)):
cur_name = histories[i].get_display_name()
new_name = name[i]
# skip if name is empty
if not isinstance(new_name, string_types) or not new_name.strip():
change_msgs.append("You must specify a valid name for History: " + cur_name)
continue
# skip if not the owner
# ??: isn't this already handled in get_history/if statement above?
if histories[i].user_id != user.id:
change_msgs.append("History: " + cur_name + " does not appear to belong to you.")
continue
# skip if it wouldn't be a change
if new_name == cur_name:
change_msgs.append("History: " + cur_name + " is already named: " + new_name)
continue
# escape, sanitize, set, and log the change
new_name = escape(new_name)
histories[i].name = sanitize_html(new_name)
trans.sa_session.add(histories[i])
trans.sa_session.flush()
trans.log_event("History renamed: id: %s, renamed to: '%s'" % (str(histories[i].id), new_name))
change_msgs.append("History: " + cur_name + " renamed to: " + new_name)
change_msg = '<br />'.join(change_msgs)
return trans.show_message(change_msg, refresh_frames=['history'])
if trans.request.method == 'GET':
return {
'title' : 'Change history name(s)',
'inputs' : [{
'name' : trans.security.encode_id(h.id),
'label' : 'Current: %s' % h.name,
'value' : h.name
} for h in histories]
}
else:
messages = []
for h in histories:
cur_name = h.get_display_name()
new_name = payload.get(trans.security.encode_id(h.id))
# validate name is empty
if not isinstance(new_name, string_types) or not new_name.strip():
messages.append('You must specify a valid name for History \'%s\'.' % cur_name)
# skip if not the owner
elif h.user_id != user.id:
messages.append('History \'%s\' does not appear to belong to you.' % cur_name)
# skip if it wouldn't be a change
elif new_name != cur_name:
# escape, sanitize, set, and log the change
h.name = sanitize_html(escape(new_name))
trans.sa_session.add(h)
trans.sa_session.flush()
trans.log_event('History renamed: id: %s, renamed to: %s' % (str(h.id), new_name))
messages.append('History \'' + cur_name + '\' renamed to \'' + new_name + '\'.')
message = sanitize_text(' '.join(messages)) if messages else 'History names remain unchanged.'
return {'message': message, 'status': 'success'}
# ------------------------------------------------------------------------- current history
@web.expose
@@ -1337,3 +1330,8 @@ class HistoryController(BaseUIController, SharableMixin, UsesAnnotations, UsesIt
new_history = trans.new_history(name)
return self.history_data(trans, new_history)
# TODO: /history/current to do all of the above: if ajax, return json; if post, read id and set to current
def message_exception(trans, message):
trans.response.status = 400
return {'err_msg': sanitize_text(message)}
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"history-list.js","sources":["../../../src/mvc/history/history-list.js"],"names":["define","Utils","GridView","HistoryModel","historyCopyDialog","View","Backbone","extend","title","initialize","options","self","this","setElement","$","model","Model","get","url","Galaxy","root","action_id","success","response","_","each","operation","label","onclick","id","_showCopyDialog","set","render","grid","attributes","$el","empty","append","history","History","fetch","fail","alert","done","window","parent","currHistoryPanel","loadCurrentHistory","location","reload"],"mappings":"AACAA,QAAU,cAAe,qBAAsB,4BAA6B,2BAA6B,SAAUC,EAAOC,EAAUC,EAAcC,GAE9I,GAAIC,GAAOC,SAASD,KAAKE,QACrBC,MAAO,YACPC,WAAY,SAAUC,GAClB,GAAIC,GAAOC,IACXA,MAAKC,WAAYC,EAAG,WACpBF,KAAKG,MAAQ,GAAIT,UAASU,MAC1Bf,EAAMgB,KACFC,IAAUC,OAAOC,KAAO,WAAaV,EAAQW,UAC7CC,QAAU,SAAUC,GAChBA,EAAwB,aAAI,EAC5BC,EAAEC,KAAMF,EAAuB,WAAG,SAAUG,GAChB,QAAnBA,EAAUC,QACXD,EAAUE,QAAU,SAAUC,GAAOlB,EAAKmB,gBAAiBD,OAGnElB,EAAKI,MAAMgB,IAAKR,GAChBZ,EAAKqB,aAKjBA,OAAQ,WACJ,GAAIC,GAAO,GAAI/B,GAAUU,KAAKG,MAAMmB,WACpCtB,MAAKuB,IAAIC,QAAQC,OAAQJ,EAAKE,MAGlCL,gBAAiB,SAAUD,GACvB,GAAIS,GAAU,GAAInC,GAAaoC,SAAWV,GAAKA,GAC/CS,GAAQE,QACAC,KAAM,WACHC,MAAO,mEAEVC,KAAM,WACHvC,EAAmBkC,MAAcK,KAAM,WAC/BC,OAAOC,QAAUD,OAAOC,OAAO1B,QAAUyB,OAAOC,OAAO1B,OAAO2B,kBAC9DF,OAAOC,OAAO1B,OAAO2B,iBAAiBC,qBAE1CH,OAAOI,SAASC,QAAQ,SAM/C,QACI5C,KAAMA"}
{"version":3,"file":"history-list.js","sources":["../../../src/mvc/history/history-list.js"],"names":["define","Utils","GridView","HistoryModel","historyCopyDialog","View","Backbone","extend","title","initialize","options","self","this","setElement","$","model","Model","get","url","Galaxy","root","action_id","param","params","success","response","_","each","operation","label","onclick","id","_showCopyDialog","set","render","grid","attributes","$el","empty","append","history","History","fetch","fail","alert","done","window","parent","currHistoryPanel","loadCurrentHistory","location","reload"],"mappings":"AACAA,QAAU,cAAe,qBAAsB,4BAA6B,2BAA6B,SAAUC,EAAOC,EAAUC,EAAcC,GAE9I,GAAIC,GAAOC,SAASD,KAAKE,QACrBC,MAAO,YACPC,WAAY,SAAUC,GAClB,GAAIC,GAAOC,IACXA,MAAKC,WAAYC,EAAG,WACpBF,KAAKG,MAAQ,GAAIT,UAASU,MAC1Bf,EAAMgB,KACFC,IAAUC,OAAOC,KAAO,WAAaV,EAAQW,UAAY,IAAOP,EAAEQ,MAAOH,OAAOI,QAChFC,QAAU,SAAUC,GAChBA,EAAwB,aAAI,EAC5BC,EAAEC,KAAMF,EAAuB,WAAG,SAAUG,GAChB,QAAnBA,EAAUC,QACXD,EAAUE,QAAU,SAAUC,GAAOpB,EAAKqB,gBAAiBD,OAGnEpB,EAAKI,MAAMkB,IAAKR,GAChBd,EAAKuB,aAKjBA,OAAQ,WACJ,GAAIC,GAAO,GAAIjC,GAAUU,KAAKG,MAAMqB,WACpCxB,MAAKyB,IAAIC,QAAQC,OAAQJ,EAAKE,MAGlCL,gBAAiB,SAAUD,GACvB,GAAIS,GAAU,GAAIrC,GAAasC,SAAWV,GAAKA,GAC/CS,GAAQE,QACAC,KAAM,WACHC,MAAO,mEAEVC,KAAM,WACHzC,EAAmBoC,MAAcK,KAAM,WAC/BC,OAAOC,QAAUD,OAAOC,OAAO5B,QAAU2B,OAAOC,OAAO5B,OAAO6B,kBAC9DF,OAAOC,OAAO5B,OAAO6B,iBAAiBC,qBAE1CH,OAAOI,SAASC,QAAQ,SAM/C,QACI9C,KAAMA"}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,2 +1,2 @@
define(["utils/utils","mvc/grid/grid-view","mvc/history/history-model","mvc/history/copy-dialog"],function(a,b,c,d){var e=Backbone.View.extend({title:"Histories",initialize:function(b){var c=this;this.setElement($("<div/>")),this.model=new Backbone.Model,a.get({url:Galaxy.root+"history/"+b.action_id,success:function(a){a.dict_format=!0,_.each(a.operations,function(a){"Copy"==a.label&&(a.onclick=function(a){c._showCopyDialog(a)})}),c.model.set(a),c.render()}})},render:function(){var a=new b(this.model.attributes);this.$el.empty().append(a.$el)},_showCopyDialog:function(a){var b=new c.History({id:a});b.fetch().fail(function(){alert("History could not be fetched. Please contact an administrator")}).done(function(){d(b,{}).done(function(){window.parent&&window.parent.Galaxy&&window.parent.Galaxy.currHistoryPanel&&window.parent.Galaxy.currHistoryPanel.loadCurrentHistory(),window.location.reload(!0)})})}});return{View:e}});
define(["utils/utils","mvc/grid/grid-view","mvc/history/history-model","mvc/history/copy-dialog"],function(a,b,c,d){var e=Backbone.View.extend({title:"Histories",initialize:function(b){var c=this;this.setElement($("<div/>")),this.model=new Backbone.Model,a.get({url:Galaxy.root+"history/"+b.action_id+"?"+$.param(Galaxy.params),success:function(a){a.dict_format=!0,_.each(a.operations,function(a){"Copy"==a.label&&(a.onclick=function(a){c._showCopyDialog(a)})}),c.model.set(a),c.render()}})},render:function(){var a=new b(this.model.attributes);this.$el.empty().append(a.$el)},_showCopyDialog:function(a){var b=new c.History({id:a});b.fetch().fail(function(){alert("History could not be fetched. Please contact an administrator")}).done(function(){d(b,{}).done(function(){window.parent&&window.parent.Galaxy&&window.parent.Galaxy.currHistoryPanel&&window.parent.Galaxy.currHistoryPanel.loadCurrentHistory(),window.location.reload(!0)})})}});return{View:e}});
//# sourceMappingURL=../../../maps/mvc/history/history-list.js.map
@@ -1,38 +0,0 @@
<%inherit file="/base.mako"/>
<%def name="title()">${_('Rename History')}</%def>
<div class="toolForm">
<div class="toolFormTitle">${_('Rename')}</div>
<div class="toolFormBody">
<form action="${h.url_for( controller='history', action='rename' )}" method="post" >
<div class="form-row">
<table>
<thead>
<tr>
<th>${_('Current Name')}</th>
<th>${_('New Name')}</th>
</tr>
</thead>
<tbody>
%for history in histories:
<tr>
<td>
<input type="hidden" name="id" value="${trans.security.encode_id( history.id )}">
${history.get_display_name() | h}
</td>
<td>
<input type="text" name="name" value="${history.get_display_name() | h}" size="40">
</td>
</tr>
%endfor
</tbody>
<tr>
<td colspan="2">
<input type="submit" name="history_rename_btn" value="${_('Rename Histories')}">
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
+2 -5
View File
@@ -63,14 +63,11 @@ class SavedHistoriesTestCase(SharedStateSeleniumTestCase):
self.click_popup_option('Unnamed history', 'Rename')
# Rename the history
history_name_input = self.wait_for_selector('input[name="name"]')
history_name_input = self.wait_for_selector('.ui-form-element input.ui-input')
history_name_input.clear()
history_name_input.send_keys(self.history1_name)
self.send_enter(history_name_input)
message = self.wait_for_selector_visible('.infomessagelarge')
expected_message = 'History: Unnamed history renamed to: %s' % self.history1_name
self.assertEqual(expected_message, message.text)
self.wait_for_and_click_selector("button#submit")
self.navigate_to_saved_histories_page()