Add container arrays with 3D drawer grid view
Locations can now be container arrays (up to 20x20). Each drawer is a child location with a grid position and color, shown in a 3D cabinet view with hover/tap slide-out, content summary peek, drag (or touch and hold) to swap, and a modal to rename, recolor, or relocate drawers. Deleting a drawer leaves its slot empty. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
423e1552f8
commit
c0375f651a
14 files changed
+1335
-14
No files matched your search
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.0.1",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "solis",
|
||||
"runtimeExecutable": "go",
|
||||
"runtimeArgs": ["run", "."],
|
||||
"port": 8889
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -113,6 +113,42 @@ func migrate(conn *sql.DB) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure container array / drawer columns exist in locations (for existing databases)
|
||||
{
|
||||
rows, err := conn.Query("PRAGMA table_info(locations)")
|
||||
if err != nil {
|
||||
return fmt.Errorf("pragma table_info for locations: %w", err)
|
||||
}
|
||||
existing := map[string]bool{}
|
||||
for rows.Next() {
|
||||
var cid int
|
||||
var name, ctype string
|
||||
var notnull, pk int
|
||||
var dfltValue interface{}
|
||||
if err := rows.Scan(&cid, &name, &ctype, ¬null, &dfltValue, &pk); err != nil {
|
||||
rows.Close()
|
||||
return fmt.Errorf("scanning table_info for locations: %w", err)
|
||||
}
|
||||
existing[name] = true
|
||||
}
|
||||
rows.Close()
|
||||
|
||||
gridColumns := map[string]string{
|
||||
"grid_rows": "INTEGER NOT NULL DEFAULT 0",
|
||||
"grid_cols": "INTEGER NOT NULL DEFAULT 0",
|
||||
"grid_row": "INTEGER",
|
||||
"grid_col": "INTEGER",
|
||||
"color": "TEXT NOT NULL DEFAULT ''",
|
||||
}
|
||||
for _, col := range []string{"grid_rows", "grid_cols", "grid_row", "grid_col", "color"} {
|
||||
if !existing[col] {
|
||||
if _, err := conn.Exec(fmt.Sprintf("ALTER TABLE locations ADD COLUMN %s %s", col, gridColumns[col])); err != nil {
|
||||
return fmt.Errorf("adding %s column to locations: %w", col, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Populate empty location slugs
|
||||
{
|
||||
rows, err := conn.Query("SELECT id, name FROM locations WHERE slug = '' OR slug IS NULL")
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"Solis/internal/slug"
|
||||
)
|
||||
|
||||
const MaxGridSize = 20
|
||||
|
||||
// SetLocationGrid turns a location into a container array (or resizes/disables one).
|
||||
// Shrinking is rejected while drawers occupy cells outside the new bounds.
|
||||
func (d *DB) SetLocationGrid(id int64, rows, cols int64) error {
|
||||
if rows < 0 || cols < 0 || rows > MaxGridSize || cols > MaxGridSize {
|
||||
return fmt.Errorf("grid size must be between 0 and %d", MaxGridSize)
|
||||
}
|
||||
// A container array needs both dimensions; treat a half-set grid as disabled
|
||||
if rows == 0 || cols == 0 {
|
||||
rows, cols = 0, 0
|
||||
}
|
||||
|
||||
var occupied int
|
||||
err := d.Conn.QueryRow(
|
||||
"SELECT COUNT(*) FROM locations WHERE parent_id = ? AND grid_row IS NOT NULL AND (grid_row >= ? OR grid_col >= ?)",
|
||||
id, rows, cols,
|
||||
).Scan(&occupied)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if occupied > 0 {
|
||||
return fmt.Errorf("cannot shrink container array: %d drawer(s) sit outside the new size", occupied)
|
||||
}
|
||||
|
||||
_, err = d.Conn.Exec("UPDATE locations SET grid_rows = ?, grid_cols = ?, updated_at = datetime('now') WHERE id = ?", rows, cols, id)
|
||||
return err
|
||||
}
|
||||
|
||||
// ListDrawers returns the active drawers of a container array with a content summary.
|
||||
func (d *DB) ListDrawers(arrayID int64) ([]Drawer, error) {
|
||||
rows, err := d.Conn.Query(`
|
||||
SELECT l.id, l.name, l.slug, l.color, l.grid_row, l.grid_col,
|
||||
COUNT(i.id) AS item_count,
|
||||
COALESCE(GROUP_CONCAT(i.name, ', '), '') AS item_names
|
||||
FROM locations l
|
||||
LEFT JOIN items i ON i.location_id = l.id AND i.lifecycle_state = 'active'
|
||||
WHERE l.parent_id = ? AND l.grid_row IS NOT NULL AND l.grid_col IS NOT NULL AND l.lifecycle_state = 'active'
|
||||
GROUP BY l.id
|
||||
ORDER BY l.grid_row, l.grid_col`,
|
||||
arrayID,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var drawers []Drawer
|
||||
for rows.Next() {
|
||||
var dr Drawer
|
||||
if err := rows.Scan(&dr.ID, &dr.Name, &dr.Slug, &dr.Color, &dr.Row, &dr.Col, &dr.ItemCount, &dr.ItemNames); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
drawers = append(drawers, dr)
|
||||
}
|
||||
return drawers, rows.Err()
|
||||
}
|
||||
|
||||
// CreateDrawer creates a child location occupying a cell of a container array.
|
||||
func (d *DB) CreateDrawer(arrayID int64, row, col int64, name, color string) (*Location, error) {
|
||||
array, err := d.GetLocation(arrayID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if array.GridRows == 0 || array.GridCols == 0 {
|
||||
return nil, fmt.Errorf("location is not a container array")
|
||||
}
|
||||
if row < 0 || col < 0 || row >= array.GridRows || col >= array.GridCols {
|
||||
return nil, fmt.Errorf("drawer position out of bounds")
|
||||
}
|
||||
|
||||
tx, err := d.Conn.Begin()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
|
||||
var occupied int
|
||||
err = tx.QueryRow(
|
||||
"SELECT COUNT(*) FROM locations WHERE parent_id = ? AND grid_row = ? AND grid_col = ? AND lifecycle_state = 'active'",
|
||||
arrayID, row, col,
|
||||
).Scan(&occupied)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if occupied > 0 {
|
||||
return nil, fmt.Errorf("drawer slot is already occupied")
|
||||
}
|
||||
|
||||
slugVal := slug.Slugify(name)
|
||||
uniqueSlug := slugVal
|
||||
index := 1
|
||||
for {
|
||||
var count int
|
||||
if err := tx.QueryRow("SELECT COUNT(*) FROM locations WHERE slug = ?", uniqueSlug).Scan(&count); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if count == 0 {
|
||||
break
|
||||
}
|
||||
uniqueSlug = fmt.Sprintf("%s-%d", slugVal, index)
|
||||
index++
|
||||
}
|
||||
|
||||
res, err := tx.Exec(
|
||||
"INSERT INTO locations (name, slug, description, parent_id, grid_row, grid_col, color) VALUES (?, ?, '', ?, ?, ?, ?)",
|
||||
name, uniqueSlug, arrayID, row, col, color,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id, _ := res.LastInsertId()
|
||||
|
||||
if err := tx.Commit(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Location{
|
||||
ID: id,
|
||||
Name: name,
|
||||
Slug: uniqueSlug,
|
||||
ParentID: sql.NullInt64{Int64: arrayID, Valid: true},
|
||||
GridRow: sql.NullInt64{Int64: row, Valid: true},
|
||||
GridCol: sql.NullInt64{Int64: col, Valid: true},
|
||||
Color: color,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UpdateDrawer renames and recolors a drawer, optionally moving it to another
|
||||
// parent location (which frees its slot in the container array).
|
||||
func (d *DB) UpdateDrawer(id int64, name, color string, parentID sql.NullInt64) error {
|
||||
tx, err := d.Conn.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
|
||||
var oldParentID sql.NullInt64
|
||||
if err := tx.QueryRow("SELECT parent_id FROM locations WHERE id = ?", id).Scan(&oldParentID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
slugVal := slug.Slugify(name)
|
||||
uniqueSlug := slugVal
|
||||
index := 1
|
||||
for {
|
||||
var count int
|
||||
if err := tx.QueryRow("SELECT COUNT(*) FROM locations WHERE slug = ? AND id != ?", uniqueSlug, id).Scan(&count); err != nil {
|
||||
return err
|
||||
}
|
||||
if count == 0 {
|
||||
break
|
||||
}
|
||||
uniqueSlug = fmt.Sprintf("%s-%d", slugVal, index)
|
||||
index++
|
||||
}
|
||||
|
||||
_, err = tx.Exec(
|
||||
"UPDATE locations SET name = ?, slug = ?, color = ?, parent_id = ?, updated_at = datetime('now') WHERE id = ?",
|
||||
name, uniqueSlug, color, parentID, id,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Reparenting pulls a drawer out of its container array grid, freeing the slot
|
||||
if oldParentID != parentID {
|
||||
if _, err = tx.Exec("UPDATE locations SET grid_row = NULL, grid_col = NULL WHERE id = ?", id); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
// MoveDrawer moves a drawer to a target cell of its container array. If the
|
||||
// target cell is occupied, the two drawers swap positions.
|
||||
func (d *DB) MoveDrawer(drawerID, toRow, toCol int64) error {
|
||||
drawer, err := d.GetLocation(drawerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !drawer.ParentID.Valid || !drawer.GridRow.Valid || !drawer.GridCol.Valid {
|
||||
return fmt.Errorf("location is not a drawer in a container array")
|
||||
}
|
||||
|
||||
array, err := d.GetLocation(drawer.ParentID.Int64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if toRow < 0 || toCol < 0 || toRow >= array.GridRows || toCol >= array.GridCols {
|
||||
return fmt.Errorf("drawer position out of bounds")
|
||||
}
|
||||
|
||||
tx, err := d.Conn.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
|
||||
// Move any occupant of the target cell into the source cell (swap)
|
||||
_, err = tx.Exec(
|
||||
"UPDATE locations SET grid_row = ?, grid_col = ?, updated_at = datetime('now') WHERE parent_id = ? AND grid_row = ? AND grid_col = ? AND lifecycle_state = 'active' AND id != ?",
|
||||
drawer.GridRow.Int64, drawer.GridCol.Int64, array.ID, toRow, toCol, drawerID,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tx.Exec(
|
||||
"UPDATE locations SET grid_row = ?, grid_col = ?, updated_at = datetime('now') WHERE id = ?",
|
||||
toRow, toCol, drawerID,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
+39
-11
@@ -17,10 +17,28 @@ type Location struct {
|
||||
ParentName sql.NullString // Resolved parent location name
|
||||
ImagePath string
|
||||
LifecycleState string // 'active', 'archived', 'removed'
|
||||
GridRows int64 // Container array height (0 = not a container array)
|
||||
GridCols int64 // Container array width (0 = not a container array)
|
||||
GridRow sql.NullInt64
|
||||
GridCol sql.NullInt64
|
||||
Color string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
// Drawer is a child location positioned inside a parent container array,
|
||||
// enriched with a summary of its contents.
|
||||
type Drawer struct {
|
||||
ID int64
|
||||
Name string
|
||||
Slug string
|
||||
Color string
|
||||
Row int64
|
||||
Col int64
|
||||
ItemCount int64
|
||||
ItemNames string // comma-separated preview of item names
|
||||
}
|
||||
|
||||
func (d *DB) CreateLocation(name, description string, parentID sql.NullInt64, imagePath string) (*Location, error) {
|
||||
tx, err := d.Conn.Begin()
|
||||
if err != nil {
|
||||
@@ -71,7 +89,7 @@ func (d *DB) CreateLocation(name, description string, parentID sql.NullInt64, im
|
||||
|
||||
func (d *DB) GetLocation(id int64) (*Location, error) {
|
||||
row := d.Conn.QueryRow(`
|
||||
SELECT l.id, l.name, l.slug, l.description, l.parent_id, p.name AS parent_name, l.image_path, l.lifecycle_state, l.created_at, l.updated_at
|
||||
SELECT l.id, l.name, l.slug, l.description, l.parent_id, p.name AS parent_name, l.image_path, l.lifecycle_state, l.grid_rows, l.grid_cols, l.grid_row, l.grid_col, l.color, l.created_at, l.updated_at
|
||||
FROM locations l
|
||||
LEFT JOIN locations p ON l.parent_id = p.id
|
||||
WHERE l.id = ?`,
|
||||
@@ -82,7 +100,7 @@ func (d *DB) GetLocation(id int64) (*Location, error) {
|
||||
|
||||
func (d *DB) GetLocationBySlug(slug string) (*Location, error) {
|
||||
row := d.Conn.QueryRow(`
|
||||
SELECT l.id, l.name, l.slug, l.description, l.parent_id, p.name AS parent_name, l.image_path, l.lifecycle_state, l.created_at, l.updated_at
|
||||
SELECT l.id, l.name, l.slug, l.description, l.parent_id, p.name AS parent_name, l.image_path, l.lifecycle_state, l.grid_rows, l.grid_cols, l.grid_row, l.grid_col, l.color, l.created_at, l.updated_at
|
||||
FROM locations l
|
||||
LEFT JOIN locations p ON l.parent_id = p.id
|
||||
WHERE l.slug = ?`,
|
||||
@@ -103,7 +121,8 @@ func (d *DB) UpdateLocation(id int64, name, description string, parentID sql.Nul
|
||||
defer tx.Rollback()
|
||||
|
||||
var oldName string
|
||||
err = tx.QueryRow("SELECT name FROM locations WHERE id = ?", id).Scan(&oldName)
|
||||
var oldParentID sql.NullInt64
|
||||
err = tx.QueryRow("SELECT name, parent_id FROM locations WHERE id = ?", id).Scan(&oldName, &oldParentID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -132,6 +151,13 @@ func (d *DB) UpdateLocation(id int64, name, description string, parentID sql.Nul
|
||||
return err
|
||||
}
|
||||
|
||||
// Reparenting pulls a drawer out of its container array grid, freeing the slot
|
||||
if oldParentID != parentID {
|
||||
if _, err = tx.Exec("UPDATE locations SET grid_row = NULL, grid_col = NULL WHERE id = ?", id); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
@@ -171,7 +197,8 @@ func (d *DB) SoftRemoveLocation(id int64) error {
|
||||
if id == 1 {
|
||||
return fmt.Errorf("cannot remove the Default Room")
|
||||
}
|
||||
_, err := d.Conn.Exec("UPDATE locations SET lifecycle_state = 'removed', updated_at = datetime('now') WHERE id = ?", id)
|
||||
// Clearing the grid position leaves an empty drawer slot behind in the parent container array
|
||||
_, err := d.Conn.Exec("UPDATE locations SET lifecycle_state = 'removed', grid_row = NULL, grid_col = NULL, updated_at = datetime('now') WHERE id = ?", id)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -179,7 +206,7 @@ func (d *DB) ArchiveLocation(id int64) error {
|
||||
if id == 1 {
|
||||
return fmt.Errorf("cannot archive the Default Room")
|
||||
}
|
||||
_, err := d.Conn.Exec("UPDATE locations SET lifecycle_state = 'archived', updated_at = datetime('now') WHERE id = ?", id)
|
||||
_, err := d.Conn.Exec("UPDATE locations SET lifecycle_state = 'archived', grid_row = NULL, grid_col = NULL, updated_at = datetime('now') WHERE id = ?", id)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -190,7 +217,7 @@ func (d *DB) RestoreLocation(id int64) error {
|
||||
|
||||
func (d *DB) ListLocations(showRemoved bool) ([]Location, error) {
|
||||
query := `
|
||||
SELECT l.id, l.name, l.slug, l.description, l.parent_id, p.name AS parent_name, l.image_path, l.lifecycle_state, l.created_at, l.updated_at
|
||||
SELECT l.id, l.name, l.slug, l.description, l.parent_id, p.name AS parent_name, l.image_path, l.lifecycle_state, l.grid_rows, l.grid_cols, l.grid_row, l.grid_col, l.color, l.created_at, l.updated_at
|
||||
FROM locations l
|
||||
LEFT JOIN locations p ON l.parent_id = p.id`
|
||||
if !showRemoved {
|
||||
@@ -210,7 +237,7 @@ func (d *DB) ListLocations(showRemoved bool) ([]Location, error) {
|
||||
var parentID sql.NullInt64
|
||||
var parentName sql.NullString
|
||||
var created, updated string
|
||||
if err := rows.Scan(&l.ID, &l.Name, &l.Slug, &l.Description, &parentID, &parentName, &l.ImagePath, &l.LifecycleState, &created, &updated); err != nil {
|
||||
if err := rows.Scan(&l.ID, &l.Name, &l.Slug, &l.Description, &parentID, &parentName, &l.ImagePath, &l.LifecycleState, &l.GridRows, &l.GridCols, &l.GridRow, &l.GridCol, &l.Color, &created, &updated); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
l.ParentID = parentID
|
||||
@@ -224,7 +251,7 @@ func (d *DB) ListLocations(showRemoved bool) ([]Location, error) {
|
||||
|
||||
func (d *DB) ListChildLocations(parentID int64, showRemoved bool) ([]Location, error) {
|
||||
query := `
|
||||
SELECT l.id, l.name, l.slug, l.description, l.parent_id, p.name AS parent_name, l.image_path, l.lifecycle_state, l.created_at, l.updated_at
|
||||
SELECT l.id, l.name, l.slug, l.description, l.parent_id, p.name AS parent_name, l.image_path, l.lifecycle_state, l.grid_rows, l.grid_cols, l.grid_row, l.grid_col, l.color, l.created_at, l.updated_at
|
||||
FROM locations l
|
||||
LEFT JOIN locations p ON l.parent_id = p.id
|
||||
WHERE l.parent_id = ?`
|
||||
@@ -245,7 +272,7 @@ func (d *DB) ListChildLocations(parentID int64, showRemoved bool) ([]Location, e
|
||||
var pID sql.NullInt64
|
||||
var pName sql.NullString
|
||||
var created, updated string
|
||||
if err := rows.Scan(&l.ID, &l.Name, &l.Slug, &l.Description, &pID, &pName, &l.ImagePath, &l.LifecycleState, &created, &updated); err != nil {
|
||||
if err := rows.Scan(&l.ID, &l.Name, &l.Slug, &l.Description, &pID, &pName, &l.ImagePath, &l.LifecycleState, &l.GridRows, &l.GridCols, &l.GridRow, &l.GridCol, &l.Color, &created, &updated); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
l.ParentID = pID
|
||||
@@ -264,7 +291,7 @@ func scanLocation(row interface {
|
||||
var parentID sql.NullInt64
|
||||
var parentName sql.NullString
|
||||
var created, updated string
|
||||
if err := row.Scan(&l.ID, &l.Name, &l.Slug, &l.Description, &parentID, &parentName, &l.ImagePath, &l.LifecycleState, &created, &updated); err != nil {
|
||||
if err := row.Scan(&l.ID, &l.Name, &l.Slug, &l.Description, &parentID, &parentName, &l.ImagePath, &l.LifecycleState, &l.GridRows, &l.GridCols, &l.GridRow, &l.GridCol, &l.Color, &created, &updated); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
l.ParentID = parentID
|
||||
@@ -279,7 +306,8 @@ func (d *DB) MoveLocationParent(locID, newParentID int64) error {
|
||||
if newParentID > 0 {
|
||||
pID = sql.NullInt64{Int64: newParentID, Valid: true}
|
||||
}
|
||||
_, err := d.Conn.Exec("UPDATE locations SET parent_id = ?, updated_at = datetime('now') WHERE id = ?", pID, locID)
|
||||
// Reparenting pulls a drawer out of its container array grid, freeing the slot
|
||||
_, err := d.Conn.Exec("UPDATE locations SET parent_id = ?, grid_row = NULL, grid_col = NULL, updated_at = datetime('now') WHERE id = ?", pID, locID)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -9,6 +9,11 @@ CREATE TABLE IF NOT EXISTS locations (
|
||||
description TEXT NOT NULL DEFAULT '',
|
||||
parent_id INTEGER REFERENCES locations(id) ON DELETE SET NULL,
|
||||
image_path TEXT NOT NULL DEFAULT '',
|
||||
grid_rows INTEGER NOT NULL DEFAULT 0, -- Container array height (0 = not a container array)
|
||||
grid_cols INTEGER NOT NULL DEFAULT 0, -- Container array width (0 = not a container array)
|
||||
grid_row INTEGER, -- Drawer position (row) within parent container array
|
||||
grid_col INTEGER, -- Drawer position (col) within parent container array
|
||||
color TEXT NOT NULL DEFAULT '', -- Drawer color code (hex)
|
||||
lifecycle_state TEXT NOT NULL DEFAULT 'active',
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
|
||||
@@ -164,6 +164,26 @@
|
||||
"locations.none_root": "-- None (Root Location) --",
|
||||
"locations.add_location": "Add Location",
|
||||
"locations.confirm_delete": "Are you sure you want to permanently delete this location? Associated sub-locations and assets will be detached.",
|
||||
"locations.container_array": "Container array (drawer grid)",
|
||||
"locations.grid_rows": "Rows",
|
||||
"locations.grid_cols": "Columns",
|
||||
"locations.grid_dims": "rows × columns (max 20×20)",
|
||||
"locations.container_array_hint": "Turns this location into a drawer cabinet. Open it from the folder view to add, color, and rearrange drawers.",
|
||||
|
||||
"drawer.section_title": "Drawers",
|
||||
"drawer.hint": "Hover or tap a drawer to peek inside. Drag (or touch and hold) a drawer to swap it with another slot. Click an empty slot to add a drawer.",
|
||||
"drawer.items": "item(s)",
|
||||
"drawer.empty_contents": "This drawer is empty.",
|
||||
"drawer.open": "Open",
|
||||
"drawer.add": "Add drawer",
|
||||
"drawer.new_drawer": "New Drawer",
|
||||
"drawer.edit_drawer": "Edit Drawer",
|
||||
"drawer.name": "Drawer Name",
|
||||
"drawer.color": "Color",
|
||||
"drawer.location": "Location",
|
||||
"drawer.current_array": "current array",
|
||||
"drawer.location_hint": "Choosing another location moves the drawer out of this array and leaves an empty slot behind.",
|
||||
"drawer.confirm_remove": "Remove this drawer? Its slot will be left empty. The drawer can be restored from the Locations page.",
|
||||
|
||||
"folder.home": "Home",
|
||||
"folder.show_removed": "Show removed items",
|
||||
|
||||
@@ -164,6 +164,26 @@
|
||||
"locations.none_root": "-- 无(根位置)--",
|
||||
"locations.add_location": "添加位置",
|
||||
"locations.confirm_delete": "确定要永久删除此位置吗?关联的子位置和资产将被解除关联。",
|
||||
"locations.container_array": "容器阵列(抽屉网格)",
|
||||
"locations.grid_rows": "行数",
|
||||
"locations.grid_cols": "列数",
|
||||
"locations.grid_dims": "行 × 列(最大 20×20)",
|
||||
"locations.container_array_hint": "将此位置变为抽屉柜。在文件夹视图中打开它即可添加、着色和重新排列抽屉。",
|
||||
|
||||
"drawer.section_title": "抽屉",
|
||||
"drawer.hint": "悬停或轻触抽屉可预览内容。拖动(或长按)抽屉可与其他格子交换位置。点击空格子可添加抽屉。",
|
||||
"drawer.items": "件物品",
|
||||
"drawer.empty_contents": "此抽屉是空的。",
|
||||
"drawer.open": "打开",
|
||||
"drawer.add": "添加抽屉",
|
||||
"drawer.new_drawer": "新建抽屉",
|
||||
"drawer.edit_drawer": "编辑抽屉",
|
||||
"drawer.name": "抽屉名称",
|
||||
"drawer.color": "颜色",
|
||||
"drawer.location": "位置",
|
||||
"drawer.current_array": "当前阵列",
|
||||
"drawer.location_hint": "选择其他位置会将抽屉移出此阵列,并留下一个空格子。",
|
||||
"drawer.confirm_remove": "移除此抽屉?其格子将保持为空。可在位置页面恢复该抽屉。",
|
||||
|
||||
"folder.home": "首页",
|
||||
"folder.show_removed": "显示已移除的项目",
|
||||
|
||||
+186
-1
@@ -8,6 +8,7 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@@ -54,6 +55,14 @@ type PageData struct {
|
||||
CurrentLocation *db.Location
|
||||
Breadcrumbs []db.Location
|
||||
ChildLocations []db.Location
|
||||
DrawerGrid [][]DrawerCell
|
||||
}
|
||||
|
||||
// DrawerCell is one slot of a container array grid; Drawer is nil for empty slots.
|
||||
type DrawerCell struct {
|
||||
Row int64
|
||||
Col int64
|
||||
Drawer *db.Drawer
|
||||
}
|
||||
|
||||
|
||||
@@ -751,15 +760,33 @@ func (s *Server) handleLocationCreate(w http.ResponseWriter, r *http.Request) {
|
||||
parentID = sql.NullInt64{Int64: id, Valid: true}
|
||||
}
|
||||
|
||||
_, err := s.db.CreateLocation(name, desc, parentID, "")
|
||||
loc, err := s.db.CreateLocation(name, desc, parentID, "")
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to create location", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if rows, cols := parseGridSize(r); rows > 0 && cols > 0 {
|
||||
_ = s.db.SetLocationGrid(loc.ID, rows, cols)
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/admin/locations?toast=Location+created+successfully&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// parseGridSize reads the container array dimensions from the location form.
|
||||
// Returns 0,0 when the container array option is unchecked or values are invalid.
|
||||
func parseGridSize(r *http.Request) (int64, int64) {
|
||||
if r.FormValue("is_array") == "" {
|
||||
return 0, 0
|
||||
}
|
||||
rows, _ := strconv.ParseInt(r.FormValue("grid_rows"), 10, 64)
|
||||
cols, _ := strconv.ParseInt(r.FormValue("grid_cols"), 10, 64)
|
||||
if rows < 1 || cols < 1 || rows > db.MaxGridSize || cols > db.MaxGridSize {
|
||||
return 0, 0
|
||||
}
|
||||
return rows, cols
|
||||
}
|
||||
|
||||
func (s *Server) handleLocationEdit(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
@@ -777,6 +804,13 @@ func (s *Server) handleLocationEdit(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
_ = s.db.UpdateLocation(id, name, desc, parentID, "")
|
||||
|
||||
rows, cols := parseGridSize(r)
|
||||
if err := s.db.SetLocationGrid(id, rows, cols); err != nil {
|
||||
http.Redirect(w, r, "/admin/locations?toast="+url.QueryEscape(err.Error())+"&toast_type=error", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/admin/locations?toast=Location+updated+successfully&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
@@ -824,6 +858,126 @@ func (s *Server) handleLocationPermanentDelete(w http.ResponseWriter, r *http.Re
|
||||
http.Redirect(w, r, "/admin/locations?show_removed=1&toast=Location+deleted+forever+successfully&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// 4b. CONTAINER ARRAY DRAWER HANDLERS
|
||||
// ==========================================
|
||||
|
||||
// redirectToArray sends the user back to the container array folder view.
|
||||
func (s *Server) redirectToArray(w http.ResponseWriter, r *http.Request, arrayID int64, toast string) {
|
||||
target := "/admin/locations"
|
||||
if array, err := s.db.GetLocation(arrayID); err == nil && array.Slug != "" {
|
||||
target = "/" + array.Slug
|
||||
}
|
||||
http.Redirect(w, r, target+"?toast="+url.QueryEscape(toast)+"&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleDrawerCreate(w http.ResponseWriter, r *http.Request) {
|
||||
arrayID, err := strconv.ParseInt(r.FormValue("array_id"), 10, 64)
|
||||
if err != nil {
|
||||
http.Error(w, "Invalid array_id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
row, err1 := strconv.ParseInt(r.FormValue("row"), 10, 64)
|
||||
col, err2 := strconv.ParseInt(r.FormValue("col"), 10, 64)
|
||||
if err1 != nil || err2 != nil {
|
||||
http.Error(w, "Invalid drawer position", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
name := strings.TrimSpace(r.FormValue("name"))
|
||||
if name == "" {
|
||||
name = fmt.Sprintf("Drawer %c%d", 'A'+rune(row), col+1)
|
||||
}
|
||||
color := r.FormValue("color")
|
||||
|
||||
if _, err := s.db.CreateDrawer(arrayID, row, col, name, color); err != nil {
|
||||
http.Redirect(w, r, "/admin/locations?toast="+url.QueryEscape(err.Error())+"&toast_type=error", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
|
||||
s.redirectToArray(w, r, arrayID, "Drawer created successfully")
|
||||
}
|
||||
|
||||
func (s *Server) handleDrawerEdit(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
drawer, err := s.db.GetLocation(id)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
name := strings.TrimSpace(r.FormValue("name"))
|
||||
if name == "" {
|
||||
name = drawer.Name
|
||||
}
|
||||
color := r.FormValue("color")
|
||||
|
||||
parentID := drawer.ParentID
|
||||
if parentVal := r.FormValue("parent_id"); parentVal != "" {
|
||||
pid, perr := strconv.ParseInt(parentVal, 10, 64)
|
||||
if perr == nil && pid != id {
|
||||
parentID = sql.NullInt64{Int64: pid, Valid: true}
|
||||
}
|
||||
}
|
||||
|
||||
if err := s.db.UpdateDrawer(id, name, color, parentID); err != nil {
|
||||
http.Error(w, "Failed to update drawer: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Return to the array the drawer lived in before any reparenting
|
||||
if drawer.ParentID.Valid {
|
||||
s.redirectToArray(w, r, drawer.ParentID.Int64, "Drawer updated successfully")
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, "/admin/locations?toast=Drawer+updated+successfully&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleDrawerRemove(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
drawer, err := s.db.GetLocation(id)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
_ = s.db.SoftRemoveLocation(id)
|
||||
|
||||
if drawer.ParentID.Valid {
|
||||
s.redirectToArray(w, r, drawer.ParentID.Int64, "Drawer removed; slot is now empty")
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, "/admin/locations?toast=Drawer+removed&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleDrawerMove(w http.ResponseWriter, r *http.Request) {
|
||||
drawerID, err := strconv.ParseInt(r.FormValue("drawer_id"), 10, 64)
|
||||
row, err1 := strconv.ParseInt(r.FormValue("row"), 10, 64)
|
||||
col, err2 := strconv.ParseInt(r.FormValue("col"), 10, 64)
|
||||
if err != nil || err1 != nil || err2 != nil {
|
||||
http.Error(w, "Invalid drawer_id or position", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if err := s.db.MoveDrawer(drawerID, row, col); err != nil {
|
||||
http.Error(w, "Failed to move drawer: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write([]byte(`{"status":"success","message":"Drawer moved successfully"}`))
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// 5. TAGS MANAGEMENT HANDLERS
|
||||
// ==========================================
|
||||
@@ -1337,6 +1491,8 @@ func (s *Server) handleFolderView(w http.ResponseWriter, r *http.Request) {
|
||||
var showRemoved bool
|
||||
var allLocations []db.Location
|
||||
|
||||
var drawerGrid [][]DrawerCell
|
||||
|
||||
if isAuth {
|
||||
showRemoved = r.URL.Query().Get("show_removed") == "1"
|
||||
|
||||
@@ -1345,6 +1501,34 @@ func (s *Server) handleFolderView(w http.ResponseWriter, r *http.Request) {
|
||||
childLocs = []db.Location{}
|
||||
}
|
||||
|
||||
// Container array: build the drawer grid and keep drawers out of the folder list
|
||||
if loc.GridRows > 0 && loc.GridCols > 0 {
|
||||
drawers, derr := s.db.ListDrawers(loc.ID)
|
||||
if derr != nil {
|
||||
drawers = []db.Drawer{}
|
||||
}
|
||||
byCell := make(map[[2]int64]*db.Drawer, len(drawers))
|
||||
for i := range drawers {
|
||||
byCell[[2]int64{drawers[i].Row, drawers[i].Col}] = &drawers[i]
|
||||
}
|
||||
drawerGrid = make([][]DrawerCell, loc.GridRows)
|
||||
for row := int64(0); row < loc.GridRows; row++ {
|
||||
cells := make([]DrawerCell, loc.GridCols)
|
||||
for col := int64(0); col < loc.GridCols; col++ {
|
||||
cells[col] = DrawerCell{Row: row, Col: col, Drawer: byCell[[2]int64{row, col}]}
|
||||
}
|
||||
drawerGrid[row] = cells
|
||||
}
|
||||
|
||||
filtered := childLocs[:0]
|
||||
for _, c := range childLocs {
|
||||
if !c.GridRow.Valid {
|
||||
filtered = append(filtered, c)
|
||||
}
|
||||
}
|
||||
childLocs = filtered
|
||||
}
|
||||
|
||||
items, err = s.db.ListItemsByLocation(loc.ID, showRemoved)
|
||||
if err != nil {
|
||||
items = []db.Item{}
|
||||
@@ -1383,6 +1567,7 @@ func (s *Server) handleFolderView(w http.ResponseWriter, r *http.Request) {
|
||||
Breadcrumbs: breadcrumbs,
|
||||
Locations: allLocations,
|
||||
ShowRemoved: showRemoved,
|
||||
DrawerGrid: drawerGrid,
|
||||
}
|
||||
|
||||
s.render(w, r, "location_folder.html", data)
|
||||
|
||||
@@ -144,6 +144,12 @@ func (s *Server) Start() error {
|
||||
mux.HandleFunc("POST /admin/locations/restore/{id}", s.requireAuth(s.requireCSRF(s.handleLocationRestore)))
|
||||
mux.HandleFunc("POST /admin/locations/permanent-delete/{id}", s.requireAuth(s.requireCSRF(s.handleLocationPermanentDelete)))
|
||||
|
||||
// 7b. Container array drawer management
|
||||
mux.HandleFunc("POST /admin/drawers/new", s.requireAuth(s.requireCSRF(s.handleDrawerCreate)))
|
||||
mux.HandleFunc("POST /admin/drawers/edit/{id}", s.requireAuth(s.requireCSRF(s.handleDrawerEdit)))
|
||||
mux.HandleFunc("POST /admin/drawers/remove/{id}", s.requireAuth(s.requireCSRF(s.handleDrawerRemove)))
|
||||
mux.HandleFunc("POST /admin/drawers/move", s.requireAuth(s.requireCSRF(s.handleDrawerMove)))
|
||||
|
||||
// 8. Admin tags management
|
||||
mux.HandleFunc("GET /admin/tags", s.requireAuth(s.handleAdminTags))
|
||||
mux.HandleFunc("POST /admin/tags/new", s.requireAuth(s.requireCSRF(s.handleTagCreate)))
|
||||
|
||||
@@ -1445,3 +1445,315 @@ tr:last-child .actions-dropdown-menu {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ==========================================
|
||||
Container Array Drawer Grid (3D view)
|
||||
========================================== */
|
||||
|
||||
.drawer-array-hint {
|
||||
color: var(--color-text-muted);
|
||||
font-size: 0.85rem;
|
||||
margin-bottom: 0.85rem;
|
||||
}
|
||||
|
||||
.drawer-cabinet-wrapper {
|
||||
overflow-x: auto;
|
||||
padding: 1rem 0.25rem 1.5rem;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
|
||||
.drawer-cabinet {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(var(--drawer-cols, 4), minmax(86px, 1fr));
|
||||
gap: 10px;
|
||||
padding: 14px;
|
||||
background: linear-gradient(160deg, #57534e, #3f3c39);
|
||||
border-radius: 14px;
|
||||
border: 1px solid #292524;
|
||||
box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.45), 0 10px 24px rgba(0, 0, 0, 0.18);
|
||||
perspective: 1100px;
|
||||
width: max-content;
|
||||
min-width: 100%;
|
||||
}
|
||||
|
||||
.drawer-cell {
|
||||
position: relative;
|
||||
aspect-ratio: 5 / 4;
|
||||
min-width: 86px;
|
||||
transform-style: preserve-3d;
|
||||
perspective: 700px;
|
||||
}
|
||||
|
||||
/* Dark cavity revealed behind a slid-out drawer */
|
||||
.drawer-cavity {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
border-radius: 8px;
|
||||
background: radial-gradient(ellipse at 50% 30%, #1c1917 20%, #000 100%);
|
||||
box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.8);
|
||||
}
|
||||
|
||||
.drawer-tray {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
transform-style: preserve-3d;
|
||||
transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
|
||||
cursor: grab;
|
||||
touch-action: pan-y;
|
||||
}
|
||||
|
||||
.drawer-tray.empty-tray {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.drawer-front {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
padding: 6px;
|
||||
border-radius: 8px;
|
||||
background: linear-gradient(180deg,
|
||||
color-mix(in srgb, var(--drawer-color, #e7e5e4) 88%, white),
|
||||
var(--drawer-color, #d6d3d1));
|
||||
border: 1px solid rgba(0, 0, 0, 0.25);
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), 0 2px 4px rgba(0, 0, 0, 0.35);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Drawer side walls give depth when the tray slides forward */
|
||||
.drawer-tray::before,
|
||||
.drawer-tray::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 6%;
|
||||
bottom: 6%;
|
||||
width: 34px;
|
||||
background: linear-gradient(90deg, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0.2));
|
||||
transform-origin: left center;
|
||||
opacity: 0;
|
||||
transition: opacity 0.25s ease;
|
||||
}
|
||||
|
||||
.drawer-tray::before {
|
||||
left: 1px;
|
||||
transform: rotateY(-86deg);
|
||||
}
|
||||
|
||||
.drawer-tray::after {
|
||||
right: 1px;
|
||||
transform-origin: right center;
|
||||
transform: rotateY(86deg);
|
||||
}
|
||||
|
||||
.drawer-label {
|
||||
font-size: 0.72rem;
|
||||
font-weight: 700;
|
||||
color: rgba(28, 25, 23, 0.85);
|
||||
text-align: center;
|
||||
line-height: 1.15;
|
||||
max-height: 2.3em;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
word-break: break-word;
|
||||
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
|
||||
}
|
||||
|
||||
.drawer-handle {
|
||||
width: 46%;
|
||||
height: 7px;
|
||||
border-radius: 4px;
|
||||
background: linear-gradient(180deg, #fafaf9, #a8a29e);
|
||||
border: 1px solid rgba(0, 0, 0, 0.35);
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
/* Slide-out animation: hover (desktop) or .open (tap on mobile) */
|
||||
@media (hover: hover) {
|
||||
.drawer-cell.has-drawer:hover .drawer-tray {
|
||||
transform: translate3d(0, 12%, 46px) rotateX(-7deg);
|
||||
z-index: 5;
|
||||
}
|
||||
.drawer-cell.has-drawer:hover .drawer-tray::before,
|
||||
.drawer-cell.has-drawer:hover .drawer-tray::after {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.drawer-cell.open .drawer-tray {
|
||||
transform: translate3d(0, 12%, 46px) rotateX(-7deg);
|
||||
z-index: 5;
|
||||
}
|
||||
|
||||
.drawer-cell.open .drawer-tray::before,
|
||||
.drawer-cell.open .drawer-tray::after {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* Empty slot */
|
||||
.drawer-cell.empty .drawer-front {
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
border: 1.5px dashed rgba(255, 255, 255, 0.28);
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.drawer-cell.empty .drawer-add-icon {
|
||||
font-size: 1.3rem;
|
||||
font-weight: 600;
|
||||
color: rgba(255, 255, 255, 0.45);
|
||||
transition: color 0.2s ease, transform 0.2s ease;
|
||||
}
|
||||
|
||||
.drawer-cell.empty:hover .drawer-add-icon,
|
||||
.drawer-cell.empty:focus-visible .drawer-add-icon {
|
||||
color: rgba(255, 255, 255, 0.85);
|
||||
transform: scale(1.2);
|
||||
}
|
||||
|
||||
/* Drag & drop swap states */
|
||||
.drawer-cell.drag-source .drawer-tray {
|
||||
opacity: 0.35;
|
||||
}
|
||||
|
||||
.drawer-cell.drop-target .drawer-front {
|
||||
outline: 3px solid var(--color-brand-accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.drawer-drag-ghost {
|
||||
position: fixed;
|
||||
z-index: 1000;
|
||||
pointer-events: none;
|
||||
opacity: 0.85;
|
||||
transform: translate(-50%, -50%) scale(1.05) rotate(-2deg);
|
||||
filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.35));
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
/* Content summary peek (relocated to <body> and fixed-positioned by JS) */
|
||||
.drawer-peek {
|
||||
display: none;
|
||||
position: fixed;
|
||||
z-index: 900;
|
||||
width: 215px;
|
||||
background: var(--color-bg-surface);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
|
||||
padding: 0.7rem 0.8rem;
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
|
||||
.drawer-peek.show {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.drawer-peek-name {
|
||||
display: block;
|
||||
font-weight: 700;
|
||||
margin-bottom: 0.15rem;
|
||||
}
|
||||
|
||||
.drawer-peek-count {
|
||||
display: block;
|
||||
color: var(--color-brand-primary);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.drawer-peek-items {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
color: var(--color-text-muted);
|
||||
font-style: normal;
|
||||
margin-top: 0.2rem;
|
||||
}
|
||||
|
||||
.drawer-peek-actions {
|
||||
display: flex;
|
||||
gap: 0.4rem;
|
||||
margin-top: 0.55rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.drawer-peek-btn {
|
||||
border: 1px solid var(--color-border);
|
||||
background: var(--color-bg-base);
|
||||
color: var(--color-text-main);
|
||||
border-radius: 6px;
|
||||
padding: 0.25rem 0.55rem;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.drawer-peek-btn:hover {
|
||||
border-color: var(--color-brand-primary);
|
||||
color: var(--color-brand-primary);
|
||||
}
|
||||
|
||||
.drawer-peek-btn.danger {
|
||||
color: #b91c1c;
|
||||
}
|
||||
|
||||
.drawer-peek-btn.danger:hover {
|
||||
border-color: #b91c1c;
|
||||
}
|
||||
|
||||
/* Drawer modal */
|
||||
.drawer-modal-backdrop[hidden] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.drawer-modal-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 950;
|
||||
background: rgba(28, 25, 23, 0.45);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.drawer-modal {
|
||||
width: 100%;
|
||||
max-width: 380px;
|
||||
max-height: 90vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.drawer-swatch {
|
||||
width: 1.7rem;
|
||||
height: 1.7rem;
|
||||
border-radius: 50%;
|
||||
border: 2px solid rgba(0, 0, 0, 0.15);
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.drawer-swatch:hover {
|
||||
transform: scale(1.12);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.drawer-cabinet {
|
||||
grid-template-columns: repeat(var(--drawer-cols, 4), minmax(64px, 1fr));
|
||||
gap: 7px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.drawer-cell {
|
||||
min-width: 64px;
|
||||
}
|
||||
|
||||
.drawer-label {
|
||||
font-size: 0.6rem;
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,9 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
|
||||
// 5. Mobile sidebar drawer interactions
|
||||
initMobileSidebar();
|
||||
|
||||
// 6. Container array drawer grid (3D view)
|
||||
initDrawerArray();
|
||||
});
|
||||
|
||||
// Mobile off-canvas sidebar drawer
|
||||
@@ -306,3 +309,309 @@ function showToast(message, type) {
|
||||
container.appendChild(toast);
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// 6. Container Array Drawer Grid (3D view)
|
||||
// ==========================================
|
||||
|
||||
function initDrawerArray() {
|
||||
const cabinet = document.getElementById("drawer-cabinet");
|
||||
if (!cabinet) return;
|
||||
|
||||
const cells = Array.from(cabinet.querySelectorAll(".drawer-cell.has-drawer"));
|
||||
|
||||
// --- Content summary peek -------------------------------------------
|
||||
// Peeks are relocated to <body> so the scrollable cabinet wrapper and
|
||||
// 3D transforms can't clip them; they are fixed-positioned per cell.
|
||||
let activePeek = null;
|
||||
let peekHideTimer = null;
|
||||
|
||||
function peekFor(cell) {
|
||||
let peek = cell._peek;
|
||||
if (!peek) {
|
||||
peek = cell.querySelector(".drawer-peek");
|
||||
if (!peek) return null;
|
||||
document.body.appendChild(peek);
|
||||
cell._peek = peek;
|
||||
// Keep the peek open while the cursor is over it
|
||||
peek.addEventListener("mouseenter", () => clearTimeout(peekHideTimer));
|
||||
peek.addEventListener("mouseleave", scheduleHidePeek);
|
||||
}
|
||||
return peek;
|
||||
}
|
||||
|
||||
function showPeek(cell) {
|
||||
clearTimeout(peekHideTimer);
|
||||
if (activePeek && activePeek.cell !== cell) hidePeek();
|
||||
|
||||
const peek = peekFor(cell);
|
||||
if (!peek) return;
|
||||
|
||||
peek.classList.add("show");
|
||||
const rect = cell.getBoundingClientRect();
|
||||
const peekRect = peek.getBoundingClientRect();
|
||||
let left = rect.left + rect.width / 2 - peekRect.width / 2;
|
||||
left = Math.max(8, Math.min(left, window.innerWidth - peekRect.width - 8));
|
||||
let top = rect.top - peekRect.height - 10;
|
||||
if (top < 8) top = rect.bottom + 10;
|
||||
peek.style.left = left + "px";
|
||||
peek.style.top = top + "px";
|
||||
|
||||
activePeek = { cell, peek };
|
||||
cell.classList.add("open");
|
||||
}
|
||||
|
||||
function hidePeek() {
|
||||
if (!activePeek) return;
|
||||
activePeek.peek.classList.remove("show");
|
||||
activePeek.cell.classList.remove("open");
|
||||
activePeek = null;
|
||||
}
|
||||
|
||||
function scheduleHidePeek() {
|
||||
clearTimeout(peekHideTimer);
|
||||
peekHideTimer = setTimeout(hidePeek, 180);
|
||||
}
|
||||
|
||||
const supportsHover = window.matchMedia("(hover: hover)").matches;
|
||||
|
||||
cells.forEach(cell => {
|
||||
if (supportsHover) {
|
||||
cell.addEventListener("mouseenter", () => { if (!dragState.active) showPeek(cell); });
|
||||
cell.addEventListener("mouseleave", scheduleHidePeek);
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("scroll", hidePeek, true);
|
||||
window.addEventListener("resize", hidePeek);
|
||||
// Tap outside any drawer closes the peek (mobile)
|
||||
document.addEventListener("click", (e) => {
|
||||
if (!e.target.closest(".drawer-cell") && !e.target.closest(".drawer-peek")) hidePeek();
|
||||
});
|
||||
|
||||
// --- Drag to swap (mouse drag / touch long-press) --------------------
|
||||
const dragState = { active: false, cell: null, ghost: null, target: null, suppressClick: false };
|
||||
|
||||
function startDrag(cell, x, y) {
|
||||
dragState.active = true;
|
||||
dragState.cell = cell;
|
||||
cell.classList.add("drag-source");
|
||||
hidePeek();
|
||||
|
||||
const front = cell.querySelector(".drawer-front");
|
||||
const rect = front.getBoundingClientRect();
|
||||
const ghost = front.cloneNode(true);
|
||||
ghost.classList.add("drawer-drag-ghost");
|
||||
ghost.style.position = "fixed";
|
||||
ghost.style.inset = "auto";
|
||||
ghost.style.width = rect.width + "px";
|
||||
ghost.style.height = rect.height + "px";
|
||||
document.body.appendChild(ghost);
|
||||
dragState.ghost = ghost;
|
||||
moveDrag(x, y);
|
||||
|
||||
if (navigator.vibrate) navigator.vibrate(30);
|
||||
}
|
||||
|
||||
function moveDrag(x, y) {
|
||||
if (!dragState.active) return;
|
||||
dragState.ghost.style.left = x + "px";
|
||||
dragState.ghost.style.top = y + "px";
|
||||
|
||||
dragState.ghost.style.display = "none";
|
||||
const under = document.elementFromPoint(x, y);
|
||||
dragState.ghost.style.display = "";
|
||||
|
||||
const target = under ? under.closest(".drawer-cell") : null;
|
||||
if (dragState.target && dragState.target !== target) {
|
||||
dragState.target.classList.remove("drop-target");
|
||||
}
|
||||
if (target && target !== dragState.cell && cabinet.contains(target)) {
|
||||
target.classList.add("drop-target");
|
||||
dragState.target = target;
|
||||
} else {
|
||||
dragState.target = null;
|
||||
}
|
||||
}
|
||||
|
||||
async function endDrag() {
|
||||
if (!dragState.active) return;
|
||||
const cell = dragState.cell;
|
||||
const ghost = dragState.ghost;
|
||||
const target = dragState.target;
|
||||
dragState.active = false;
|
||||
dragState.suppressClick = true;
|
||||
setTimeout(() => { dragState.suppressClick = false; }, 50);
|
||||
|
||||
cell.classList.remove("drag-source");
|
||||
if (ghost) ghost.remove();
|
||||
if (target) target.classList.remove("drop-target");
|
||||
dragState.cell = dragState.ghost = dragState.target = null;
|
||||
|
||||
if (!target || target === cell) return;
|
||||
|
||||
const csrfToken = document.querySelector('meta[name="csrf-token"]')?.getAttribute('content');
|
||||
try {
|
||||
const response = await fetch("/admin/drawers/move", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
"X-CSRF-Token": csrfToken
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
"drawer_id": cell.dataset.drawerId,
|
||||
"row": target.dataset.row,
|
||||
"col": target.dataset.col,
|
||||
"csrf_token": csrfToken
|
||||
})
|
||||
});
|
||||
if (response.ok) {
|
||||
showSuccessToast("Drawer moved successfully!");
|
||||
setTimeout(() => window.location.reload(), 600);
|
||||
} else {
|
||||
const errMsg = await response.text();
|
||||
showErrorToast(errMsg || "Failed to move drawer");
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Drawer move failed:", err);
|
||||
showErrorToast("An error occurred while moving the drawer");
|
||||
}
|
||||
}
|
||||
|
||||
cells.forEach(cell => {
|
||||
const tray = cell.querySelector(".drawer-tray");
|
||||
|
||||
// Mouse: drag starts after a small movement threshold; plain click navigates
|
||||
tray.addEventListener("mousedown", (e) => {
|
||||
if (e.button !== 0) return;
|
||||
const startX = e.clientX, startY = e.clientY;
|
||||
let started = false;
|
||||
|
||||
const onMove = (ev) => {
|
||||
if (!started && Math.hypot(ev.clientX - startX, ev.clientY - startY) > 6) {
|
||||
started = true;
|
||||
startDrag(cell, ev.clientX, ev.clientY);
|
||||
}
|
||||
if (started) moveDrag(ev.clientX, ev.clientY);
|
||||
};
|
||||
const onUp = () => {
|
||||
document.removeEventListener("mousemove", onMove);
|
||||
document.removeEventListener("mouseup", onUp);
|
||||
endDrag();
|
||||
};
|
||||
document.addEventListener("mousemove", onMove);
|
||||
document.addEventListener("mouseup", onUp);
|
||||
});
|
||||
|
||||
// Touch: long-press (450ms) starts drag; quick tap toggles the peek
|
||||
tray.addEventListener("touchstart", (e) => {
|
||||
const touch = e.touches[0];
|
||||
const startX = touch.clientX, startY = touch.clientY;
|
||||
let pressTimer = setTimeout(() => {
|
||||
pressTimer = null;
|
||||
startDrag(cell, startX, startY);
|
||||
}, 450);
|
||||
|
||||
const onTouchMove = (ev) => {
|
||||
const t = ev.touches[0];
|
||||
if (dragState.active) {
|
||||
ev.preventDefault(); // keep the page from scrolling while dragging
|
||||
moveDrag(t.clientX, t.clientY);
|
||||
} else if (pressTimer && Math.hypot(t.clientX - startX, t.clientY - startY) > 10) {
|
||||
clearTimeout(pressTimer); // finger is scrolling, not holding
|
||||
pressTimer = null;
|
||||
}
|
||||
};
|
||||
const onTouchEnd = () => {
|
||||
tray.removeEventListener("touchmove", onTouchMove);
|
||||
tray.removeEventListener("touchend", onTouchEnd);
|
||||
tray.removeEventListener("touchcancel", onTouchEnd);
|
||||
if (pressTimer) clearTimeout(pressTimer);
|
||||
endDrag();
|
||||
};
|
||||
tray.addEventListener("touchmove", onTouchMove, { passive: false });
|
||||
tray.addEventListener("touchend", onTouchEnd);
|
||||
tray.addEventListener("touchcancel", onTouchEnd);
|
||||
}, { passive: true });
|
||||
|
||||
// Click: navigate on hover devices, toggle the peek on touch devices
|
||||
tray.addEventListener("click", (e) => {
|
||||
if (dragState.suppressClick) { e.preventDefault(); return; }
|
||||
if (supportsHover) {
|
||||
window.location.href = "/" + cell.dataset.drawerSlug;
|
||||
} else {
|
||||
cell.classList.contains("open") ? hidePeek() : showPeek(cell);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Block the long-press context menu over drawers (mobile drag)
|
||||
cabinet.addEventListener("contextmenu", (e) => {
|
||||
if (e.target.closest(".drawer-cell.has-drawer")) e.preventDefault();
|
||||
});
|
||||
|
||||
// Keyboard access for empty slots
|
||||
cabinet.querySelectorAll(".drawer-cell.empty").forEach(cell => {
|
||||
cell.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Enter" || e.key === " ") {
|
||||
e.preventDefault();
|
||||
openDrawerModal(cell);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// --- Drawer create/edit modal --------------------------------------------
|
||||
|
||||
function openDrawerModal(cell) {
|
||||
const modal = document.getElementById("drawer-modal");
|
||||
if (!modal) return;
|
||||
|
||||
const form = document.getElementById("drawer-modal-form");
|
||||
const title = document.getElementById("drawer-modal-title");
|
||||
const nameInput = document.getElementById("drawer-form-name");
|
||||
const colorInput = document.getElementById("drawer-form-color");
|
||||
const locationGroup = document.getElementById("drawer-form-location-group");
|
||||
const parentSelect = document.getElementById("drawer-form-parent");
|
||||
|
||||
document.getElementById("drawer-form-row").value = cell.dataset.row;
|
||||
document.getElementById("drawer-form-col").value = cell.dataset.col;
|
||||
|
||||
if (cell.dataset.drawerId) {
|
||||
// Edit existing drawer
|
||||
form.action = "/admin/drawers/edit/" + cell.dataset.drawerId;
|
||||
title.textContent = modal.dataset.titleEdit;
|
||||
nameInput.value = cell.dataset.drawerName || "";
|
||||
colorInput.value = /^#[0-9a-fA-F]{6}$/.test(cell.dataset.drawerColor) ? cell.dataset.drawerColor : "#d97706";
|
||||
locationGroup.hidden = false;
|
||||
if (parentSelect) parentSelect.selectedIndex = 0;
|
||||
} else {
|
||||
// Create a drawer in an empty slot
|
||||
form.action = "/admin/drawers/new";
|
||||
title.textContent = modal.dataset.titleCreate;
|
||||
nameInput.value = "";
|
||||
colorInput.value = "#d97706";
|
||||
locationGroup.hidden = true;
|
||||
}
|
||||
|
||||
modal.hidden = false;
|
||||
nameInput.focus();
|
||||
}
|
||||
|
||||
function closeDrawerModal() {
|
||||
const modal = document.getElementById("drawer-modal");
|
||||
if (modal) modal.hidden = true;
|
||||
}
|
||||
|
||||
document.addEventListener("click", (e) => {
|
||||
if (e.target.id === "drawer-modal") closeDrawerModal();
|
||||
});
|
||||
|
||||
document.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Escape") closeDrawerModal();
|
||||
});
|
||||
|
||||
function setDrawerColor(hex) {
|
||||
const colorInput = document.getElementById("drawer-form-color");
|
||||
if (colorInput) colorInput.value = hex;
|
||||
}
|
||||
|
||||
@@ -64,6 +64,123 @@
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
<!-- Container Array Drawer Grid -->
|
||||
{{if and .IsAuthenticated .DrawerGrid}}
|
||||
<div class="directory-section drawer-array-section">
|
||||
<h2 class="section-title">{{T "drawer.section_title"}}</h2>
|
||||
<p class="drawer-array-hint">{{T "drawer.hint"}}</p>
|
||||
<div class="drawer-cabinet-wrapper">
|
||||
<div class="drawer-cabinet" id="drawer-cabinet"
|
||||
data-array-id="{{.CurrentLocation.ID}}"
|
||||
style="--drawer-cols: {{.CurrentLocation.GridCols}};">
|
||||
{{range $row := .DrawerGrid}}
|
||||
{{range $cell := $row}}
|
||||
{{if $cell.Drawer}}
|
||||
<div class="drawer-cell has-drawer"
|
||||
data-row="{{$cell.Row}}" data-col="{{$cell.Col}}"
|
||||
data-drawer-id="{{$cell.Drawer.ID}}"
|
||||
data-drawer-name="{{$cell.Drawer.Name}}"
|
||||
data-drawer-color="{{$cell.Drawer.Color}}"
|
||||
data-drawer-slug="{{$cell.Drawer.Slug}}">
|
||||
<div class="drawer-box">
|
||||
<div class="drawer-cavity"></div>
|
||||
<div class="drawer-tray" {{if $cell.Drawer.Color}}style="--drawer-color: {{$cell.Drawer.Color}};"{{end}}>
|
||||
<div class="drawer-front">
|
||||
<span class="drawer-label">{{$cell.Drawer.Name}}</span>
|
||||
<span class="drawer-handle"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="drawer-peek">
|
||||
<strong class="drawer-peek-name">{{$cell.Drawer.Name}}</strong>
|
||||
<span class="drawer-peek-count">{{$cell.Drawer.ItemCount}} {{T "drawer.items"}}</span>
|
||||
{{if $cell.Drawer.ItemNames}}
|
||||
<em class="drawer-peek-items">{{$cell.Drawer.ItemNames}}</em>
|
||||
{{else}}
|
||||
<em class="drawer-peek-items">{{T "drawer.empty_contents"}}</em>
|
||||
{{end}}
|
||||
<div class="drawer-peek-actions">
|
||||
<a href="/{{$cell.Drawer.Slug}}" class="drawer-peek-btn">{{T "drawer.open"}}</a>
|
||||
<button type="button" class="drawer-peek-btn" onclick="openDrawerModal(this.closest('.drawer-cell'))">{{T "common.edit"}}</button>
|
||||
<form action="/admin/drawers/remove/{{$cell.Drawer.ID}}" method="POST" style="margin:0;" onsubmit="return confirm('{{T "drawer.confirm_remove"}}');">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<button type="submit" class="drawer-peek-btn danger">{{T "common.delete"}}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="drawer-cell empty"
|
||||
data-row="{{$cell.Row}}" data-col="{{$cell.Col}}"
|
||||
role="button" tabindex="0"
|
||||
aria-label="{{T "drawer.add"}}"
|
||||
onclick="openDrawerModal(this)">
|
||||
<div class="drawer-box">
|
||||
<div class="drawer-tray empty-tray">
|
||||
<div class="drawer-front">
|
||||
<span class="drawer-add-icon">+</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Drawer Create / Edit Modal -->
|
||||
<div class="drawer-modal-backdrop" id="drawer-modal" hidden
|
||||
data-title-create="{{T "drawer.new_drawer"}}" data-title-edit="{{T "drawer.edit_drawer"}}">
|
||||
<div class="drawer-modal card" role="dialog" aria-modal="true">
|
||||
<h3 id="drawer-modal-title" style="font-weight: 700; margin-bottom: 1rem;">{{T "drawer.edit_drawer"}}</h3>
|
||||
<form id="drawer-modal-form" method="POST" action="/admin/drawers/new">
|
||||
<input type="hidden" name="csrf_token" value="{{.CSRFToken}}">
|
||||
<input type="hidden" name="array_id" value="{{.CurrentLocation.ID}}">
|
||||
<input type="hidden" name="row" id="drawer-form-row" value="">
|
||||
<input type="hidden" name="col" id="drawer-form-col" value="">
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="drawer-form-name">{{T "drawer.name"}}</label>
|
||||
<input type="text" id="drawer-form-name" name="name" class="form-control" placeholder="e.g. Resistors A1">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="drawer-form-color">{{T "drawer.color"}}</label>
|
||||
<div style="display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap;">
|
||||
<input type="color" id="drawer-form-color" name="color" value="#d97706" style="width: 3rem; height: 2.2rem; padding: 0.15rem; border: 1px solid var(--color-border); border-radius: 6px; background: var(--color-bg-surface); cursor: pointer;">
|
||||
<button type="button" class="drawer-swatch" style="background:#d97706;" onclick="setDrawerColor('#d97706')" aria-label="amber"></button>
|
||||
<button type="button" class="drawer-swatch" style="background:#ef4444;" onclick="setDrawerColor('#ef4444')" aria-label="red"></button>
|
||||
<button type="button" class="drawer-swatch" style="background:#10b981;" onclick="setDrawerColor('#10b981')" aria-label="green"></button>
|
||||
<button type="button" class="drawer-swatch" style="background:#3b82f6;" onclick="setDrawerColor('#3b82f6')" aria-label="blue"></button>
|
||||
<button type="button" class="drawer-swatch" style="background:#8b5cf6;" onclick="setDrawerColor('#8b5cf6')" aria-label="purple"></button>
|
||||
<button type="button" class="drawer-swatch" style="background:#64748b;" onclick="setDrawerColor('#64748b')" aria-label="slate"></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" id="drawer-form-location-group" hidden>
|
||||
<label class="form-label" for="drawer-form-parent">{{T "drawer.location"}}</label>
|
||||
<select id="drawer-form-parent" name="parent_id" class="form-control">
|
||||
<option value="{{.CurrentLocation.ID}}">{{.CurrentLocation.Name}} ({{T "drawer.current_array"}})</option>
|
||||
{{range .Locations}}
|
||||
{{if ne .ID $.CurrentLocation.ID}}
|
||||
<option value="{{.ID}}">{{.Name}}</option>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</select>
|
||||
<p style="color: var(--color-text-light); font-size: 0.8rem; margin-top: 0.35rem;">{{T "drawer.location_hint"}}</p>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 0.5rem; margin-top: 1.25rem;">
|
||||
<button type="submit" class="btn btn-primary" style="flex-grow: 1;">{{T "common.save"}}</button>
|
||||
<button type="button" class="btn btn-secondary" onclick="closeDrawerModal()">{{T "common.cancel"}}</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
<!-- Sub-folders Section -->
|
||||
{{if .IsAuthenticated}}
|
||||
<div class="directory-section">
|
||||
|
||||
@@ -145,11 +145,27 @@
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="margin-bottom: 1.75rem;">
|
||||
<div class="form-group">
|
||||
<label for="description" class="form-label">{{T "common.description"}}</label>
|
||||
<textarea id="description" name="description" class="form-control" rows="3" placeholder="e.g. Red plastic storage box on shelf 2">{{.EditingLocation.Description}}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="margin-bottom: 1.75rem;">
|
||||
<label style="display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; font-weight: 500; cursor: pointer;">
|
||||
<input type="checkbox" name="is_array" value="1" {{if gt .EditingLocation.GridRows 0}}checked{{end}} onchange="toggleGridFields(this)" style="accent-color: var(--color-brand-primary);">
|
||||
{{T "locations.container_array"}}
|
||||
</label>
|
||||
<div class="grid-size-fields" {{if not (gt .EditingLocation.GridRows 0)}}hidden{{end}} style="margin-top: 0.6rem;">
|
||||
<div style="display: flex; gap: 0.5rem; align-items: center;">
|
||||
<input type="number" name="grid_rows" class="form-control" min="1" max="20" value="{{if gt .EditingLocation.GridRows 0}}{{.EditingLocation.GridRows}}{{else}}4{{end}}" style="width: 5.5rem;" aria-label="{{T "locations.grid_rows"}}">
|
||||
<span style="color: var(--color-text-muted);">×</span>
|
||||
<input type="number" name="grid_cols" class="form-control" min="1" max="20" value="{{if gt .EditingLocation.GridCols 0}}{{.EditingLocation.GridCols}}{{else}}4{{end}}" style="width: 5.5rem;" aria-label="{{T "locations.grid_cols"}}">
|
||||
<span style="color: var(--color-text-muted); font-size: 0.85rem;">{{T "locations.grid_dims"}}</span>
|
||||
</div>
|
||||
<p style="color: var(--color-text-light); font-size: 0.8rem; margin-top: 0.4rem;">{{T "locations.container_array_hint"}}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 0.5rem;">
|
||||
<button type="submit" class="btn btn-primary" style="flex-grow: 1;">{{T "common.save"}}</button>
|
||||
<a href="/admin/locations" class="btn btn-secondary">{{T "common.cancel"}}</a>
|
||||
@@ -175,15 +191,38 @@
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="margin-bottom: 1.75rem;">
|
||||
<div class="form-group">
|
||||
<label for="description" class="form-label">{{T "common.description"}}</label>
|
||||
<textarea id="description" name="description" class="form-control" rows="3" placeholder="e.g. First floor living room cupboard"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="margin-bottom: 1.75rem;">
|
||||
<label style="display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; font-weight: 500; cursor: pointer;">
|
||||
<input type="checkbox" name="is_array" value="1" onchange="toggleGridFields(this)" style="accent-color: var(--color-brand-primary);">
|
||||
{{T "locations.container_array"}}
|
||||
</label>
|
||||
<div class="grid-size-fields" hidden style="margin-top: 0.6rem;">
|
||||
<div style="display: flex; gap: 0.5rem; align-items: center;">
|
||||
<input type="number" name="grid_rows" class="form-control" min="1" max="20" value="4" style="width: 5.5rem;" aria-label="{{T "locations.grid_rows"}}">
|
||||
<span style="color: var(--color-text-muted);">×</span>
|
||||
<input type="number" name="grid_cols" class="form-control" min="1" max="20" value="4" style="width: 5.5rem;" aria-label="{{T "locations.grid_cols"}}">
|
||||
<span style="color: var(--color-text-muted); font-size: 0.85rem;">{{T "locations.grid_dims"}}</span>
|
||||
</div>
|
||||
<p style="color: var(--color-text-light); font-size: 0.8rem; margin-top: 0.4rem;">{{T "locations.container_array_hint"}}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary" style="width: 100%;">{{T "locations.add_location"}}</button>
|
||||
</form>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function toggleGridFields(checkbox) {
|
||||
const fields = checkbox.closest(".form-group").querySelector(".grid-size-fields");
|
||||
if (fields) fields.hidden = !checkbox.checked;
|
||||
}
|
||||
</script>
|
||||
{{end}}
|
||||
@@ -11,6 +11,11 @@ CREATE TABLE IF NOT EXISTS locations (
|
||||
description TEXT NOT NULL DEFAULT '',
|
||||
parent_id INTEGER REFERENCES locations(id) ON DELETE SET NULL,
|
||||
image_path TEXT NOT NULL DEFAULT '',
|
||||
grid_rows INTEGER NOT NULL DEFAULT 0, -- Container array height (0 = not a container array)
|
||||
grid_cols INTEGER NOT NULL DEFAULT 0, -- Container array width (0 = not a container array)
|
||||
grid_row INTEGER, -- Drawer position (row) within parent container array
|
||||
grid_col INTEGER, -- Drawer position (col) within parent container array
|
||||
color TEXT NOT NULL DEFAULT '', -- Drawer color code (hex)
|
||||
lifecycle_state TEXT NOT NULL DEFAULT 'active',
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
|
||||
Reference in new issue
Block a user