forked from galaxyproject/galaxy
/
default-row.js
316 lines (291 loc) · 11.1 KB
/
default-row.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
/** Renders the default uploader rows */
import $ from "jquery";
import _ from "underscore";
import Backbone from "backbone";
import _l from "utils/localization";
import Utils from "utils/utils";
import UploadSettings from "mvc/upload/upload-settings";
import Popover from "mvc/ui/ui-popover";
import UploadExtension from "mvc/upload/upload-extension";
import Select from "mvc/ui/ui-select";
export default Backbone.View.extend({
/** Dictionary of upload states and associated icons */
status_classes: {
init: "upload-icon-button fa fa-trash-o",
queued: "upload-icon fa fa-spinner fa-spin",
running: "upload-icon fa fa-spinner fa-spin",
warning: "upload-icon fa fa-spinner fa-spin",
success: "upload-icon-button fa fa-check",
error: "upload-icon-button fa fa-exclamation-triangle"
},
initialize: function(app, options) {
var self = this;
this.app = app;
this.list_extensions = app.list_extensions;
this.model = options.model;
this.setElement(this._template(options.model));
this.$mode = this.$(".upload-mode");
this.$title = this.$(".upload-title");
this.$text = this.$(".upload-text");
this.$size = this.$(".upload-size");
this.$info_text = this.$(".upload-info-text");
this.$info_progress = this.$(".upload-info-progress");
this.$text_content = this.$(".upload-text-content");
this.$settings = this.$(".upload-settings");
this.$symbol = this.$(".upload-symbol");
this.$progress_bar = this.$(".upload-progress-bar");
this.$percentage = this.$(".upload-percentage");
// append popup to settings icon
this.settings = new Popover({
title: _l("Upload configuration"),
container: this.$(".upload-settings"),
placement: "bottom"
});
// identify default genome and extension values
var default_genome = this.app.select_genome.value();
var default_extension = this.app.select_extension.value();
// create select genomes
this.select_genome = new Select.View({
css: "upload-genome",
data: self.app.list_genomes,
container: this.$(".upload-genome"),
value: default_genome,
onchange: function(genome) {
self.model.set("genome", genome);
}
});
// create select extension
this.select_extension = new Select.View({
css: "upload-extension",
data: _.filter(this.list_extensions, ext => !ext.composite_files),
container: this.$(".upload-extension"),
value: default_extension,
onchange: function(extension) {
self.model.set("extension", extension);
}
});
// initialize genome and extension values
this.model.set({
genome: default_genome,
extension: default_extension
});
// handle click event
this.$symbol.on("click", () => {
self._removeRow();
});
// handle extension info popover
this.$(".upload-extension-info")
.on("click", e => {
let upload_ext = this.upload_extension;
if (upload_ext) {
if (upload_ext.extension_popup.visible) {
upload_ext.extension_popup.hide();
} else {
upload_ext.extension_popup.remove();
this._makeUploadExtensionsPopover(e);
}
} else {
this._makeUploadExtensionsPopover(e);
}
})
.on("mousedown", e => {
e.preventDefault();
});
// handle settings popover
this.$settings
.on("click", e => {
self._showSettings();
})
.on("mousedown", e => {
e.preventDefault();
});
// handle text editing event
this.$text_content.on("change input", e => {
self.model.set({
url_paste: $(e.target).val(),
file_size: $(e.target).val().length
});
});
// handle text editing event
this.$title.on("change input", e => {
self.model.set({ file_name: $(e.target).val() });
});
// model events
this.listenTo(this.model, "change:percentage", () => {
self._refreshPercentage();
});
this.listenTo(this.model, "change:status", () => {
self._refreshStatus();
});
this.listenTo(this.model, "change:info", () => {
self._refreshInfo();
});
this.listenTo(this.model, "change:genome", () => {
self._refreshGenome();
});
this.listenTo(this.model, "change:extension", () => {
self._refreshExtension();
});
this.listenTo(this.model, "change:file_size", () => {
self._refreshFileSize();
});
},
render: function() {
this._refreshType();
this._refreshPercentage();
this._refreshStatus();
this._refreshInfo();
this._refreshGenome();
this._refreshExtension();
this._refreshFileSize();
},
/** Remove view */
remove: function() {
this.select_genome.remove();
this.select_extension.remove();
Backbone.View.prototype.remove.apply(this);
},
/** Render type */
_refreshType: function() {
var options = this.model.attributes;
this.$title.val(_.escape(options.file_name));
this.$size.html(Utils.bytesToString(options.file_size));
this.$mode
.removeClass()
.addClass("upload-mode")
.addClass("text-primary");
if (options.file_mode == "new") {
this.$text
.css({
width: `${this.$el.width() - 16}px`,
top: `${this.$el.height() - 8}px`
})
.show();
this.$el.height(this.$el.height() - 8 + this.$text.height() + 16);
this.$mode.addClass("fa fa-edit");
} else if (options.file_mode == "local") {
this.$mode.addClass("fa fa-laptop");
} else if (options.file_mode == "ftp") {
this.$mode.addClass("fa fa-folder-open-o");
}
},
/** Update extension */
_refreshExtension: function() {
this.select_extension.value(this.model.get("extension"));
},
/** Update genome */
_refreshGenome: function() {
this.select_genome.value(this.model.get("genome"));
},
/** Refresh info text */
_refreshInfo: function() {
var info = this.model.get("info");
if (info) {
this.$info_text.html(`<strong>Warning: </strong>${info}`).show();
} else {
this.$info_text.hide();
}
},
/** Refresh percentage status */
_refreshPercentage: function() {
var percentage = parseInt(this.model.get("percentage"));
this.$progress_bar.css({ width: `${percentage}%` });
this.$percentage.html(percentage != 100 ? `${percentage}%` : "Adding to history...");
},
/** Refresh status */
_refreshStatus: function() {
var status = this.model.get("status");
this.$symbol
.removeClass()
.addClass("upload-symbol")
.addClass(this.status_classes[status]);
this.model.set("enabled", status == "init");
var enabled = this.model.get("enabled");
this.$text_content.attr("disabled", !enabled);
this.$title.attr("disabled", !enabled);
if (enabled) {
this.select_genome.enable();
this.select_extension.enable();
} else {
this.select_genome.disable();
this.select_extension.disable();
}
this.$info_progress.show();
this.$el.removeClass().addClass("upload-row");
if (status == "success") {
this.$el.addClass("table-success");
this.$percentage.html("100%");
} else if (status == "error") {
this.$el.addClass("table-danger");
this.$info_progress.hide();
} else if (status == "warning") {
this.$el.addClass("table-warning");
this.$info_progress.hide();
}
},
/** Refresh file size */
_refreshFileSize: function() {
this.$size.html(Utils.bytesToString(this.model.get("file_size")));
},
/** Remove row */
_removeRow: function() {
if (["init", "success", "error"].indexOf(this.model.get("status")) !== -1) {
this.app.collection.remove(this.model);
}
},
/** Attach file info popup */
_showSettings: function() {
this.settings.show(new UploadSettings(this).$el);
},
/** Make extension popover */
_makeUploadExtensionsPopover: function(e) {
this.upload_extension = new UploadExtension({
$el: $(e.target),
title: this.select_extension.text(),
extension: this.select_extension.value(),
list: this.list_extensions
});
},
/** View template */
_template: function(options) {
return `<tr id="upload-row-${options.id}" class="upload-row">
<td>
<div class="upload-text-column">
<div class="upload-mode"/>
<input class="upload-title ml-2 border rounded"/>
<div class="upload-text">
<div class="upload-text-info">
Download data from the web by entering URLs (one per line) or directly paste content.
</div>
<textarea class="upload-text-content form-control"/>
</div>
</div>
</td>
<td>
<div class="upload-size"/>
</td>
<td>
<div class="upload-extension float-left mr-1"/>
<div class="upload-extension-info upload-icon-button fa fa-search"/>
</td>
<td>
<div class="upload-genome"/>
</td>
<td>
<div class="upload-settings upload-icon-button fa fa-gear"/>
</td>
<td>
<div class="upload-info">
<div class="upload-info-text"/>
<div class="upload-info-progress progress">
<div class="upload-progress-bar progress-bar progress-bar-success"/>
<div class="upload-percentage">0%</div>
</div>
</div>
</td>
<td>
<div class="upload-symbol ${this.status_classes.init}"/>
</td>
</tr>`;
}
});