Skip to content

Commit

Permalink
Use client builder for history renaming form
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Sep 22, 2017
1 parent 00677fc commit 7921c8b
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 79 deletions.
6 changes: 6 additions & 0 deletions client/galaxy/scripts/apps/analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 } ) );
},
Expand Down
2 changes: 1 addition & 1 deletion client/galaxy/scripts/mvc/history/history-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
1 change: 1 addition & 0 deletions lib/galaxy/webapps/galaxy/buildapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
114 changes: 58 additions & 56 deletions lib/galaxy/webapps/galaxy/controllers/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
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 nice_size, Params, parse_int, sanitize_text, listify
from galaxy.util.odict import odict
from galaxy.util.sanitize_html import sanitize_html
from galaxy.web import url_for
Expand Down Expand Up @@ -109,7 +109,7 @@ def sort(self, trans, query, ascending, column_name=None):
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),
Expand Down Expand Up @@ -240,16 +240,17 @@ def list_published(self, trans, **kwargs):
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')
print kwargs
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
Expand Down Expand Up @@ -308,7 +309,10 @@ def list(self, trans, **kwargs):
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"""
Expand Down Expand Up @@ -424,7 +428,7 @@ def list_shared(self, trans, **kwargs):
"""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:
Expand Down Expand Up @@ -680,7 +684,7 @@ def sharing(self, trans, id=None, histories=[], **kwargs):
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]
Expand Down Expand Up @@ -747,7 +751,7 @@ def share(self, trans, id=None, email="", **kwd):
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:
Expand Down Expand Up @@ -887,7 +891,7 @@ def _get_histories(self, trans, ids):
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)
Expand All @@ -898,7 +902,7 @@ def _get_histories(self, trans, ids):
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
Expand Down Expand Up @@ -1237,59 +1241,52 @@ def set_accessible_async(self, trans, id=None, accessible=False):
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()
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 history.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
new_name = escape(new_name)
history.name = sanitize_html(new_name)
trans.sa_session.add(history)
trans.sa_session.flush()
trans.log_event('History renamed: id: %s, renamed to: \'%s\'' % (str(history.id), new_name))
messages.append('History \'' + cur_name + '\' renamed to \'' + new_name + '\'.')
return {'message': ' '.join(messages), 'status': 'success'}
#return trans.show_message(change_msg, refresh_frames=['history'])

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'])

# ------------------------------------------------------------------------- current history
@web.expose
Expand Down Expand Up @@ -1337,3 +1334,8 @@ def create_new_current(self, trans, name=None):
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)}
2 changes: 1 addition & 1 deletion static/maps/mvc/history/history-list.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions static/scripts/bundled/admin.bundled.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/scripts/bundled/admin.bundled.js.map

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions static/scripts/bundled/analysis.bundled.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/scripts/bundled/analysis.bundled.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions static/scripts/bundled/libs.bundled.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/scripts/bundled/libs.bundled.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/scripts/mvc/history/history-list.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7921c8b

Please sign in to comment.