Commit 81a66247 authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Fix file extention for local files client-side, Implements #42

parent 562e7c3d
String.prototype.rsplit = function(sep, maxsplit) {
let split = this.split(sep);
return maxsplit ? [ split.slice(0, -maxsplit).join(sep) ].concat(split.slice(-maxsplit)) : split;
};
\ No newline at end of file
......@@ -4,9 +4,11 @@ if (!dgenies) {
dgenies.run = {};
// Init global variables:
dgenies.run.allowed_ext = [];
dgenies.run.files = [undefined, undefined];
dgenies.run.init = function () {
dgenies.run.init = function (allowed_ext) {
dgenies.run.allowed_ext = allowed_ext;
dgenies.run.restore_form();
dgenies.run.set_events();
dgenies.run.init_fileuploads();
......@@ -36,11 +38,23 @@ dgenies.run.__upload_server_error = function(fasta, data) {
dgenies.run.enable_form();
};
dgenies.run.allowed_file = function (filename) {
return filename.indexOf('.') !== -1 &&
(dgenies.run.allowed_ext.indexOf(filename.rsplit('.', 1)[1].toLowerCase()) !== -1 ||
dgenies.run.allowed_ext.indexOf(filename.rsplit('.', 2).splice(1).join(".").toLowerCase()) !== -1);
};
dgenies.run.init_fileuploads = function () {
$('input.file-query').fileupload({
dataType: 'json',
add: function (e, data) {
dgenies.run.files[0] = data;
let filename = data.files[0].name
if (dgenies.run.allowed_file(filename))
dgenies.run.files[0] = data;
else {
$("input.file-query").trigger("change"); // The value is null after fired
dgenies.notify(`File ${filename} is not supported!`, "error", 3000)
}
},
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
......@@ -72,7 +86,13 @@ dgenies.run.init_fileuploads = function () {
dataType: 'json',
formData: {folder: dgenies.run.upload_folder},
add: function (e, data) {
dgenies.run.files[1] = data;
let filename = data.files[0].name
if (dgenies.run.allowed_file(filename))
dgenies.run.files[1] = data;
else {
$("input.file-target").trigger("change"); // The value is null after fired
dgenies.notify(`File ${filename} is not supported!`, "error", 3000)
}
},
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
......
......@@ -8,7 +8,7 @@ from flask import Flask, render_template, request, url_for, jsonify, session
from lib.paf import Paf
from config_reader import AppConfigReader
from lib.job_manager import JobManager
from lib.functions import Functions
from lib.functions import Functions, ALLOWED_EXTENSIONS
from lib.upload_file import UploadFile
from lib.Fasta import Fasta
......@@ -60,7 +60,7 @@ def run():
if "email" in request.args:
email = request.args["email"]
return render_template("run.html", title=app_title, id_job=id_job, email=email,
menu="run")
menu="run", allowed_ext=ALLOWED_EXTENSIONS)
# Launch analysis
......
......@@ -10,6 +10,7 @@
<script src="{{ url_for('static', filename='js/bootstrap.min.js') }}" type="text/JavaScript"></script>
<script src="{{ url_for('static', filename='js/notify.min.js') }}" type="text/JavaScript"></script>
<script src="{{ url_for('static', filename='js/dgenies.js') }}" type="text/JavaScript"></script>
<script src="{{ url_for('static', filename='js/dgenies.prototypes.js') }}" type="text/JavaScript"></script>
{% endblock %}
<link rel="stylesheet" href="{{ url_for('static', filename='css/jquery-ui.min.css') }}" type="text/css">
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css') }}" type="text/css">
......
......@@ -9,7 +9,7 @@
<script src="{{ url_for('static', filename='js/jquery.fileupload-validate.js') }}"></script>
<script src="{{ url_for('static', filename='js/dgenies.run.js') }}" type="text/JavaScript"></script>
{% endblock %}
{% block onload %}dgenies.run.init();{% endblock %}
{% block onload %}dgenies.run.init({{ allowed_ext }});{% endblock %}
{% block content %}
<form id="submit_minimap" method=post action="#">
<h2 class="title-launch">Launch map analysis</h2>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment