feat(frontend): mount static UI at /app with simple auditories/equipment browser
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
# backend/main.py
|
# backend/main.py
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.responses import RedirectResponse
|
from fastapi.responses import RedirectResponse
|
||||||
|
from starlette.staticfiles import StaticFiles
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
from backend.routers.equipment_types import equipment_types
|
from backend.routers.equipment_types import equipment_types
|
||||||
@@ -29,9 +30,12 @@ def ping():
|
|||||||
return {"message": "pong"}
|
return {"message": "pong"}
|
||||||
|
|
||||||
|
|
||||||
|
# Serve static frontend
|
||||||
|
app.mount("/app", StaticFiles(directory="frontend", html=True), name="frontend")
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
def root():
|
def root():
|
||||||
return RedirectResponse(url="/docs")
|
return RedirectResponse(url="/app/")
|
||||||
|
|
||||||
|
|
||||||
# Подключение роутов
|
# Подключение роутов
|
||||||
|
|||||||
76
frontend/app.js
Normal file
76
frontend/app.js
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
const api = {
|
||||||
|
auds: "/auditories/",
|
||||||
|
oboruds: (audId) => `/oboruds/?aud_id=${encodeURIComponent(audId)}`,
|
||||||
|
};
|
||||||
|
|
||||||
|
async function fetchJSON(url) {
|
||||||
|
const res = await fetch(url);
|
||||||
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
function setStatus(msg, type = "info") {
|
||||||
|
const el = document.getElementById("status");
|
||||||
|
el.textContent = msg || "";
|
||||||
|
el.className = `status ${type}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadAuditories() {
|
||||||
|
setStatus("Загрузка аудиторий…");
|
||||||
|
try {
|
||||||
|
const data = await fetchJSON(api.auds);
|
||||||
|
const select = document.getElementById("aud-select");
|
||||||
|
select.innerHTML = '<option value="">— выберите аудиторию —</option>';
|
||||||
|
data.forEach((a) => {
|
||||||
|
const opt = document.createElement("option");
|
||||||
|
opt.value = a.id;
|
||||||
|
opt.textContent = `${a.id} — ${a.audnazvanie}`;
|
||||||
|
select.appendChild(opt);
|
||||||
|
});
|
||||||
|
setStatus("");
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
setStatus("Не удалось загрузить аудитории", "error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderOboruds(items) {
|
||||||
|
const tbody = document.querySelector("#ob-table tbody");
|
||||||
|
tbody.innerHTML = "";
|
||||||
|
items.forEach((it) => {
|
||||||
|
const tr = document.createElement("tr");
|
||||||
|
tr.innerHTML = `
|
||||||
|
<td>${it.id}</td>
|
||||||
|
<td>${it.invNumber ?? ""}</td>
|
||||||
|
<td>${it.nazvanie ?? ""}</td>
|
||||||
|
<td>${it.raspologenie ?? ""}</td>
|
||||||
|
<td>${it.kolichestvo ?? ""}</td>
|
||||||
|
<td>${it.type?.name ?? ""}</td>
|
||||||
|
`;
|
||||||
|
tbody.appendChild(tr);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadOborudsForSelected() {
|
||||||
|
const select = document.getElementById("aud-select");
|
||||||
|
const audId = select.value;
|
||||||
|
if (!audId) {
|
||||||
|
setStatus("Выберите аудиторию", "warn");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setStatus("Загрузка оборудования…");
|
||||||
|
try {
|
||||||
|
const data = await fetchJSON(api.oboruds(audId));
|
||||||
|
renderOboruds(data);
|
||||||
|
setStatus("");
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
setStatus("Не удалось загрузить оборудование", "error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
document.getElementById("load-btn").addEventListener("click", loadOborudsForSelected);
|
||||||
|
loadAuditories();
|
||||||
|
});
|
||||||
|
|
||||||
47
frontend/index.html
Normal file
47
frontend/index.html
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="ru">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>ASU Inventory — Фронт</title>
|
||||||
|
<link rel="stylesheet" href="/app/styles.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<h1>ASU Inventory</h1>
|
||||||
|
<nav>
|
||||||
|
<a href="/docs" target="_blank">API Docs</a>
|
||||||
|
</nav>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<section class="panel">
|
||||||
|
<h2>Оборудование по аудитории</h2>
|
||||||
|
<div class="controls">
|
||||||
|
<label for="aud-select">Аудитория:</label>
|
||||||
|
<select id="aud-select">
|
||||||
|
<option value="">— выберите аудиторию —</option>
|
||||||
|
</select>
|
||||||
|
<button id="load-btn">Показать</button>
|
||||||
|
</div>
|
||||||
|
<div id="status" class="status"></div>
|
||||||
|
<table id="ob-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Инв. номер</th>
|
||||||
|
<th>Название</th>
|
||||||
|
<th>Расположение</th>
|
||||||
|
<th>Кол-во</th>
|
||||||
|
<th>Тип</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody></tbody>
|
||||||
|
</table>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<script src="/app/app.js" defer></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
19
frontend/styles.css
Normal file
19
frontend/styles.css
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
:root { --bg: #0f172a; --fg: #e2e8f0; --muted: #94a3b8; --accent: #38bdf8; --err: #ef4444; --warn: #f59e0b; }
|
||||||
|
* { box-sizing: border-box; }
|
||||||
|
body { margin: 0; font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; background: var(--bg); color: var(--fg); }
|
||||||
|
header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid #1f2937; }
|
||||||
|
header h1 { margin: 0; font-size: 20px; }
|
||||||
|
header nav a { color: var(--accent); text-decoration: none; }
|
||||||
|
main { padding: 20px; max-width: 1000px; margin: 0 auto; }
|
||||||
|
.panel { background: #0b1220; border: 1px solid #1f2937; border-radius: 8px; padding: 16px; }
|
||||||
|
.controls { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
|
||||||
|
select, button { padding: 8px 10px; border-radius: 6px; border: 1px solid #1f2937; background: #0a0f1a; color: var(--fg); }
|
||||||
|
button { cursor: pointer; }
|
||||||
|
button:hover { border-color: var(--accent); }
|
||||||
|
.status { min-height: 20px; color: var(--muted); margin-bottom: 8px; }
|
||||||
|
.status.error { color: var(--err); }
|
||||||
|
.status.warn { color: var(--warn); }
|
||||||
|
table { width: 100%; border-collapse: collapse; }
|
||||||
|
th, td { border-bottom: 1px solid #1f2937; padding: 8px; text-align: left; }
|
||||||
|
th { color: var(--muted); font-weight: 600; }
|
||||||
|
|
||||||
Reference in New Issue
Block a user