Skip to content

Commit

Permalink
removed disable selected; added handling for multiple users: collate …
Browse files Browse the repository at this point in the history
…subdir timestamp
  • Loading branch information
linxOD committed Oct 3, 2022
1 parent af74f9a commit 9d0e745
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
33 changes: 19 additions & 14 deletions app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,22 @@
var btn = document.createElement("a");
btn.setAttribute('class', 'btn btn-primary');
btn.setAttribute('id', 'to_collate');
btn.setAttribute('style', 'display:block;');
btn.setAttribute('style', 'display:block;margin-bottom:2em;');
btn.setAttribute("onclick", `collateMe('${selected}');`);
btn.innerHTML = `Mit konstituierten Text: ${manifest} Kollationierung starten`;
result2 = document.getElementById('result2');
while (result2.firstChild) {
if (result2.firstChild) {
result2.removeChild(result2.firstChild);
}
result2.append(btn);
result2.prepend(btn);
}
function collateMe(selected) {
var pom_div = document.createElement('div');
var pom_attr = `pom_div__${Date.now()}`;
pom_div.setAttribute("id", pom_attr);
var result2 = document.getElementById('result2');
result2.append(pom_div);
/*
let customSelect = document.querySelectorAll(".custom-select");
customSelect.forEach(function(el) {
el.setAttribute("disabled", "");
Expand All @@ -54,12 +60,11 @@
let attr = to_collate.getAttribute("onclick");
to_collate.removeAttribute("onclick");
to_collate.classList.remove("btn-primary");

*/
var spinner = document.createElement('p');
spinner.setAttribute('id', 'loading');
spinner.innerHTML = "Kollationierung läuft...";
var result2 = document.getElementById('result2');
result2.append(spinner);
spinner.innerHTML = `Kollationierung läuft: ${selected.split(',')[0]} ...`;
document.getElementById(pom_attr).append(spinner);
$.ajax({
type: "POST",
url: `/collate/${[selected]}`,
Expand All @@ -81,11 +86,11 @@
pom.setAttribute('class', 'btn btn-success');
pom.setAttribute('style', 'display:block;margin-bottom:2em;');
pom.innerHTML = `Kollationierung herunterladen (${selected.split(',')[0]}) `;
result2.append(pom);
document.getElementById(pom_attr).append(pom);

let loader = document.getElementById('loading');
loader.innerHTML = "Kollationierung abgeschlossen";

loader.innerHTML = `Kollationierung abgeschlossen: ${selected.split(',')[0]}`;
/*
customSelect.forEach(function(el) {
el.removeAttribute("disabled");
});
Expand All @@ -95,7 +100,7 @@
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");
Expand All @@ -104,7 +109,7 @@
app.style.backgroundColor = "#000";
app.style.color = "#fff";
app.innerHTML = "Create WebApp";
result2.append(app);
document.getElementById(pom_attr).append(app);

document.getElementById("get_app").addEventListener("click", function() {
$.ajax({
Expand All @@ -127,7 +132,7 @@
pom.style.backgroundColor = "orange";
pom.classList.add('dragout');
pom.innerHTML = `WebApp (index.html) zur Kollationierung herunterladen`;
result2.append(pom);
document.getElementById(pom_attr).append(pom);
}
});
});
Expand Down Expand Up @@ -162,7 +167,7 @@
pom.style.backgroundColor = "red";
pom.classList.add('dragout');
pom.innerHTML = `Konstituierten Text herunterladen (${selected.split(',')[0]})`;
result2.append(pom);
document.getElementById(pom_attr).append(pom);
}
});
}
Expand Down
20 changes: 13 additions & 7 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import shutil
import requests
import xml.etree.ElementTree as ET
from datetime import datetime

from zipfile import ZipFile
from acdh_collatex_utils.acdh_collatex_utils import CxCollate, CxReader
Expand Down Expand Up @@ -110,7 +111,11 @@ def collate_tei(save_path, path_dir, select):
werk = el[1].replace('s__', '')
manifest = el[0]
all_manifests_pre = glob.glob(os.path.join(save_path, '*', path_dir, werk, '*.xml'))
os.makedirs("tmp_to_collate", exist_ok=True)
dt = datetime.now()
ts = datetime.timestamp(dt)
ts_str = str(ts).replace('.', '')
tmp_dir = os.path.join("tmp_to_collate", ts_str)
os.makedirs(tmp_dir, exist_ok=True)
for x in all_manifests_pre:
tei = CxReader(
xml=x,
Expand All @@ -119,14 +124,15 @@ def collate_tei(save_path, path_dir, select):
chunk_size=CHUNK_SIZE,
to_compare_xpath=XPATH
).preprocess()
new_save_path = os.path.join("tmp_to_collate", x.split('/')[-1])
new_save_path = os.path.join(tmp_dir, x.split('/')[-1])
with open(new_save_path, 'wb') as f:
f.write(tei)
print(f"TEI updated ({new_save_path})")
all_manifests = os.path.join(".", "tmp_to_collate", '*.xml')
os.makedirs('collate-out', exist_ok=True)
os.makedirs('collate-out/collated', exist_ok=True)
output_dir = "./collate-out/collated"
all_manifests = os.path.join(".", tmp_dir, '*.xml')
col_out = os.path.join('collate-out', ts_str)
os.makedirs(col_out, exist_ok=True)
os.makedirs(os.path.join(col_out, 'collated'), exist_ok=True)
output_dir = f"./{col_out}/collated"
result_file = f'{output_dir}/collated.xml'
result_html = './index.html'

Expand Down Expand Up @@ -165,7 +171,7 @@ def collate_tei(save_path, path_dir, select):
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')
shutil.rmtree("tmp_to_collate")
shutil.rmtree(tmp_dir)
for x in glob.glob(f"{output_dir}/out__*"):
print(f"removing {x}")
os.remove(x)
Expand Down

0 comments on commit 9d0e745

Please sign in to comment.