343 lines
10 KiB
HTML
343 lines
10 KiB
HTML
<!doctype html>
|
|
<html lang="ru">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Alice Stations Plugin</title>
|
|
<style>
|
|
:root {
|
|
--bg-main: #000;
|
|
--bg-soft: #070b14;
|
|
--card: rgba(255, 255, 255, 0.06);
|
|
--card-strong: rgba(255, 255, 255, 0.08);
|
|
--accent: rgba(255, 255, 255, 0.14);
|
|
--text: rgb(228, 228, 228);
|
|
--muted: rgba(228, 228, 228, 0.78);
|
|
--ok: #2ad384;
|
|
--err: #ff6a6a;
|
|
--line: rgba(255, 255, 255, 0.18);
|
|
}
|
|
html, body {
|
|
margin: 0;
|
|
padding: 0;
|
|
height: 100%;
|
|
background: #000;
|
|
}
|
|
* { box-sizing: border-box; }
|
|
body {
|
|
min-height: 100svh;
|
|
position: relative;
|
|
overflow-x: hidden;
|
|
padding-top: 12px;
|
|
background: linear-gradient(160deg, var(--bg-main), var(--bg-soft));
|
|
color: var(--text);
|
|
font: 14px/1.35 "Artifakt Element", "IBM Plex Sans Condensed", "Segoe UI", "Noto Sans", sans-serif;
|
|
}
|
|
body::before,
|
|
body::after {
|
|
content: "";
|
|
position: fixed;
|
|
inset: 0;
|
|
pointer-events: none;
|
|
z-index: -2;
|
|
}
|
|
body::before {
|
|
background:
|
|
radial-gradient(70vw 70vw at -10% -20%, rgba(255, 255, 255, 0.05), transparent 56%),
|
|
radial-gradient(60vw 60vw at 110% 20%, rgba(100, 120, 180, 0.10), transparent 60%),
|
|
radial-gradient(50vw 50vw at 50% 120%, rgba(80, 60, 120, 0.12), transparent 62%);
|
|
}
|
|
body::after {
|
|
z-index: -1;
|
|
background-image: linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
|
|
linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
|
|
background-size: 24px 24px;
|
|
opacity: 0.24;
|
|
}
|
|
.wrap {
|
|
width: min(980px, 100%);
|
|
max-width: 980px;
|
|
margin: 0 auto;
|
|
padding: 0 12px;
|
|
}
|
|
.card {
|
|
background: var(--card);
|
|
border: 1px solid var(--line);
|
|
border-radius: 10px;
|
|
backdrop-filter: blur(8px);
|
|
padding: 7px;
|
|
box-shadow: none;
|
|
margin-bottom: 8px;
|
|
overflow: hidden;
|
|
}
|
|
.card:last-child { margin-bottom: 0; }
|
|
.card:first-child {
|
|
background:
|
|
linear-gradient(130deg, rgba(255, 255, 255, 0.04), rgba(80, 60, 120, 0.18)),
|
|
var(--card-strong);
|
|
text-align: center;
|
|
}
|
|
h1 {
|
|
margin: 0;
|
|
font-size: 18px;
|
|
letter-spacing: .2px;
|
|
text-transform: none;
|
|
font-family: "IBM Plex Sans Condensed", "Artifakt Element", sans-serif;
|
|
}
|
|
.muted { color: var(--muted); }
|
|
.row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
|
|
input {
|
|
border: 1px solid var(--line);
|
|
border-radius: 6px;
|
|
padding: 6px 9px;
|
|
height: 27px;
|
|
line-height: 27px;
|
|
font: inherit;
|
|
color: var(--text);
|
|
background: rgba(255, 255, 255, 0.08);
|
|
font-family: "Fira Mono", "Artifakt Element", monospace;
|
|
}
|
|
input::placeholder { color: rgba(228, 228, 228, 0.64); }
|
|
.btn {
|
|
border: 1px solid rgba(255, 255, 255, 0.25);
|
|
border-radius: 6px;
|
|
padding: 0 10px;
|
|
height: 27px;
|
|
line-height: 27px;
|
|
cursor: pointer;
|
|
color: #fff;
|
|
background: var(--accent);
|
|
font: inherit;
|
|
font-weight: 500;
|
|
box-shadow: none;
|
|
transition: background .2s ease, transform .08s ease;
|
|
}
|
|
.btn:hover { background: rgba(255, 255, 255, 0.2); }
|
|
.btn:active { transform: translateY(1px); }
|
|
.btn.gray {
|
|
background: rgba(255, 255, 255, 0.08);
|
|
}
|
|
.btn.green {
|
|
background: rgba(42, 211, 132, 0.22);
|
|
border-color: rgba(42, 211, 132, 0.42);
|
|
height: 20px;
|
|
line-height: 20px;
|
|
padding: 0 8px;
|
|
font-size: 11px;
|
|
}
|
|
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
.field-input {
|
|
flex: 1 1 240px;
|
|
min-width: 180px;
|
|
}
|
|
.table-wrap {
|
|
width: 100%;
|
|
overflow-x: auto;
|
|
overflow-y: hidden;
|
|
-webkit-overflow-scrolling: touch;
|
|
}
|
|
table {
|
|
width: max-content;
|
|
min-width: 100%;
|
|
border-collapse: collapse;
|
|
font-size: 12px;
|
|
}
|
|
th, td {
|
|
border-bottom: 1px solid rgba(255, 255, 255, 0.12);
|
|
text-align: left;
|
|
padding: 6px 5px;
|
|
vertical-align: middle;
|
|
white-space: nowrap;
|
|
}
|
|
th { color: #fff; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .3px; }
|
|
#status { display: none; margin-top: 0; }
|
|
#status.show { display: block; margin-top: 8px; }
|
|
#status.ok { color: var(--ok); }
|
|
#status.err { color: var(--err); }
|
|
@media (max-width: 720px) {
|
|
h1 { font-size: 16px; }
|
|
.btn { width: 100%; }
|
|
.card { border-radius: 8px; }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="wrap">
|
|
<div class="card">
|
|
<h1>Alice Stations Plugin</h1>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="row">
|
|
<input class="field-input" id="token" placeholder="Yandex OAuth token">
|
|
<button class="btn" id="saveToken">Сохранить токен</button>
|
|
<input class="field-input" id="controllerHost" placeholder="IP для шаблонов (например 192.168.1.50)">
|
|
<button class="btn gray" id="saveHost">Сохранить IP</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="row">
|
|
<button class="btn" id="refresh">Найти колонки</button>
|
|
<button class="btn" id="dlLoxone">Скачать для Loxone</button>
|
|
<button class="btn" id="dlWb">Скачать для WB-rules</button>
|
|
</div>
|
|
<div id="status" class="muted"></div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="table-wrap">
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Имя</th>
|
|
<th>ID</th>
|
|
<th>Local ID</th>
|
|
<th>Комната</th>
|
|
<th>Модель</th>
|
|
<th>IP</th>
|
|
<th id="thInstall" style="display:none;">wb-rules</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="stations"></tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const q = (s) => document.querySelector(s);
|
|
const statusEl = q('#status');
|
|
let wbMode = false;
|
|
|
|
function setStatus(msg, ok = true) {
|
|
const text = String(msg || '').trim();
|
|
if (!text) {
|
|
statusEl.textContent = '';
|
|
statusEl.className = 'muted';
|
|
return;
|
|
}
|
|
statusEl.className = (ok ? 'ok' : 'err') + ' show';
|
|
statusEl.textContent = text;
|
|
}
|
|
|
|
async function api(path, method = 'GET', body = null) {
|
|
const r = await fetch(path, {
|
|
method,
|
|
headers: body ? {'Content-Type': 'application/json'} : undefined,
|
|
body: body ? JSON.stringify(body) : undefined,
|
|
});
|
|
const j = await r.json().catch(() => ({}));
|
|
if (!r.ok || j.ok === false) throw new Error(j.error || ('HTTP ' + r.status));
|
|
return j;
|
|
}
|
|
|
|
function stationRow(s) {
|
|
const tr = document.createElement('tr');
|
|
tr.innerHTML = `
|
|
<td>${s.name || ''}</td>
|
|
<td>${s.id || ''}</td>
|
|
<td>${s.local_id || ''}</td>
|
|
<td>${s.room || ''}</td>
|
|
<td>${s.model || ''}</td>
|
|
<td>${s.ip || s.con_url || ''}</td>
|
|
<td class="wb-cell" style="display:${wbMode ? '' : 'none'}"></td>
|
|
`;
|
|
if (wbMode) {
|
|
const btn = document.createElement('button');
|
|
btn.className = 'btn green';
|
|
btn.textContent = 'Установить';
|
|
btn.onclick = async () => {
|
|
try {
|
|
setStatus('Устанавливаю wb-rules для ' + (s.name || s.id) + '...');
|
|
const out = await api('/api/wb-rules/install', 'POST', {station_id: s.id});
|
|
setStatus('Установлено: ' + (out.installed || []).join(', '));
|
|
} catch (e) {
|
|
setStatus(e.message, false);
|
|
}
|
|
};
|
|
tr.querySelector('.wb-cell').appendChild(btn);
|
|
}
|
|
return tr;
|
|
}
|
|
|
|
function renderStations(items) {
|
|
const tbody = q('#stations');
|
|
tbody.innerHTML = '';
|
|
const rows = items || [];
|
|
if (!rows.length) {
|
|
const tr = document.createElement('tr');
|
|
tr.innerHTML = `<td colspan="7" class="muted">Станции пока не найдены. Сохрани токен и нажми «Найти колонки».</td>`;
|
|
tbody.appendChild(tr);
|
|
return;
|
|
}
|
|
rows.forEach((s) => tbody.appendChild(stationRow(s)));
|
|
}
|
|
|
|
async function refreshStatus() {
|
|
const st = await api('/api/status');
|
|
wbMode = !!st.is_wiren_board;
|
|
q('#thInstall').style.display = wbMode ? '' : 'none';
|
|
q('#controllerHost').value = (st.config && st.config.controller_host) || st.controller_host || '';
|
|
renderStations(st.stations || []);
|
|
}
|
|
|
|
q('#saveToken').onclick = async () => {
|
|
try {
|
|
await api('/api/token', 'POST', {token: q('#token').value});
|
|
setStatus('Токен сохранён');
|
|
q('#token').value = '';
|
|
await refreshStatus();
|
|
} catch (e) {
|
|
setStatus(e.message, false);
|
|
}
|
|
};
|
|
|
|
q('#saveHost').onclick = async () => {
|
|
try {
|
|
await api('/api/controller-host', 'POST', {controller_host: q('#controllerHost').value});
|
|
setStatus('IP сохранён');
|
|
await refreshStatus();
|
|
} catch (e) {
|
|
setStatus(e.message, false);
|
|
}
|
|
};
|
|
|
|
q('#refresh').onclick = async () => {
|
|
try {
|
|
setStatus('Обновляю список колонок...');
|
|
const out = await api('/api/stations/refresh', 'POST');
|
|
renderStations(out.stations || []);
|
|
setStatus('Готово, колонок: ' + (out.stations || []).length);
|
|
} catch (e) {
|
|
setStatus(e.message, false);
|
|
}
|
|
};
|
|
|
|
q('#dlLoxone').onclick = async () => {
|
|
try {
|
|
setStatus('Генерирую Loxone шаблоны и готовлю архив...');
|
|
await api('/api/templates/loxone', 'POST');
|
|
window.location.href = '/api/download/loxone';
|
|
setStatus('Скачивание Loxone ZIP запущено. Локальная копия лежит в configs/loxone/loxone_templates.zip');
|
|
} catch (e) {
|
|
setStatus(e.message, false);
|
|
}
|
|
};
|
|
|
|
q('#dlWb').onclick = async () => {
|
|
try {
|
|
setStatus('Генерирую wb-rules шаблоны и готовлю архив...');
|
|
await api('/api/templates/wb-rules', 'POST');
|
|
window.location.href = '/api/download/wb-rules';
|
|
setStatus('Скачивание wb-rules ZIP запущено. Локальная копия лежит в configs/wb-rules/wb_rules_templates.zip');
|
|
} catch (e) {
|
|
setStatus(e.message, false);
|
|
}
|
|
};
|
|
|
|
refreshStatus().catch((e) => setStatus(e.message, false));
|
|
</script>
|
|
</body>
|
|
</html>
|