Update public source
This commit is contained in:
+160
-1
@@ -626,6 +626,164 @@ def update_block(
|
|||||||
|
|
||||||
return html
|
return html
|
||||||
|
|
||||||
|
def recalculate_block(job=None):
|
||||||
|
|
||||||
|
html = """
|
||||||
|
<div class="card">
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
Перерасчёт производителей точек доступа
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Операция проверяет все записи AP по установленной базе OUI.
|
||||||
|
Она заполняет неизвестные значения, обновляет устаревшие
|
||||||
|
названия производителей и очищает значения, которые больше
|
||||||
|
не определяются.
|
||||||
|
</p>
|
||||||
|
"""
|
||||||
|
|
||||||
|
if job is None:
|
||||||
|
|
||||||
|
html += """
|
||||||
|
<form
|
||||||
|
method="POST"
|
||||||
|
action="/reports/vendors/recalculate"
|
||||||
|
onsubmit="return confirm('Запустить полный перерасчёт производителей всех точек доступа?');"
|
||||||
|
>
|
||||||
|
|
||||||
|
<button type="submit" class="button">
|
||||||
|
Пересчитать производителей AP
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
"""
|
||||||
|
|
||||||
|
elif job["status"] == "ready":
|
||||||
|
|
||||||
|
result = job["result"]
|
||||||
|
|
||||||
|
labels = (
|
||||||
|
("total", "Всего точек доступа"),
|
||||||
|
("checked", "Проверено"),
|
||||||
|
("updated", "Изменено"),
|
||||||
|
("filled", "Заполнено"),
|
||||||
|
("refreshed", "Обновлено"),
|
||||||
|
("cleared", "Очищено"),
|
||||||
|
("unknown", "Неизвестный производитель"),
|
||||||
|
("unchanged", "Без изменений")
|
||||||
|
)
|
||||||
|
|
||||||
|
html += """
|
||||||
|
<p>
|
||||||
|
Перерасчёт завершён.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>Показатель</th>
|
||||||
|
<th>Количество</th>
|
||||||
|
</tr>
|
||||||
|
"""
|
||||||
|
|
||||||
|
for key, label in labels:
|
||||||
|
|
||||||
|
html += f"""
|
||||||
|
<tr>
|
||||||
|
<td>{label}</td>
|
||||||
|
<td>{result[key]}</td>
|
||||||
|
</tr>
|
||||||
|
"""
|
||||||
|
|
||||||
|
html += """
|
||||||
|
</table>
|
||||||
|
"""
|
||||||
|
|
||||||
|
elif job["status"] == "error":
|
||||||
|
|
||||||
|
html += f"""
|
||||||
|
<p>
|
||||||
|
Ошибка перерасчёта:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>{escape(job["error"] or "Неизвестная ошибка")}</strong>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<form
|
||||||
|
method="POST"
|
||||||
|
action="/reports/vendors/recalculate"
|
||||||
|
>
|
||||||
|
|
||||||
|
<button type="submit" class="button">
|
||||||
|
Повторить перерасчёт
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
"""
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
html += f"""
|
||||||
|
<p id="vendor-recalc-status">
|
||||||
|
{escape(job["message"] or "Перерасчёт выполняется")}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
(function() {{
|
||||||
|
|
||||||
|
const jobId = {job["id"]!r};
|
||||||
|
|
||||||
|
const statusElement = document.getElementById(
|
||||||
|
"vendor-recalc-status"
|
||||||
|
);
|
||||||
|
|
||||||
|
async function checkStatus() {{
|
||||||
|
|
||||||
|
try {{
|
||||||
|
|
||||||
|
const response = await fetch(
|
||||||
|
"/reports/vendors/recalculate/status/" + jobId
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!response.ok) {{
|
||||||
|
throw new Error("Ошибка получения статуса");
|
||||||
|
}}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (data.message) {{
|
||||||
|
statusElement.textContent = data.message;
|
||||||
|
}}
|
||||||
|
|
||||||
|
if (data.status === "ready" || data.status === "error") {{
|
||||||
|
|
||||||
|
window.location.href =
|
||||||
|
"/reports/vendors/?recalc_job_id=" + jobId;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}}
|
||||||
|
|
||||||
|
}} catch (error) {{
|
||||||
|
|
||||||
|
statusElement.textContent = error.message;
|
||||||
|
|
||||||
|
}}
|
||||||
|
|
||||||
|
window.setTimeout(checkStatus, 1000);
|
||||||
|
}}
|
||||||
|
|
||||||
|
window.setTimeout(checkStatus, 1000);
|
||||||
|
|
||||||
|
}})();
|
||||||
|
</script>
|
||||||
|
"""
|
||||||
|
|
||||||
|
html += """
|
||||||
|
</div>
|
||||||
|
"""
|
||||||
|
|
||||||
|
return html
|
||||||
|
|
||||||
def render_vendors_page(
|
def render_vendors_page(
|
||||||
conn,
|
conn,
|
||||||
@@ -685,10 +843,11 @@ def render_vendors_page(
|
|||||||
preview,
|
preview,
|
||||||
token,
|
token,
|
||||||
job
|
job
|
||||||
|
)
|
||||||
|
|
||||||
html += recalculate_block(
|
html += recalculate_block(
|
||||||
recalc_job
|
recalc_job
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
html += page_end()
|
html += page_end()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user