details: http://www.bx.psu.edu/hg/galaxy/rev/99782dc9d022 changeset: 3643:99782dc9d022 user: Kanwei Li <kanwei@gmail.com> date: Tue Apr 13 20:21:57 2010 -0400 description: - Add support for custom dbkeys using user prefs db table (currently only enabled when enable_tracks=True) - Fix async dataset delete: dataset was disappearing when not successfully deleted diffstat: lib/galaxy/web/controllers/user.py | 54 +++++++++++++++++ templates/root/history.mako | 34 ++++++---- templates/user/dbkeys.mako | 94 +++++++++++++++++++++++++++++++ templates/webapps/galaxy/base_panels.mako | 3 + 4 files changed, 170 insertions(+), 15 deletions(-) diffs (225 lines): diff -r 122a4568c046 -r 99782dc9d022 lib/galaxy/web/controllers/user.py --- a/lib/galaxy/web/controllers/user.py Tue Apr 13 17:29:18 2010 -0400 +++ b/lib/galaxy/web/controllers/user.py Tue Apr 13 20:21:57 2010 -0400 @@ -7,6 +7,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 log = logging.getLogger( __name__ ) @@ -841,3 +842,56 @@ user_id=user_id, message='Address <b>%s</b> undeleted' % user_address.desc, status='done') ) + + @web.expose + @web.require_login() + def dbkeys( self, trans, **kwds ): + user = trans.get_user() + message = None + lines_skipped = 0 + if 'dbkeys' not in user.preferences: + dbkeys = {} + else: + dbkeys = from_json_string(user.preferences['dbkeys']) + + if 'delete' in kwds: + key = kwds.get('key', '') + if key and key in dbkeys: + del dbkeys[key] + + elif 'add' in kwds: + name = kwds.get('name', '') + key = kwds.get('key', '') + len_file = kwds.get('len_file', None) + if getattr(len_file, "file", None): # Check if it's a FieldStorage object + len_text = len_file.file.read() + else: + len_text = kwds.get('len_text', '') + if not name or not key or not len_text: + message = "You must specify values for all the fields." + else: + chrom_dict = {} + for line in len_text.split("\n"): + lst = line.strip().split() + if not lst or len(lst) < 2: + lines_skipped += 1 + continue + chrom, length = lst[0], lst[1] + try: + length = int(length) + except ValueError: + lines_skipped += 1 + continue + chrom_dict[chrom] = length + dbkeys[key] = { "name": name, "chroms": chrom_dict } + + user.preferences['dbkeys'] = to_json_string(dbkeys) + trans.sa_session.flush() + + return trans.fill_template( 'user/dbkeys.mako', + user=user, + dbkeys=dbkeys, + message=message, + lines_skipped=lines_skipped ) + + \ No newline at end of file diff -r 122a4568c046 -r 99782dc9d022 templates/root/history.mako --- a/templates/root/history.mako Tue Apr 13 17:29:18 2010 -0400 +++ b/templates/root/history.mako Tue Apr 13 20:21:57 2010 -0400 @@ -33,21 +33,25 @@ $( '#historyItem-' + data_id + "> div.historyItemTitleBar" ).addClass( "spinner" ); $.ajax({ url: "${h.url_for( action='delete_async', id='XXX' )}".replace( 'XXX', data_id ), - error: function() { alert( "Delete failed" ) }, - success: function() { - %if show_deleted: - var to_update = {}; - to_update[data_id] = "none"; - updater( to_update ); - %else: - $( "#historyItem-" + data_id ).fadeOut( "fast", function() { - $( "#historyItemContainer-" + data_id ).remove(); - if ( $( "div.historyItemContainer" ).length < 1 ) { - $( "#emptyHistoryMessage" ).show(); - } - }); - %endif - $(".tipsy").remove(); + error: function() { alert( "Delete failed" ); }, + success: function(msg) { + if (msg === "OK") { + %if show_deleted: + var to_update = {}; + to_update[data_id] = "none"; + updater( to_update ); + %else: + $( "#historyItem-" + data_id ).fadeOut( "fast", function() { + $( "#historyItemContainer-" + data_id ).remove(); + if ( $( "div.historyItemContainer" ).length < 1 ) { + $( "#emptyHistoryMessage" ).show(); + } + }); + %endif + $(".tipsy").remove(); + } else { + alert( "Delete failed" ); + } } }); return false; diff -r 122a4568c046 -r 99782dc9d022 templates/user/dbkeys.mako --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/user/dbkeys.mako Tue Apr 13 20:21:57 2010 -0400 @@ -0,0 +1,94 @@ +<%inherit file="/base.mako"/> +<%def name="title()">Custom Database Builds</%def> + +<style type="text/css"> + th, td { + min-width: 100px; + vertical-align: text-top; + } + pre { + padding: 0; + margin: 0; + } +</style> + +<script type="text/javascript"> + +$(function() { + $(".db_hide").each(function() { + var pre = $(this); + pre.hide(); + pre.siblings("span").wrap( "<a href='javascript:void();'></a>" ).click( function() { + pre.toggle(); + }); + }); +}); + +</script> + +% if message: + <div class="errormessagelarge">${message}</div> +% endif + +% if lines_skipped > 0: + <div class="warningmessagelarge">Skipped ${lines_skipped} lines that could not be parsed</div> +% endif + +<h2>Custom Database/Builds</h2> + +<p>You may specify your own database/builds here.</p> + +% if dbkeys: + <table class="colored" cellspacing="0" cellpadding="0"> + <tr class="header"> + <th>Name</th> + <th>Key</th> + <th>Chroms/Lengths</th> + <th></th> + </tr> + % for key, dct in dbkeys.iteritems(): + <tr> + <td>${dct["name"] | h}</td> + <td>${key | h}</td> + <td> + <span>${len(dct["chroms"])} entries</span> + <pre id="pre_${key}" class="db_hide"> + <table cellspacing="0" cellpadding="0"> + <tr><th>Chrom</th><th>Length</th></tr> + % for chrom, chrom_len in dct["chroms"].iteritems(): + <tr><td>${chrom | h}</td><td>${chrom_len | h}</td></tr> + % endfor + </table> + </pre> + </td> + <td><form action="dbkeys" method="post"><input type="hidden" name="key" value="${key}" /><input type="submit" name="delete" value="Delete" /></form></td> + </tr> + % endfor + </table> +% else: + <p>You currently have no custom builds.</p> +% endif +<br /> +<form action="dbkeys" method="post" enctype="multipart/form-data"> + <div class="toolForm"> + <div class="toolFormTitle">Add a Build</div> + <div class="toolFormBody"> + <div class="form-row"> + <label for="name">Name (eg: Human Chromosome):</label> + <input type="text" id="name" name="name" /> + </div> + <div class="form-row"> + <label for="key">Key (eg: hg18):</label> + <input type="text" id="key" name="key" /> + </div> + <div class="form-row"> + <label for="len_file">Chromosome Length file upload (.len file):</label> + <input type="file" id="len_file" name="len_file" /><br /> + <label for="len_text">Alternatively, paste length info:</label> + <textarea id="len_text" name="len_text" cols="40" rows="10"></textarea> + </div> + + <div class="form-row"><input type="submit" name="add" value="Submit"/></div> + </div> + </div> +</form> \ No newline at end of file diff -r 122a4568c046 -r 99782dc9d022 templates/webapps/galaxy/base_panels.mako --- a/templates/webapps/galaxy/base_panels.mako Tue Apr 13 17:29:18 2010 -0400 +++ b/templates/webapps/galaxy/base_panels.mako Tue Apr 13 20:21:57 2010 -0400 @@ -119,6 +119,9 @@ else: logout_url = h.url_for( controller='/user', action='logout' ) %> + %if app.config.get_bool( 'enable_tracks', False ): + <li><a target="galaxy_main" href="${h.url_for( controller='/user', action='dbkeys' )}">Custom Builds</a></li> + %endif <li><a target="_top" href="${logout_url}">Logout</a></li> %endif <li><hr style="color: inherit; background-color: gray"/></li>