Files
silo/internal/api/web.go
Zoe Forbes 8c0689991e feat: Infor-style split-panel layout, projects page, fuzzy search, Odoo scaffold
Web UI - Infor CloudSuite-style split-panel layout (items.html rewrite):
- Replace modal-based item detail with inline split-panel workspace
- Horizontal mode: item list on left, tabbed detail panel on right
- Vertical mode: detail panel on top, item list below
- Detail tabs: Main, Properties, Revisions, BOM, Where Used
- Ctrl+F opens in-page filter overlay with fuzzy search
- Column config gear icon with per-layout-mode persistence
- Search scope toggle pills (All / Part Number / Description)
- Selected row highlight with accent border
- Responsive breakpoint forces vertical below 900px
- Create/Edit/Delete remain as modal dialogs

Web UI - Projects page:
- New projects.html template with full CRUD
- Project table: Code, Name, Description, Item count, Created, Actions
- Create/Edit/Delete modals
- Click project code navigates to items filtered by project
- 3-tab navigation in base.html: Items, Projects, Schemas

Fuzzy search:
- Add sahilm/fuzzy dependency for ranked text matching
- New internal/api/search.go with SearchableItems fuzzy.Source
- GET /api/items/search endpoint with field scope and type/project filters
- Frontend routes to fuzzy endpoint when search input is non-empty

Odoo ERP integration scaffold:
- Migration 008: integrations and sync_log tables
- internal/odoo/ package: types, client stubs, sync stubs
- internal/db/integrations.go: IntegrationRepository
- internal/config/config.go: OdooConfig struct
- 6 API endpoints for config CRUD, sync log, test, push, pull
- All sync operations return stub responses

Documentation:
- docs/REPOSITORY_STATUS.md: comprehensive repository state report
  with architecture overview, API surface, feature stubs, and
  potential issues analysis
2026-01-31 09:20:27 -06:00

107 lines
2.9 KiB
Go

package api
import (
"bytes"
"embed"
"html/template"
"net/http"
"github.com/rs/zerolog"
)
//go:embed templates/*.html
var templatesFS embed.FS
// WebHandler serves HTML pages.
type WebHandler struct {
templates *template.Template
logger zerolog.Logger
}
// NewWebHandler creates a new web handler.
func NewWebHandler(logger zerolog.Logger) (*WebHandler, error) {
// Parse templates from embedded filesystem
tmpl, err := template.ParseFS(templatesFS, "templates/*.html")
if err != nil {
return nil, err
}
return &WebHandler{
templates: tmpl,
logger: logger,
}, nil
}
// PageData holds data for page rendering.
type PageData struct {
Title string
Page string
Data any
}
// render executes a page template within the base layout.
func (h *WebHandler) render(w http.ResponseWriter, page string, data PageData) {
// First, render the page-specific content
var contentBuf bytes.Buffer
if err := h.templates.ExecuteTemplate(&contentBuf, page+".html", data); err != nil {
h.logger.Error().Err(err).Str("page", page).Msg("failed to render page template")
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
// Now render the base template with the content
w.Header().Set("Content-Type", "text/html; charset=utf-8")
if err := h.templates.ExecuteTemplate(w, "base.html", data); err != nil {
h.logger.Error().Err(err).Msg("failed to render base template")
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
}
}
// HandleIndex serves the main items page.
func (h *WebHandler) HandleIndex(w http.ResponseWriter, r *http.Request) {
// Check if this is the root path
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
data := PageData{
Title: "Items",
Page: "items",
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
if err := h.templates.ExecuteTemplate(w, "base.html", data); err != nil {
h.logger.Error().Err(err).Msg("failed to render template")
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
}
}
// HandleProjectsPage serves the projects page.
func (h *WebHandler) HandleProjectsPage(w http.ResponseWriter, r *http.Request) {
data := PageData{
Title: "Projects",
Page: "projects",
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
if err := h.templates.ExecuteTemplate(w, "base.html", data); err != nil {
h.logger.Error().Err(err).Msg("failed to render template")
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
}
}
// HandleSchemasPage serves the schemas page.
func (h *WebHandler) HandleSchemasPage(w http.ResponseWriter, r *http.Request) {
data := PageData{
Title: "Schemas",
Page: "schemas",
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
if err := h.templates.ExecuteTemplate(w, "base.html", data); err != nil {
h.logger.Error().Err(err).Msg("failed to render template")
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
}
}