mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
trackster: Add new dbkey column to viz tables, finish "Visualize in Trackster" button functionality
- Dbkey now shown in "Saved Visualizations" grid - "Visualize in Trackster" icon in history pane for supported dataset now works, letting you add that dataset to an existing browser or to a new browser. Dbkey for existing browsers is also shown.
This commit is contained in:
@@ -641,6 +641,7 @@ Visualization.table = Table( "visualization", metadata,
|
||||
ForeignKey( "visualization_revision.id", use_alter=True, name='visualization_latest_revision_id_fk' ), index=True ),
|
||||
Column( "title", TEXT ),
|
||||
Column( "type", TEXT ),
|
||||
Column( "dbkey", TEXT, index=True ),
|
||||
Column( "deleted", Boolean, default=False, index=True ),
|
||||
Column( "importable", Boolean, default=False, index=True ),
|
||||
Column( "slug", TEXT, index=True ),
|
||||
@@ -653,6 +654,7 @@ VisualizationRevision.table = Table( "visualization_revision", metadata,
|
||||
Column( "update_time", DateTime, default=now, onupdate=now ),
|
||||
Column( "visualization_id", Integer, ForeignKey( "visualization.id" ), index=True, nullable=False ),
|
||||
Column( "title", TEXT ),
|
||||
Column( "dbkey", TEXT, index=True ),
|
||||
Column( "config", JSONType )
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
"""
|
||||
Migration script to add dbkey column for visualization.
|
||||
"""
|
||||
|
||||
from sqlalchemy import *
|
||||
from sqlalchemy.orm import *
|
||||
from migrate import *
|
||||
from migrate.changeset import *
|
||||
from galaxy.util.json import from_json_string
|
||||
|
||||
import logging
|
||||
log = logging.getLogger( __name__ )
|
||||
|
||||
metadata = MetaData( migrate_engine )
|
||||
db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) )
|
||||
|
||||
Visualization_table = Table( "visualization", metadata, autoload=True )
|
||||
Visualization_revision_table = Table( "visualization_revision", metadata, autoload=True )
|
||||
|
||||
def upgrade():
|
||||
|
||||
print __doc__
|
||||
metadata.reflect()
|
||||
|
||||
# Create dbkey columns.
|
||||
x = Column( "dbkey", TEXT, index=True )
|
||||
y = Column( "dbkey", TEXT, index=True )
|
||||
x.create( Visualization_table )
|
||||
y.create( Visualization_revision_table )
|
||||
assert x is Visualization_table.c.dbkey
|
||||
assert y is Visualization_revision_table.c.dbkey
|
||||
|
||||
try:
|
||||
i = Index( "ix_visualization_dbkey", Visualization_table.c.dbkey )
|
||||
i.create()
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
i = Index( "ix_visualization_revision_dbkey", Visualization_revision_table.c.dbkey )
|
||||
i.create()
|
||||
except:
|
||||
pass
|
||||
|
||||
all_viz = db_session.execute( "SELECT visualization.id as viz_id, visualization_revision.id as viz_rev_id, visualization_revision.config FROM visualization_revision \
|
||||
LEFT JOIN visualization ON visualization.id=visualization_revision.visualization_id" )
|
||||
for viz in all_viz:
|
||||
viz_id = viz['viz_id']
|
||||
viz_rev_id = viz['viz_rev_id']
|
||||
dbkey = from_json_string(viz[Visualization_revision_table.c.config]).get('dbkey', "").replace("'", "\\'")
|
||||
db_session.execute("UPDATE visualization_revision SET dbkey='%s' WHERE id=%s" % (dbkey, viz_rev_id))
|
||||
db_session.execute("UPDATE visualization SET dbkey='%s' WHERE id=%s" % (dbkey, viz_id))
|
||||
|
||||
def downgrade():
|
||||
metadata.reflect()
|
||||
|
||||
Visualization_table.c.dbkey.drop()
|
||||
Visualization_revision_table.c.dbkey.drop()
|
||||
@@ -7,10 +7,6 @@ of datasets associated with the same dbkey to display. Once selected, jobs
|
||||
are started to create any necessary indexes in the background, and the user
|
||||
is redirected to the browser interface, which loads the appropriate datasets.
|
||||
|
||||
Problems
|
||||
--------
|
||||
- Must have a LEN file, not currently able to infer from data (not sure we
|
||||
need to support that, but need to make user defined build support better)
|
||||
"""
|
||||
|
||||
import math, re, logging, glob, pkg_resources
|
||||
@@ -88,12 +84,6 @@ class DatasetSelectionGrid( grids.Grid ):
|
||||
.filter( model.HistoryDatasetAssociation.deleted == False )
|
||||
|
||||
class TracksterSelectionGrid( grids.Grid ):
|
||||
# class DbKeyColumn( grids.GridColumn ):
|
||||
# def filter( self, trans, user, query, dbkey ):
|
||||
# """ Filter by dbkey. """
|
||||
# # use raw SQL b/c metadata is a BLOB
|
||||
# dbkey = dbkey.replace("'", "\\'")
|
||||
# return query.filter( or_( "metadata like '%%\"dbkey\": [\"%s\"]%%'" % dbkey, "metadata like '%%\"dbkey\": \"%s\"%%'" % dbkey ) )
|
||||
|
||||
# Grid definition.
|
||||
title = "Insert into visualization"
|
||||
@@ -105,7 +95,8 @@ class TracksterSelectionGrid( grids.Grid ):
|
||||
use_async = True
|
||||
use_paging = False
|
||||
columns = [
|
||||
grids.TextColumn( "Title", key="title", model_class=model.Visualization )
|
||||
grids.TextColumn( "Title", key="title", model_class=model.Visualization ),
|
||||
grids.TextColumn( "Dbkey", key="dbkey", model_class=model.Visualization )
|
||||
]
|
||||
columns.append(
|
||||
grids.MulticolFilterColumn( "Search", cols_to_filter=[ columns[0] ],
|
||||
@@ -138,15 +129,16 @@ class TracksController( BaseController, UsesVisualization ):
|
||||
|
||||
@web.expose
|
||||
@web.require_login()
|
||||
def index( self, trans ):
|
||||
def index( self, trans, **kwargs ):
|
||||
config = {}
|
||||
|
||||
return trans.fill_template( "tracks/browser.mako", config=config )
|
||||
return trans.fill_template( "tracks/browser.mako", config=config, add_dataset=kwargs.get("dataset_id", None), \
|
||||
default_dbkey=kwargs.get("default_dbkey", None) )
|
||||
|
||||
@web.expose
|
||||
@web.require_login()
|
||||
def new_browser( self, trans ):
|
||||
return trans.fill_template( "tracks/new_browser.mako", dbkeys=self._get_dbkeys( trans ) )
|
||||
def new_browser( self, trans, **kwargs ):
|
||||
return trans.fill_template( "tracks/new_browser.mako", dbkeys=self._get_dbkeys( trans ), default_dbkey=kwargs.get("default_dbkey", None) )
|
||||
|
||||
@web.json
|
||||
@web.require_login()
|
||||
@@ -204,7 +196,7 @@ class TracksController( BaseController, UsesVisualization ):
|
||||
visualization = self.get_visualization( trans, vis_id, check_ownership=False, check_accessible=True )
|
||||
visualization.config = self.get_visualization_config( trans, visualization )
|
||||
vis_user = visualization.user
|
||||
vis_dbkey = visualization.config['dbkey']
|
||||
vis_dbkey = visualization.dbkey
|
||||
else:
|
||||
# No vis_id, so visualization is new. User is current user, dbkey must be given.
|
||||
vis_user = trans.user
|
||||
@@ -330,6 +322,7 @@ class TracksController( BaseController, UsesVisualization ):
|
||||
vis.user = trans.user
|
||||
vis.title = kwargs['vis_title']
|
||||
vis.type = "trackster"
|
||||
vis.dbkey = dbkey
|
||||
session.add( vis )
|
||||
else:
|
||||
decoded_id = trans.security.decode_id( vis_id )
|
||||
@@ -339,6 +332,7 @@ class TracksController( BaseController, UsesVisualization ):
|
||||
vis_rev = model.VisualizationRevision()
|
||||
vis_rev.visualization = vis
|
||||
vis_rev.title = vis.title
|
||||
vis_rev.dbkey = dbkey
|
||||
tracks = []
|
||||
for track in decoded_payload:
|
||||
tracks.append( { "dataset_id": str(track['dataset_id']),
|
||||
@@ -346,7 +340,7 @@ class TracksController( BaseController, UsesVisualization ):
|
||||
"track_type": track['track_type'],
|
||||
"prefs": track['prefs']
|
||||
} )
|
||||
vis_rev.config = { "dbkey": dbkey, "tracks": tracks }
|
||||
vis_rev.config = { "tracks": tracks }
|
||||
vis.latest_revision = vis_rev
|
||||
session.add( vis_rev )
|
||||
session.flush()
|
||||
|
||||
@@ -14,7 +14,7 @@ class VisualizationListGrid( grids.Grid ):
|
||||
columns = [
|
||||
grids.TextColumn( "Title", key="title", model_class=model.Visualization, attach_popup=True,
|
||||
link=( lambda item: dict( controller="tracks", action="browser", id=item.id ) ) ),
|
||||
grids.TextColumn( "Type", key="type", model_class=model.Visualization ),
|
||||
grids.TextColumn( "Dbkey", key="dbkey", model_class=model.Visualization ),
|
||||
grids.IndividualTagsColumn( "Tags", "tags", model.Visualization, model.VisualizationTagAssociation, filterable="advanced", grid_name="VisualizationListGrid" ),
|
||||
grids.SharingStatusColumn( "Sharing", key="sharing", model_class=model.Visualization, filterable="advanced", sortable=False ),
|
||||
grids.GridColumn( "Created", key="create_time", format=time_ago ),
|
||||
|
||||
@@ -559,18 +559,19 @@ $(".trackster-add").live("click", function() {
|
||||
dataset_jquery = $(this);
|
||||
$.ajax({
|
||||
url: dataset_jquery.attr("data-url"),
|
||||
data: { "f-dbkey": "hi" },
|
||||
dataType: "html",
|
||||
error: function() { alert( "Could not add this dataset to browser." ); },
|
||||
success: function(table_html) {
|
||||
var parent = window.parent;
|
||||
parent.show_modal("Add to Browser:", table_html, {
|
||||
"Insert Dataset Into": function() {
|
||||
"Insert into selected": function() {
|
||||
$(parent.document).find('input[name=id]:checked').each(function() {
|
||||
var vis_id = $(this).val();
|
||||
parent.location = dataset_jquery.attr("action-url") + "&id=" + vis_id;
|
||||
});
|
||||
parent.hide_modal();
|
||||
},
|
||||
"Insert into new browser": function() {
|
||||
parent.location = dataset_jquery.attr("new-url");
|
||||
},
|
||||
"Cancel": function() {
|
||||
parent.hide_modal();
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -120,7 +120,8 @@
|
||||
<a href="${h.url_for( controller='tool_runner', action='rerun', id=data.id )}" target="galaxy_main" title="Run this job again" class="icon-button arrow-circle tooltip"></a>
|
||||
%if app.config.get_bool( 'enable_tracks', False ) and data.ext in app.datatypes_registry.get_available_tracks():
|
||||
<a data-url="${h.url_for( controller='tracks', action='list_tracks' )}" class="icon-button vis-chart tooltip trackster-add"
|
||||
action-url="${h.url_for( controller='tracks', action='browser', dataset_id=dataset_id)}" title="Visualize in Trackster"></a>
|
||||
action-url="${h.url_for( controller='tracks', action='browser', dataset_id=dataset_id)}"
|
||||
new-url="${h.url_for( controller='tracks', action='index', dataset_id=dataset_id, default_dbkey=data.dbkey)}" title="Visualize in Trackster"></a>
|
||||
%endif
|
||||
%if trans.user:
|
||||
<div style="float: right">
|
||||
|
||||
@@ -94,7 +94,7 @@ ${h.js( "galaxy.base", "galaxy.panels", "json2", "jquery", "jquery.event.drag",
|
||||
hide_modal();
|
||||
};
|
||||
$.ajax({
|
||||
url: "${h.url_for( action='new_browser' )}",
|
||||
url: "${h.url_for( action='new_browser', default_dbkey=default_dbkey )}",
|
||||
data: {},
|
||||
error: function() { alert( "Couldn't create new browser" ) },
|
||||
success: function(form_html) {
|
||||
@@ -126,10 +126,6 @@ ${h.js( "galaxy.base", "galaxy.panels", "json2", "jquery", "jquery.event.drag",
|
||||
|
||||
// Execute initializer for EDITOR specific javascript
|
||||
function init() {
|
||||
%if add_dataset:
|
||||
console.log("Adding dataset");
|
||||
## Code for adding new dataset
|
||||
%endif
|
||||
|
||||
if (view.num_tracks === 0) {
|
||||
$("#no-tracks").show();
|
||||
@@ -148,6 +144,27 @@ ${h.js( "galaxy.base", "galaxy.panels", "json2", "jquery", "jquery.event.drag",
|
||||
return "There are unsaved changes to your visualization which will be lost.";
|
||||
}
|
||||
};
|
||||
|
||||
var add_async_success = function(track_data) {
|
||||
var td = track_data,
|
||||
track_types = { "LineTrack": LineTrack, "FeatureTrack": FeatureTrack, "ReadTrack": ReadTrack },
|
||||
new_track = new track_types[track_data.track_type]( track_data.name, view, track_data.dataset_id, track_data.prefs);
|
||||
|
||||
view.add_track(new_track);
|
||||
view.has_changes = true;
|
||||
$("#no-tracks").hide();
|
||||
sidebar_box(new_track);
|
||||
};
|
||||
|
||||
%if add_dataset is not None:
|
||||
$.ajax( {
|
||||
url: "${h.url_for( action='add_track_async' )}",
|
||||
data: { id: "${add_dataset}" },
|
||||
dataType: "json",
|
||||
success: add_async_success
|
||||
});
|
||||
|
||||
%endif
|
||||
|
||||
// Use a popup grid to add more tracks
|
||||
$("#add-track").bind( "click", function(e) {
|
||||
@@ -164,17 +181,7 @@ ${h.js( "galaxy.base", "galaxy.panels", "json2", "jquery", "jquery.event.drag",
|
||||
url: "${h.url_for( action='add_track_async' )}",
|
||||
data: { id: item_id },
|
||||
dataType: "json",
|
||||
error: function() {},
|
||||
success: function(track_data) {
|
||||
var td = track_data,
|
||||
track_types = { "LineTrack": LineTrack, "FeatureTrack": FeatureTrack, "ReadTrack": ReadTrack },
|
||||
new_track = new track_types[track_data.track_type]( track_data.name, view, track_data.dataset_id, track_data.prefs);
|
||||
|
||||
view.add_track(new_track);
|
||||
view.has_changes = true;
|
||||
$("#no-tracks").hide();
|
||||
sidebar_box(new_track);
|
||||
}
|
||||
success: add_async_success
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -21,4 +21,10 @@
|
||||
Is your build not listed here?
|
||||
<a href="${h.url_for( controller='user', action='dbkeys', panels=True )}">Add a Custom Build</a>
|
||||
</div>
|
||||
%if default_dbkey is not None:
|
||||
<script type="text/javascript">
|
||||
console.log("${default_dbkey}");
|
||||
$("#new-dbkey option[value='${default_dbkey}']").attr("selected", true);
|
||||
</script>
|
||||
%endif
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user