chore: import MCTF services
- Added all seven issued service trees without omissions. - Preserved the supplied runtime configuration, binaries, and assets.
This commit is contained in:
commit
13f936bee9
1222 files changed
+21280
No files matched your search
Executable
+150
@@ -0,0 +1,150 @@
|
||||
<!doctype html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="theme-color" content="#101015">
|
||||
<title>Передать показания — Dark Tariff</title>
|
||||
<link rel="stylesheet" href="/static/src/styles/main.css">
|
||||
</head>
|
||||
<body>
|
||||
<header class="topbar">
|
||||
<div class="shell topbar-inner">
|
||||
<a class="brand" href="#/submit" aria-label="Dark Tariff — главная">
|
||||
<svg id="brand-mark" class="brand-mark" viewBox="0 0 36 36" aria-hidden="true">
|
||||
<path class="meter-shell" d="M10 2h16l8 8v16l-8 8H10l-8-8V10z"/>
|
||||
<path class="meter-screen" d="M8 8h20v10H8z"/>
|
||||
<path class="meter-readout" d="M12 13h4m4 0h4"/>
|
||||
<path class="meter-dial" d="M9 28a9 9 0 0 1 18 0M18 27l6-6"/>
|
||||
<circle class="meter-core" cx="18" cy="27" r="2"/>
|
||||
</svg><span>Dark Tariff</span>
|
||||
</a>
|
||||
<nav class="main-nav" aria-label="Основные разделы">
|
||||
<a href="#/submit" data-route="submit">Передать показания</a>
|
||||
<a href="#/history" data-route="history">Показания</a>
|
||||
<a href="#/receipts" data-route="receipts">Квитанции</a>
|
||||
<a href="#/finance" data-route="finance">Финансы</a>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="shell">
|
||||
<section class="page" data-page="submit" aria-labelledby="submit-page-title">
|
||||
<p class="eyebrow">Учёт ресурсов</p>
|
||||
<h1 id="submit-page-title">Передавайте показания</h1>
|
||||
<p class="intro">Фиксируйте показания в новом сервисе Night City — Dark Tariff</p>
|
||||
<button id="reading-open" class="primary" type="button" disabled>Передать показания</button>
|
||||
<div id="page-note" class="note" role="status" aria-live="polite" hidden></div>
|
||||
</section>
|
||||
|
||||
<section class="page" data-page="history" aria-labelledby="history-page-title" hidden>
|
||||
<p class="eyebrow">Переданные показания</p>
|
||||
<h1 id="history-page-title">Показания</h1>
|
||||
<div id="history-note" class="note" role="status" aria-live="polite">Загрузка…</div>
|
||||
<div id="history" class="history-grid"></div>
|
||||
</section>
|
||||
<section class="page" data-page="receipts" aria-labelledby="receipts-page-title" hidden>
|
||||
<p class="eyebrow">Расчёт ресурсов</p>
|
||||
<h1 id="receipts-page-title">Квитанции</h1>
|
||||
<div id="receipts-note" class="note" role="status" aria-live="polite">Загрузка…</div>
|
||||
<div id="receipts" class="history-grid"></div>
|
||||
</section>
|
||||
<section class="page" data-page="finance" aria-labelledby="finance-page-title" hidden>
|
||||
<p class="eyebrow">Финансовый отчёт</p>
|
||||
<h1 id="finance-page-title">Финансы</h1>
|
||||
<div class="finance-controls">
|
||||
<label><span>Период</span><input id="finance-period" type="month" required></label>
|
||||
<label><span>Сортировка</span><select id="finance-sort"></select></label>
|
||||
<label><span>Группировка</span><select id="finance-group">
|
||||
<option value="period, resource, tariff">По ресурсу и тарифу</option>
|
||||
<option value="period, resource">По ресурсу</option>
|
||||
<option value="period">По месяцу</option>
|
||||
</select></label>
|
||||
<label><span>Ресурс содержит</span><input id="finance-filter" type="text" placeholder="Например, Вода"></label>
|
||||
<button id="finance-export" class="primary" type="button" disabled>Скачать CSV</button>
|
||||
</div>
|
||||
<fieldset class="finance-options">
|
||||
<legend>Колонки отчёта</legend>
|
||||
<div id="finance-fields"></div>
|
||||
</fieldset>
|
||||
<div id="finance-note" class="note" role="status" aria-live="polite">Загрузка…</div>
|
||||
<div class="finance-scroll"><table id="finance-table" hidden></table></div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<dialog id="reading-dialog" aria-labelledby="reading-dialog-title">
|
||||
<div class="panel-head">
|
||||
<h2 id="reading-dialog-title">Передать показания</h2>
|
||||
<button id="reading-close" class="action" type="button" aria-label="Закрыть форму">×</button>
|
||||
</div>
|
||||
<form id="reading-form" autocomplete="off">
|
||||
<label><span>Серийный ID счётчика</span><input name="serial" maxlength="128" required></label>
|
||||
<label><span>Вид измеряемой величины</span><select name="kind" required><option value="">Выберите ресурс</option></select></label>
|
||||
<div id="metric-fields" class="metric-grid"></div>
|
||||
<div id="reading-note" class="note" role="status" aria-live="polite" hidden></div>
|
||||
<button class="primary" type="submit">Отправить показания</button>
|
||||
</form>
|
||||
</dialog>
|
||||
|
||||
<dialog id="verification-dialog" aria-labelledby="verification-title">
|
||||
<div class="panel-head">
|
||||
<h2 id="verification-title">Сохраните идентификаторы</h2>
|
||||
<button id="verification-close" class="action" type="button" aria-label="Закрыть идентификаторы">×</button>
|
||||
</div>
|
||||
<div class="verification-body">
|
||||
<p>Сохраните оба идентификатора. Они показываются только один раз: для проверки показания и открытия квитанции.</p>
|
||||
<p>ID показания: <strong id="verification-reading"></strong></p>
|
||||
<p>ID квитанции: <strong id="verification-receipt"></strong></p>
|
||||
<label><span>Идентификатор проверки</span><textarea id="verification-secret" rows="4" readonly spellcheck="false"></textarea></label>
|
||||
<label><span>Расчётный идентификатор</span><textarea id="calculation-secret" rows="2" readonly spellcheck="false"></textarea></label>
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
<dialog id="receipt-dialog" aria-labelledby="receipt-dialog-title">
|
||||
<div class="panel-head">
|
||||
<h2 id="receipt-dialog-title">Квитанция</h2>
|
||||
<button id="receipt-close" class="action" type="button" aria-label="Закрыть квитанцию">×</button>
|
||||
</div>
|
||||
<form id="receipt-form" autocomplete="off">
|
||||
<label><span>Расчётный идентификатор</span><input name="calculation_id" type="password" minlength="44" maxlength="44" required></label>
|
||||
<div id="receipt-note" class="note" role="status" aria-live="polite" hidden></div>
|
||||
<button class="primary" type="submit">Открыть квитанцию</button>
|
||||
</form>
|
||||
<div id="receipt-content" class="verification-body" hidden>
|
||||
<dl id="receipt-details" class="receipt-details"></dl>
|
||||
<label><span>Публичные параметры показания</span><textarea id="receipt-parameters" rows="4" readonly spellcheck="false"></textarea></label>
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
<dialog id="reading-result-dialog" aria-labelledby="reading-result-title">
|
||||
<div class="panel-head">
|
||||
<h2 id="reading-result-title">Показание</h2>
|
||||
<button id="reading-result-close" class="action" type="button" aria-label="Закрыть показание">×</button>
|
||||
</div>
|
||||
<div class="verification-body"><dl id="reading-result-details" class="receipt-details"></dl></div>
|
||||
</dialog>
|
||||
|
||||
<section id="help-chat" class="help-chat panel" role="dialog" aria-labelledby="help-chat-title" hidden>
|
||||
<div class="panel-head">
|
||||
<h2 id="help-chat-title">Помощник Dark Tariff</h2>
|
||||
<button id="help-close" type="button" class="action" aria-label="Закрыть чат">×</button>
|
||||
</div>
|
||||
<div class="help-messages" role="log" aria-live="polite">
|
||||
<p id="help-message">Загрузка…</p>
|
||||
</div>
|
||||
<div class="help-controls">
|
||||
<button id="help-question" class="action" type="button" disabled>Помогите мне проверить мои переданные показания</button>
|
||||
<form id="help-form" autocomplete="off" hidden>
|
||||
<label id="help-id-label"><span>ID показания</span><input id="help-id" name="reading_id" type="number" min="1" step="1" required></label>
|
||||
<label id="help-data-label" hidden><span>Данные проверки (JSON)</span><textarea id="help-data" rows="5" maxlength="24000" spellcheck="false" disabled required></textarea></label>
|
||||
<div id="help-note" class="note" role="status" aria-live="polite" hidden></div>
|
||||
<button class="primary" type="submit">Отправить</button>
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
<button id="help-launcher" class="help-launcher" type="button" aria-controls="help-chat" aria-expanded="false">
|
||||
<span class="help-hint">Нужна помощь?</span>
|
||||
<svg class="brand-mark" viewBox="0 0 36 36" aria-hidden="true"><use href="#brand-mark"/></svg>
|
||||
</button>
|
||||
<script type="module" src="/static/src/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
function jsonPost(body) {
|
||||
return { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) };
|
||||
}
|
||||
|
||||
function responseError(result, fallback) {
|
||||
return new Error(typeof result.detail === "string" ? result.detail : fallback);
|
||||
}
|
||||
|
||||
export async function api(path, opts = {}) {
|
||||
const response = await fetch(path, opts);
|
||||
const result = await response.json();
|
||||
if (!response.ok) throw responseError(result, "Проверьте поля запроса.");
|
||||
return result;
|
||||
}
|
||||
|
||||
export function post(path, body) {
|
||||
return api(path, jsonPost(body));
|
||||
}
|
||||
|
||||
export async function download(path, body, fallback) {
|
||||
const response = await fetch(path, jsonPost(body));
|
||||
if (!response.ok) {
|
||||
const result = await response.json();
|
||||
throw responseError(result, "Не удалось скачать отчёт.");
|
||||
}
|
||||
const url = URL.createObjectURL(await response.blob());
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = response.headers.get("content-disposition")?.match(/filename="?([^";]+)"?/i)?.[1] || fallback;
|
||||
document.body.append(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
Executable
+115
@@ -0,0 +1,115 @@
|
||||
import { api, post } from "../api/client.js";
|
||||
import { $, cell, note } from "../shared/dom.js";
|
||||
|
||||
export async function initChat(resourcesPromise) {
|
||||
const launcher = $("#help-launcher");
|
||||
const chat = $("#help-chat");
|
||||
const close = $("#help-close");
|
||||
const question = $("#help-question");
|
||||
const form = $("#help-form");
|
||||
const input = $("#help-id");
|
||||
const data = $("#help-data");
|
||||
const messages = $(".help-messages");
|
||||
const dialog = $("#reading-result-dialog");
|
||||
const details = $("#reading-result-details");
|
||||
let greeting;
|
||||
let stage = "id";
|
||||
let check;
|
||||
let round;
|
||||
|
||||
function message(text, kind = "") {
|
||||
messages.append(cell("p", text, kind));
|
||||
messages.scrollTop = messages.scrollHeight;
|
||||
}
|
||||
function setOpen(open) {
|
||||
chat.hidden = !open;
|
||||
launcher.setAttribute("aria-expanded", String(open));
|
||||
(open ? close : launcher).focus();
|
||||
}
|
||||
function finish() {
|
||||
form.hidden = true;
|
||||
form.reset();
|
||||
question.hidden = false;
|
||||
check = null;
|
||||
}
|
||||
$("#reading-result-close").addEventListener("click", () => dialog.close());
|
||||
dialog.addEventListener("close", () => details.replaceChildren());
|
||||
launcher.addEventListener("click", () => setOpen(chat.hidden));
|
||||
close.addEventListener("click", () => setOpen(false));
|
||||
chat.addEventListener("keydown", (event) => {
|
||||
if (event.key === "Escape") setOpen(false);
|
||||
});
|
||||
question.addEventListener("click", () => {
|
||||
stage = "id";
|
||||
form.reset();
|
||||
question.hidden = true;
|
||||
form.hidden = false;
|
||||
$("#help-note").hidden = true;
|
||||
$("#help-id-label").hidden = false;
|
||||
$("#help-data-label").hidden = true;
|
||||
input.disabled = false;
|
||||
data.disabled = true;
|
||||
message(question.textContent, "help-user");
|
||||
message(greeting.prompt);
|
||||
input.focus();
|
||||
});
|
||||
form.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
const button = event.submitter;
|
||||
button.disabled = true;
|
||||
$("#help-note").hidden = true;
|
||||
try {
|
||||
let result;
|
||||
if (stage === "id") {
|
||||
result = await post("/api/chat/checks", { reading_id: Number(input.value) });
|
||||
check = result.id;
|
||||
input.disabled = true;
|
||||
data.disabled = false;
|
||||
$("#help-id-label").hidden = true;
|
||||
$("#help-data-label").hidden = false;
|
||||
} else {
|
||||
let value;
|
||||
try { value = JSON.parse(data.value); }
|
||||
catch { throw new Error("Проверьте формат JSON."); }
|
||||
result = await post(`/api/chat/checks/${check}/${stage === "commit" ? "commit" : "answer"}`,
|
||||
stage === "commit" ? { round, values: value } : { round, data: value });
|
||||
}
|
||||
stage = result.stage;
|
||||
round = result.round;
|
||||
data.value = "";
|
||||
message(result.message);
|
||||
if (stage === "done") {
|
||||
finish();
|
||||
const reading = result.reading;
|
||||
const resource = (await resourcesPromise).find((item) => item.id === reading.kind);
|
||||
const rows = [
|
||||
["ID показания", reading.id], ["Дата показания", new Date(reading.created_at).toLocaleString("ru-RU")],
|
||||
["Серийный ID", reading.serial], ["Вид ресурса", resource.title],
|
||||
...resource.metrics.map((metric) => [metric.label, `${reading.metrics[metric.key]} ${metric.unit}`]),
|
||||
];
|
||||
details.replaceChildren();
|
||||
for (const [label, value] of rows) details.append(cell("dt", label), cell("dd", value));
|
||||
dialog.showModal();
|
||||
} else if (stage === "failed") {
|
||||
finish();
|
||||
} else {
|
||||
data.focus();
|
||||
}
|
||||
} catch (error) {
|
||||
note($("#help-note"), error.message, "err");
|
||||
} finally {
|
||||
button.disabled = false;
|
||||
}
|
||||
});
|
||||
try {
|
||||
greeting = await api("/api/chat/greeting");
|
||||
$("#help-message").textContent = greeting.text;
|
||||
question.disabled = false;
|
||||
} catch {
|
||||
$("#help-message").textContent = "Не удалось загрузить сообщение. Обновите страницу.";
|
||||
}
|
||||
return () => {
|
||||
setOpen(true);
|
||||
if (!question.hidden) question.click();
|
||||
};
|
||||
}
|
||||
Executable
+117
@@ -0,0 +1,117 @@
|
||||
import { api, download } from "../api/client.js";
|
||||
import { $, cell, note } from "../shared/dom.js";
|
||||
import { onRoute } from "../shared/router.js";
|
||||
|
||||
export function initFinance() {
|
||||
const period = $("#finance-period");
|
||||
const fields = $("#finance-fields");
|
||||
const sort = $("#finance-sort");
|
||||
const group = $("#finance-group");
|
||||
const filter = $("#finance-filter");
|
||||
const button = $("#finance-export");
|
||||
const table = $("#finance-table");
|
||||
const status = $("#finance-note");
|
||||
const money = new Intl.NumberFormat("ru-RU", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
||||
const today = new Date();
|
||||
period.value = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, "0")}`;
|
||||
let loading = 0;
|
||||
|
||||
function selected() {
|
||||
return Array.from(fields.querySelectorAll("input:checked"), (input) => input.value);
|
||||
}
|
||||
|
||||
function query() {
|
||||
const text = filter.value.trim().replace(/[\\%_]/g, "\\$&").replaceAll("'", "''");
|
||||
return { report: "finance", period: period.value, fields: selected(), sort: sort.value,
|
||||
group_by: group.value, filter: text ? `resource ilike '%${text}%'` : "", having: "" };
|
||||
}
|
||||
|
||||
function selectSort() {
|
||||
const ids = selected();
|
||||
for (const option of sort.options) option.disabled = !ids.includes(option.value.split(" ")[0]);
|
||||
if (sort.selectedOptions[0]?.disabled) sort.value = Array.from(sort.options).find((option) => !option.disabled)?.value || "";
|
||||
sort.disabled = !ids.length;
|
||||
}
|
||||
|
||||
function selectGroup() {
|
||||
const dimensions = group.options[0].value.split(", ");
|
||||
for (const input of fields.querySelectorAll("input")) {
|
||||
if (dimensions.includes(input.value)) input.checked = group.value.split(", ").includes(input.value);
|
||||
}
|
||||
selectSort();
|
||||
}
|
||||
|
||||
async function load() {
|
||||
const request = ++loading;
|
||||
button.disabled = true;
|
||||
table.hidden = true;
|
||||
note(status, "Загрузка…");
|
||||
try {
|
||||
if (!fields.children.length) {
|
||||
const catalogue = await api("/api/reports/finance/fields");
|
||||
if (request !== loading) return;
|
||||
for (const field of catalogue) {
|
||||
const label = document.createElement("label");
|
||||
const input = document.createElement("input");
|
||||
input.type = "checkbox";
|
||||
input.value = field.id;
|
||||
input.checked = true;
|
||||
label.append(input, cell("span", field.title));
|
||||
fields.append(label);
|
||||
for (const direction of ["asc", "desc"]) {
|
||||
const option = cell("option", `${field.title} ${direction === "asc" ? "↑" : "↓"}`);
|
||||
option.value = `${field.id} ${direction}`;
|
||||
sort.append(option);
|
||||
}
|
||||
}
|
||||
sort.value = "resource asc";
|
||||
selectGroup();
|
||||
}
|
||||
const data = query();
|
||||
if (!data.fields.length) return note(status, "Выберите хотя бы одну колонку.");
|
||||
const params = new URLSearchParams({ period: data.period, sort: data.sort, group_by: data.group_by, filter: data.filter, having: data.having });
|
||||
for (const field of data.fields) params.append("fields", field);
|
||||
const report = await api(`/api/reports/finance/summary?${params}`);
|
||||
if (request !== loading) return;
|
||||
const head = document.createElement("thead");
|
||||
const row = document.createElement("tr");
|
||||
for (const column of report.columns) {
|
||||
const title = cell("th", column.title);
|
||||
title.scope = "col";
|
||||
row.append(title);
|
||||
}
|
||||
head.append(row);
|
||||
const body = document.createElement("tbody");
|
||||
for (const values of report.rows) {
|
||||
const row = document.createElement("tr");
|
||||
report.columns.forEach((column, index) => row.append(cell("td", ["tariff", "amount"].includes(column.id) ? money.format(values[index]) : values[index])));
|
||||
body.append(row);
|
||||
}
|
||||
table.replaceChildren(head, body);
|
||||
table.hidden = !report.rows.length;
|
||||
status.hidden = report.rows.length > 0;
|
||||
if (!report.rows.length) note(status, "За выбранный период показаний нет.");
|
||||
button.disabled = false;
|
||||
} catch (error) {
|
||||
if (request === loading) note(status, error.message, "err");
|
||||
}
|
||||
}
|
||||
|
||||
period.addEventListener("change", load);
|
||||
sort.addEventListener("change", load);
|
||||
filter.addEventListener("input", load);
|
||||
fields.addEventListener("change", () => { selectSort(); load(); });
|
||||
group.addEventListener("change", () => { selectGroup(); load(); });
|
||||
button.addEventListener("click", async () => {
|
||||
const request = loading;
|
||||
button.disabled = true;
|
||||
try {
|
||||
await download("/api/reports/export", query(), `finance-${period.value}.csv`);
|
||||
} catch (error) {
|
||||
note(status, error.message, "err");
|
||||
} finally {
|
||||
if (request === loading) button.disabled = !selected().length;
|
||||
}
|
||||
});
|
||||
onRoute("finance", load);
|
||||
}
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
import { api, post } from "../api/client.js";
|
||||
import { $, cell, note } from "../shared/dom.js";
|
||||
import { navigateTo, onRoute } from "../shared/router.js";
|
||||
|
||||
export async function initReadings(resourcesPromise, chatPromise) {
|
||||
const dialog = $("#reading-dialog");
|
||||
const form = $("#reading-form");
|
||||
const selector = form.elements.kind;
|
||||
let resources;
|
||||
try {
|
||||
resources = await resourcesPromise;
|
||||
} catch (error) {
|
||||
note($("#page-note"), error.message, "err");
|
||||
note($("#history-note"), error.message, "err");
|
||||
return;
|
||||
}
|
||||
for (const resource of resources) {
|
||||
const option = cell("option", resource.title);
|
||||
option.value = resource.id;
|
||||
selector.append(option);
|
||||
}
|
||||
|
||||
function renderFields() {
|
||||
const fields = $("#metric-fields");
|
||||
fields.replaceChildren();
|
||||
const resource = resources.find((item) => item.id === selector.value);
|
||||
if (!resource) return;
|
||||
for (const metric of resource.metrics) {
|
||||
const label = document.createElement("label");
|
||||
const input = document.createElement("input");
|
||||
input.type = "number";
|
||||
input.name = metric.key;
|
||||
input.step = "any";
|
||||
input.min = metric.min;
|
||||
input.max = metric.max;
|
||||
input.required = true;
|
||||
label.append(cell("span", `${metric.label}, ${metric.unit}`), input);
|
||||
fields.append(label);
|
||||
}
|
||||
}
|
||||
|
||||
let loading = 0;
|
||||
async function loadHistory() {
|
||||
const request = ++loading;
|
||||
const status = $("#history-note");
|
||||
note(status, "Загрузка…");
|
||||
try {
|
||||
const readings = await api("/api/readings");
|
||||
if (request !== loading) return;
|
||||
const cards = $("#history");
|
||||
cards.replaceChildren();
|
||||
for (const reading of readings) {
|
||||
const card = cell("article", "", "reading-card panel");
|
||||
const label = cell("label", "");
|
||||
const parameters = document.createElement("textarea");
|
||||
parameters.value = reading.parameters;
|
||||
parameters.readOnly = true;
|
||||
parameters.rows = 4;
|
||||
parameters.spellcheck = false;
|
||||
label.append(cell("span", "Параметры проверки"), parameters);
|
||||
const button = cell("button", "Проверка", "action reading-check");
|
||||
button.type = "button";
|
||||
button.setAttribute("aria-label", `Проверка показания #${reading.id}`);
|
||||
button.addEventListener("click", async () => {
|
||||
const openCheck = await chatPromise;
|
||||
openCheck();
|
||||
});
|
||||
card.append(cell("h2", `ID показания: ${reading.id}`), label, button);
|
||||
cards.append(card);
|
||||
}
|
||||
status.hidden = readings.length > 0;
|
||||
if (!readings.length) note(status, "Показаний пока нет.");
|
||||
} catch (error) {
|
||||
if (request === loading) note(status, error.message, "err");
|
||||
}
|
||||
}
|
||||
|
||||
$("#verification-close").addEventListener("click", () => $("#verification-dialog").close());
|
||||
$("#verification-dialog").addEventListener("close", () => {
|
||||
$("#verification-secret").value = "";
|
||||
$("#verification-reading").textContent = "";
|
||||
$("#verification-receipt").textContent = "";
|
||||
$("#calculation-secret").value = "";
|
||||
});
|
||||
selector.addEventListener("change", renderFields);
|
||||
$("#reading-open").addEventListener("click", () => {
|
||||
$("#reading-note").hidden = true;
|
||||
dialog.showModal();
|
||||
});
|
||||
$("#reading-close").addEventListener("click", () => dialog.close());
|
||||
form.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
const button = event.submitter;
|
||||
button.disabled = true;
|
||||
try {
|
||||
const data = new FormData(form);
|
||||
const resource = resources.find((item) => item.id === data.get("kind"));
|
||||
const metrics = Object.fromEntries(resource.metrics.map((metric) => [metric.key, data.get(metric.key)]));
|
||||
const result = await post("/api/readings", { serial: data.get("serial").trim(), kind: resource.id, metrics });
|
||||
form.reset();
|
||||
renderFields();
|
||||
dialog.close();
|
||||
navigateTo("history");
|
||||
$("#verification-reading").textContent = result.id;
|
||||
$("#verification-secret").value = result.verification_id;
|
||||
$("#verification-receipt").textContent = result.receipt_id;
|
||||
$("#calculation-secret").value = result.calculation_id;
|
||||
$("#verification-dialog").showModal();
|
||||
} catch (error) {
|
||||
note($("#reading-note"), error.message, "err");
|
||||
} finally {
|
||||
button.disabled = false;
|
||||
}
|
||||
});
|
||||
$("#reading-open").disabled = false;
|
||||
onRoute("history", loadHistory);
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
import { api, post } from "../api/client.js";
|
||||
import { $, cell, note } from "../shared/dom.js";
|
||||
import { onRoute } from "../shared/router.js";
|
||||
|
||||
export async function initReceipts(resourcesPromise) {
|
||||
const dialog = $("#receipt-dialog");
|
||||
const form = $("#receipt-form");
|
||||
const details = $("#receipt-details");
|
||||
const amount = new Intl.NumberFormat("ru-RU", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
||||
let selected;
|
||||
let opening = 0;
|
||||
let resources;
|
||||
let loading = 0;
|
||||
try {
|
||||
resources = await resourcesPromise;
|
||||
} catch (error) {
|
||||
note($("#receipts-note"), error.message, "err");
|
||||
return;
|
||||
}
|
||||
|
||||
async function loadReceipts() {
|
||||
const request = ++loading;
|
||||
note($("#receipts-note"), "Загрузка…");
|
||||
try {
|
||||
const receipts = await api("/api/receipts");
|
||||
if (request !== loading) return;
|
||||
const cards = $("#receipts");
|
||||
cards.replaceChildren();
|
||||
for (const receipt of receipts) {
|
||||
const card = cell("article", "", "reading-card panel");
|
||||
const time = cell("time", new Date(receipt.created_at).toLocaleString("ru-RU"));
|
||||
time.dateTime = receipt.created_at;
|
||||
const button = cell("button", "Открыть", "action");
|
||||
button.type = "button";
|
||||
button.setAttribute("aria-label", `Открыть квитанцию #${receipt.id}`);
|
||||
button.addEventListener("click", () => {
|
||||
opening++;
|
||||
selected = receipt.id;
|
||||
form.querySelector("button[type=submit]").disabled = false;
|
||||
form.reset();
|
||||
form.hidden = false;
|
||||
$("#receipt-note").hidden = true;
|
||||
$("#receipt-content").hidden = true;
|
||||
details.replaceChildren();
|
||||
$("#receipt-parameters").value = "";
|
||||
$("#receipt-dialog-title").textContent = `Квитанция #${receipt.id}`;
|
||||
dialog.showModal();
|
||||
});
|
||||
card.append(cell("h2", `ID квитанции: ${receipt.id}`), time, button);
|
||||
cards.append(card);
|
||||
}
|
||||
$("#receipts-note").hidden = receipts.length > 0;
|
||||
if (!receipts.length) note($("#receipts-note"), "Квитанций пока нет.");
|
||||
} catch (error) {
|
||||
if (request === loading) note($("#receipts-note"), error.message, "err");
|
||||
}
|
||||
}
|
||||
|
||||
$("#receipt-close").addEventListener("click", () => dialog.close());
|
||||
dialog.addEventListener("close", () => {
|
||||
opening++;
|
||||
form.reset();
|
||||
details.replaceChildren();
|
||||
$("#receipt-parameters").value = "";
|
||||
$("#receipt-content").hidden = true;
|
||||
});
|
||||
form.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
const request = ++opening;
|
||||
const button = event.submitter;
|
||||
button.disabled = true;
|
||||
try {
|
||||
const receipt = await post(`/api/receipts/${selected}/open`, { calculation_id: form.elements.calculation_id.value.trim() });
|
||||
if (request !== opening) return;
|
||||
const reading = receipt.reading;
|
||||
const calculation = receipt.calculation;
|
||||
const resource = resources.find((item) => item.id === reading.kind);
|
||||
const rows = [
|
||||
["ID квитанции", receipt.id], ["ID показания", receipt.reading_id],
|
||||
["Дата квитанции", new Date(receipt.created_at).toLocaleString("ru-RU")],
|
||||
["Дата показания", new Date(reading.created_at).toLocaleString("ru-RU")],
|
||||
["Серийный ID", reading.serial], ["Вид ресурса", resource.title],
|
||||
...resource.metrics.map((metric) => [metric.label, `${reading.metrics[metric.key]} ${metric.unit}`]),
|
||||
["Количество", `${calculation.quantity} ${calculation.unit}`],
|
||||
["Тариф", `${amount.format(calculation.unit_price)} €$ / ${calculation.unit}`],
|
||||
["Расчёт", `${calculation.quantity} × ${calculation.unit_price}`],
|
||||
["К оплате", `${amount.format(calculation.amount)} €$`],
|
||||
];
|
||||
details.replaceChildren();
|
||||
for (const [label, value] of rows) {
|
||||
details.append(cell("dt", label), cell("dd", value, label === "К оплате" ? "receipt-total" : ""));
|
||||
}
|
||||
$("#receipt-parameters").value = reading.parameters;
|
||||
form.reset();
|
||||
form.hidden = true;
|
||||
$("#receipt-content").hidden = false;
|
||||
} catch (error) {
|
||||
if (request === opening) note($("#receipt-note"), error.message, "err");
|
||||
} finally {
|
||||
if (request === opening) button.disabled = false;
|
||||
}
|
||||
});
|
||||
onRoute("receipts", loadReceipts);
|
||||
}
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
import { api } from "./api/client.js";
|
||||
import { initReadings } from "./features/readings.js";
|
||||
import { initReceipts } from "./features/receipts.js";
|
||||
import { initChat } from "./features/chat.js";
|
||||
import { initFinance } from "./features/finance.js";
|
||||
import { initRouter } from "./shared/router.js";
|
||||
|
||||
initRouter();
|
||||
const resources = api("/api/resources");
|
||||
const chat = initChat(resources);
|
||||
initReadings(resources, chat);
|
||||
initReceipts(resources);
|
||||
initFinance();
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
export const $ = (sel) => document.querySelector(sel);
|
||||
|
||||
export function cell(tag, text, cls) {
|
||||
const element = document.createElement(tag);
|
||||
element.textContent = text;
|
||||
if (cls) element.className = cls;
|
||||
return element;
|
||||
}
|
||||
|
||||
export function note(element, text, kind = "ok") {
|
||||
element.textContent = text;
|
||||
element.className = `note ${kind}`;
|
||||
element.hidden = false;
|
||||
}
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
const routes = {
|
||||
submit: "Передать показания",
|
||||
history: "Показания",
|
||||
receipts: "Квитанции",
|
||||
finance: "Финансы",
|
||||
};
|
||||
|
||||
function currentRoute() {
|
||||
const route = window.location.hash.replace(/^#\//, "");
|
||||
return routes[route] ? route : "submit";
|
||||
}
|
||||
|
||||
function renderRoute() {
|
||||
const route = currentRoute();
|
||||
for (const page of document.querySelectorAll("[data-page]")) {
|
||||
page.hidden = page.dataset.page !== route;
|
||||
}
|
||||
for (const link of document.querySelectorAll("[data-route]")) {
|
||||
if (link.dataset.route === route) link.setAttribute("aria-current", "page");
|
||||
else link.removeAttribute("aria-current");
|
||||
}
|
||||
document.title = routes[route] + " — Dark Tariff";
|
||||
}
|
||||
|
||||
export function onRoute(route, callback) {
|
||||
function load() {
|
||||
if (window.location.hash === "#/" + route) callback();
|
||||
}
|
||||
window.addEventListener("hashchange", load);
|
||||
load();
|
||||
}
|
||||
|
||||
export function navigateTo(route) {
|
||||
if (!routes[route]) return;
|
||||
if (currentRoute() === route) renderRoute();
|
||||
else window.location.hash = "#/" + route;
|
||||
}
|
||||
|
||||
export function initRouter() {
|
||||
if (!window.location.hash || !routes[window.location.hash.replace(/^#\//, "")]) {
|
||||
window.history.replaceState(null, "", "#/submit");
|
||||
}
|
||||
window.addEventListener("hashchange", renderRoute);
|
||||
renderRoute();
|
||||
}
|
||||
Executable
+207
@@ -0,0 +1,207 @@
|
||||
:root {
|
||||
color-scheme: dark;
|
||||
--bg: #101015;
|
||||
--panel: #18181f;
|
||||
--field: #111117;
|
||||
--raised: #22222c;
|
||||
--line: #373744;
|
||||
--ink: #f3f2f5;
|
||||
--dim: #aaa8b6;
|
||||
--acid: #efff43;
|
||||
--cyan: #70ede1;
|
||||
--pink: #ff5090;
|
||||
--error: #ff9dbd;
|
||||
--sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
||||
--mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
[hidden] { display: none !important; }
|
||||
body { min-width: 1168px; min-height: 100vh; margin: 0; overflow-x: clip; isolation: isolate; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--sans); }
|
||||
body::before, body::after { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none; }
|
||||
body::before {
|
||||
background: repeating-linear-gradient(0deg, transparent 0 3px, #70ede104 3px 4px),
|
||||
linear-gradient(#70ede109 1px, transparent 1px), linear-gradient(90deg, #70ede109 1px, transparent 1px);
|
||||
background-size: auto, 80px 80px, 80px 80px;
|
||||
mask-image: linear-gradient(#0009, #0002);
|
||||
}
|
||||
body::after {
|
||||
inset: -12%;
|
||||
background: radial-gradient(ellipse at 80% 25%, #70ede11c, transparent 48%), radial-gradient(ellipse at 10% 85%, #efff4310, transparent 42%);
|
||||
animation: ambient-drift 20s ease-in-out infinite alternate;
|
||||
}
|
||||
button, input, select, textarea { font: inherit; }
|
||||
button { cursor: pointer; }
|
||||
button:disabled { opacity: .55; cursor: default; }
|
||||
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
|
||||
.shell { width: 1120px; margin-inline: auto; }
|
||||
.topbar { border-bottom: 1px solid var(--line); background: #0c0c11e8; box-shadow: 0 1px 0 #70ede10b; }
|
||||
.topbar-inner { min-height: 80px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
|
||||
.brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
color: var(--ink);
|
||||
font-size: 24px;
|
||||
font-weight: 850;
|
||||
letter-spacing: -.05em;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.brand-mark {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
flex: 0 0 auto;
|
||||
filter: drop-shadow(0 0 7px #efff4366);
|
||||
}
|
||||
.meter-shell { fill: #17190c; stroke: var(--acid); stroke-width: 2; }
|
||||
.meter-screen { fill: #70ede122; stroke: var(--cyan); stroke-width: 1.5; }
|
||||
.meter-readout, .meter-dial { fill: none; stroke: var(--acid); stroke-linecap: square; stroke-width: 2; }
|
||||
.meter-core { fill: var(--pink); }
|
||||
|
||||
.main-nav { display: flex; gap: 24px; }
|
||||
.main-nav a { position: relative; padding-block: 8px; color: var(--dim); text-decoration: none; font-size: 13px; font-weight: 750; letter-spacing: .025em; text-transform: uppercase; transition: color .18s ease; }
|
||||
.main-nav a::after { content: ""; position: absolute; inset: auto 0 0; height: 2px; background: var(--acid); box-shadow: 0 0 12px #efff4340; transform: scaleX(0); transform-origin: left; transition: transform .2s ease; }
|
||||
.main-nav a:hover::after, .main-nav a[aria-current="page"]::after { transform: scaleX(1); }
|
||||
.main-nav a:hover, .main-nav a[aria-current="page"] { color: var(--acid); }
|
||||
.page { position: relative; padding: 60px 0 110px; }
|
||||
.page:not([hidden]) { animation: reveal .32s ease-out backwards; }
|
||||
.page::before { content: ""; position: absolute; top: 38px; right: 0; width: 88px; height: 4px; background: repeating-linear-gradient(135deg, var(--acid) 0 5px, transparent 5px 10px); opacity: .65; }
|
||||
h1 { margin: 14px 0 20px; font-size: 68px; font-weight: 900; letter-spacing: -.055em; line-height: 1.02; text-transform: uppercase; }
|
||||
#submit-page-title { max-width: 940px; margin-top: 24px; font-size: 96px; line-height: .98; }
|
||||
[data-page="submit"] { padding-top: clamp(60px, 9vh, 108px); }
|
||||
.eyebrow { display: flex; align-items: center; gap: 12px; margin: 0; color: var(--cyan); font: 700 12px/1.5 var(--mono); letter-spacing: .16em; text-transform: uppercase; }
|
||||
.eyebrow::before { content: ""; width: 8px; height: 8px; background: var(--acid); box-shadow: 0 0 14px #efff4340; }
|
||||
.intro { max-width: 620px; margin-bottom: 28px; color: var(--dim); }
|
||||
.primary, .action { min-height: 44px; padding: 11px 18px; border: 1px solid var(--line); font-weight: 750; clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 8px, 100% 100%, 8px 100%, 0 calc(100% - 8px)); transition: transform .18s ease, background .18s ease, border-color .18s ease, color .18s ease; }
|
||||
.primary { border-color: var(--acid); background: var(--acid); color: var(--bg); }
|
||||
.primary:hover:not(:disabled) { background: #fbff9e; transform: translate(2px, -2px); }
|
||||
.primary:active:not(:disabled), .action:active:not(:disabled) { transform: translateY(1px); }
|
||||
.primary:focus-visible { box-shadow: inset 0 0 0 2px var(--bg); }
|
||||
.action:focus-visible { box-shadow: inset 0 0 0 2px var(--cyan); }
|
||||
.action { background: var(--field); color: var(--ink); }
|
||||
.action:hover:not(:disabled) { border-color: var(--cyan); background: #70ede10a; color: var(--cyan); transform: translateY(-2px); }
|
||||
.panel, dialog { background: linear-gradient(135deg, #70ede109, transparent 60%), var(--panel); border: 1px solid var(--line); border-radius: 0; clip-path: polygon(0 0, calc(100% - 16px) 0, 100% 16px, 100% 100%, 16px 100%, 0 calc(100% - 16px)); }
|
||||
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 24px; border-bottom: 1px solid var(--line); }
|
||||
.panel-head h2 { margin: 0; font: 750 18px/1.4 var(--mono); letter-spacing: -.025em; }
|
||||
dialog[open], .help-chat:not([hidden]) { animation: reveal .2s ease-out backwards; }
|
||||
dialog { width: 640px; max-height: calc(100vh - 32px); padding: 0; overflow: auto; color: var(--ink); }
|
||||
dialog::backdrop { background: #08080dcc; backdrop-filter: blur(6px); animation: backdrop-in .2s ease-out; }
|
||||
form { display: grid; gap: 20px; padding: 24px; }
|
||||
label { display: grid; gap: 7px; color: var(--dim); font-size: 14px; }
|
||||
input, select, textarea { width: 100%; min-width: 0; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); background: var(--field); color: var(--ink); }
|
||||
input:not([type="checkbox"]), select, textarea { transition: border-color .2s ease, box-shadow .2s ease; }
|
||||
input:not([type="checkbox"]):focus, select:focus, textarea:focus { border-color: var(--cyan); box-shadow: inset 3px 0 var(--cyan); }
|
||||
input, textarea, time, .receipt-details dd, #verification-reading, #verification-receipt { font-family: var(--mono); font-variant-numeric: tabular-nums; }
|
||||
.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
|
||||
.field-help { margin: 0; color: var(--dim); font-size: 13px; }
|
||||
.note { margin-top: 12px; padding: 10px 14px; border-left: 2px solid var(--cyan); background: var(--field); color: var(--cyan); overflow-wrap: anywhere; }
|
||||
.note.err { color: var(--error); border-color: var(--error); }
|
||||
.history-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
|
||||
.reading-card { position: relative; min-width: 0; padding: 24px; animation: reveal .34s ease-out backwards; transition: transform .2s ease, border-color .2s ease; }
|
||||
.reading-card::before { content: ""; position: absolute; top: 0; left: 0; width: 48px; height: 3px; background: var(--acid); }
|
||||
.reading-card::after { content: ""; position: absolute; right: 10px; bottom: 10px; width: 8px; height: 8px; border-right: 1px solid var(--cyan); border-bottom: 1px solid var(--cyan); opacity: .5; }
|
||||
.reading-card:hover { transform: translateY(-4px); border-color: var(--cyan); }
|
||||
.reading-card:nth-child(2) { animation-delay: 40ms; }
|
||||
.reading-card:nth-child(3) { animation-delay: 80ms; }
|
||||
.reading-card:nth-child(n+4) { animation-delay: 120ms; }
|
||||
.reading-card h2 { margin: 8px 0; overflow-wrap: anywhere; font: 750 20px/1.4 var(--mono); }
|
||||
.reading-check { min-height: 32px; margin-top: 16px; padding: 6px 12px; font-size: 12px; }
|
||||
|
||||
|
||||
.help-launcher {
|
||||
position: fixed;
|
||||
right: 24px;
|
||||
bottom: 24px;
|
||||
z-index: 20;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
padding: 10px;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: var(--ink);
|
||||
}
|
||||
.help-hint {
|
||||
position: relative;
|
||||
padding: 10px 14px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 0;
|
||||
background: var(--raised);
|
||||
}
|
||||
.help-hint::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
right: -5px;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-top: 1px solid var(--line);
|
||||
border-right: 1px solid var(--line);
|
||||
background: var(--raised);
|
||||
transform: translateY(-50%) rotate(45deg);
|
||||
}
|
||||
.help-chat {
|
||||
position: fixed;
|
||||
right: 24px;
|
||||
bottom: 100px;
|
||||
z-index: 20;
|
||||
width: 360px;
|
||||
max-height: calc(100vh - 124px);
|
||||
overflow: auto;
|
||||
}
|
||||
.help-chat .panel-head { min-height: 0; gap: 12px; padding: 16px; }
|
||||
.help-chat .panel-head h2 { font-size: 18px; }
|
||||
.help-messages p {
|
||||
margin: 0 0 10px;
|
||||
padding: 12px 14px;
|
||||
border-left: 2px solid var(--line);
|
||||
border-radius: 0;
|
||||
background: var(--raised);
|
||||
overflow-wrap: anywhere;
|
||||
animation: reveal .2s ease-out backwards;
|
||||
}
|
||||
|
||||
textarea { resize: vertical; font-size: 13px; line-height: 1.55; }
|
||||
.verification-body { display: grid; gap: 16px; padding: 24px; }
|
||||
.verification-body p { margin: 0; }
|
||||
.reading-card label { margin-top: 16px; }
|
||||
.help-controls { padding: 0 16px 16px; }
|
||||
.help-controls .action { width: 100%; text-align: left; font-size: 13px; }
|
||||
.help-controls form { gap: 12px; padding: 0; }
|
||||
.help-messages { min-height: 0; max-height: 240px; overflow-y: auto; padding: 16px; }
|
||||
.help-messages .help-user { color: var(--cyan); }
|
||||
|
||||
.reading-card time { display: block; margin: 8px 0 16px; color: var(--dim); font-size: 13px; }
|
||||
.receipt-details { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; margin: 0; }
|
||||
.receipt-details dt { color: var(--dim); }
|
||||
.receipt-details dd { margin: 0; overflow-wrap: anywhere; }
|
||||
.receipt-details .receipt-total { color: var(--acid); font-weight: 750; }
|
||||
|
||||
.finance-controls { display: flex; flex-wrap: wrap; align-items: end; gap: 16px; margin-block: 24px; }
|
||||
.finance-controls label { display: grid; gap: 8px; }
|
||||
.finance-options { margin: 0 0 24px; padding: 16px; border: 1px solid var(--line); }
|
||||
#finance-fields { display: flex; flex-wrap: wrap; gap: 16px; }
|
||||
#finance-fields label { display: flex; align-items: center; gap: 8px; }
|
||||
#finance-fields input { width: auto; accent-color: var(--acid); }
|
||||
.finance-scroll { overflow-x: auto; }
|
||||
#finance-table { width: 100%; border-collapse: collapse; }
|
||||
#finance-table th, #finance-table td { padding: 12px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
|
||||
#finance-table th { color: var(--cyan); }
|
||||
#finance-table tbody tr { transition: background .18s ease; }
|
||||
#finance-table tbody tr:hover { background: #70ede107; }
|
||||
|
||||
@keyframes ambient-drift {
|
||||
from { transform: translate(-2%, -1%); }
|
||||
to { transform: translate(3%, 3%); }
|
||||
}
|
||||
|
||||
@keyframes reveal {
|
||||
from { opacity: 0; transform: translateY(12px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
|
||||
@keyframes backdrop-in {
|
||||
from { opacity: 0; }
|
||||
to { opacity: 1; }
|
||||
}
|
||||
Reference in new issue
Block a user