forked from galaxyproject/galaxy
/
composite-view.js
211 lines (196 loc) · 7.3 KB
/
composite-view.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
/** Renders contents of the composite uploader */
import _l from "utils/localization";
import _ from "underscore";
import $ from "jquery";
import Backbone from "backbone";
import { getGalaxyInstance } from "app";
// import Utils from "utils/utils";
import UploadModel from "mvc/upload/upload-model";
import UploadRow from "mvc/upload/composite/composite-row";
import UploadExtension from "mvc/upload/upload-extension";
import Select from "mvc/ui/ui-select";
import Ui from "mvc/ui/ui-misc";
export default Backbone.View.extend({
collection: new UploadModel.Collection(),
initialize: function(app) {
var self = this;
this.app = app;
this.options = app.options;
this.list_extensions = app.list_extensions;
this.list_genomes = app.list_genomes;
this.ftp_upload_site = app.currentFtp();
this.setElement(this._template());
// create button section
this.btnStart = new Ui.Button({
title: _l("Start"),
onclick: function() {
self._eventStart();
}
});
this.btnClose = new Ui.Button({
title: _l("Close"),
onclick: function() {
self.app.modal.hide();
}
});
// append buttons to dom
_.each([this.btnStart, this.btnClose], button => {
self.$(".upload-buttons").prepend(button.$el);
});
// select extension
this.select_extension = new Select.View({
css: "upload-footer-selection",
container: this.$(".upload-footer-extension"),
data: _.filter(this.list_extensions, ext => ext.composite_files),
onchange: function(extension) {
self.collection.reset();
var details = _.findWhere(self.list_extensions, {
id: extension
});
if (details && details.composite_files) {
_.each(details.composite_files, item => {
self.collection.add({
id: self.collection.size(),
file_desc: item.description || item.name
});
});
}
}
});
// handle extension info popover
this.$(".upload-footer-extension-info")
.on("click", e => {
new UploadExtension({
$el: $(e.target),
title: self.select_extension.text(),
extension: self.select_extension.value(),
list: self.list_extensions,
placement: "top"
});
})
.on("mousedown", e => {
e.preventDefault();
});
// genome extension
this.select_genome = new Select.View({
css: "upload-footer-selection",
container: this.$(".upload-footer-genome"),
data: this.list_genomes,
value: this.options.default_genome
});
// listener for collection triggers on change in composite datatype and extension selection
this.listenTo(this.collection, "add", model => {
self._eventAnnounce(model);
});
this.listenTo(this.collection, "change add", () => {
self.render();
});
this.select_extension.options.onchange(this.select_extension.value());
this.render();
},
render: function() {
var model = this.collection.first();
if (model && model.get("status") == "running") {
this.select_genome.disable();
this.select_extension.disable();
} else {
this.select_genome.enable();
this.select_extension.enable();
}
if (this.collection.where({ status: "ready" }).length == this.collection.length && this.collection.length > 0) {
this.btnStart.enable();
this.btnStart.$el.addClass("btn-primary");
} else {
this.btnStart.disable();
this.btnStart.$el.removeClass("btn-primary");
}
this.$(".upload-table")[this.collection.length > 0 ? "show" : "hide"]();
},
//
// upload events / process pipeline
//
/** Builds the basic ui with placeholder rows for each composite data type file */
_eventAnnounce: function(model) {
var upload_row = new UploadRow(this, { model: model });
this.$(".upload-table > tbody:first").append(upload_row.$el);
this.$(".upload-table")[this.collection.length > 0 ? "show" : "hide"]();
upload_row.render();
},
/** Start upload process */
_eventStart: function() {
var self = this;
this.collection.each(model => {
model.set({
genome: self.select_genome.value(),
extension: self.select_extension.value()
});
});
$.uploadpost({
url: this.app.options.upload_path,
data: this.app.toData(this.collection.filter()),
success: function(message) {
self._eventSuccess(message);
},
error: function(message) {
self._eventError(message);
},
progress: function(percentage) {
self._eventProgress(percentage);
}
});
},
/** Refresh progress state */
_eventProgress: function(percentage) {
this.collection.each(it => {
it.set("percentage", percentage);
});
},
/** Refresh success state */
_eventSuccess: function(message) {
let Galaxy = getGalaxyInstance();
this.collection.each(it => {
it.set("status", "success");
});
Galaxy.currHistoryPanel.refreshContents();
},
/** Refresh error state */
_eventError: function(message) {
this.collection.each(it => {
it.set({ status: "error", info: message });
});
},
/** Load html template */
_template: function() {
return (
`<div class="upload-view-composite">
<div class="upload-top">
<div class="upload-top-info"> </div>
</div>
<div class="upload-box">
<table class="upload-table ui-table-striped" style="display: none;">
<thead>
<tr>
<th/>
<th/>
<th>Description</th>
<th>Name</th>
<th>Size</th>
<th>Settings</th>
<th>Status</th>
</tr>
</thead>
<tbody/>
</table>
</div>
<div class="upload-footer">
<span class="upload-footer-title">Composite Type:</span>
<span class="upload-footer-extension"/>
<span class="upload-footer-extension-info upload-icon-button fa fa-search"/>
<span class="upload-footer-title">Genome/Build:</span>
<span class="upload-footer-genome"/>
</div>
<div class="upload-buttons"/>
</div>`
);
}
});