/
analysis.js
194 lines (171 loc) · 6.97 KB
/
analysis.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
var jQuery = require( 'jquery' ),
$ = jQuery,
GalaxyApp = require( 'galaxy' ).GalaxyApp,
QUERY_STRING = require( 'utils/query-string-parsing' ),
ToolPanel = require( './panels/tool-panel' ),
HistoryPanel = require( './panels/history-panel' ),
Page = require( 'layout/page' ),
ToolForm = require( 'mvc/tool/tool-form' ),
UserPreferences = require( 'mvc/user/user-preferences' ),
CustomBuilds = require( 'mvc/user/user-custom-builds' ),
Tours = require( 'mvc/tours' ),
Workflows = require( 'mvc/workflow/workflow' );
/** define the 'Analyze Data'/analysis/main/home page for Galaxy
* * has a masthead
* * a left tool menu to allow the user to load tools in the center panel
* * a right history menu that shows the user's current data
* * a center panel
* Both panels (generally) persist while the center panel shows any
* UI needed for the current step of an analysis, like:
* * tool forms to set tool parameters,
* * tables showing the contents of datasets
* * etc.
*/
window.app = function app( options, bootstrapped ){
window.Galaxy = new GalaxyApp( options, bootstrapped );
Galaxy.debug( 'analysis app' );
Galaxy.params = Galaxy.config.params;
var routingMessage = Backbone.View.extend({
initialize: function(options) {
this.message = options.message || "Undefined Message";
this.msg_status = options.type || 'info';
this.render();
},
render: function(){
this.$el.html(_.escape(this.message)).addClass(this.msg_status + "message");
}
});
/** Routes */
var Router = Backbone.Router.extend({
// TODO: not many client routes at this point - fill and remove from server.
// since we're at root here, this may be the last to be routed entirely on the client.
initialize : function( page, options ){
this.page = page;
this.options = options;
},
/** helper to push a new navigation state */
push: function( url, data ) {
data = data || {};
data.__identifer = Math.random().toString( 36 ).substr( 2 );
if ( !$.isEmptyObject( data ) ) {
url += url.indexOf( '?' ) == -1 ? '?' : '&';
url += $.param( data , true );
}
this.navigate( url, { 'trigger': true } );
},
/** override to parse query string into obj and send to each route */
execute: function( callback, args, name ){
Galaxy.debug( 'router execute:', callback, args, name );
var queryObj = QUERY_STRING.parse( args.pop() );
args.push( queryObj );
if( callback ){
if ( this.authenticate( args, name ) ) {
callback.apply( this, args );
} else {
this.loginRequired();
}
}
},
routes : {
'(/)' : 'home',
'(/)root*' : 'home',
'(/)tours(/)(:tour_id)' : 'show_tours',
'(/)user(/)' : 'show_user',
'(/)user(/)(:form_id)' : 'show_user_form',
'(/)workflow(/)' : 'show_workflows',
'(/)custom_builds' : 'show_custom_builds',
'(/)workflow/run(/)' : 'show_run',
'(/)workflow/import_workflow' : 'show_import_workflow',
},
require_login: [
'show_user',
'show_user_form'
],
loginRequired: function() {
this.page.display( new routingMessage({type: 'error', message: "You must be logged in to make this request."}) );
},
authenticate: function( args, name ) {
return ( Galaxy.user && Galaxy.user.id ) || this.require_login.indexOf( name ) == -1;
},
show_tours : function( tour_id ){
if ( tour_id ){
Tours.giveTour( tour_id );
} else {
this.page.display( new Tours.ToursView() );
}
},
show_user : function(){
this.page.display( new UserPreferences.View() );
},
show_user_form : function( form_id ) {
this.page.display( new UserPreferences.Forms( { form_id: form_id, user_id: Galaxy.params.id } ) );
},
show_workflows : function(){
this.page.display( new Workflows.View() );
},
show_run : function() {
this.page.display( new Workflows.Run_Workflow_View() );
},
show_import_workflow : function() {
this.page.display( new Workflows.Import_Workflow_View() );
},
show_custom_builds : function() {
var self = this;
var historyPanel = this.page.historyPanel.historyView;
if ( !historyPanel || !historyPanel.model || !historyPanel.model.id ) {
window.setTimeout(function() { self.show_custom_builds() }, 500)
return;
}
this.page.display( new CustomBuilds.View() );
},
/** */
home : function( params ){
// TODO: to router, remove Globals
// load a tool by id (tool_id) or rerun a previous tool execution (job_id)
if( params.tool_id || params.job_id ) {
if ( params.tool_id === 'upload1' ) {
this.page.toolPanel.upload.show();
this._loadCenterIframe( 'welcome' );
} else {
this._loadToolForm( params );
}
} else {
// show the workflow run form
if( params.workflow_id ){
this.page.display( new Workflows.Run_Workflow_View() )
// load the center iframe with controller.action: galaxy.org/?m_c=history&m_a=list -> history/list
} else if( params.m_c ){
this._loadCenterIframe( params.m_c + '/' + params.m_a );
// show the workflow run form
} else {
this._loadCenterIframe( 'welcome' );
}
}
},
/** load the center panel with a tool form described by the given params obj */
_loadToolForm : function( params ){
//TODO: load tool form code async
params.id = params.tool_id;
this.page.display( new ToolForm.View( params ) );
},
/** load the center panel iframe using the given url */
_loadCenterIframe : function( url, root ){
root = root || Galaxy.root;
url = root + url;
this.page.$( '#galaxy_main' ).prop( 'src', url );
},
});
// render and start the router
$(function(){
Galaxy.page = new Page.View( _.extend( options, {
Left : ToolPanel,
Right : HistoryPanel,
Router : Router
} ) );
// start the router - which will call any of the routes above
Backbone.history.start({
root : Galaxy.root,
pushState : true,
});
});
};