diff --git a/fsnb_ref.py b/fsnb_ref.py
index a93a187..82d0fd0 100644
--- a/fsnb_ref.py
+++ b/fsnb_ref.py
@@ -152,6 +152,7 @@ def _provenance(src: dict | None) -> dict:
if not src:
return {}
return {"decree": src["decree"], "file": src["file"], "dataset": src["dataset"],
+ "url": src.get("url"),
"base": src["base"], "zip_sha256": src["zip_sha256"],
"fetched_at": src["fetched_at"]}
diff --git a/main.py b/main.py
index 3dc81d6..6f83956 100644
--- a/main.py
+++ b/main.py
@@ -555,7 +555,7 @@ MAX_MESSAGE_LEN = 10_000
# ⚠️ Версия UI — единый источник. БАМПАТЬ ПРИ КАЖДОМ ДЕПЛОЕ (формат: YYYY-MM-DD + буква).
# Фронт берёт её через GET /api/version (chat.html + admin.html, элемент .app-version).
-APP_VERSION = "2026-12-04e"
+APP_VERSION = "2026-12-04f"
# Audit: path → action name mapping
_AUDIT_MAP = [
@@ -2452,6 +2452,34 @@ async def public_norm_finder_catalog(request: Request):
return {"bases": await asyncio.to_thread(norm_finder.catalog)}
+@app.get("/api/public/norm-finder/browse")
+async def public_norm_finder_browse(request: Request, base: str = "2022", base_type: str = "ГЭСН",
+ path: str = "", limit: int = 20, offset: int = 0):
+ _check_public_finder_rate(request)
+ if limit > 20:
+ raise HTTPException(400, "Публичный каталог показывает до 20 норм за запрос")
+ import norm_finder
+ try:
+ return await asyncio.to_thread(norm_finder.browse, base, base_type, path, limit, offset)
+ except ValueError as exc:
+ raise HTTPException(400, str(exc)) from exc
+ except RuntimeError as exc:
+ raise HTTPException(503, str(exc)) from exc
+
+
+@app.get("/api/norm-finder/browse")
+async def norm_finder_browse(request: Request, base: str = "2022", base_type: str = "ГЭСН",
+ path: str = "", limit: int = 40, offset: int = 0):
+ _get_user(request)
+ import norm_finder
+ try:
+ return await asyncio.to_thread(norm_finder.browse, base, base_type, path, limit, offset)
+ except ValueError as exc:
+ raise HTTPException(400, str(exc)) from exc
+ except RuntimeError as exc:
+ raise HTTPException(503, str(exc)) from exc
+
+
@app.get("/api/public/norm-finder/search")
async def public_norm_finder_search(request: Request, q: str = "", base: str = "2022", limit: int = 8,
offset: int = 0):
diff --git a/norm_finder.py b/norm_finder.py
index 5dd9aa2..f6a9c56 100644
--- a/norm_finder.py
+++ b/norm_finder.py
@@ -3,6 +3,7 @@ from __future__ import annotations
import math
import re
+from functools import lru_cache
import fsnb_ref
@@ -85,6 +86,66 @@ def catalog() -> list[dict]:
con.close()
+@lru_cache(maxsize=32)
+def _section_paths(db_key: tuple[str, int, int], base: str, base_type: str) -> tuple[str, ...]:
+ """Cache the section index; a rebuilt SQLite file gets a new cache key."""
+ con = fsnb_ref._connect()
+ if con is None:
+ raise RuntimeError("Нормативная база недоступна")
+ try:
+ return tuple(row[0] for row in con.execute(
+ "SELECT DISTINCT section_path FROM works WHERE base=? AND base_type=? "
+ "AND section_path IS NOT NULL AND section_path != '' ORDER BY section_path",
+ (base, base_type)))
+ finally:
+ con.close()
+
+
+def browse(base: str, base_type: str, path: str = "", limit: int = 40,
+ offset: int = 0) -> dict:
+ """Browse one source-backed section and a bounded page of its norms."""
+ if (base not in BASES or base_type not in TYPES
+ or not base_type.startswith("ГЭСН" if base == "2022" else "ФЕР")
+ or not isinstance(path, str) or len(path) > 800
+ or not isinstance(limit, int) or isinstance(limit, bool) or not 1 <= limit <= 50
+ or not isinstance(offset, int) or isinstance(offset, bool) or not 0 <= offset <= 5000):
+ raise ValueError("Укажите существующий раздел, базу, тип и страницу до 50 норм")
+ db = fsnb_ref.db_path()
+ try:
+ stat = db.stat()
+ except OSError as exc:
+ raise RuntimeError("Нормативная база недоступна") from exc
+ paths = _section_paths((str(db), stat.st_mtime_ns, stat.st_size), BASES[base], base_type)
+ prefix = path + " > " if path else ""
+ if path and not any(p == path or p.startswith(prefix) for p in paths):
+ raise ValueError("Раздел не найден в выбранном сборнике")
+ children = sorted({p[len(prefix):].split(" > ", 1)[0] for p in paths
+ if p.startswith(prefix) and p != path})
+ con = fsnb_ref._connect()
+ if con is None:
+ raise RuntimeError("Нормативная база недоступна")
+ try:
+ if path:
+ # Escape LIKE metacharacters even when they occur in a real section name.
+ escaped = path.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_")
+ clause = "AND (section_path=? OR section_path LIKE ? ESCAPE '\\')"
+ params = (BASES[base], base_type, path, escaped + " > %")
+ else:
+ clause = ""
+ params = (BASES[base], base_type)
+ rows = con.execute(
+ "SELECT code,name,unit,cost,price_level,section_path FROM works "
+ f"WHERE base=? AND base_type=? {clause} ORDER BY code,name LIMIT ? OFFSET ?",
+ (*params, limit + 1, offset)).fetchall()
+ finally:
+ con.close()
+ return {"base": BASES[base], "base_type": base_type, "path": path,
+ "children": [{"name": name, "path": prefix + name} for name in children],
+ "items": [dict(row) | {"base": BASES[base], "base_type": base_type}
+ for row in rows[:limit]],
+ "offset": offset, "has_more": len(rows) > limit}
+
+
def search(query: str, base: str, limit: int = 12, offset: int = 0) -> dict:
query = query.strip() if isinstance(query, str) else ""
if (not 2 <= len(query) <= 160 or base not in BASES or not isinstance(limit, int)
diff --git a/static/norm-finder.html b/static/norm-finder.html
index 9f4b500..a4dc4a7 100644
--- a/static/norm-finder.html
+++ b/static/norm-finder.html
@@ -13,7 +13,7 @@
button { cursor:pointer; }
:focus-visible { outline:3px solid #65aba4; outline-offset:2px; }
a { color:var(--accent); }
- .wrap { max-width:1240px; margin:auto; padding:24px clamp(16px,3vw,40px) 64px; }
+ .wrap { max-width:1600px; margin:auto; padding:24px clamp(16px,3vw,40px) 64px; }
header { display:flex; align-items:center; justify-content:space-between; gap:16px; margin-bottom:32px; }
.brand { font-weight:750; font-size:1.15rem; text-decoration:none; color:var(--text); }
h1 { font-size:clamp(2rem,4vw,3rem); line-height:1.1; margin:0 0 12px; }
@@ -71,23 +71,72 @@
.draft-row input { width:110px; }
.quote-controls label { min-width:140px; }
.quote-controls #qty { width:125px; }
+ .workspace { display:grid; grid-template-columns:minmax(230px,280px) minmax(0,1fr); gap:16px; align-items:start; }
+ .catalog-tree { max-height:72vh; overflow:auto; position:sticky; top:12px; }
+ .catalog-tree h2 { font-size:1.05rem; }
+ .tree-list { list-style:none; margin:0; padding:0 0 0 12px; border-left:1px solid var(--line); }
+ .tree-list button { width:100%; text-align:left; border:0; border-radius:5px; background:transparent;
+ padding:6px; color:var(--text); font-size:.84rem; line-height:1.3; }
+ .tree-list button:hover,.tree-list button[aria-current="true"] { background:#e9f4f1; color:var(--accent); }
+ .table-panel { min-width:0; }
+ .table-panel h2 { margin:0; }
+ .table-heading { display:flex; justify-content:space-between; align-items:center; gap:12px; margin-bottom:12px; }
+ .norm-scroll { max-width:100%; overflow-x:auto; }
+ .norm-table { min-width:680px; }
+ .norm-table th { background:#f6f7f4; position:sticky; top:0; z-index:1; }
+ .norm-table .norm-row:hover { background:#f8faf8; }
+ .norm-table .norm-row button { min-height:32px; }
+ .norm-table .norm-name { min-width:240px; }
+ .norm-table .inline-cell { padding:0; background:#f8faf8; }
+ .inline-content { padding:16px; border-left:3px solid var(--accent); }
+ .inline-content .detail-grid { grid-template-columns:minmax(0,1fr); }
+ .inline-content .panel { border:0; padding:12px 0; background:transparent; }
+ .inline-content #quote-panel { border-top:1px solid var(--line); }
+ .inline-actions { display:flex; align-items:center; flex-wrap:wrap; gap:6px; }
+ .inline-actions .secondary { min-height:32px; }
+ .breadcrumb { color:var(--muted); font-size:.84rem; overflow-wrap:anywhere; }
+ .catalog-mobile { display:none; }
[hidden] { display:none !important; }
@media (max-width:760px) { .wrap { padding:18px 14px 40px; } header { margin-bottom:24px; }
.detail-grid,.comparison { grid-template-columns:minmax(0,1fr); } .panel,.card { padding:15px; }
.search-row > *, .controls > label { flex:1 1 100%; } .search-row button { width:100%; }
- .quote-controls label { min-width:0; } }
+ .quote-controls label { min-width:0; } .workspace { display:block; }
+ .catalog-mobile { display:block; margin-bottom:10px; }
+ .catalog-tree { position:static; max-height:45vh; margin-bottom:12px; }
+ .catalog-tree[hidden] { display:none !important; }
+ .norm-scroll { overflow:visible; }
+ .norm-table,.norm-table > tbody,.norm-table > tbody > .norm-detail-row,
+ .norm-table > tbody > .norm-detail-row > td { display:block; min-width:0; width:100%; }
+ .norm-table thead { display:none; }
+ .norm-table .norm-row { display:grid; grid-template-columns:minmax(0,1fr) auto;
+ gap:5px 12px; padding:13px 0; border-top:1px solid var(--line); }
+ .norm-table .norm-row td { border:0; padding:0; min-width:0; }
+ .norm-table .norm-row td:nth-child(1) { grid-column:1 / -1; }
+ .norm-table .norm-row td:nth-child(2) { grid-column:1 / -1; overflow-wrap:anywhere; }
+ .norm-table .norm-row td:nth-child(3) { grid-column:1; }
+ .norm-table .norm-row td:nth-child(4) { grid-column:2; }
+ .norm-table .norm-row td:nth-child(5) { grid-column:1 / -1; }
+ .norm-table .norm-row .inline-actions { gap:6px; }
+ .norm-table .norm-row .inline-actions button { flex:1 1 auto; }
+ .inline-content { padding:12px 10px; }
+ .inline-content #detail-title { font-size:1.05rem; overflow-wrap:anywhere; }
+ .inline-content .scroll { overflow-x:auto; }
+ .inline-content .scroll table { min-width:560px; }
+ .inline-content .detail-grid { display:block; }
+ }
Подбор норм
- Найдите работу по названию или шифру, проверьте состав и измеритель, сравните варианты. Цены считаются только по доступной форме выбранной зоны и квартала.
+ Выберите сборник и раздел или найдите норму по шифру и названию. Раскройте строку, чтобы увидеть состав работ, ресурсы и источник.
- Подходящие нормы
- Показать ещё нормы
+ Разделы сборника
+
+
+
+
Нормы сборника
+
+
+ Показать ещё нормы
+
+
Предварительный расчёт Объём вводится в выбранной единице. Недостающие цены и затраты будут отмечены.
@@ -124,6 +181,6 @@
-
+