From 2ae18dea27d2720558fd2cc8981be912f043beeb Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 11 May 2026 16:50:52 +0300 Subject: [PATCH] feat: add home page with search/unassigned tables; center login card - Add home view as default: search by inv number, unassigned equipment table with auditory assignment, search results (assigned) table - Add inv_number query param to GET /oboruds/ for backend search - Center login card vertically and horizontally via flexbox Co-Authored-By: Claude Sonnet 4.6 --- backend/routers/oboruds.py | 4 +- frontend/app.js | 71 +++++++++++++++++++++++++++- frontend/index.html | 97 +++++++++++++++++++++++++++++++++++++- frontend/login.html | 6 ++- 4 files changed, 173 insertions(+), 5 deletions(-) diff --git a/backend/routers/oboruds.py b/backend/routers/oboruds.py index cc2e061..e3ed15a 100644 --- a/backend/routers/oboruds.py +++ b/backend/routers/oboruds.py @@ -15,12 +15,14 @@ def create_oborud(item: schemas.OborudCreate, db: Session = Depends(database.get return obj @oboruds.get("/", response_model=list[schemas.OborudRead]) -def list_oboruds(aud_id: Optional[int] = None, sort_by_inv: bool = False, unassigned: bool = False, db: Session = Depends(database.get_db)): +def list_oboruds(aud_id: Optional[int] = None, sort_by_inv: bool = False, unassigned: bool = False, inv_number: Optional[int] = None, db: Session = Depends(database.get_db)): query = db.query(models.Oboruds) if unassigned: query = query.filter(models.Oboruds.aud_id == None) elif aud_id is not None: query = query.filter(models.Oboruds.aud_id == aud_id) + if inv_number is not None: + query = query.filter(models.Oboruds.invNumber == inv_number) if sort_by_inv: query = query.order_by(models.Oboruds.invNumber.asc()) return query.all() diff --git a/frontend/app.js b/frontend/app.js index 9b25b1f..a90db2d 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -17,7 +17,7 @@ async function fetchJSON(url) { createApp({ data() { return { - view: 'byAud', + view: 'home', auditories: [], selectedAudId: '', oboruds: [], @@ -27,6 +27,11 @@ createApp({ status: '', error: '', printTitle: '', + // home view + homeSearch: '', + homeUnassigned: [], + homeSearchResults: [], + homeSearchDone: false, // auth/user management token: '', role: '', @@ -72,6 +77,69 @@ createApp({ canEdit() { return this.isAdmin || this.isEditor; }, }, methods: { + async showHome() { + this.view = 'home'; + this.status = ''; + this.error = ''; + this.homeSearch = ''; + this.homeSearchResults = []; + this.homeSearchDone = false; + await this.loadHomeUnassigned(); + }, + async loadHomeUnassigned() { + this.status = 'Загрузка нераспределённого оборудования…'; + this.error = ''; + try { + const data = await fetchJSON('/oboruds/?unassigned=true&sort_by_inv=true'); + this.homeUnassigned = data.map(it => ({ ...it, selectedAudId: '' })); + this.status = ''; + } catch (e) { + console.error(e); + this.error = 'Не удалось загрузить данные'; + this.status = ''; + } + }, + async doHomeSearch() { + const q = this.homeSearch.trim(); + if (!q) { + this.status = 'Введите инвентарный номер'; + return; + } + this.status = 'Поиск…'; + this.error = ''; + this.homeSearchDone = false; + try { + const data = await fetchJSON(`/oboruds/?inv_number=${encodeURIComponent(q)}`); + this.homeSearchResults = data.filter(it => it.aud_id).map(it => ({ ...it, selectedAudId: '' })); + this.homeSearchDone = true; + this.status = ''; + } catch (e) { + console.error(e); + this.error = 'Не удалось выполнить поиск'; + this.status = ''; + } + }, + async assignToAuditory(item) { + if (!item.selectedAudId) { + this.status = 'Выберите аудиторию'; + return; + } + try { + this.status = 'Сохранение…'; + this.error = ''; + await this.fetchAuth(`/oboruds/${item.id}`, { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ aud_id: item.selectedAudId }), + }); + await this.loadHomeUnassigned(); + this.status = 'Сохранено'; + } catch (e) { + console.error(e); + this.error = 'Не удалось назначить аудиторию'; + this.status = ''; + } + }, logout() { try { localStorage.removeItem('access_token'); @@ -592,6 +660,7 @@ createApp({ this.loadAuditories(); this.loadOwners(); this.loadEquipmentTypes(); + this.loadHomeUnassigned(); if (this.isAdmin) { this.loadUsers(); } diff --git a/frontend/index.html b/frontend/index.html index f8b5256..fa0fe79 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -18,12 +18,13 @@