/
analysis.js
412 lines (373 loc) · 15 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
import $ from "jquery";
import "bootstrap";
import * as _ from "underscore";
import decodeUriComponent from "decode-uri-component";
import GalaxyApp from "galaxy";
import Router from "layout/router";
import ToolPanel from "./panels/tool-panel";
import HistoryPanel from "./panels/history-panel";
import Page from "layout/page";
import ToolForm from "mvc/tool/tool-form";
import FormWrapper from "mvc/form/form-wrapper";
import Sharing from "components/Sharing.vue";
import UserPreferences from "mvc/user/user-preferences";
import CustomBuilds from "mvc/user/user-custom-builds";
import Tours from "mvc/tours";
import GridView from "mvc/grid/grid-view";
import GridShared from "mvc/grid/grid-shared";
import Workflows from "mvc/workflow/workflow";
import WorkflowImport from "components/WorkflowImport.vue";
import HistoryImport from "components/HistoryImport.vue";
import HistoryView from "components/HistoryView.vue";
import HistoryList from "mvc/history/history-list";
import PluginList from "components/PluginList.vue";
import ToolFormComposite from "mvc/tool/tool-form-composite";
import QueryStringParsing from "utils/query-string-parsing";
import Utils from "utils/utils";
import Ui from "mvc/ui/ui-misc";
import DatasetError from "mvc/dataset/dataset-error";
import DatasetEditAttributes from "mvc/dataset/dataset-edit-attributes";
import Citations from "components/Citations.vue";
import DisplayStructure from "components/DisplayStructured.vue";
import Vue from "vue";
/* global Galaxy */
/** 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.GalaxyApp(options, bootstrapped);
Galaxy.debug("analysis app");
/** Routes */
var AnalysisRouter = Router.extend({
routes: {
"(/)(#)(_=_)": "home",
"(/)root*": "home",
"(/)tours(/)(:tour_id)": "show_tours",
"(/)user(/)": "show_user",
"(/)user(/)(:form_id)": "show_user_form",
"(/)openids(/)list": "show_openids",
"(/)pages(/)create(/)": "show_pages_create",
"(/)pages(/)edit(/)": "show_pages_edit",
"(/)pages(/)sharing(/)": "show_pages_sharing",
"(/)pages(/)(:action_id)": "show_pages",
"(/)visualizations(/)": "show_plugins",
"(/)visualizations(/)edit(/)": "show_visualizations_edit",
"(/)visualizations(/)sharing(/)": "show_visualizations_sharing",
"(/)visualizations/(:action_id)": "show_visualizations",
"(/)workflows/import": "show_workflows_import",
"(/)workflows/run(/)": "show_workflows_run",
"(/)workflows(/)list": "show_workflows",
"(/)workflows/list_published(/)": "show_workflows_published",
"(/)workflows/create(/)": "show_workflows_create",
"(/)histories(/)citations(/)": "show_history_citations",
"(/)histories(/)rename(/)": "show_histories_rename",
"(/)histories(/)sharing(/)": "show_histories_sharing",
"(/)histories(/)import(/)": "show_histories_import",
"(/)histories(/)permissions(/)": "show_histories_permissions",
"(/)histories/view": "show_history_view",
"(/)histories/show_structure": "show_history_structure",
"(/)histories(/)(:action_id)": "show_histories",
"(/)datasets(/)list(/)": "show_datasets",
"(/)custom_builds": "show_custom_builds",
"(/)datasets/edit": "show_dataset_edit_attributes",
"(/)datasets/error": "show_dataset_error"
},
require_login: ["show_user", "show_user_form", "show_workflows"],
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.giveTourById(tour_id);
} else {
this.page.display(new Tours.ToursView());
}
},
show_user: function() {
this.page.display(new UserPreferences.View());
},
show_user_form: function(form_id) {
var model = new UserPreferences.Model({
user_id: Galaxy.params.id
});
this.page.display(new FormWrapper.View(_.extend(model.get(form_id), { active_tab: "user" })));
},
show_visualizations: function(action_id) {
var activeTab = action_id == "list_published" ? "shared" : "user";
this.page.display(
new GridShared.View({
action_id: action_id,
plural: "Visualizations",
item: "visualization",
active_tab: activeTab
})
);
},
show_visualizations_edit: function() {
this.page.display(
new FormWrapper.View({
url: `visualization/edit?id=${QueryStringParsing.get("id")}`,
redirect: "visualizations/list",
active_tab: "visualization"
})
);
},
show_visualizations_sharing: function() {
var sharingInstance = Vue.extend(Sharing);
var vm = document.createElement("div");
this.page.display(vm);
new sharingInstance({
propsData: {
id: QueryStringParsing.get("id"),
plural_name: "Visualizations",
model_class: "Visualization"
}
}).$mount(vm);
},
show_workflows_published: function() {
this.page.display(
new GridView({
url_base: `${Galaxy.root}workflow/list_published`,
active_tab: "shared"
})
);
},
show_history_view: function() {
var historyInstance = Vue.extend(HistoryView);
var vm = document.createElement("div");
this.page.display(vm);
new historyInstance({ propsData: { id: QueryStringParsing.get("id") } }).$mount(vm);
},
show_history_structure: function() {
let displayStructureInstance = Vue.extend(DisplayStructure);
let vm = document.createElement("div");
this.page.display(vm);
new displayStructureInstance({ propsData: { id: QueryStringParsing.get(" id: ") } }).$mount(vm);
},
show_histories: function(action_id) {
this.page.display(new HistoryList.View({ action_id: action_id }));
},
show_history_citations: function() {
var citationInstance = Vue.extend(Citations);
var vm = document.createElement("div");
this.page.display(vm);
new citationInstance({ propsData: { id: QueryStringParsing.get("id"), source: "histories" } }).$mount(vm);
},
show_histories_rename: function() {
this.page.display(
new FormWrapper.View({
url: `history/rename?id=${QueryStringParsing.get("id")}`,
redirect: "histories/list"
})
);
},
show_histories_sharing: function() {
var sharingInstance = Vue.extend(Sharing);
var vm = document.createElement("div");
this.page.display(vm);
new sharingInstance({
propsData: {
id: QueryStringParsing.get("id"),
plural_name: "Histories",
model_class: "History"
}
}).$mount(vm);
},
show_histories_import: function() {
var historyImportInstance = Vue.extend(HistoryImport);
var vm = document.createElement("div");
this.page.display(vm);
new historyImportInstance().$mount(vm);
},
show_histories_permissions: function() {
this.page.display(
new FormWrapper.View({
url: `history/permissions?id=${QueryStringParsing.get("id")}`,
redirect: "histories/list"
})
);
},
show_openids: function() {
this.page.display(
new GridView({
url_base: `${Galaxy.root}user/openids_list`,
active_tab: "user"
})
);
},
show_datasets: function() {
this.page.display(
new GridView({
url_base: `${Galaxy.root}dataset/list`,
active_tab: "user"
})
);
},
show_pages: function(action_id) {
var activeTab = action_id == "list_published" ? "shared" : "user";
this.page.display(
new GridShared.View({
action_id: action_id,
plural: "Pages",
item: "page",
active_tab: activeTab
})
);
},
show_pages_create: function() {
this.page.display(
new FormWrapper.View({
url: "page/create",
redirect: "pages/list",
active_tab: "user"
})
);
},
show_pages_edit: function() {
this.page.display(
new FormWrapper.View({
url: `page/edit?id=${QueryStringParsing.get("id")}`,
redirect: "pages/list",
active_tab: "user"
})
);
},
show_pages_sharing: function() {
var sharingInstance = Vue.extend(Sharing);
var vm = document.createElement("div");
this.page.display(vm);
new sharingInstance({
propsData: {
id: QueryStringParsing.get("id"),
plural_name: "Pages",
model_class: "Page"
}
}).$mount(vm);
},
show_plugins: function() {
var pluginListInstance = Vue.extend(PluginList);
var vm = document.createElement("div");
this.page.display(vm);
new pluginListInstance().$mount(vm);
},
show_workflows: function() {
this.page.display(new Workflows.View());
},
show_workflows_create: function() {
this.page.display(
new FormWrapper.View({
url: `workflow/create`,
redirect: "workflow/editor",
active_tab: "workflow"
})
);
},
show_workflows_run: function() {
this._loadWorkflow();
},
show_workflows_import: function() {
var workflowImportInstance = Vue.extend(WorkflowImport);
var vm = document.createElement("div");
this.page.display(vm);
new workflowImportInstance().$mount(vm);
},
show_custom_builds: function() {
var historyPanel = this.page.historyPanel.historyView;
if (!historyPanel || !historyPanel.model || !historyPanel.model.id) {
window.setTimeout(() => {
this.show_custom_builds();
}, 500);
return;
}
this.page.display(new CustomBuilds.View());
},
show_dataset_edit_attributes: function() {
this.page.display(new DatasetEditAttributes.View());
},
show_dataset_error: function() {
this.page.display(new DatasetError.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._loadWorkflow();
// 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
if (params.tool_id) {
params.id = decodeUriComponent(params.tool_id);
}
if (params.version) {
params.version = decodeUriComponent(params.version);
}
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);
},
/** load workflow by its url in run mode */
_loadWorkflow: function() {
Utils.get({
url: `${Galaxy.root}api/workflows/${Utils.getQueryString("id")}/download?style=run`,
success: response => {
this.page.display(new ToolFormComposite.View(_.extend(response, { active_tab: "workflow" })));
},
error: response => {
var error_msg = response.err_msg || "Error occurred while loading the resource.";
var options = {
message: error_msg,
status: "danger",
persistent: true,
active_tab: "workflow"
};
this.page.display(new Ui.Message(options));
}
});
}
});
// render and start the router
$(() => {
options.config = _.extend(options.config, {
hide_panels: Galaxy.params.hide_panels,
hide_masthead: Galaxy.params.hide_masthead
});
Galaxy.page = new Page.View(
_.extend(options, {
Left: ToolPanel,
Right: HistoryPanel,
Router: AnalysisRouter
})
);
});
};