Skip to content

Commit

Permalink
added better handling for webapp download; added timeout to ajax request
Browse files Browse the repository at this point in the history
  • Loading branch information
linxOD committed Sep 27, 2022
1 parent b61c796 commit 97aca47
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2,667 deletions.
68 changes: 38 additions & 30 deletions app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,44 @@

to_collate.setAttribute("onclick", attr);
to_collate.classList.add("btn-primary");
}

let app = document.createElement('a');
app.setAttribute("class", "btn btn-success");
app.setAttribute("id", "get_app");
app.setAttribute("href", "#");
app.setAttribute('style', 'display:block;margin-bottom:2em;');
app.style.backgroundColor = "#000";
app.style.color = "#fff";
app.innerHTML = "Create WebApp";
result2.append(app);

document.getElementById("get_app").addEventListener("click", function() {
$.ajax({
type: "POST",
url: "/html",
success: function (data3) {
let html = data3;
let filename = "index.html"
let result2 = document.getElementById('result2');
let pom = document.createElement('a');
let bb = new Blob([html], {type: 'text/plain'});

pom.setAttribute('href', window.URL.createObjectURL(bb));
pom.setAttribute('download', filename);

pom.dataset.downloadurl = ['text/plain', pom.download, pom.href].join(':');
pom.draggable = true;
pom.setAttribute('class', 'btn btn-success');
pom.setAttribute('style', 'display:block;margin-bottom:2em;');
pom.style.backgroundColor = "orange";
pom.classList.add('dragout');
pom.innerHTML = `WebApp (index.html) zur Kollationierung herunterladen`;
result2.append(pom);
}
});
});
},
timeout: 60000
});
$.ajax({
type: "POST",
Expand All @@ -116,35 +153,6 @@
pom.classList.add('dragout');
pom.innerHTML = `Konstituierten Text herunterladen (${selected.split(',')[0]})`;
result2.append(pom);

// var filename3 = "index.html"
// var pom3 = document.createElement('a');
// pom3.setAttribute('download', filename3);
// pom3.innerHTML = `KollationierungsApp (${selected.split(',')[0]}) herunterladen.´`;
// result2.append(pom3);
}
});
$.ajax({
type: "POST",
url: "/html",
success: function (data3) {
let html = data3;
let filename = "index.html"
let result2 = document.getElementById('result2');
let pom = document.createElement('a');
let bb = new Blob([html], {type: 'text/plain'});

pom.setAttribute('href', window.URL.createObjectURL(bb));
pom.setAttribute('download', filename);

pom.dataset.downloadurl = ['text/plain', pom.download, pom.href].join(':');
pom.draggable = true;
pom.setAttribute('class', 'btn btn-success');
pom.setAttribute('style', 'display:block;margin-bottom:2em;');
pom.style.backgroundColor = "orange";
pom.classList.add('dragout');
pom.innerHTML = `WebApp (index.html) zur Kollationierung herunterladen`;
result2.append(pom);
}
});
}
Expand Down
8 changes: 4 additions & 4 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ def copy_xml(save_path, path_dir, select):


def copy_html():
html = HTML
html = ET.parse(html)
h = HTML
html = ET.parse(h)
os.remove(h)
root = html.getroot()
html = ET.tostring(root, encoding="utf-8")
return html
Expand Down Expand Up @@ -163,8 +164,7 @@ def collate_tei(save_path, path_dir, select):
full_doc = merge_html_fragments(files)
with open(result_html, 'w') as f:
f.write(full_doc.prettify("utf-8").decode('utf-8'))
# result_html = full_doc.prettify("utf-8").decode('utf-8')

result_html = full_doc.prettify("utf-8").decode('utf-8')
shutil.rmtree("tmp_to_collate")
for x in glob.glob(f"{output_dir}/out__*"):
print(f"removing {x}")
Expand Down
Loading

0 comments on commit 97aca47

Please sign in to comment.