Add 'recently used tools' section to tools menu. Recently used tools is a list of the five most recent tools that a user has run. This menu is hidden by default but can be shown via the tools menu options. A user must be logged in to use this option.

This commit is contained in:
Jeremy Goecks
2010-06-18 15:14:27 -04:00
parent b243311c92
commit c099dc895f
5 changed files with 169 additions and 23 deletions
+18 -1
View File
@@ -6,6 +6,7 @@ from cgi import escape, FieldStorage
from galaxy import util, datatypes, jobs, web, util
from galaxy.web.base.controller import *
from galaxy.util.sanitize_html import sanitize_html
from galaxy.util.odict import odict
from galaxy.model.orm import *
log = logging.getLogger( __name__ )
@@ -30,7 +31,23 @@ class RootController( BaseController, UsesHistory, UsesAnnotations ):
if trans.app.config.require_login and not trans.user:
return trans.fill_template( '/no_access.mako', message = 'Please log in to access Galaxy tools.' )
else:
return trans.fill_template('/root/tool_menu.mako', toolbox=self.get_toolbox() )
## Get most recently used tools.
toolbox = self.get_toolbox()
recent_tool_ids = odict()
if trans.user:
for row in trans.sa_session.query( self.app.model.Job.tool_id ).join( self.app.model.History ). \
filter( self.app.model.GalaxySession.user==trans.user ). \
order_by( self.app.model.Job.create_time.desc() ):
tool_id = row[0]
recent_tool_ids[tool_id] = tool_id
## TODO: make number of recently used tools a user preference.
if len ( recent_tool_ids ) == 5:
break
# Create list of recently used tools.
recent_tools = [ toolbox.tools_by_id[ tool_id ] for tool_id in recent_tool_ids.keys() ]
return trans.fill_template('/root/tool_menu.mako', toolbox=toolbox, recent_tools=recent_tools )
@web.json
def tool_search( self, trans, query ):
+26
View File
@@ -8,6 +8,7 @@ import logging, os, string, re
from random import choice
from galaxy.web.form_builder import *
from galaxy.util.json import from_json_string, to_json_string
from galaxy.web.framework.helpers import iff
log = logging.getLogger( __name__ )
@@ -650,6 +651,31 @@ class User( BaseController ):
else:
# User not logged in, history group must be only public
return trans.show_error_message( "You must be logged in to change your default permitted actions." )
@web.expose
@web.require_login( "to get most recently used tool" )
@web.json_pretty
def get_most_recently_used_tool_async( self, trans ):
""" Returns information about the most recently used tool. """
# Get most recently used tool.
query = trans.sa_session.query( self.app.model.Job.tool_id ).join( self.app.model.History ). \
filter( self.app.model.History.user==trans.user ). \
order_by( self.app.model.Job.create_time.desc() ).limit(1)
tool_id = query[0][0] # Get first element in first row of query.
tool = self.get_toolbox().tools_by_id[ tool_id ]
# Return tool info.
tool_info = {
"id" : tool.id,
"link" : url_for( controller='tool_runner', tool_id=tool.id ),
"target" : tool.target,
"name" : tool.name, ## TODO: translate this using _()
"minsizehint" : tool.uihints.get( 'minwidth', -1 ),
"description" : tool.description
}
return tool_info
@web.expose
def manage_addresses(self, trans, **kwd):
if trans.user:
+44 -20
View File
@@ -53,12 +53,12 @@
});
// Init tool options.
%if trans.app.toolbox_search.enabled:
make_popupmenu( $("#tools-options-button"), {
"Search Tools": function() {
make_popupmenu( $("#tools-options-button"), {
## Search tools menu item.
%if trans.app.toolbox_search.enabled:
"Search Tools": function() {
// Show/hide menu and update user preference for menu visibility.
var tool_menu_frame = $("#galaxy_tools").contents();
var menu = tool_menu_frame.find('#tool-search');
var menu = $("#galaxy_tools").contents().find('#tool-search');
if (menu.is(":visible"))
{
// Hide menu.
@@ -78,24 +78,48 @@
}
// Update menu option.
$("#tools-options-button-menu").find("li").first().text(menu_option_text);
$("#tools-options-button-menu").find("li").eq(0).text(menu_option_text);
// TODO: Set user preference.
/*
TODO: uncomment this when this method is working.
$.ajax({
url: "${h.url_for( controller='/user', action='set_user_pref_async' )}",
data: { "pref_name" : "show_tool_search",
"pref_value" : pref_value
},
error: function() {
alert( "Failed to set user preference." );
},
});
*/
},
%endif
## Recently used tools menu.
%if trans.user:
<%
if 'show_recently_used_menu' in trans.user.preferences and trans.user.preferences['show_recently_used_menu'] == 'True':
action = "Hide"
else:
action = "Show"
%>
"${action} Recently Used": function() {
// Show/hide menu.
var ru_menu = $('#galaxy_tools').contents().find('#recently_used_wrapper');
var ru_menu_body = ru_menu.find(".toolSectionBody");
var pref_value = null;
var menu_option_text = null;
if (ru_menu.is(":visible"))
{
// Hide menu.
ru_menu_body.slideUp();
ru_menu.slideUp();
pref_value = "False";
menu_option_text = "Show Recently Used";
}
else
{
// Show menu.
ru_menu.slideDown();
pref_value = "True";
menu_option_text = "Hide Recently Used";
}
// Update menu option.
$("#tools-options-button-menu").find("li").eq(1).text(menu_option_text);
// TODO: Set user preference.
}
});
%endif
%endif
});
});
</script>
</%def>
+73 -1
View File
@@ -149,7 +149,56 @@
}
this.lastValue = this.value;
});
});
});
// Update recently used tools menu. Function inserts a new item and removes the last item.
function update_recently_used()
{
$.ajax({
url: "${h.url_for( controller='/user', action='get_most_recently_used_tool_async' )}",
dataType: 'json',
error: function() {
console.log( "Failed to update recently used list." );
},
success: function(new_tool_info) {
var recently_used_elts = $("#recently_used").find(".toolTitle");
var first_elt = $(recently_used_elts.first());
var found_in_list = false;
// Look for new tool in current list. If found, rearrange list to move tool to top.
recently_used_elts.each( function(index) {
var anchor = $(this).find("a");
var tool_id = anchor.attr("id").split("-")[1];
if (tool_id == new_tool_info.id)
{
found_in_list = true;
// If tool is first, do nothing.
if (index == 0)
return;
else
{
// Tool not first; reorder.
$(this).remove();
first_elt.before($(this));
}
}
});
// If tool not in list, create new element, remove last element, and put new element first in list.
if (!found_in_list)
{
new_tool_elt = $("<div class='toolTitle'> \
<a id='link-" + new_tool_info.id + "' href='" + new_tool_info.link + "' target='" +
new_tool_info.target + "' minsizehint='" + new_tool_info.minsizehint + "'>" +
new_tool_info.name + "</a> " + new_tool_info.description + " \
</div>");
recently_used_elts.last().remove();
recently_used_elts.first().before(new_tool_elt);
}
}
});
}
</script>
</head>
@@ -162,6 +211,29 @@
<img src="${h.url_for('/static/images/loading_small_white_bg.gif')}" id="search-spinner" style="display: none; position: absolute; right: 0; top: 5px;"/>
</div>
## Recently used tools.
%if trans.user:
<%
if 'show_recently_used_menu' in trans.user.preferences and trans.user.preferences['show_recently_used_menu'] == 'True':
display = "block"
else:
display = "none"
%>
<div class="toolSectionWrapper" id="recently_used_wrapper" style="display: ${display}; padding-bottom: 5px">
<div class="toolSectionTitle">
<span>Recently Used</span>
</div>
<div id="recently_used" class="toolSectionBody">
<div class="toolSectionBg">
%for tool in recent_tools:
${render_tool( tool, True )}
%endfor
</div>
</div>
<div class="toolSectionPad"></div>
</div>
%endif
## Tools.
%for key, val in toolbox.tool_panel.items():
<div class="toolSectionWrapper">
+8 -1
View File
@@ -12,6 +12,13 @@
parent.frames.galaxy_history.location.href="${h.url_for( controller='root', action='history' )}";
inside_galaxy_frameset = true;
}
%if trans.user:
if (inside_galaxy_frameset)
{
parent.frames.galaxy_tools.update_recently_used();
}
%endif
if ( parent.handle_minwidth_hint ) {
parent.handle_minwidth_hint( -1 );
@@ -29,7 +36,7 @@
function refresh() {
top.location.href = '${h.url_for( "/" )}';
}
}
</script>