Merge remote-tracking branch 'origin/korekturovatko'

This commit is contained in:
Jonas Havelka 2025-03-05 14:55:23 +01:00
commit 2d6ad5f369
10 changed files with 89 additions and 53 deletions

View file

@ -101,9 +101,11 @@ def opravy_a_komentare_view(request, pdf_id: int, **kwargs):
if komentar_id != -1:
komentar = get_object_or_404(Komentar, id=komentar_id)
komentar.text = text
komentar.autor = autor
komentar.save()
if komentar.text != text:
komentar.text = text
komentar.autor = autor
komentar.save()
oprava = komentar.oprava
else:
if oprava_id != -1:
oprava = get_object_or_404(Oprava, id=oprava_id)
@ -116,13 +118,16 @@ def opravy_a_komentare_view(request, pdf_id: int, **kwargs):
y=y,
)
tagy_raw = q.get('tagy')
if tagy_raw != "":
tagy = list(map(int, tagy_raw.split(",")))
oprava.tagy.add(*KorekturaTag.objects.filter(id__in=tagy))
Komentar.objects.create(oprava=oprava, autor=autor, text=text)
send_email_notification_komentar(oprava, autor, request)
tagy_raw = q.get('tagy')
if tagy_raw is not None:
oprava.tagy.clear()
if tagy_raw != "":
tagy = list(map(int, tagy_raw.split(",")))
oprava.tagy.add(*KorekturaTag.objects.filter(id__in=tagy))
opravy = Oprava.objects.filter(pdf=pdf_id).all()
# Serializovat list je prý security vulnerability, tedy je přidán slovník pro bezpečnost

View file

@ -0,0 +1,10 @@
<svg id="icon-reload" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 120 120" xml:space="preserve">
<g>
<path d="M60,95.5c-19.575,0-35.5-15.926-35.5-35.5c0-19.575,15.925-35.5,35.5-35.5c13.62,0,25.467,7.714,31.418,19h22.627
C106.984,20.347,85.462,3.5,60,3.5C28.796,3.5,3.5,28.796,3.5,60c0,31.203,25.296,56.5,56.5,56.5
c16.264,0,30.911-6.882,41.221-17.88L85.889,84.255C79.406,91.168,70.201,95.5,60,95.5z"/>
</g>
<line fill="none" x1="120" y1="0" x2="120" y2="45.336"/>
<line fill="none" x1="91.418" y1="43.5" x2="114.045" y2="43.5"/>
<polygon points="120,21.832 119.992,68.842 74.827,55.811 "/>
</svg>

After

Width:  |  Height:  |  Size: 712 B

View file

@ -20,6 +20,11 @@ body {
}
}
#sbal-korektury, #rozbal-korektury {
float: right;
margin-left: 4pt;
}
img{background:white;}
/* Barvy korektur */
@ -55,31 +60,6 @@ img{background:white;}
.toggle-button { transform: rotate(180deg); }
}
/* Tlačítko na aktualizaci */
#korektury-aktualizace {
position: absolute;
right: 10px;
top: 10px;
border-radius: 10px;
/* copy-paste .button */
margin: 10px 0 10px 0;
padding: 4px 0; /*vertikální centování textu*/
text-align: center;
background-color: #e84e10;
color: #fffbf6;
font-size: 150%;
font-weight: bold;
font-variant: small-caps;
filter: drop-shadow(0px 5px 5px rgba(0, 0, 0, 0.4));
&:hover {
background-color: #df490e;
}
}
/* Čára od textu k místu korektury */
.pointer{
@ -168,7 +148,8 @@ form {
margin: 2px;
padding: 2px;
&[data-selected="false"] { opacity: 0.7; }
&[data-selected="false"] { background: unset !important; }
/*&[data-selected="true"] { border-color: unset !important; }*/
}
/* Šipky na posouvání korektur */
@ -176,6 +157,7 @@ form {
position: fixed;
bottom: 5px;
left: 5px;
opacity: 50%;
button, img {
border: 1px solid white;
@ -203,6 +185,11 @@ form {
#predchozi-korektura-k-zaneseni, #dalsi-korektura-k-zaneseni {
background-color: #00FF00;
}
/* Tlačítko na aktualizaci */
#korektury-aktualizace {
background-color: #e84e10;
}
}

View file

@ -20,6 +20,12 @@
<button type='button' id="dalsi-korektura-k-zaneseni" title='Další korektura k zaneseni'>
<img class='toggle-button' src='{% static "korektury/imgs/hide.png" %}' alt='⬇' style="transform: rotate(180deg);"/>
</button>
<button type='button' id='korektury-aktualizace'
title='Aktualizuj korektury
Nemusíš mačkat, pokud ti stačí, že se korektury aktualizují samy každé 2 minuty a při každém přidání korektury/komentáře.'
>
<img class='toggle-button' src='{% static "korektury/imgs/reload.svg" %}' alt='↻' style="width: 15px"/>
</button>
</div>
<script>
@ -64,4 +70,7 @@
dalsi_k_o.addEventListener('click', _ => { dalsi_nebo_predchozi_korektura(true, "k_oprave") });
predchozi_k_z.addEventListener('click', _ => { dalsi_nebo_predchozi_korektura(false, "k_zaneseni") });
dalsi_k_z.addEventListener('click', _ => { dalsi_nebo_predchozi_korektura(true, "k_zaneseni") });
// FIXME není mi jasné, zda v {} nemá být `cache: "no-store"`, aby prohlížeč necachoval GET.
document.getElementById("korektury-aktualizace").addEventListener("click", _ => update_all({}, false));
</script>

View file

@ -5,11 +5,12 @@
<br/>
<textarea id="commform-text" cols=40 rows=10 name="txt"></textarea>
<br/>
<span id="commform-tagy">
<div id="commform-tagy-info">Úprava tagů celé korektury:</div>
<div id="commform-tagy">
{% for tag in tagy %}
<button type="button" class="korektury-tag" value="{{tag.id}}" data-selected="false" style="background: {{ tag.barva }};">{{tag.nazev}}</button>
<button type="button" class="korektury-tag" value="{{tag.id}}" data-selected="false" style="background: {{ tag.barva }}; border-color: {{ tag.barva }};">{{tag.nazev}}</button>
{% endfor %}
</span>
</div>
</div>
<script>
@ -20,6 +21,7 @@
this.submit_button = document.getElementById('commform-submit');
const close_button = document.getElementById('commform-close');
this.tagy = document.getElementById('commform-tagy');
this.tagy_info = document.getElementById('commform-tagy-info');
// ctrl-enter submits form
@ -71,8 +73,16 @@
this.text.value = text;
// show form
if (oprava_id === -1 && komentar_id === -1) this.tagy.style.display = 'unset'; else this.tagy.style.display = 'none';
if (this.reset_tags_every_open) this.reset_tags();
if (oprava_id === -1 && komentar_id === -1) {
if (this.reset_tags_every_open) this.reset_tags();
this.tagy_info.style.display = 'none';
} else {
const oprava = opravy[oprava_id];
this.tagy_info.style.display = 'unset';
for (const tag of this.tagy.getElementsByTagName("button"))
tag.dataset.selected = String(oprava.tagy.has(parseInt(tag.value)));
}
this._show(img_id, x, y);
}
@ -84,13 +94,12 @@
data.append('img_id', this.imgID);
data.append('oprava_id', this.oprava_id);
data.append('komentar_id', this.komentar_id);
if (this.oprava_id === -1 && this.komentar_id === -1) {
const tagy = [];
for (const tag of this.tagy.getElementsByTagName("button")) {
if (tag.dataset.selected !== "false") tagy.push(tag.value);
}
data.append('tagy', String(tagy));
const tagy = [];
for (const tag of this.tagy.getElementsByTagName("button")) {
if (tag.dataset.selected !== "false") tagy.push(tag.value);
}
data.append('tagy', String(tagy));
data.append('text', this.text.value);

View file

@ -81,7 +81,7 @@
// show comment form when 'update-comment' button pressed
#update_comment() {
return commform.show(this.oprava.img_id, this.oprava.x, this.oprava.y, this.#text.textContent, -1, this.id);
return commform.show(this.oprava.img_id, this.oprava.x, this.oprava.y, this.#text.textContent, this.oprava.id, this.id);
}
#delete_comment() {

View file

@ -72,6 +72,7 @@
#komentare; #tagy;
htmlElement; pointer;
id; x; y; img_id; status; zobrazit = true; {# oprava_data; #}
tagy;
constructor(oprava_data) {
this.htmlElement = preoprava.cloneNode(true);
@ -109,7 +110,9 @@
{# this.oprava_data = oprava_data; #}
this.set_status(oprava_data['status']);
this.#tagy.innerHTML = "";
this.tagy = new Set();
for (const tag of oprava_data["tagy"]) {
this.tagy.add(tag["id"]);
const span = document.createElement("span");
span.innerHTML = tag["nazev"];
span.classList.add("korektury-tag");
@ -131,9 +134,12 @@
// hide or show text of correction
#toggle_visibility(){
toggle_visibility() {
this.zobrazit = !this.zobrazit;
this.htmlElement.dataset.opravazobrazit = String(this.zobrazit);
}
#toggle_visibility(){
this.toggle_visibility();
place_comments()
}

View file

@ -8,8 +8,6 @@
{% include "korektury/korekturovatko/__dalsi_korektura.html" %}
<button type="button" id="korektury-aktualizace">Aktualizuj korektury.</button>
<script>
/**
*
@ -44,9 +42,6 @@
});
});
// FIXME není mi jasné, zda v {} nemá být `cache: "no-store"`, aby prohlížeč necachoval GET.
document.getElementById("korektury-aktualizace").addEventListener("click", _ => update_all({}, false));
// FIXME není mi jasné, zda v {} nemá být `cache: "no-store"`, aby prohlížeč necachoval GET.
setInterval(() => update_all({}, false), 120000); // Každý dvě minuty fetchni korektury
</script>

View file

@ -20,6 +20,10 @@ Zobrazit:
onchange="toggle_corrections('k_zaneseni')" checked>
<label for="k_zaneseni_checkbox">K zanesení (<span id="k_zaneseni_pocet"></span>)</label>
<button type="button" id="sbal-korektury">Sbal korektury</button>
<button type="button" id="rozbal-korektury">Rozbal korektury</button>
<hr/>
<script>
@ -65,4 +69,15 @@ Zobrazit:
}
for (let [stav, pocet] of Object.entries(pocty_stavu)) spany_s_pocty_stavu[stav].innerText = pocet;
}
document.getElementById("sbal-korektury").addEventListener("click", () => {
for (const oprava of Object.values(opravy))
if (oprava.zobrazit) oprava.toggle_visibility();
place_comments();
})
document.getElementById("rozbal-korektury").addEventListener("click", () => {
for (const oprava of Object.values(opravy))
if (!oprava.zobrazit) oprava.toggle_visibility();
place_comments();
})
</script>

View file

@ -4,8 +4,8 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" title="opraf-css" type="text/css" media="screen, projection" href="{% static "korektury/opraf.css"%}?version=1" />
<link href="{% static 'css/rozliseni.css' %}?version=1" rel="stylesheet">
<script src="{% static "korektury/opraf.js"%}?version=1"></script>
<link href="{% static 'css/rozliseni.css' %}?version=2" rel="stylesheet">
<script src="{% static "korektury/opraf.js"%}?version=2"></script>
<title>Korektury {{korekturovanepdf.nazev}}</title>
</head>
<body class="{{ LOCAL_TEST_PROD }}web" data-status="{{ korekturovanepdf.status }}">