Implement non-destructive Remove & Archive lifecycle system across assets, locations, tags, and shortlinks
This commit is contained in:
1 parent
3391257f6c
commit
960c375557
20 files changed
+1751
-185
No files matched your search
@@ -48,6 +48,37 @@ func migrate(conn *sql.DB) error {
|
||||
return fmt.Errorf("running schema migrations: %w", err)
|
||||
}
|
||||
|
||||
// Ensure lifecycle_state column exists in items, locations, tags, links (for existing databases)
|
||||
for _, tableName := range []string{"items", "locations", "tags", "links"} {
|
||||
rows, err := conn.Query(fmt.Sprintf("PRAGMA table_info(%s)", tableName))
|
||||
if err != nil {
|
||||
return fmt.Errorf("pragma table_info for %s: %w", tableName, err)
|
||||
}
|
||||
|
||||
hasLifecycleState := false
|
||||
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 %s: %w", tableName, err)
|
||||
}
|
||||
if name == "lifecycle_state" {
|
||||
hasLifecycleState = true
|
||||
}
|
||||
}
|
||||
rows.Close()
|
||||
|
||||
if !hasLifecycleState {
|
||||
alterQuery := fmt.Sprintf("ALTER TABLE %s ADD COLUMN lifecycle_state TEXT NOT NULL DEFAULT 'active'", tableName)
|
||||
if _, err := conn.Exec(alterQuery); err != nil {
|
||||
return fmt.Errorf("adding lifecycle_state column to %s: %w", tableName, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if locations count is 0
|
||||
var count int
|
||||
err = conn.QueryRow("SELECT COUNT(*) FROM locations").Scan(&count)
|
||||
|
||||
+29
-8
@@ -23,6 +23,7 @@ type Item struct {
|
||||
CustomFields string // JSON text
|
||||
ImagePath string
|
||||
ReceiptPath string
|
||||
LifecycleState string // 'active', 'archived', 'removed'
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Tags []Tag // Loaded on demand
|
||||
@@ -86,7 +87,7 @@ func (d *DB) GetItem(id int64) (*Item, error) {
|
||||
i.id, i.name, i.description, i.quantity, i.model_number, i.serial_number, i.status,
|
||||
i.location_id, l.name AS location_name, i.purchase_price, i.purchase_date, i.warranty_months,
|
||||
i.supplier, i.custom_fields, i.image_path, i.receipt_path, i.created_at, i.updated_at,
|
||||
COALESCE(lk.slug, '') AS short_slug
|
||||
COALESCE(lk.slug, '') AS short_slug, i.lifecycle_state
|
||||
FROM items i
|
||||
LEFT JOIN locations l ON i.location_id = l.id
|
||||
LEFT JOIN links lk ON lk.item_id = i.id
|
||||
@@ -160,18 +161,38 @@ func (d *DB) DeleteItem(id int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DB) ListItems() ([]Item, error) {
|
||||
rows, err := d.Conn.Query(`
|
||||
func (d *DB) SoftRemoveItem(id int64) error {
|
||||
_, err := d.Conn.Exec("UPDATE items SET lifecycle_state = 'removed', updated_at = datetime('now') WHERE id = ?", id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DB) ArchiveItem(id int64) error {
|
||||
_, err := d.Conn.Exec("UPDATE items SET lifecycle_state = 'archived', updated_at = datetime('now') WHERE id = ?", id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DB) RestoreItem(id int64) error {
|
||||
_, err := d.Conn.Exec("UPDATE items SET lifecycle_state = 'active', updated_at = datetime('now') WHERE id = ?", id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DB) ListItems(showRemoved bool) ([]Item, error) {
|
||||
query := `
|
||||
SELECT
|
||||
i.id, i.name, i.description, i.quantity, i.model_number, i.serial_number, i.status,
|
||||
i.location_id, l.name AS location_name, i.purchase_price, i.purchase_date, i.warranty_months,
|
||||
i.supplier, i.custom_fields, i.image_path, i.receipt_path, i.created_at, i.updated_at,
|
||||
COALESCE(lk.slug, '') AS short_slug
|
||||
COALESCE(lk.slug, '') AS short_slug, i.lifecycle_state
|
||||
FROM items i
|
||||
LEFT JOIN locations l ON i.location_id = l.id
|
||||
LEFT JOIN links lk ON lk.item_id = i.id
|
||||
ORDER BY i.id DESC`,
|
||||
)
|
||||
`
|
||||
if !showRemoved {
|
||||
query += " WHERE i.lifecycle_state != 'removed'"
|
||||
}
|
||||
query += " ORDER BY CASE i.lifecycle_state WHEN 'archived' THEN 1 WHEN 'removed' THEN 2 ELSE 0 END, i.id DESC"
|
||||
|
||||
rows, err := d.Conn.Query(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -191,7 +212,7 @@ func (d *DB) ListItems() ([]Item, error) {
|
||||
err := rows.Scan(
|
||||
&i.ID, &i.Name, &i.Description, &i.Quantity, &i.ModelNumber, &i.SerialNumber, &i.Status,
|
||||
&locID, &locName, &price, &date, &warranty, &i.Supplier, &i.CustomFields, &i.ImagePath,
|
||||
&i.ReceiptPath, &created, &updated, &i.ShortSlug,
|
||||
&i.ReceiptPath, &created, &updated, &i.ShortSlug, &i.LifecycleState,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -312,7 +333,7 @@ func scanItem(row interface {
|
||||
err := row.Scan(
|
||||
&i.ID, &i.Name, &i.Description, &i.Quantity, &i.ModelNumber, &i.SerialNumber, &i.Status,
|
||||
&locID, &locName, &price, &date, &warranty, &i.Supplier, &i.CustomFields, &i.ImagePath,
|
||||
&i.ReceiptPath, &created, &updated, &i.ShortSlug,
|
||||
&i.ReceiptPath, &created, &updated, &i.ShortSlug, &i.LifecycleState,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+35
-13
@@ -6,13 +6,14 @@ import (
|
||||
)
|
||||
|
||||
type Link struct {
|
||||
ID int64
|
||||
Slug string
|
||||
URL string
|
||||
ItemID sql.NullInt64
|
||||
CreatedBy string
|
||||
Clicks int64
|
||||
CreatedAt time.Time
|
||||
ID int64
|
||||
Slug string
|
||||
URL string
|
||||
ItemID sql.NullInt64
|
||||
CreatedBy string
|
||||
Clicks int64
|
||||
LifecycleState string // 'active', 'archived', 'removed'
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
func (d *DB) CreateLink(slug, url, createdBy string, itemID sql.NullInt64) (*Link, error) {
|
||||
@@ -35,12 +36,12 @@ func (d *DB) CreateLink(slug, url, createdBy string, itemID sql.NullInt64) (*Lin
|
||||
}
|
||||
|
||||
func (d *DB) GetLinkBySlug(slug string) (*Link, error) {
|
||||
row := d.Conn.QueryRow("SELECT id, slug, url, item_id, created_by, clicks, created_at FROM links WHERE slug = ?", slug)
|
||||
row := d.Conn.QueryRow("SELECT id, slug, url, item_id, created_by, clicks, lifecycle_state, created_at FROM links WHERE slug = ?", slug)
|
||||
return scanLink(row)
|
||||
}
|
||||
|
||||
func (d *DB) GetLinkByItemID(itemID int64) (*Link, error) {
|
||||
row := d.Conn.QueryRow("SELECT id, slug, url, item_id, created_by, clicks, created_at FROM links WHERE item_id = ?", itemID)
|
||||
row := d.Conn.QueryRow("SELECT id, slug, url, item_id, created_by, clicks, lifecycle_state, created_at FROM links WHERE item_id = ?", itemID)
|
||||
return scanLink(row)
|
||||
}
|
||||
|
||||
@@ -49,8 +50,29 @@ func (d *DB) IncrementLinkClicks(slug string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DB) ListLinks() ([]Link, error) {
|
||||
rows, err := d.Conn.Query("SELECT id, slug, url, item_id, created_by, clicks, created_at FROM links ORDER BY id DESC")
|
||||
func (d *DB) SoftRemoveLink(id int64) error {
|
||||
_, err := d.Conn.Exec("UPDATE links SET lifecycle_state = 'removed' WHERE id = ?", id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DB) ArchiveLink(id int64) error {
|
||||
_, err := d.Conn.Exec("UPDATE links SET lifecycle_state = 'archived' WHERE id = ?", id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DB) RestoreLink(id int64) error {
|
||||
_, err := d.Conn.Exec("UPDATE links SET lifecycle_state = 'active' WHERE id = ?", id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DB) ListLinks(showRemoved bool) ([]Link, error) {
|
||||
query := "SELECT id, slug, url, item_id, created_by, clicks, lifecycle_state, created_at FROM links"
|
||||
if !showRemoved {
|
||||
query += " WHERE lifecycle_state != 'removed'"
|
||||
}
|
||||
query += " ORDER BY CASE lifecycle_state WHEN 'archived' THEN 1 WHEN 'removed' THEN 2 ELSE 0 END, id DESC"
|
||||
|
||||
rows, err := d.Conn.Query(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -61,7 +83,7 @@ func (d *DB) ListLinks() ([]Link, error) {
|
||||
var l Link
|
||||
var itemID sql.NullInt64
|
||||
var ts string
|
||||
if err := rows.Scan(&l.ID, &l.Slug, &l.URL, &itemID, &l.CreatedBy, &l.Clicks, &ts); err != nil {
|
||||
if err := rows.Scan(&l.ID, &l.Slug, &l.URL, &itemID, &l.CreatedBy, &l.Clicks, &l.LifecycleState, &ts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
l.ItemID = itemID
|
||||
@@ -93,7 +115,7 @@ func scanLink(row interface {
|
||||
var l Link
|
||||
var itemID sql.NullInt64
|
||||
var ts string
|
||||
if err := row.Scan(&l.ID, &l.Slug, &l.URL, &itemID, &l.CreatedBy, &l.Clicks, &ts); err != nil {
|
||||
if err := row.Scan(&l.ID, &l.Slug, &l.URL, &itemID, &l.CreatedBy, &l.Clicks, &l.LifecycleState, &ts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
l.ItemID = itemID
|
||||
|
||||
+43
-17
@@ -7,14 +7,15 @@ import (
|
||||
)
|
||||
|
||||
type Location struct {
|
||||
ID int64
|
||||
Name string
|
||||
Description string
|
||||
ParentID sql.NullInt64
|
||||
ParentName sql.NullString // Resolved parent location name
|
||||
ImagePath string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
ID int64
|
||||
Name string
|
||||
Description string
|
||||
ParentID sql.NullInt64
|
||||
ParentName sql.NullString // Resolved parent location name
|
||||
ImagePath string
|
||||
LifecycleState string // 'active', 'archived', 'removed'
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
func (d *DB) CreateLocation(name, description string, parentID sql.NullInt64, imagePath string) (*Location, error) {
|
||||
@@ -63,7 +64,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.description, l.parent_id, p.name AS parent_name, l.image_path, l.created_at, l.updated_at
|
||||
SELECT l.id, l.name, l.description, l.parent_id, p.name AS parent_name, l.image_path, l.lifecycle_state, l.created_at, l.updated_at
|
||||
FROM locations l
|
||||
LEFT JOIN locations p ON l.parent_id = p.id
|
||||
WHERE l.id = ?`,
|
||||
@@ -174,13 +175,38 @@ func (d *DB) DeleteLocation(id int64) error {
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (d *DB) ListLocations() ([]Location, error) {
|
||||
rows, err := d.Conn.Query(`
|
||||
SELECT l.id, l.name, l.description, l.parent_id, p.name AS parent_name, l.image_path, l.created_at, l.updated_at
|
||||
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)
|
||||
return err
|
||||
}
|
||||
|
||||
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)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DB) RestoreLocation(id int64) error {
|
||||
_, err := d.Conn.Exec("UPDATE locations SET lifecycle_state = 'active', updated_at = datetime('now') WHERE id = ?", id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DB) ListLocations(showRemoved bool) ([]Location, error) {
|
||||
query := `
|
||||
SELECT l.id, l.name, l.description, l.parent_id, p.name AS parent_name, l.image_path, l.lifecycle_state, l.created_at, l.updated_at
|
||||
FROM locations l
|
||||
LEFT JOIN locations p ON l.parent_id = p.id
|
||||
ORDER BY l.name ASC`,
|
||||
)
|
||||
LEFT JOIN locations p ON l.parent_id = p.id`
|
||||
if !showRemoved {
|
||||
query += " WHERE l.lifecycle_state != 'removed'"
|
||||
}
|
||||
query += " ORDER BY CASE l.lifecycle_state WHEN 'archived' THEN 1 WHEN 'removed' THEN 2 ELSE 0 END, l.name ASC"
|
||||
|
||||
rows, err := d.Conn.Query(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -192,7 +218,7 @@ func (d *DB) ListLocations() ([]Location, error) {
|
||||
var parentID sql.NullInt64
|
||||
var parentName sql.NullString
|
||||
var created, updated string
|
||||
if err := rows.Scan(&l.ID, &l.Name, &l.Description, &parentID, &parentName, &l.ImagePath, &created, &updated); err != nil {
|
||||
if err := rows.Scan(&l.ID, &l.Name, &l.Description, &parentID, &parentName, &l.ImagePath, &l.LifecycleState, &created, &updated); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
l.ParentID = parentID
|
||||
@@ -211,7 +237,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.Description, &parentID, &parentName, &l.ImagePath, &created, &updated); err != nil {
|
||||
if err := row.Scan(&l.ID, &l.Name, &l.Description, &parentID, &parentName, &l.ImagePath, &l.LifecycleState, &created, &updated); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
l.ParentID = parentID
|
||||
|
||||
+23
-19
@@ -3,24 +3,26 @@
|
||||
|
||||
-- 1. Locations Table (Supports hierarchical locations via parent_id)
|
||||
CREATE TABLE IF NOT EXISTS locations (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT NOT NULL DEFAULT '',
|
||||
parent_id INTEGER REFERENCES locations(id) ON DELETE SET NULL,
|
||||
image_path TEXT NOT NULL DEFAULT '',
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT NOT NULL DEFAULT '',
|
||||
parent_id INTEGER REFERENCES locations(id) ON DELETE SET NULL,
|
||||
image_path TEXT NOT NULL DEFAULT '',
|
||||
lifecycle_state TEXT NOT NULL DEFAULT 'active',
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_locations_parent ON locations(parent_id);
|
||||
|
||||
-- 2. Tags Table (Sleek labels for grouping items)
|
||||
CREATE TABLE IF NOT EXISTS tags (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
color TEXT NOT NULL DEFAULT '#e2e8f0', -- Hex code for pill color
|
||||
description TEXT NOT NULL DEFAULT '',
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
color TEXT NOT NULL DEFAULT '#e2e8f0', -- Hex code for pill color
|
||||
description TEXT NOT NULL DEFAULT '',
|
||||
lifecycle_state TEXT NOT NULL DEFAULT 'active',
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
);
|
||||
|
||||
-- 3. Items Table (Asset entries with purchase records and JSON custom fields)
|
||||
@@ -40,6 +42,7 @@ CREATE TABLE IF NOT EXISTS items (
|
||||
custom_fields TEXT NOT NULL DEFAULT '{}', -- JSON text field containing arbitrary key-value custom metadata
|
||||
image_path TEXT NOT NULL DEFAULT '',
|
||||
receipt_path TEXT NOT NULL DEFAULT '',
|
||||
lifecycle_state TEXT NOT NULL DEFAULT 'active',
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
);
|
||||
@@ -55,13 +58,14 @@ CREATE TABLE IF NOT EXISTS item_tags (
|
||||
|
||||
-- 5. Links Table (Ported and enhanced from Glimmer)
|
||||
CREATE TABLE IF NOT EXISTS links (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
slug TEXT NOT NULL UNIQUE,
|
||||
url TEXT NOT NULL, -- Redirect target (internal, e.g., '/items/12', or external)
|
||||
item_id INTEGER REFERENCES items(id) ON DELETE CASCADE, -- Nullable; links specific assets to short URLs
|
||||
created_by TEXT NOT NULL DEFAULT 'admin',
|
||||
clicks INTEGER NOT NULL DEFAULT 0,
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
slug TEXT NOT NULL UNIQUE,
|
||||
url TEXT NOT NULL, -- Redirect target (internal, e.g., '/items/12', or external)
|
||||
item_id INTEGER REFERENCES items(id) ON DELETE CASCADE, -- Nullable; links specific assets to short URLs
|
||||
created_by TEXT NOT NULL DEFAULT 'admin',
|
||||
clicks INTEGER NOT NULL DEFAULT 0,
|
||||
lifecycle_state TEXT NOT NULL DEFAULT 'active',
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_links_slug ON links(slug);
|
||||
|
||||
+43
-11
@@ -6,11 +6,12 @@ import (
|
||||
)
|
||||
|
||||
type Tag struct {
|
||||
ID int64
|
||||
Name string
|
||||
Color string // Hex representation, e.g. "#3b82f6"
|
||||
Description string
|
||||
CreatedAt time.Time
|
||||
ID int64
|
||||
Name string
|
||||
Color string // Hex representation, e.g. "#3b82f6"
|
||||
Description string
|
||||
LifecycleState string // 'active', 'archived', 'removed'
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
func (d *DB) CreateTag(name, color, description string) (*Tag, error) {
|
||||
@@ -35,12 +36,12 @@ func (d *DB) CreateTag(name, color, description string) (*Tag, error) {
|
||||
}
|
||||
|
||||
func (d *DB) GetTag(id int64) (*Tag, error) {
|
||||
row := d.Conn.QueryRow("SELECT id, name, color, description, created_at FROM tags WHERE id = ?", id)
|
||||
row := d.Conn.QueryRow("SELECT id, name, color, description, lifecycle_state, created_at FROM tags WHERE id = ?", id)
|
||||
return scanTag(row)
|
||||
}
|
||||
|
||||
func (d *DB) GetTagByName(name string) (*Tag, error) {
|
||||
row := d.Conn.QueryRow("SELECT id, name, color, description, created_at FROM tags WHERE name = ?", name)
|
||||
row := d.Conn.QueryRow("SELECT id, name, color, description, lifecycle_state, created_at FROM tags WHERE name = ?", name)
|
||||
return scanTag(row)
|
||||
}
|
||||
|
||||
@@ -74,8 +75,39 @@ func (d *DB) DeleteTag(id int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DB) ListTags() ([]Tag, error) {
|
||||
rows, err := d.Conn.Query("SELECT id, name, color, description, created_at FROM tags ORDER BY name ASC")
|
||||
func (d *DB) SoftRemoveTag(id int64) error {
|
||||
var name string
|
||||
err := d.Conn.QueryRow("SELECT name FROM tags WHERE id = ?", id).Scan(&name)
|
||||
if err == nil && name == "Default Room" {
|
||||
return fmt.Errorf("cannot remove the Default Room tag")
|
||||
}
|
||||
_, err = d.Conn.Exec("UPDATE tags SET lifecycle_state = 'removed' WHERE id = ?", id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DB) ArchiveTag(id int64) error {
|
||||
var name string
|
||||
err := d.Conn.QueryRow("SELECT name FROM tags WHERE id = ?", id).Scan(&name)
|
||||
if err == nil && name == "Default Room" {
|
||||
return fmt.Errorf("cannot archive the Default Room tag")
|
||||
}
|
||||
_, err = d.Conn.Exec("UPDATE tags SET lifecycle_state = 'archived' WHERE id = ?", id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DB) RestoreTag(id int64) error {
|
||||
_, err := d.Conn.Exec("UPDATE tags SET lifecycle_state = 'active' WHERE id = ?", id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DB) ListTags(showRemoved bool) ([]Tag, error) {
|
||||
query := "SELECT id, name, color, description, lifecycle_state, created_at FROM tags"
|
||||
if !showRemoved {
|
||||
query += " WHERE lifecycle_state != 'removed'"
|
||||
}
|
||||
query += " ORDER BY CASE lifecycle_state WHEN 'archived' THEN 1 WHEN 'removed' THEN 2 ELSE 0 END, name ASC"
|
||||
|
||||
rows, err := d.Conn.Query(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -85,7 +117,7 @@ func (d *DB) ListTags() ([]Tag, error) {
|
||||
for rows.Next() {
|
||||
var t Tag
|
||||
var created string
|
||||
if err := rows.Scan(&t.ID, &t.Name, &t.Color, &t.Description, &created); err != nil {
|
||||
if err := rows.Scan(&t.ID, &t.Name, &t.Color, &t.Description, &t.LifecycleState, &created); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t.CreatedAt, _ = time.Parse("2006-01-02 15:04:05", created)
|
||||
@@ -99,7 +131,7 @@ func scanTag(row interface {
|
||||
}) (*Tag, error) {
|
||||
var t Tag
|
||||
var created string
|
||||
if err := row.Scan(&t.ID, &t.Name, &t.Color, &t.Description, &created); err != nil {
|
||||
if err := row.Scan(&t.ID, &t.Name, &t.Color, &t.Description, &t.LifecycleState, &created); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t.CreatedAt, _ = time.Parse("2006-01-02 15:04:05", created)
|
||||
|
||||
+197
-30
@@ -9,6 +9,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -44,6 +45,8 @@ type PageData struct {
|
||||
SelectedStatus string
|
||||
SelectedLocation int64
|
||||
CatalogJSON string
|
||||
SlugLength int
|
||||
ShowRemoved bool
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
@@ -167,8 +170,9 @@ func (s *Server) handleLogout(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (s *Server) handleAdminItems(w http.ResponseWriter, r *http.Request) {
|
||||
csrf := csrfToken(w, r)
|
||||
locations, _ := s.db.ListLocations()
|
||||
tags, _ := s.db.ListTags()
|
||||
showRemoved := r.URL.Query().Get("show_removed") == "1"
|
||||
locations, _ := s.db.ListLocations(showRemoved)
|
||||
tags, _ := s.db.ListTags(showRemoved)
|
||||
|
||||
// 1. DETAIL VIEW MODE
|
||||
if viewIDStr := r.URL.Query().Get("view"); viewIDStr != "" {
|
||||
@@ -188,6 +192,7 @@ func (s *Server) handleAdminItems(w http.ResponseWriter, r *http.Request) {
|
||||
CustomFieldsMap: cfMap,
|
||||
Locations: locations,
|
||||
Tags: tags,
|
||||
ShowRemoved: showRemoved,
|
||||
Toast: r.URL.Query().Get("toast"),
|
||||
ToastType: r.URL.Query().Get("toast_type"),
|
||||
}
|
||||
@@ -202,7 +207,7 @@ func (s *Server) handleAdminItems(w http.ResponseWriter, r *http.Request) {
|
||||
statusQuery := r.URL.Query().Get("status")
|
||||
locationQuery := r.URL.Query().Get("location")
|
||||
|
||||
allItems, err := s.db.ListItems()
|
||||
allItems, err := s.db.ListItems(showRemoved)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to load assets", http.StatusInternalServerError)
|
||||
return
|
||||
@@ -239,6 +244,7 @@ func (s *Server) handleAdminItems(w http.ResponseWriter, r *http.Request) {
|
||||
SearchQuery: searchQuery,
|
||||
SelectedStatus: statusQuery,
|
||||
SelectedLocation: locFilterID,
|
||||
ShowRemoved: showRemoved,
|
||||
Toast: r.URL.Query().Get("toast"),
|
||||
ToastType: r.URL.Query().Get("toast_type"),
|
||||
}
|
||||
@@ -247,8 +253,8 @@ func (s *Server) handleAdminItems(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *Server) handleItemNew(w http.ResponseWriter, r *http.Request) {
|
||||
locations, _ := s.db.ListLocations()
|
||||
tags, _ := s.db.ListTags()
|
||||
locations, _ := s.db.ListLocations(false)
|
||||
tags, _ := s.db.ListTags(false)
|
||||
|
||||
catalogJSON, err := json.Marshal(s.catalog)
|
||||
if err != nil {
|
||||
@@ -448,8 +454,8 @@ func (s *Server) handleItemEdit(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
locations, _ := s.db.ListLocations()
|
||||
tags, _ := s.db.ListTags()
|
||||
locations, _ := s.db.ListLocations(false)
|
||||
tags, _ := s.db.ListTags(false)
|
||||
|
||||
// Translate custom JSON string back to raw lines for edit comfort
|
||||
customFieldsRaw := formatCustomFields(item.CustomFields)
|
||||
@@ -570,7 +576,40 @@ func (s *Server) handleItemSave(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, fmt.Sprintf("/admin?view=%d&toast=Asset+updated+successfully&toast_type=success", item.ID), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleItemDelete(w http.ResponseWriter, r *http.Request) {
|
||||
func (s *Server) handleItemRemove(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
_ = s.db.SoftRemoveItem(id)
|
||||
http.Redirect(w, r, "/admin?toast=Asset+moved+to+soon-to-be-deleted+queue&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleItemArchive(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
_ = s.db.ArchiveItem(id)
|
||||
http.Redirect(w, r, "/admin?toast=Asset+archived+successfully&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleItemRestore(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
_ = s.db.RestoreItem(id)
|
||||
http.Redirect(w, r, "/admin?show_removed=1&toast=Asset+restored+successfully&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleItemPermanentDelete(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
@@ -589,7 +628,7 @@ func (s *Server) handleItemDelete(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
_ = s.db.DeleteItem(id)
|
||||
http.Redirect(w, r, "/admin?toast=Asset+deleted+successfully&toast_type=success", http.StatusSeeOther)
|
||||
http.Redirect(w, r, "/admin?show_removed=1&toast=Asset+deleted+forever+successfully&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
@@ -598,7 +637,8 @@ func (s *Server) handleItemDelete(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (s *Server) handleAdminLocations(w http.ResponseWriter, r *http.Request) {
|
||||
csrf := csrfToken(w, r)
|
||||
locations, _ := s.db.ListLocations()
|
||||
showRemoved := r.URL.Query().Get("show_removed") == "1"
|
||||
locations, _ := s.db.ListLocations(showRemoved)
|
||||
|
||||
var editLoc *db.Location
|
||||
if editIDStr := r.URL.Query().Get("edit"); editIDStr != "" {
|
||||
@@ -613,6 +653,7 @@ func (s *Server) handleAdminLocations(w http.ResponseWriter, r *http.Request) {
|
||||
ActiveNav: "locations",
|
||||
Locations: locations,
|
||||
EditingLocation: editLoc,
|
||||
ShowRemoved: showRemoved,
|
||||
Toast: r.URL.Query().Get("toast"),
|
||||
ToastType: r.URL.Query().Get("toast_type"),
|
||||
}
|
||||
@@ -658,7 +699,40 @@ func (s *Server) handleLocationEdit(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "/admin/locations?toast=Location+updated+successfully&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleLocationDelete(w http.ResponseWriter, r *http.Request) {
|
||||
func (s *Server) handleLocationRemove(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
_ = s.db.SoftRemoveLocation(id)
|
||||
http.Redirect(w, r, "/admin/locations?toast=Location+moved+to+soon-to-be-deleted+queue&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleLocationArchive(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
_ = s.db.ArchiveLocation(id)
|
||||
http.Redirect(w, r, "/admin/locations?toast=Location+archived+successfully&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleLocationRestore(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
_ = s.db.RestoreLocation(id)
|
||||
http.Redirect(w, r, "/admin/locations?show_removed=1&toast=Location+restored+successfully&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleLocationPermanentDelete(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
@@ -666,7 +740,7 @@ func (s *Server) handleLocationDelete(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
_ = s.db.DeleteLocation(id)
|
||||
http.Redirect(w, r, "/admin/locations?toast=Location+deleted+successfully&toast_type=success", http.StatusSeeOther)
|
||||
http.Redirect(w, r, "/admin/locations?show_removed=1&toast=Location+deleted+forever+successfully&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
@@ -675,7 +749,8 @@ func (s *Server) handleLocationDelete(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (s *Server) handleAdminTags(w http.ResponseWriter, r *http.Request) {
|
||||
csrf := csrfToken(w, r)
|
||||
tags, _ := s.db.ListTags()
|
||||
showRemoved := r.URL.Query().Get("show_removed") == "1"
|
||||
tags, _ := s.db.ListTags(showRemoved)
|
||||
|
||||
var editTag *db.Tag
|
||||
if editIDStr := r.URL.Query().Get("edit"); editIDStr != "" {
|
||||
@@ -686,12 +761,13 @@ func (s *Server) handleAdminTags(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
data := PageData{
|
||||
CSRFToken: csrf,
|
||||
ActiveNav: "tags",
|
||||
Tags: tags,
|
||||
EditingTag: editTag,
|
||||
Toast: r.URL.Query().Get("toast"),
|
||||
ToastType: r.URL.Query().Get("toast_type"),
|
||||
CSRFToken: csrf,
|
||||
ActiveNav: "tags",
|
||||
Tags: tags,
|
||||
EditingTag: editTag,
|
||||
ShowRemoved: showRemoved,
|
||||
Toast: r.URL.Query().Get("toast"),
|
||||
ToastType: r.URL.Query().Get("toast_type"),
|
||||
}
|
||||
renderTemplate(w, "tags.html", data)
|
||||
}
|
||||
@@ -725,7 +801,40 @@ func (s *Server) handleTagEdit(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "/admin/tags?toast=Tag+updated+successfully&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleTagDelete(w http.ResponseWriter, r *http.Request) {
|
||||
func (s *Server) handleTagRemove(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
_ = s.db.SoftRemoveTag(id)
|
||||
http.Redirect(w, r, "/admin/tags?toast=Tag+moved+to+soon-to-be-deleted+queue&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleTagArchive(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
_ = s.db.ArchiveTag(id)
|
||||
http.Redirect(w, r, "/admin/tags?toast=Tag+archived+successfully&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleTagRestore(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
_ = s.db.RestoreTag(id)
|
||||
http.Redirect(w, r, "/admin/tags?show_removed=1&toast=Tag+restored+successfully&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleTagPermanentDelete(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
@@ -733,7 +842,7 @@ func (s *Server) handleTagDelete(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
_ = s.db.DeleteTag(id)
|
||||
http.Redirect(w, r, "/admin/tags?toast=Tag+deleted+successfully&toast_type=success", http.StatusSeeOther)
|
||||
http.Redirect(w, r, "/admin/tags?show_removed=1&toast=Tag+deleted+forever+successfully&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
@@ -742,20 +851,18 @@ func (s *Server) handleTagDelete(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (s *Server) handleAdminShortener(w http.ResponseWriter, r *http.Request) {
|
||||
csrf := csrfToken(w, r)
|
||||
links, _ := s.db.ListLinks()
|
||||
showRemoved := r.URL.Query().Get("show_removed") == "1"
|
||||
links, _ := s.db.ListLinks(showRemoved)
|
||||
|
||||
var editLink *db.Link
|
||||
if editIDStr := r.URL.Query().Get("edit"); editIDStr != "" {
|
||||
id, err := strconv.ParseInt(editIDStr, 10, 64)
|
||||
if err == nil {
|
||||
editLink, _ = s.db.GetLinkBySlug(editIDStr) // Note: ListLinks uses ID, so let's match by ID instead of slug in the select queries if possible. Wait!
|
||||
// Actually let's query by id using db.Conn directly or adding a GetLinkByID function.
|
||||
// Let's query by ID in database:
|
||||
row := s.db.Conn.QueryRow("SELECT id, slug, url, item_id, created_by, clicks, created_at FROM links WHERE id = ?", id)
|
||||
row := s.db.Conn.QueryRow("SELECT id, slug, url, item_id, created_by, clicks, lifecycle_state, created_at FROM links WHERE id = ?", id)
|
||||
var l db.Link
|
||||
var itemID sql.NullInt64
|
||||
var ts string
|
||||
if row.Scan(&l.ID, &l.Slug, &l.URL, &itemID, &l.CreatedBy, &l.Clicks, &ts) == nil {
|
||||
if row.Scan(&l.ID, &l.Slug, &l.URL, &itemID, &l.CreatedBy, &l.Clicks, &l.LifecycleState, &ts) == nil {
|
||||
l.ItemID = itemID
|
||||
l.CreatedAt, _ = time.Parse("2006-01-02 15:04:05", ts)
|
||||
editLink = &l
|
||||
@@ -768,6 +875,8 @@ func (s *Server) handleAdminShortener(w http.ResponseWriter, r *http.Request) {
|
||||
ActiveNav: "shortener",
|
||||
Links: links,
|
||||
EditingLink: editLink,
|
||||
SlugLength: s.cfg.Slugs.Length,
|
||||
ShowRemoved: showRemoved,
|
||||
Toast: r.URL.Query().Get("toast"),
|
||||
ToastType: r.URL.Query().Get("toast_type"),
|
||||
}
|
||||
@@ -845,7 +954,40 @@ func (s *Server) handleLinkSave(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "/admin/shortener?toast=Shortlink+updated+successfully&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleLinkDelete(w http.ResponseWriter, r *http.Request) {
|
||||
func (s *Server) handleLinkRemove(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
_ = s.db.SoftRemoveLink(id)
|
||||
http.Redirect(w, r, "/admin/shortener?toast=Shortlink+moved+to+soon-to-be-deleted+queue&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleLinkArchive(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
_ = s.db.ArchiveLink(id)
|
||||
http.Redirect(w, r, "/admin/shortener?toast=Shortlink+archived+successfully&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleLinkRestore(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
_ = s.db.RestoreLink(id)
|
||||
http.Redirect(w, r, "/admin/shortener?show_removed=1&toast=Shortlink+restored+successfully&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleLinkPermanentDelete(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
@@ -853,7 +995,32 @@ func (s *Server) handleLinkDelete(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
_ = s.db.DeleteLink(id)
|
||||
http.Redirect(w, r, "/admin/shortener?toast=Shortlink+deleted+successfully&toast_type=success", http.StatusSeeOther)
|
||||
http.Redirect(w, r, "/admin/shortener?show_removed=1&toast=Shortlink+deleted+forever+successfully&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleSlugLengthUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
lengthStr := strings.TrimSpace(r.FormValue("slug_length"))
|
||||
length, err := strconv.Atoi(lengthStr)
|
||||
if err != nil || length < 3 || length > 16 {
|
||||
http.Redirect(w, r, "/admin/shortener?toast=Slug+length+must+be+between+3+and+16&toast_type=error", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
|
||||
// Update in-memory config
|
||||
s.cfg.Slugs.Length = length
|
||||
|
||||
// Persist to config.toml
|
||||
configPath := "config.toml"
|
||||
data, err := os.ReadFile(configPath)
|
||||
if err == nil {
|
||||
content := string(data)
|
||||
// Replace the length line in the [slugs] section
|
||||
re := regexp.MustCompile(`(?m)^(\s*length\s*=\s*)\d+`)
|
||||
content = re.ReplaceAllString(content, "${1}"+strconv.Itoa(length))
|
||||
_ = os.WriteFile(configPath, []byte(content), 0644)
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/admin/shortener?toast=Slug+length+updated+to+"+strconv.Itoa(length)+"+characters&toast_type=success", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
@@ -862,7 +1029,7 @@ func (s *Server) handleLinkDelete(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (s *Server) handlePrintLabels(w http.ResponseWriter, r *http.Request) {
|
||||
csrf := csrfToken(w, r)
|
||||
items, err := s.db.ListItems()
|
||||
items, err := s.db.ListItems(false)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to load labels", http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -112,25 +112,42 @@ func (s *Server) Start() error {
|
||||
mux.HandleFunc("POST /admin/items/new", s.requireAuth(s.requireCSRF(s.handleItemCreate)))
|
||||
mux.HandleFunc("GET /admin/items/edit/{id}", s.requireAuth(s.handleItemEdit))
|
||||
mux.HandleFunc("POST /admin/items/edit/{id}", s.requireAuth(s.requireCSRF(s.handleItemSave)))
|
||||
mux.HandleFunc("POST /admin/items/delete/{id}", s.requireAuth(s.requireCSRF(s.handleItemDelete)))
|
||||
mux.HandleFunc("POST /admin/items/delete/{id}", s.requireAuth(s.requireCSRF(s.handleItemRemove)))
|
||||
mux.HandleFunc("POST /admin/items/remove/{id}", s.requireAuth(s.requireCSRF(s.handleItemRemove)))
|
||||
mux.HandleFunc("POST /admin/items/archive/{id}", s.requireAuth(s.requireCSRF(s.handleItemArchive)))
|
||||
mux.HandleFunc("POST /admin/items/restore/{id}", s.requireAuth(s.requireCSRF(s.handleItemRestore)))
|
||||
mux.HandleFunc("POST /admin/items/permanent-delete/{id}", s.requireAuth(s.requireCSRF(s.handleItemPermanentDelete)))
|
||||
|
||||
// 7. Admin locations management
|
||||
mux.HandleFunc("GET /admin/locations", s.requireAuth(s.handleAdminLocations))
|
||||
mux.HandleFunc("POST /admin/locations/new", s.requireAuth(s.requireCSRF(s.handleLocationCreate)))
|
||||
mux.HandleFunc("POST /admin/locations/edit/{id}", s.requireAuth(s.requireCSRF(s.handleLocationEdit)))
|
||||
mux.HandleFunc("POST /admin/locations/delete/{id}", s.requireAuth(s.requireCSRF(s.handleLocationDelete)))
|
||||
mux.HandleFunc("POST /admin/locations/delete/{id}", s.requireAuth(s.requireCSRF(s.handleLocationRemove)))
|
||||
mux.HandleFunc("POST /admin/locations/remove/{id}", s.requireAuth(s.requireCSRF(s.handleLocationRemove)))
|
||||
mux.HandleFunc("POST /admin/locations/archive/{id}", s.requireAuth(s.requireCSRF(s.handleLocationArchive)))
|
||||
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)))
|
||||
|
||||
// 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)))
|
||||
mux.HandleFunc("POST /admin/tags/edit/{id}", s.requireAuth(s.requireCSRF(s.handleTagEdit)))
|
||||
mux.HandleFunc("POST /admin/tags/delete/{id}", s.requireAuth(s.requireCSRF(s.handleTagDelete)))
|
||||
mux.HandleFunc("POST /admin/tags/delete/{id}", s.requireAuth(s.requireCSRF(s.handleTagRemove)))
|
||||
mux.HandleFunc("POST /admin/tags/remove/{id}", s.requireAuth(s.requireCSRF(s.handleTagRemove)))
|
||||
mux.HandleFunc("POST /admin/tags/archive/{id}", s.requireAuth(s.requireCSRF(s.handleTagArchive)))
|
||||
mux.HandleFunc("POST /admin/tags/restore/{id}", s.requireAuth(s.requireCSRF(s.handleTagRestore)))
|
||||
mux.HandleFunc("POST /admin/tags/permanent-delete/{id}", s.requireAuth(s.requireCSRF(s.handleTagPermanentDelete)))
|
||||
|
||||
// 9. Admin custom shortlinks manager
|
||||
mux.HandleFunc("GET /admin/shortener", s.requireAuth(s.handleAdminShortener))
|
||||
mux.HandleFunc("POST /admin/shortener/new", s.requireAuth(s.requireCSRF(s.handleLinkCreate)))
|
||||
mux.HandleFunc("POST /admin/shortener/edit/{id}", s.requireAuth(s.requireCSRF(s.handleLinkSave)))
|
||||
mux.HandleFunc("POST /admin/shortener/delete/{id}", s.requireAuth(s.requireCSRF(s.handleLinkDelete)))
|
||||
mux.HandleFunc("POST /admin/shortener/delete/{id}", s.requireAuth(s.requireCSRF(s.handleLinkRemove)))
|
||||
mux.HandleFunc("POST /admin/shortener/remove/{id}", s.requireAuth(s.requireCSRF(s.handleLinkRemove)))
|
||||
mux.HandleFunc("POST /admin/shortener/archive/{id}", s.requireAuth(s.requireCSRF(s.handleLinkArchive)))
|
||||
mux.HandleFunc("POST /admin/shortener/restore/{id}", s.requireAuth(s.requireCSRF(s.handleLinkRestore)))
|
||||
mux.HandleFunc("POST /admin/shortener/permanent-delete/{id}", s.requireAuth(s.requireCSRF(s.handleLinkPermanentDelete)))
|
||||
mux.HandleFunc("POST /admin/shortener/slug-length", s.requireAuth(s.requireCSRF(s.handleSlugLengthUpdate)))
|
||||
|
||||
// 10. QR & Labels
|
||||
mux.HandleFunc("GET /admin/qr/{slug}", s.requireAuth(s.handleQR))
|
||||
|
||||
@@ -587,3 +587,106 @@ body {
|
||||
margin-top: 4px !important;
|
||||
}
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Solis Lifecycle Styles (Archive, Soft-Remove & Premium Dropdowns)
|
||||
========================================================================== */
|
||||
|
||||
/* Actions Dropdown Container */
|
||||
.actions-dropdown {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
/* Actions Menu Popup */
|
||||
.actions-dropdown-menu {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 100%;
|
||||
margin-top: 0.35rem;
|
||||
background-color: var(--color-bg-surface);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-sm);
|
||||
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
|
||||
z-index: 999;
|
||||
min-width: 160px;
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
padding: 0.35rem 0;
|
||||
animation: dropdownFadeIn 0.15s cubic-bezier(0.16, 1, 0.3, 1);
|
||||
}
|
||||
|
||||
@keyframes dropdownFadeIn {
|
||||
from { opacity: 0; transform: translateY(-4px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
|
||||
/* Toggle Menu Display */
|
||||
.actions-dropdown.show .actions-dropdown-menu {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
/* Menu Items (Forms & Buttons) */
|
||||
.actions-dropdown-item {
|
||||
background: none;
|
||||
border: none;
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
padding: 0.6rem 1rem;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 500;
|
||||
color: var(--color-text-main);
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
transition: background-color 0.15s ease, color 0.15s ease;
|
||||
text-decoration: none;
|
||||
font-family: var(--font-sans);
|
||||
}
|
||||
|
||||
.actions-dropdown-item:hover {
|
||||
background-color: var(--color-bg-base);
|
||||
color: var(--color-brand-primary);
|
||||
}
|
||||
|
||||
/* Muted / Red text variations for drop options */
|
||||
.actions-dropdown-item.text-danger {
|
||||
color: #b91c1c;
|
||||
}
|
||||
.actions-dropdown-item.text-danger:hover {
|
||||
background-color: #fee2e2;
|
||||
color: #991b1b;
|
||||
}
|
||||
|
||||
.actions-dropdown-item.text-warning {
|
||||
color: #b45309;
|
||||
}
|
||||
.actions-dropdown-item.text-warning:hover {
|
||||
background-color: #fef3c7;
|
||||
color: #92400e;
|
||||
}
|
||||
|
||||
/* Visual States for Soft Removed Elements */
|
||||
tr.lifecycle-removed {
|
||||
opacity: 0.65;
|
||||
background-color: var(--color-bg-base) !important;
|
||||
}
|
||||
|
||||
tr.lifecycle-removed td:not(.actions-cell) {
|
||||
text-decoration: line-through;
|
||||
color: var(--color-text-light);
|
||||
}
|
||||
|
||||
/* Visual States for Archived Elements */
|
||||
tr.lifecycle-archived {
|
||||
background-color: #fcfbfb;
|
||||
}
|
||||
|
||||
.status-pill.archived {
|
||||
background-color: var(--color-bg-base);
|
||||
color: var(--color-text-muted);
|
||||
border: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
@@ -96,3 +96,30 @@ function initRoomTagLock() {
|
||||
// Run immediately on page load to lock the default/current room tag
|
||||
updateRoomTag();
|
||||
}
|
||||
|
||||
// 4. Dropdown Action Menu Manager
|
||||
function toggleActionsDropdown(btn, event) {
|
||||
if (event) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
}
|
||||
const container = btn.parentElement;
|
||||
const isShown = container.classList.contains("show");
|
||||
|
||||
// Close any other open dropdowns first
|
||||
document.querySelectorAll(".actions-dropdown").forEach(d => {
|
||||
d.classList.remove("show");
|
||||
});
|
||||
|
||||
if (!isShown) {
|
||||
container.classList.add("show");
|
||||
}
|
||||
}
|
||||
|
||||
// Close dropdowns on outside click
|
||||
document.addEventListener("click", () => {
|
||||
document.querySelectorAll(".actions-dropdown").forEach(d => {
|
||||
d.classList.remove("show");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -100,5 +100,42 @@
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
<!-- QR Code Preview Modal -->
|
||||
<div id="qr-modal-overlay" style="display:none; position:fixed; inset:0; z-index:9999; background:rgba(0,0,0,0.55); backdrop-filter:blur(4px); justify-content:center; align-items:center;">
|
||||
<div id="qr-modal-card" style="background:var(--color-bg-surface, #fff); border-radius:16px; padding:2.5rem 2rem 2rem; max-width:380px; width:90%; box-shadow:0 24px 48px -12px rgba(0,0,0,0.25); display:flex; flex-direction:column; align-items:center; gap:1.25rem; position:relative; animation:qrModalIn 0.25s cubic-bezier(0.16,1,0.3,1);">
|
||||
<button onclick="closeQRModal()" style="position:absolute; top:0.75rem; right:0.75rem; background:none; border:none; font-size:1.5rem; cursor:pointer; color:var(--color-text-light); line-height:1;" aria-label="Close">×</button>
|
||||
<h3 style="font-weight:700; font-size:1.15rem; color:var(--color-text-main); margin:0;">QR Code Preview</h3>
|
||||
<img id="qr-modal-image" src="" alt="QR Code" style="width:220px; height:220px; border:1px solid var(--color-border); border-radius:8px; background:#fff; padding:8px;">
|
||||
<code id="qr-modal-link" style="font-family:monospace; background:var(--color-bg-base, #f5f5f5); padding:0.4rem 0.85rem; border-radius:6px; border:1px solid var(--color-border); font-weight:600; font-size:0.95rem; word-break:break-all; text-align:center;"></code>
|
||||
<a id="qr-modal-download" download="" href="" class="btn btn-primary" style="width:100%; font-size:0.9rem; text-align:center;">Download QR Image</a>
|
||||
</div>
|
||||
</div>
|
||||
<style>
|
||||
@keyframes qrModalIn {
|
||||
from { opacity:0; transform:scale(0.92) translateY(12px); }
|
||||
to { opacity:1; transform:scale(1) translateY(0); }
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
function openQRModal(slug, name) {
|
||||
var overlay = document.getElementById('qr-modal-overlay');
|
||||
document.getElementById('qr-modal-image').src = '/admin/qr/' + slug;
|
||||
document.getElementById('qr-modal-link').textContent = '/s/' + slug;
|
||||
var dl = document.getElementById('qr-modal-download');
|
||||
dl.href = '/admin/qr/' + slug;
|
||||
dl.download = (name || slug) + '_QR.png';
|
||||
overlay.style.display = 'flex';
|
||||
}
|
||||
function closeQRModal() {
|
||||
document.getElementById('qr-modal-overlay').style.display = 'none';
|
||||
}
|
||||
document.addEventListener('click', function(e) {
|
||||
if (e.target && e.target.id === 'qr-modal-overlay') closeQRModal();
|
||||
});
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Escape') closeQRModal();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -943,12 +943,18 @@
|
||||
{{end}}
|
||||
</select>
|
||||
|
||||
<label style="display: flex; align-items: center; gap: 0.35rem; font-size: 0.9rem; font-weight: 500; cursor: pointer; white-space: nowrap; margin: 0 0.5rem;">
|
||||
<input type="checkbox" name="show_removed" value="1" {{if .ShowRemoved}}checked{{end}} onchange="this.form.submit()">
|
||||
Show removed
|
||||
</label>
|
||||
|
||||
<button type="submit" class="btn btn-secondary">Filter</button>
|
||||
{{if or .SearchQuery (or .SelectedStatus .SelectedLocation)}}
|
||||
{{if or .SearchQuery (or .SelectedStatus (or .SelectedLocation .ShowRemoved))}}
|
||||
<a href="/admin" class="btn btn-secondary" style="padding: 0.625rem;">Reset</a>
|
||||
{{end}}
|
||||
</form>
|
||||
|
||||
|
||||
<!-- Assets Inventory Table -->
|
||||
<div class="card" style="padding: 0;">
|
||||
<div class="data-table-wrapper">
|
||||
@@ -967,11 +973,11 @@
|
||||
<tbody>
|
||||
{{if .Items}}
|
||||
{{range .Items}}
|
||||
<tr>
|
||||
<tr class="{{if eq .LifecycleState "removed"}}lifecycle-removed{{else if eq .LifecycleState "archived"}}lifecycle-archived{{end}}">
|
||||
<td style="text-align: center; vertical-align: middle;">
|
||||
{{if .ShortSlug}}
|
||||
<a href="/admin/qr/{{.ShortSlug}}" target="_blank">
|
||||
<img src="/admin/qr/{{.ShortSlug}}" alt="QR Label" style="width: 42px; height: 42px; border: 1px solid var(--color-border); padding: 1px; border-radius: 4px; background: white;">
|
||||
<a href="javascript:void(0)" onclick="openQRModal('{{.ShortSlug}}', '{{.Name}}')">
|
||||
<img src="/admin/qr/{{.ShortSlug}}" alt="QR Label" style="width: 42px; height: 42px; border: 1px solid var(--color-border); padding: 1px; border-radius: 4px; background: white; cursor: pointer;">
|
||||
</a>
|
||||
{{else}}
|
||||
<span style="color: var(--color-text-light); font-size: 0.75rem;">--</span>
|
||||
@@ -997,9 +1003,13 @@
|
||||
{{end}}
|
||||
</td>
|
||||
<td>
|
||||
<span class="status-pill {{if eq .Status "In Use"}}in-use{{else if eq .Status "In Storage"}}in-storage{{else if eq .Status "Borrowed"}}borrowed{{else if eq .Status "Lost"}}lost{{else}}disposed{{end}}">
|
||||
{{.Status}}
|
||||
</span>
|
||||
{{if eq .LifecycleState "archived"}}
|
||||
<span class="status-pill archived">Archived</span>
|
||||
{{else}}
|
||||
<span class="status-pill {{if eq .Status "In Use"}}in-use{{else if eq .Status "In Storage"}}in-storage{{else if eq .Status "Borrowed"}}borrowed{{else if eq .Status "Lost"}}lost{{else}}disposed{{end}}">
|
||||
{{.Status}}
|
||||
</span>
|
||||
{{end}}
|
||||
</td>
|
||||
<td style="font-weight: 600; font-size: 0.95rem; color: var(--color-text-muted); text-align: center;">
|
||||
{{.Quantity}}
|
||||
@@ -1011,20 +1021,56 @@
|
||||
{{end}}
|
||||
</div>
|
||||
</td>
|
||||
<td style="text-align: right;">
|
||||
<td class="actions-cell" style="text-align: right;">
|
||||
<div style="display: inline-flex; gap: 0.5rem; align-items: center;">
|
||||
<a href="/admin?view={{.ID}}" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
|
||||
Details
|
||||
</a>
|
||||
<a href="/admin/items/edit/{{.ID}}" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
|
||||
Edit
|
||||
</a>
|
||||
<form action="/admin/items/delete/{{.ID}}" method="POST" onsubmit="return confirm('Are you sure you want to delete this asset? This cannot be undone.')" style="margin: 0;">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<button type="submit" class="btn btn-danger" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
|
||||
Delete
|
||||
</button>
|
||||
</form>
|
||||
{{if eq .LifecycleState "removed"}}
|
||||
<!-- Soft removed item actions -->
|
||||
<form action="/admin/items/restore/{{.ID}}" method="POST" style="margin: 0;">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<button type="submit" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem; border-color: #10b981; color: #10b981;">
|
||||
Restore
|
||||
</button>
|
||||
</form>
|
||||
<form action="/admin/items/permanent-delete/{{.ID}}" method="POST" onsubmit="return confirm('Are you sure you want to permanently delete this asset? This will clean up all associated media files on disk and cannot be undone.')" style="margin: 0;">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<button type="submit" class="btn btn-danger" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
|
||||
Delete Forever
|
||||
</button>
|
||||
</form>
|
||||
{{else}}
|
||||
<!-- Active or Archived item actions -->
|
||||
<a href="/admin?view={{.ID}}" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
|
||||
Details
|
||||
</a>
|
||||
|
||||
{{if ne .LifecycleState "archived"}}
|
||||
<a href="/admin/items/edit/{{.ID}}" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
|
||||
Edit
|
||||
</a>
|
||||
{{end}}
|
||||
|
||||
<div class="actions-dropdown">
|
||||
<button class="btn btn-danger" onclick="toggleActionsDropdown(this, event)" style="padding: 0.35rem 0.65rem; font-size: 0.8rem; display: inline-flex; align-items: center; gap: 0.25rem;">
|
||||
Delete <span style="font-size: 0.65rem;">▼</span>
|
||||
</button>
|
||||
<div class="actions-dropdown-menu">
|
||||
<form action="/admin/items/remove/{{.ID}}" method="POST" style="margin: 0;">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<button type="submit" class="actions-dropdown-item text-danger">
|
||||
🗑 Remove Item
|
||||
</button>
|
||||
</form>
|
||||
{{if ne .LifecycleState "archived"}}
|
||||
<form action="/admin/items/archive/{{.ID}}" method="POST" style="margin: 0;">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<button type="submit" class="actions-dropdown-item text-warning">
|
||||
📦 Archive Item
|
||||
</button>
|
||||
</form>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -8,6 +8,17 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form action="/admin/locations" method="GET" class="filter-bar" style="margin-bottom: 1.5rem; justify-content: flex-end;">
|
||||
{{if .EditingLocation}}
|
||||
<input type="hidden" name="edit" value="{{.EditingLocation.ID}}">
|
||||
{{end}}
|
||||
<label style="display: flex; align-items: center; gap: 0.35rem; font-size: 0.9rem; font-weight: 500; cursor: pointer; white-space: nowrap;">
|
||||
<input type="checkbox" name="show_removed" value="1" {{if .ShowRemoved}}checked{{end}} onchange="this.form.submit()">
|
||||
Show removed locations
|
||||
</label>
|
||||
</form>
|
||||
|
||||
|
||||
<div class="detail-grid">
|
||||
<!-- Left Column: Locations List -->
|
||||
<div class="detail-main">
|
||||
@@ -25,8 +36,13 @@
|
||||
<tbody>
|
||||
{{if .Locations}}
|
||||
{{range .Locations}}
|
||||
<tr>
|
||||
<td style="font-weight: 600; color: var(--color-brand-primary);">{{.Name}}</td>
|
||||
<tr class="{{if eq .LifecycleState "removed"}}lifecycle-removed{{else if eq .LifecycleState "archived"}}lifecycle-archived{{end}}">
|
||||
<td style="font-weight: 600; color: var(--color-brand-primary);">
|
||||
{{.Name}}
|
||||
{{if eq .LifecycleState "archived"}}
|
||||
<span class="status-pill archived" style="margin-left: 0.5rem; font-size: 0.7rem; padding: 0.1rem 0.4rem;">Archived</span>
|
||||
{{end}}
|
||||
</td>
|
||||
<td>
|
||||
{{if .ParentName.Valid}}
|
||||
<span style="color: var(--color-text-muted); font-size: 0.9rem;">
|
||||
@@ -37,21 +53,53 @@
|
||||
{{end}}
|
||||
</td>
|
||||
<td style="color: var(--color-text-muted); font-size: 0.9rem;">{{.Description}}</td>
|
||||
<td style="text-align: right;">
|
||||
<div style="display: inline-flex; gap: 0.5rem;">
|
||||
<!-- Edit Location triggers loading edit state in the right-side form -->
|
||||
<a href="/admin/locations?edit={{.ID}}" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
|
||||
Edit
|
||||
</a>
|
||||
{{if ne .ID 1}}
|
||||
<form action="/admin/locations/delete/{{.ID}}" method="POST" onsubmit="return confirm('Are you sure you want to delete this location? Sub-locations and assets will be detached.')" style="margin: 0;">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<button type="submit" class="btn btn-danger" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
|
||||
Delete
|
||||
</button>
|
||||
</form>
|
||||
{{else}}
|
||||
<td class="actions-cell" style="text-align: right;">
|
||||
<div style="display: inline-flex; gap: 0.5rem; align-items: center;">
|
||||
{{if eq .ID 1}}
|
||||
<span style="color: var(--color-text-light); font-size: 0.8rem; font-style: italic; padding: 0.35rem 0.65rem;">Locked</span>
|
||||
{{else if eq .LifecycleState "removed"}}
|
||||
<!-- Soft removed actions -->
|
||||
<form action="/admin/locations/restore/{{.ID}}" method="POST" style="margin: 0;">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<button type="submit" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem; border-color: #10b981; color: #10b981;">
|
||||
Restore
|
||||
</button>
|
||||
</form>
|
||||
<form action="/admin/locations/permanent-delete/{{.ID}}" method="POST" onsubmit="return confirm('Are you sure you want to permanently delete this location? Associated sub-locations and assets will be detached.')" style="margin: 0;">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<button type="submit" class="btn btn-danger" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
|
||||
Delete Forever
|
||||
</button>
|
||||
</form>
|
||||
{{else}}
|
||||
<!-- Active / Archived actions -->
|
||||
{{if ne .LifecycleState "archived"}}
|
||||
<a href="/admin/locations?edit={{.ID}}&show_removed={{if $.ShowRemoved}}1{{else}}0{{end}}" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
|
||||
Edit
|
||||
</a>
|
||||
{{end}}
|
||||
|
||||
<div class="actions-dropdown">
|
||||
<button class="btn btn-danger" onclick="toggleActionsDropdown(this, event)" style="padding: 0.35rem 0.65rem; font-size: 0.8rem; display: inline-flex; align-items: center; gap: 0.25rem;">
|
||||
Delete <span style="font-size: 0.65rem;">▼</span>
|
||||
</button>
|
||||
<div class="actions-dropdown-menu">
|
||||
<form action="/admin/locations/remove/{{.ID}}" method="POST" style="margin: 0;">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<button type="submit" class="actions-dropdown-item text-danger">
|
||||
🗑 Remove
|
||||
</button>
|
||||
</form>
|
||||
{{if ne .LifecycleState "archived"}}
|
||||
<form action="/admin/locations/archive/{{.ID}}" method="POST" style="margin: 0;">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<button type="submit" class="actions-dropdown-item text-warning">
|
||||
📦 Archive
|
||||
</button>
|
||||
</form>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</td>
|
||||
|
||||
@@ -7,6 +7,15 @@
|
||||
<p>Manage custom manual redirects (e.g. warranties, external manuals) or review auto-generated asset short URLs.</p>
|
||||
</div>
|
||||
</div>
|
||||
<form action="/admin/shortener" method="GET" class="filter-bar" style="margin-bottom: 1.5rem; justify-content: flex-end;">
|
||||
{{if .EditingLink}}
|
||||
<input type="hidden" name="edit" value="{{.EditingLink.ID}}">
|
||||
{{end}}
|
||||
<label style="display: flex; align-items: center; gap: 0.35rem; font-size: 0.9rem; font-weight: 500; cursor: pointer; white-space: nowrap;">
|
||||
<input type="checkbox" name="show_removed" value="1" {{if .ShowRemoved}}checked{{end}} onchange="this.form.submit()">
|
||||
Show removed links
|
||||
</label>
|
||||
</form>
|
||||
|
||||
<div class="detail-grid">
|
||||
<!-- Left Column: Links List -->
|
||||
@@ -26,14 +35,19 @@
|
||||
<tbody>
|
||||
{{if .Links}}
|
||||
{{range .Links}}
|
||||
<tr>
|
||||
<tr class="{{if eq .LifecycleState "removed"}}lifecycle-removed{{else if eq .LifecycleState "archived"}}lifecycle-archived{{end}}">
|
||||
<td>
|
||||
<div style="display: flex; flex-direction: column; gap: 0.15rem;">
|
||||
<a href="/s/{{.Slug}}" target="_blank" style="font-weight: 700; color: var(--color-brand-primary); text-decoration: none;">
|
||||
/s/{{.Slug}}
|
||||
</a>
|
||||
<div style="display: flex; align-items: center; gap: 0.35rem;">
|
||||
<a href="/s/{{.Slug}}" target="_blank" style="font-weight: 700; color: var(--color-brand-primary); text-decoration: none;">
|
||||
/s/{{.Slug}}
|
||||
</a>
|
||||
{{if eq .LifecycleState "archived"}}
|
||||
<span class="status-pill archived" style="font-size: 0.7rem; padding: 0.1rem 0.4rem;">Archived</span>
|
||||
{{end}}
|
||||
</div>
|
||||
<!-- QR code link quick view in printer sheet -->
|
||||
<a href="/admin/qr/{{.Slug}}" target="_blank" style="font-size: 0.75rem; color: var(--color-text-light); text-decoration: underline;">
|
||||
<a href="javascript:void(0)" onclick="openQRModal('{{.Slug}}', '{{.Slug}}')" style="font-size: 0.75rem; color: var(--color-text-light); text-decoration: underline; cursor: pointer;">
|
||||
View QR Code
|
||||
</a>
|
||||
</div>
|
||||
@@ -57,21 +71,56 @@
|
||||
<td style="text-align: center; font-weight: 600; font-size: 0.95rem; color: var(--color-text-muted);">
|
||||
{{.Clicks}}
|
||||
</td>
|
||||
<td style="text-align: right;">
|
||||
<td class="actions-cell" style="text-align: right;">
|
||||
{{if .ItemID.Valid}}
|
||||
<!-- Asset link modifications are handled through items CRUD -->
|
||||
<span style="color: var(--color-text-light); font-size: 0.85rem; font-style: italic;">Managed by Asset</span>
|
||||
{{else}}
|
||||
<div style="display: inline-flex; gap: 0.5rem;">
|
||||
<a href="/admin/shortener?edit={{.ID}}" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
|
||||
Edit
|
||||
</a>
|
||||
<form action="/admin/shortener/delete/{{.ID}}" method="POST" onsubmit="return confirm('Are you sure you want to delete this custom redirect?')" style="margin: 0;">
|
||||
{{else if eq .LifecycleState "removed"}}
|
||||
<!-- Soft removed manual redirects -->
|
||||
<div style="display: inline-flex; gap: 0.5rem; align-items: center;">
|
||||
<form action="/admin/shortener/restore/{{.ID}}" method="POST" style="margin: 0;">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<button type="submit" class="btn btn-danger" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
|
||||
Delete
|
||||
<button type="submit" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem; border-color: #10b981; color: #10b981;">
|
||||
Restore
|
||||
</button>
|
||||
</form>
|
||||
<form action="/admin/shortener/permanent-delete/{{.ID}}" method="POST" onsubmit="return confirm('Are you sure you want to permanently delete this redirect? This action cannot be undone.')" style="margin: 0;">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<button type="submit" class="btn btn-danger" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
|
||||
Delete Forever
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
{{else}}
|
||||
<!-- Active / Archived manual redirects -->
|
||||
<div style="display: inline-flex; gap: 0.5rem; align-items: center;">
|
||||
{{if ne .LifecycleState "archived"}}
|
||||
<a href="/admin/shortener?edit={{.ID}}&show_removed={{if $.ShowRemoved}}1{{else}}0{{end}}" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
|
||||
Edit
|
||||
</a>
|
||||
{{end}}
|
||||
|
||||
<div class="actions-dropdown">
|
||||
<button class="btn btn-danger" onclick="toggleActionsDropdown(this, event)" style="padding: 0.35rem 0.65rem; font-size: 0.8rem; display: inline-flex; align-items: center; gap: 0.25rem;">
|
||||
Delete <span style="font-size: 0.65rem;">▼</span>
|
||||
</button>
|
||||
<div class="actions-dropdown-menu">
|
||||
<form action="/admin/shortener/remove/{{.ID}}" method="POST" style="margin: 0;">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<button type="submit" class="actions-dropdown-item text-danger">
|
||||
🗑 Remove
|
||||
</button>
|
||||
</form>
|
||||
{{if ne .LifecycleState "archived"}}
|
||||
<form action="/admin/shortener/archive/{{.ID}}" method="POST" style="margin: 0;">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<button type="submit" class="actions-dropdown-item text-warning">
|
||||
📦 Archive
|
||||
</button>
|
||||
</form>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
</td>
|
||||
@@ -138,6 +187,20 @@
|
||||
</form>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
<!-- Slug Length Settings -->
|
||||
<div class="card" style="margin-top: 1rem;">
|
||||
<h3 style="font-weight: 700; margin-bottom: 0.5rem; font-size: 1rem;">URL Slug Length</h3>
|
||||
<p style="font-size: 0.8rem; color: var(--color-text-light); margin-bottom: 1rem;">Controls the character length of auto-generated short URL slugs. Shorter slugs make smaller QR codes. Changes apply to newly created assets only.</p>
|
||||
<form action="/admin/shortener/slug-length" method="POST">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<div style="display: flex; gap: 0.5rem; align-items: center;">
|
||||
<input type="number" name="slug_length" class="form-control" value="{{.SlugLength}}" min="3" max="16" style="width: 80px; text-align: center; font-weight: 700; font-size: 1.1rem;">
|
||||
<span style="font-size: 0.85rem; color: var(--color-text-muted);">characters</span>
|
||||
<button type="submit" class="btn btn-primary" style="margin-left: auto; padding: 0.5rem 1rem; font-size: 0.85rem;">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
@@ -7,6 +7,15 @@
|
||||
<p>Label and categorize assets to easily group similar items together (e.g. Tools, Electronics, Fragile)</p>
|
||||
</div>
|
||||
</div>
|
||||
<form action="/admin/tags" method="GET" class="filter-bar" style="margin-bottom: 1.5rem; justify-content: flex-end;">
|
||||
{{if .EditingTag}}
|
||||
<input type="hidden" name="edit" value="{{.EditingTag.ID}}">
|
||||
{{end}}
|
||||
<label style="display: flex; align-items: center; gap: 0.35rem; font-size: 0.9rem; font-weight: 500; cursor: pointer; white-space: nowrap;">
|
||||
<input type="checkbox" name="show_removed" value="1" {{if .ShowRemoved}}checked{{end}} onchange="this.form.submit()">
|
||||
Show removed tags
|
||||
</label>
|
||||
</form>
|
||||
|
||||
<div class="detail-grid">
|
||||
<!-- Left Column: Tags List -->
|
||||
@@ -25,11 +34,14 @@
|
||||
<tbody>
|
||||
{{if .Tags}}
|
||||
{{range .Tags}}
|
||||
<tr>
|
||||
<tr class="{{if eq .LifecycleState "removed"}}lifecycle-removed{{else if eq .LifecycleState "archived"}}lifecycle-archived{{end}}">
|
||||
<td>
|
||||
<span class="tag-pill" style="background-color: {{.Color}}; color: #1c1917; padding: 0.35rem 0.75rem; font-size: 0.85rem;">
|
||||
{{.Name}}
|
||||
</span>
|
||||
{{if eq .LifecycleState "archived"}}
|
||||
<span class="status-pill archived" style="margin-left: 0.5rem; font-size: 0.7rem; padding: 0.1rem 0.4rem;">Archived</span>
|
||||
{{end}}
|
||||
</td>
|
||||
<td>
|
||||
<code style="font-family: monospace; font-size: 0.9rem; background-color: var(--color-bg-base); padding: 0.15rem 0.35rem; border-radius: 4px; border: 1px solid var(--color-border);">
|
||||
@@ -37,20 +49,53 @@
|
||||
</code>
|
||||
</td>
|
||||
<td style="color: var(--color-text-muted); font-size: 0.9rem;">{{.Description}}</td>
|
||||
<td style="text-align: right;">
|
||||
<div style="display: inline-flex; gap: 0.5rem;">
|
||||
<a href="/admin/tags?edit={{.ID}}" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
|
||||
Edit
|
||||
</a>
|
||||
{{if ne .Name "Default Room"}}
|
||||
<form action="/admin/tags/delete/{{.ID}}" method="POST" onsubmit="return confirm('Are you sure you want to delete this tag? All associated items will lose this tag reference.')" style="margin: 0;">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<button type="submit" class="btn btn-danger" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
|
||||
Delete
|
||||
</button>
|
||||
</form>
|
||||
{{else}}
|
||||
<td class="actions-cell" style="text-align: right;">
|
||||
<div style="display: inline-flex; gap: 0.5rem; align-items: center;">
|
||||
{{if eq .Name "Default Room"}}
|
||||
<span style="color: var(--color-text-light); font-size: 0.8rem; font-style: italic; padding: 0.35rem 0.65rem;">Locked</span>
|
||||
{{else if eq .LifecycleState "removed"}}
|
||||
<!-- Soft removed actions -->
|
||||
<form action="/admin/tags/restore/{{.ID}}" method="POST" style="margin: 0;">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<button type="submit" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem; border-color: #10b981; color: #10b981;">
|
||||
Restore
|
||||
</button>
|
||||
</form>
|
||||
<form action="/admin/tags/permanent-delete/{{.ID}}" method="POST" onsubmit="return confirm('Are you sure you want to permanently delete this tag? All associated items will lose this tag reference.')" style="margin: 0;">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<button type="submit" class="btn btn-danger" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
|
||||
Delete Forever
|
||||
</button>
|
||||
</form>
|
||||
{{else}}
|
||||
<!-- Active / Archived actions -->
|
||||
{{if ne .LifecycleState "archived"}}
|
||||
<a href="/admin/tags?edit={{.ID}}&show_removed={{if $.ShowRemoved}}1{{else}}0{{end}}" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
|
||||
Edit
|
||||
</a>
|
||||
{{end}}
|
||||
|
||||
<div class="actions-dropdown">
|
||||
<button class="btn btn-danger" onclick="toggleActionsDropdown(this, event)" style="padding: 0.35rem 0.65rem; font-size: 0.8rem; display: inline-flex; align-items: center; gap: 0.25rem;">
|
||||
Delete <span style="font-size: 0.65rem;">▼</span>
|
||||
</button>
|
||||
<div class="actions-dropdown-menu">
|
||||
<form action="/admin/tags/remove/{{.ID}}" method="POST" style="margin: 0;">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<button type="submit" class="actions-dropdown-item text-danger">
|
||||
🗑 Remove
|
||||
</button>
|
||||
</form>
|
||||
{{if ne .LifecycleState "archived"}}
|
||||
<form action="/admin/tags/archive/{{.ID}}" method="POST" style="margin: 0;">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<button type="submit" class="actions-dropdown-item text-warning">
|
||||
📦 Archive
|
||||
</button>
|
||||
</form>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</td>
|
||||
|
||||
+23
-19
@@ -5,24 +5,26 @@ PRAGMA foreign_keys = ON;
|
||||
|
||||
-- 1. Locations Table (Supports hierarchical locations via parent_id)
|
||||
CREATE TABLE IF NOT EXISTS locations (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT NOT NULL DEFAULT '',
|
||||
parent_id INTEGER REFERENCES locations(id) ON DELETE SET NULL,
|
||||
image_path TEXT NOT NULL DEFAULT '',
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT NOT NULL DEFAULT '',
|
||||
parent_id INTEGER REFERENCES locations(id) ON DELETE SET NULL,
|
||||
image_path TEXT NOT NULL DEFAULT '',
|
||||
lifecycle_state TEXT NOT NULL DEFAULT 'active',
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_locations_parent ON locations(parent_id);
|
||||
|
||||
-- 2. Tags Table (Sleek labels for grouping items)
|
||||
CREATE TABLE IF NOT EXISTS tags (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
color TEXT NOT NULL DEFAULT '#e2e8f0', -- Hex code for pill color
|
||||
description TEXT NOT NULL DEFAULT '',
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
color TEXT NOT NULL DEFAULT '#e2e8f0', -- Hex code for pill color
|
||||
description TEXT NOT NULL DEFAULT '',
|
||||
lifecycle_state TEXT NOT NULL DEFAULT 'active',
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
);
|
||||
|
||||
-- 3. Items Table (Asset entries with purchase records and JSON custom fields)
|
||||
@@ -42,6 +44,7 @@ CREATE TABLE IF NOT EXISTS items (
|
||||
custom_fields TEXT NOT NULL DEFAULT '{}', -- JSON text field containing arbitrary key-value custom metadata
|
||||
image_path TEXT NOT NULL DEFAULT '',
|
||||
receipt_path TEXT NOT NULL DEFAULT '',
|
||||
lifecycle_state TEXT NOT NULL DEFAULT 'active',
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
);
|
||||
@@ -57,13 +60,14 @@ CREATE TABLE IF NOT EXISTS item_tags (
|
||||
|
||||
-- 5. Links Table (Ported and enhanced from Glimmer)
|
||||
CREATE TABLE IF NOT EXISTS links (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
slug TEXT NOT NULL UNIQUE,
|
||||
url TEXT NOT NULL, -- Redirect target (internal, e.g., '/items/12', or external)
|
||||
item_id INTEGER REFERENCES items(id) ON DELETE CASCADE, -- Nullable; links specific assets to short URLs
|
||||
created_by TEXT NOT NULL DEFAULT 'admin',
|
||||
clicks INTEGER NOT NULL DEFAULT 0,
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
slug TEXT NOT NULL UNIQUE,
|
||||
url TEXT NOT NULL, -- Redirect target (internal, e.g., '/items/12', or external)
|
||||
item_id INTEGER REFERENCES items(id) ON DELETE CASCADE, -- Nullable; links specific assets to short URLs
|
||||
created_by TEXT NOT NULL DEFAULT 'admin',
|
||||
clicks INTEGER NOT NULL DEFAULT 0,
|
||||
lifecycle_state TEXT NOT NULL DEFAULT 'active',
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_links_slug ON links(slug);
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"os"
|
||||
|
||||
"Solis/internal/config"
|
||||
"Solis/internal/db"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 1. Load catalog
|
||||
cat, err := config.LoadCatalog("../catalog.json")
|
||||
if err != nil {
|
||||
fmt.Printf("Error loading catalog: %v\n", err)
|
||||
return
|
||||
}
|
||||
catalogJSON, _ := json.Marshal(cat)
|
||||
|
||||
// 2. Define PageData struct matching internal/server/handlers.go
|
||||
type PageData struct {
|
||||
CSRFToken string
|
||||
ActiveNav string
|
||||
Toast string
|
||||
ToastType string
|
||||
Error string
|
||||
Items []db.Item
|
||||
Item *db.Item
|
||||
Locations []db.Location
|
||||
Tags []db.Tag
|
||||
Links []db.Link
|
||||
EditingLocation *db.Location
|
||||
EditingTag *db.Tag
|
||||
EditingLink *db.Link
|
||||
EditingItem *db.Item
|
||||
FormMode bool
|
||||
ViewMode bool
|
||||
CustomFieldsRaw string
|
||||
CustomFieldsMap map[string]string
|
||||
SearchQuery string
|
||||
SelectedStatus string
|
||||
SelectedLocation int64
|
||||
CatalogJSON string
|
||||
}
|
||||
|
||||
data := PageData{
|
||||
FormMode: true,
|
||||
CatalogJSON: string(catalogJSON),
|
||||
}
|
||||
|
||||
// 3. Define the template functions matching internal/server/templates.go
|
||||
templateFuncs := template.FuncMap{
|
||||
"safeJS": func(s string) template.JS {
|
||||
return template.JS(s)
|
||||
},
|
||||
"formatPrice": func(p any) string {
|
||||
return ""
|
||||
},
|
||||
"formatDate": func(d any) string {
|
||||
return ""
|
||||
},
|
||||
"dict": func(values ...interface{}) (map[string]interface{}, error) {
|
||||
return nil, nil
|
||||
},
|
||||
"hasTag": func(itemTags []db.Tag, tagID int64) bool {
|
||||
return false
|
||||
},
|
||||
}
|
||||
|
||||
// 4. Parse templates
|
||||
t, err := template.New("base.html").Funcs(templateFuncs).ParseFiles(
|
||||
"../internal/server/templates/base.html",
|
||||
"../internal/server/templates/items.html",
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Printf("Error parsing templates: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 5. Render template
|
||||
out, err := os.Create("rendered.html")
|
||||
if err != nil {
|
||||
fmt.Printf("Error creating output file: %v\n", err)
|
||||
return
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
err = t.Execute(out, data)
|
||||
if err != nil {
|
||||
fmt.Printf("Error executing template: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Render completed successfully!")
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"os"
|
||||
|
||||
"Solis/internal/config"
|
||||
"Solis/internal/db"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 1. Load catalog
|
||||
cat, err := config.LoadCatalog("../catalog.json")
|
||||
if err != nil {
|
||||
fmt.Printf("Error loading catalog: %v\n", err)
|
||||
return
|
||||
}
|
||||
catalogJSON, _ := json.Marshal(cat)
|
||||
|
||||
// 2. Define PageData struct matching internal/server/handlers.go
|
||||
type PageData struct {
|
||||
CSRFToken string
|
||||
ActiveNav string
|
||||
Toast string
|
||||
ToastType string
|
||||
Error string
|
||||
Items []db.Item
|
||||
Item *db.Item
|
||||
Locations []db.Location
|
||||
Tags []db.Tag
|
||||
Links []db.Link
|
||||
EditingLocation *db.Location
|
||||
EditingTag *db.Tag
|
||||
EditingLink *db.Link
|
||||
EditingItem *db.Item
|
||||
FormMode bool
|
||||
ViewMode bool
|
||||
CustomFieldsRaw string
|
||||
CustomFieldsMap map[string]string
|
||||
SearchQuery string
|
||||
SelectedStatus string
|
||||
SelectedLocation int64
|
||||
CatalogJSON string
|
||||
}
|
||||
|
||||
data := PageData{
|
||||
FormMode: true,
|
||||
CatalogJSON: string(catalogJSON),
|
||||
}
|
||||
|
||||
// 3. Define the template functions matching internal/server/templates.go
|
||||
templateFuncs := template.FuncMap{
|
||||
"safeJS": func(s string) template.JS {
|
||||
return template.JS(s)
|
||||
},
|
||||
"formatPrice": func(p any) string {
|
||||
return ""
|
||||
},
|
||||
"formatDate": func(d any) string {
|
||||
return ""
|
||||
},
|
||||
"dict": func(values ...interface{}) (map[string]interface{}, error) {
|
||||
return nil, nil
|
||||
},
|
||||
"hasTag": func(itemTags []db.Tag, tagID int64) bool {
|
||||
return false
|
||||
},
|
||||
}
|
||||
|
||||
// 4. Parse templates
|
||||
t, err := template.New("base.html").Funcs(templateFuncs).ParseFiles(
|
||||
"../internal/server/templates/base.html",
|
||||
"../internal/server/templates/items.html",
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Printf("Error parsing templates: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 5. Render template
|
||||
out, err := os.Create("rendered.html")
|
||||
if err != nil {
|
||||
fmt.Printf("Error creating output file: %v\n", err)
|
||||
return
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
err = t.Execute(out, data)
|
||||
if err != nil {
|
||||
fmt.Printf("Error executing template: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Render completed successfully!")
|
||||
}
|
||||
@@ -0,0 +1,663 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Solis | Assets</title>
|
||||
|
||||
|
||||
<meta name="csrf-token" content="">
|
||||
|
||||
|
||||
<link rel="stylesheet" href="/static/css/styles.css">
|
||||
|
||||
|
||||
<script src="/static/js/htmx.min.js"></script>
|
||||
<script src="/static/js/main.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="app-container">
|
||||
|
||||
<aside class="sidebar">
|
||||
<div class="brand">
|
||||
<div class="brand-logo">S</div>
|
||||
<span class="brand-name">Solis</span>
|
||||
</div>
|
||||
|
||||
<nav class="sidebar-nav">
|
||||
<ul class="nav-list">
|
||||
<li class="nav-item ">
|
||||
<a href="/admin" class="nav-link">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M20.25 7.5l-.625 10.632a2.25 2.25 0 01-2.247 2.118H6.622a2.25 2.25 0 01-2.247-2.118L3.75 7.5M10 11.25h4M3.375 7.5h17.25c.621 0 1.125-.504 1.125-1.125v-1.5c0-.621-.504-1.125-1.125-1.125H3.375c-.621 0-1.125.504-1.125 1.125v1.5c0 .621.504 1.125 1.125 1.125z" />
|
||||
</svg>
|
||||
Assets
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item ">
|
||||
<a href="/admin/locations" class="nav-link">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M15 10.5a3 3 0 11-6 0 3 3 0 016 0z" />
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M19.5 10.5c0 7.142-7.5 11.25-7.5 11.25s-7.5-4.108-7.5-11.25g3 3 0 1115 0z" />
|
||||
</svg>
|
||||
Locations
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item ">
|
||||
<a href="/admin/tags" class="nav-link">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M9.568 3H5.25A2.25 2.25 0 003 5.25v4.318c0 .597.237 1.17.659 1.591l9.581 9.581a1.125 1.125 0 001.591 0l4.318-4.318a1.125 1.125 0 000-1.591l-9.581-9.581A2.25 2.25 0 009.568 3z" />
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M6 6h.008v.008H6V6z" />
|
||||
</svg>
|
||||
Tags
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item ">
|
||||
<a href="/admin/shortener" class="nav-link">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M13.19 8.688a4.5 4.5 0 011.242 7.244l-4.5 4.5a4.5 4.5 0 01-6.364-6.364l1.757-1.757m13.35-.622l1.757-1.757a4.5 4.5 0 00-6.364-6.364l-4.5 4.5a4.5 4.5 0 001.242 7.244" />
|
||||
</svg>
|
||||
Shortlinks
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item ">
|
||||
<a href="/admin/print" class="nav-link">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M6.72 13.829c-.24.03-.48.062-.72.096m.72-.096a42.415 42.415 0 0110.56 0m-10.56 0L6.34 18m10.94-4.171c.24.03.48.062.72.096m-.72-.096L17.66 18m0 0a2.25 2.25 0 01-2.247 2.118H8.587A2.25 2.25 0 016.34 18m11.32 0h.008v.008h-.008V18zm-12 0h.008v.008H5.66V18zm0-11.25h12.75c.621 0 1.125.504 1.125 1.125v1.5c0 .621-.504 1.125-1.125 1.125H5.66c-.621 0-1.125-.504-1.125-1.125v-1.5c0-.621.504-1.125 1.125-1.125z" />
|
||||
</svg>
|
||||
Print Labels
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="sidebar-footer">
|
||||
<form action="/admin/logout" method="POST">
|
||||
<input type="hidden" name="csrf_token" value="">
|
||||
<button type="submit" class="btn btn-secondary" style="width: 100%;">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width:16px;height:16px;margin-right:4px;">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 9V5.25A2.25 2.25 0 0013.5 3h-6a2.25 2.25 0 00-2.25 2.25v13.5A2.25 2.25 0 007.5 21h6a2.25 2.25 0 002.25-2.25V15M12 9l-3 3m0 0l3 3m-3-3h12.75" />
|
||||
</svg>
|
||||
Sign Out
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
|
||||
<main class="main-wrapper">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="page-header">
|
||||
<div class="page-title">
|
||||
<h1>Add New Asset</h1>
|
||||
<p>Catalog any device, appliance, or item in seconds using our intuitive selection wizard.</p>
|
||||
</div>
|
||||
<div>
|
||||
<a href="/admin" class="btn btn-secondary">Cancel</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="wizard-progress-bar">
|
||||
<div class="wizard-step active" id="progress-step-1">
|
||||
<span class="step-num">1</span>
|
||||
<span class="step-label">Category</span>
|
||||
</div>
|
||||
<div class="wizard-line" id="progress-line-1"></div>
|
||||
<div class="wizard-step" id="progress-step-2">
|
||||
<span class="step-num">2</span>
|
||||
<span class="step-label">Item</span>
|
||||
</div>
|
||||
<div class="wizard-line" id="progress-line-2"></div>
|
||||
<div class="wizard-step" id="progress-step-3">
|
||||
<span class="step-num">3</span>
|
||||
<span class="step-label">Brand</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="card" style="padding: 2.25rem;">
|
||||
|
||||
<form id="wizard-form" action="/admin/items/new" method="POST">
|
||||
<input type="hidden" name="csrf_token" value="">
|
||||
<input type="hidden" name="wizard_flow" value="true">
|
||||
<input type="hidden" id="input-category" name="category" value="">
|
||||
<input type="hidden" id="input-item" name="item" value="">
|
||||
<input type="hidden" id="input-brand" name="brand" value="">
|
||||
</form>
|
||||
|
||||
|
||||
<div style="margin-bottom: 2rem; display: none;" id="wizard-back-wrapper">
|
||||
<button type="button" class="btn btn-secondary" id="btn-wizard-back" style="padding: 0.5rem 1rem; font-size: 0.85rem; border-radius: var(--radius-sm);">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2.5" stroke="currentColor" style="width: 14px; height: 14px;">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 19.5L8.25 12l7.5-7.5" />
|
||||
</svg>
|
||||
Back to previous step
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="wizard-screen active" id="screen-category">
|
||||
<h3 class="wizard-screen-title">Which category of item do you want to add?</h3>
|
||||
<div class="category-grid" id="category-grid-container">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="wizard-screen" id="screen-item">
|
||||
<h3 class="wizard-screen-title" id="item-screen-heading">What kind of item is it?</h3>
|
||||
<div class="pills-grid" id="item-grid-container">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="wizard-screen" id="screen-brand">
|
||||
<h3 class="wizard-screen-title" id="brand-screen-heading">What brand is the item?</h3>
|
||||
<div class="pills-grid" id="brand-grid-container">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<style>
|
||||
.wizard-progress-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 2.5rem;
|
||||
max-width: 600px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.wizard-step {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
position: relative;
|
||||
z-index: 10;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.wizard-step .step-num {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 50%;
|
||||
background-color: var(--color-bg-base);
|
||||
border: 2px solid var(--color-border);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 700;
|
||||
color: var(--color-text-light);
|
||||
font-size: 0.95rem;
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.wizard-step .step-label {
|
||||
font-size: 0.85rem;
|
||||
font-weight: 600;
|
||||
color: var(--color-text-light);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.wizard-step.active .step-num {
|
||||
background-color: var(--color-brand-primary);
|
||||
border-color: var(--color-brand-primary);
|
||||
color: white;
|
||||
box-shadow: 0 4px 10px rgba(217, 119, 6, 0.3);
|
||||
}
|
||||
|
||||
.wizard-step.active .step-label {
|
||||
color: var(--color-brand-primary);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.wizard-step.completed .step-num {
|
||||
background-color: #10b981;
|
||||
border-color: #10b981;
|
||||
color: white;
|
||||
box-shadow: 0 4px 10px rgba(16, 185, 129, 0.2);
|
||||
}
|
||||
|
||||
.wizard-step.completed .step-label {
|
||||
color: #10b981;
|
||||
}
|
||||
|
||||
.wizard-line {
|
||||
flex-grow: 1;
|
||||
height: 3px;
|
||||
background-color: var(--color-border);
|
||||
margin: 0 -0.5rem;
|
||||
transform: translateY(-13px);
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
.wizard-line.completed {
|
||||
background-color: #10b981;
|
||||
}
|
||||
|
||||
.wizard-line.active {
|
||||
background-color: var(--color-brand-primary);
|
||||
}
|
||||
|
||||
.wizard-screen {
|
||||
display: none;
|
||||
animation: wizardFadeIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
|
||||
}
|
||||
|
||||
.wizard-screen.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
@keyframes wizardFadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(8px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.wizard-screen-title {
|
||||
font-size: 1.35rem;
|
||||
font-weight: 700;
|
||||
margin-bottom: 2rem;
|
||||
color: var(--color-text-main);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
|
||||
.category-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
|
||||
gap: 1.25rem;
|
||||
}
|
||||
|
||||
.category-card {
|
||||
aspect-ratio: 1/1;
|
||||
background-color: var(--color-bg-surface);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 1.5rem 1rem;
|
||||
cursor: pointer;
|
||||
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
box-shadow: var(--shadow-sm);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.category-card:hover {
|
||||
transform: translateY(-4px);
|
||||
box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.08);
|
||||
border-color: var(--cat-color);
|
||||
background-color: var(--cat-color-bg);
|
||||
}
|
||||
|
||||
.category-badge {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 12px;
|
||||
background-color: var(--cat-color-badge-bg);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 1.4rem;
|
||||
font-weight: 700;
|
||||
color: var(--cat-color);
|
||||
margin-bottom: 1rem;
|
||||
transition: transform 0.2s ease;
|
||||
}
|
||||
|
||||
.category-card:hover .category-badge {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.category-name {
|
||||
font-size: 0.95rem;
|
||||
font-weight: 600;
|
||||
color: var(--color-text-main);
|
||||
}
|
||||
|
||||
|
||||
.pills-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.pill-button {
|
||||
background-color: var(--color-bg-surface);
|
||||
border: 1.5px solid var(--color-border);
|
||||
border-radius: var(--radius-sm);
|
||||
padding: 1rem 1.25rem;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: var(--color-text-main);
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
|
||||
.pill-button:hover {
|
||||
border-color: var(--color-brand-primary);
|
||||
background-color: #fefaf0;
|
||||
color: var(--color-brand-primary);
|
||||
transform: translateX(2px);
|
||||
}
|
||||
|
||||
.pill-button svg {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
color: var(--color-text-light);
|
||||
transition: transform 0.2s ease, color 0.2s ease;
|
||||
}
|
||||
|
||||
.pill-button:hover svg {
|
||||
transform: translateX(3px);
|
||||
color: var(--color-brand-primary);
|
||||
}
|
||||
|
||||
.pill-button.other-pill {
|
||||
border-style: dashed;
|
||||
border-width: 2px;
|
||||
background-color: var(--color-bg-base);
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.pill-button.other-pill:hover {
|
||||
border-color: var(--color-text-muted);
|
||||
background-color: var(--color-border);
|
||||
color: var(--color-text-main);
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
|
||||
const catalog = [{"id":"tech","name":"Tech \u0026 Electronics","color":"#3b82f6","items":[{"name":"Smartphones","brands":["Apple","Samsung","Google","OnePlus","Xiaomi","Sony","Motorola","Oppo"]},{"name":"Laptops","brands":["Dell","HP","Lenovo","Apple","ASUS","Acer","Microsoft","MSI"]},{"name":"Tablets","brands":["Apple","Samsung","Lenovo","Microsoft","Amazon","Huawei","Xiaomi","OnePlus"]},{"name":"Smartwatches","brands":["Apple","Samsung","Garmin","Fitbit","Fossil","Amazfit","Huawei","Google"]},{"name":"Desktop Computers","brands":["Dell","HP","Lenovo","Apple","ASUS","Acer","Corsair","CyberPowerPC"]},{"name":"Computer Monitors","brands":["Dell","LG","Samsung","ASUS","Acer","BenQ","HP","MSI"]},{"name":"Keyboards","brands":["Logitech","SteelSeries","Razer","Corsair","Keychron","Ducky","HyperX","Redragon"]},{"name":"Computer Mice","brands":["Logitech","Razer","Corsair","SteelSeries","HyperX","Glorious","ASUS","Roccat"]}]},{"id":"kitchen","name":"Kitchen Appliances","color":"#ec4899","items":[{"name":"Coffee Makers","brands":["Keurig","Nespresso","Breville","De'Longhi","Cuisinart","Mr. Coffee","Philips","Krups"]},{"name":"Blenders","brands":["Vitamix","Ninja","Blendtec","KitchenAid","NutriBullet","Oster","Breville","Cuisinart"]},{"name":"Toasters","brands":["Breville","Cuisinart","KitchenAid","Black+Decker","Hamilton Beach","SMEG","Zojirushi","Oster"]},{"name":"Microwaves","brands":["Panasonic","Toshiba","Samsung","LG","GE","Sharp","Whirlpool","Farberware"]},{"name":"Air Fryers","brands":["Ninja","Instant Pot","Cosori","Philips","Chefman","Tefal","Breville","GoWISE"]},{"name":"Food Processors","brands":["Cuisinart","Breville","KitchenAid","Ninja","Hamilton Beach","Braun","Magimix","Kenwood"]},{"name":"Juicers","brands":["Breville","Omega","Hurom","Hamilton Beach","Cuisinart","Nama","Tribest","Mueller"]},{"name":"Rice Cookers","brands":["Zojirushi","Tiger","Instant Pot","Cuckoo","Hamilton Beach","Aroma","Panasonic","Toshiba"]}]},{"id":"furniture","name":"Furniture","color":"#8b5cf6","items":[{"name":"Office Chairs","brands":["Herman Miller","Steelcase","Ergohuman","Autonomous","Secretlab","Branch","Haworth","Hon"]},{"name":"Desks","brands":["IKEA","Uplift","Jarvis","FlexiSpot","Branch","Fully","Sauder","Bush Furniture"]},{"name":"Sofas","brands":["West Elm","Article","Joybird","IKEA","Pottery Barn","Wayfair","La-Z-Boy","Crate \u0026 Barrel"]},{"name":"Dining Tables","brands":["West Elm","Pottery Barn","IKEA","Wayfair","Crate \u0026 Barrel","Floyd","Castlery","Rove Concepts"]},{"name":"Mattresses","brands":["Casper","Purple","Tempur-Pedic","Nectar","Saatva","Helix","Tuft \u0026 Needle","Sealy"]},{"name":"Bookshelves","brands":["IKEA","West Elm","Wayfair","CB2","Crate \u0026 Barrel","Pottery Barn","Target","Sauder"]},{"name":"Coffee Tables","brands":["West Elm","IKEA","Wayfair","CB2","Article","Pottery Barn","Target","Floyd"]},{"name":"Bed Frames","brands":["Zinus","Thuma","IKEA","West Elm","Tuft \u0026 Needle","Wayfair","Casper","Floyd"]}]},{"id":"office","name":"Office Supplies","color":"#06b6d4","items":[{"name":"Paper Shredders","brands":["Fellowes","AmazonBasics","Aurora","Bonsaii","Swingline","Royal","Sentinel","GBC"]},{"name":"Label Printers","brands":["Dymo","Brother","Rollo","Munbyn","Phomemo","Zebra","Epson","Arkscan"]},{"name":"Staplers","brands":["Swingline","Bostitch","Paper Mate","Rapid","Rexel","Maped","Officemate","AmazonBasics"]},{"name":"Notebooks","brands":["Moleskine","Leuchtturm1917","Rhodia","Field Notes","Rocketbook","Clairefontaine","Paperchase","Oxford"]},{"name":"Pens","brands":["Pilot","Uni-ball","Pentel","Zebra","Parker","Lamy","Montblanc","Sharpie"]},{"name":"Whiteboards","brands":["Quartet","UBrands","Maxtek","Viz-Pro","Audio-Visual Direct","BoardGeeks","Lockways","AmazonBasics"]},{"name":"Desk Organizers","brands":["Rolodex","Jerry \u0026 Maggie","Simple Trending","Mind Reader","DecoBros","AmazonBasics","Safco","Deli"]},{"name":"Calculators","brands":["Texas Instruments","Casio","HP","Sharp","Canon","Citizen","Victor","Datexx"]}]},{"id":"tools","name":"Tools \u0026 Hardware","color":"#f97316","items":[{"name":"Power Drills","brands":["DeWalt","Milwaukee","Makita","Bosch","Ryobi","Black+Decker","Porter-Cable","Craftsman"]},{"name":"Screwdriver Sets","brands":["Wera","Wiha","Klein Tools","Craftsman","Stanley","DeWalt","Milwaukee","Gearwrench"]},{"name":"Hand Tool Sets","brands":["Stanley","Craftsman","DeWalt","Workpro","Crescent","Husky","Kobalt","Gearwrench"]},{"name":"Tape Measures","brands":["Stanley","Lufkin","Milwaukee","Komelon","Craftsman","DeWalt","Tajima","Starrett"]},{"name":"Hammers","brands":["Estwing","Stanley","Stiletto","Vaughan","Milwaukee","DeWalt","Craftsman","IRWIN"]},{"name":"Wrenches","brands":["Gearwrench","Crescent","Tekton","Craftsman","Milwaukee","DeWalt","Stanley","Proto"]},{"name":"Pliers","brands":["Knipex","Channellock","Klein Tools","IRWIN","Milwaukee","DeWalt","Stanley","Crescent"]},{"name":"Utility Knives","brands":["Stanley","OLFA","MilwaukLine truncated
|
||||
|
||||
let currentStep = 1;
|
||||
let selectedCategory = null;
|
||||
let selectedItem = null;
|
||||
let selectedBrand = null;
|
||||
|
||||
|
||||
const screenCategory = document.getElementById('screen-category');
|
||||
const screenItem = document.getElementById('screen-item');
|
||||
const screenBrand = document.getElementById('screen-brand');
|
||||
|
||||
const categoryGrid = document.getElementById('category-grid-container');
|
||||
const itemGrid = document.getElementById('item-grid-container');
|
||||
const brandGrid = document.getElementById('brand-grid-container');
|
||||
|
||||
const inputCategory = document.getElementById('input-category');
|
||||
const inputItem = document.getElementById('input-item');
|
||||
const inputBrand = document.getElementById('input-brand');
|
||||
|
||||
const wizardForm = document.getElementById('wizard-form');
|
||||
const backBtnWrapper = document.getElementById('wizard-back-wrapper');
|
||||
const backBtn = document.getElementById('btn-wizard-back');
|
||||
|
||||
|
||||
const step1 = document.getElementById('progress-step-1');
|
||||
const step2 = document.getElementById('progress-step-2');
|
||||
const step3 = document.getElementById('progress-step-3');
|
||||
|
||||
const line1 = document.getElementById('progress-line-1');
|
||||
const line2 = document.getElementById('progress-line-2');
|
||||
|
||||
|
||||
function initWizard() {
|
||||
categoryGrid.innerHTML = '';
|
||||
|
||||
catalog.forEach(cat => {
|
||||
|
||||
const color = cat.color || '#d97706';
|
||||
|
||||
|
||||
const r = parseInt(color.slice(1, 3), 16);
|
||||
const g = parseInt(color.slice(3, 5), 16);
|
||||
const b = parseInt(color.slice(5, 7), 16);
|
||||
|
||||
const card = document.createElement('div');
|
||||
card.className = 'category-card';
|
||||
card.style.setProperty('--cat-color', color);
|
||||
card.style.setProperty('--cat-color-bg', `rgba(${r}, ${g}, ${b}, 0.04)`);
|
||||
card.style.setProperty('--cat-color-badge-bg', `rgba(${r}, ${g}, ${b}, 0.1)`);
|
||||
|
||||
|
||||
const initial = cat.name.charAt(0);
|
||||
card.innerHTML = `
|
||||
<div class="category-badge">${initial}</div>
|
||||
<div class="category-name">${cat.name}</div>
|
||||
`;
|
||||
|
||||
card.addEventListener('click', () => {
|
||||
selectCategory(cat);
|
||||
});
|
||||
|
||||
categoryGrid.appendChild(card);
|
||||
});
|
||||
|
||||
|
||||
const otherCard = document.createElement('div');
|
||||
otherCard.className = 'category-card';
|
||||
otherCard.style.setProperty('--cat-color', 'var(--color-text-muted)');
|
||||
otherCard.style.setProperty('--cat-color-bg', 'var(--color-bg-base)');
|
||||
otherCard.style.setProperty('--cat-color-badge-bg', 'var(--color-border)');
|
||||
otherCard.style.borderStyle = 'dashed';
|
||||
otherCard.style.borderWidth = '2px';
|
||||
otherCard.innerHTML = `
|
||||
<div class="category-badge" style="font-weight: 500;">+</div>
|
||||
<div class="category-name">Other / Unlisted</div>
|
||||
`;
|
||||
otherCard.addEventListener('click', () => {
|
||||
selectCategory({ id: 'Other', name: 'Other', items: [] });
|
||||
});
|
||||
categoryGrid.appendChild(otherCard);
|
||||
}
|
||||
|
||||
|
||||
function selectCategory(cat) {
|
||||
selectedCategory = cat.id;
|
||||
inputCategory.value = cat.id;
|
||||
|
||||
if (cat.id === 'Other') {
|
||||
|
||||
inputItem.value = 'Other';
|
||||
inputBrand.value = 'Other';
|
||||
wizardForm.submit();
|
||||
return;
|
||||
}
|
||||
|
||||
renderItems(cat);
|
||||
goToStep(2);
|
||||
}
|
||||
|
||||
|
||||
function renderItems(cat) {
|
||||
const heading = document.getElementById('item-screen-heading');
|
||||
heading.textContent = `What kind of ${cat.name.toLowerCase()} is it?`;
|
||||
|
||||
itemGrid.innerHTML = '';
|
||||
|
||||
cat.items.forEach(item => {
|
||||
const btn = document.createElement('button');
|
||||
btn.type = 'button';
|
||||
btn.className = 'pill-button';
|
||||
btn.innerHTML = `
|
||||
<span>${item.name}</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2.5" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M8.25 4.5l7.5 7.5-7.5 7.5" />
|
||||
</svg>
|
||||
`;
|
||||
|
||||
btn.addEventListener('click', () => {
|
||||
selectItem(cat, item);
|
||||
});
|
||||
|
||||
itemGrid.appendChild(btn);
|
||||
});
|
||||
|
||||
|
||||
const otherBtn = document.createElement('button');
|
||||
otherBtn.type = 'button';
|
||||
otherBtn.className = 'pill-button other-pill';
|
||||
otherBtn.innerHTML = `
|
||||
<span>Other Item</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2.5" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" />
|
||||
</svg>
|
||||
`;
|
||||
otherBtn.addEventListener('click', () => {
|
||||
selectItem(cat, { name: 'Other', brands: [] });
|
||||
});
|
||||
itemGrid.appendChild(otherBtn);
|
||||
}
|
||||
|
||||
|
||||
function selectItem(cat, item) {
|
||||
selectedItem = item.name;
|
||||
inputItem.value = item.name;
|
||||
|
||||
if (item.name === 'Other') {
|
||||
|
||||
inputBrand.value = 'Other';
|
||||
wizardForm.submit();
|
||||
return;
|
||||
}
|
||||
|
||||
renderBrands(item);
|
||||
goToStep(3);
|
||||
}
|
||||
|
||||
|
||||
function renderBrands(item) {
|
||||
const heading = document.getElementById('brand-screen-heading');
|
||||
heading.textContent = `What brand is the ${item.name.toLowerCase()}?`;
|
||||
|
||||
brandGrid.innerHTML = '';
|
||||
|
||||
item.brands.forEach(brand => {
|
||||
const btn = document.createElement('button');
|
||||
btn.type = 'button';
|
||||
btn.className = 'pill-button';
|
||||
btn.innerHTML = `
|
||||
<span>${brand}</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2.5" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
`;
|
||||
|
||||
btn.addEventListener('click', () => {
|
||||
selectBrand(brand);
|
||||
});
|
||||
|
||||
brandGrid.appendChild(btn);
|
||||
});
|
||||
|
||||
|
||||
const otherBtn = document.createElement('button');
|
||||
otherBtn.type = 'button';
|
||||
otherBtn.className = 'pill-button other-pill';
|
||||
otherBtn.innerHTML = `
|
||||
<span>Other Brand</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2.5" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" />
|
||||
</svg>
|
||||
`;
|
||||
otherBtn.addEventListener('click', () => {
|
||||
selectBrand('Other');
|
||||
});
|
||||
brandGrid.appendChild(otherBtn);
|
||||
}
|
||||
|
||||
|
||||
function selectBrand(brand) {
|
||||
selectedBrand = brand;
|
||||
inputBrand.value = brand;
|
||||
|
||||
|
||||
wizardForm.submit();
|
||||
}
|
||||
|
||||
|
||||
function goToStep(step) {
|
||||
currentStep = step;
|
||||
|
||||
|
||||
screenCategory.classList.remove('active');
|
||||
screenItem.classList.remove('active');
|
||||
screenBrand.classList.remove('active');
|
||||
|
||||
|
||||
step1.className = 'wizard-step';
|
||||
step2.className = 'wizard-step';
|
||||
step3.className = 'wizard-step';
|
||||
|
||||
line1.className = 'wizard-line';
|
||||
line2.className = 'wizard-line';
|
||||
|
||||
if (step === 1) {
|
||||
screenCategory.classList.add('active');
|
||||
step1.classList.add('active');
|
||||
backBtnWrapper.style.display = 'none';
|
||||
} else if (step === 2) {
|
||||
screenItem.classList.add('active');
|
||||
step1.classList.add('completed');
|
||||
step2.classList.add('active');
|
||||
line1.classList.add('completed');
|
||||
backBtnWrapper.style.display = 'block';
|
||||
} else if (step === 3) {
|
||||
screenBrand.classList.add('active');
|
||||
step1.classList.add('completed');
|
||||
step2.classList.add('completed');
|
||||
step3.classList.add('active');
|
||||
line1.classList.add('completed');
|
||||
line2.classList.add('completed');
|
||||
backBtnWrapper.style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
backBtn.addEventListener('click', () => {
|
||||
if (currentStep > 1) {
|
||||
goToStep(currentStep - 1);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
initWizard();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
</main>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="toast-container">
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"Solis/internal/config"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cat, err := config.LoadCatalog("../catalog.json")
|
||||
if err != nil {
|
||||
log.Fatalf("Error: %v", err)
|
||||
}
|
||||
fmt.Printf("Loaded %d categories\n", len(cat))
|
||||
}
|
||||
Reference in new issue
Block a user