- go.mod module path (and every internal/vibetree import) inventree -> vibetree - cmd/inventree/ -> cmd/vibetree/, deploy/inventree.service -> vibetree.service - Default site name (seed data + the siteName template func's fallback) is now "vibetree", shown in the navbar, <title>, and login page - Session cookie renamed inventree_session -> vibetree_session - Default DB path data/inventree.db -> data/vibetree.db, CLI/log text, Dockerfile, docker-compose.yml, README, .gitignore/.dockerignore all updated to match Existing installs: this changes the session cookie name (users will be signed out once) and the default DB filename (point -db at your existing file, or rename it, to keep your data).
193 lines
4.4 KiB
Go
193 lines
4.4 KiB
Go
// Package models defines the core domain types shared across vibetree.
|
|
package models
|
|
|
|
import "time"
|
|
|
|
type Role string
|
|
|
|
const (
|
|
RoleAdmin Role = "admin"
|
|
RoleUser Role = "user"
|
|
// RoleContact is an assignable person (end user) with no ability to
|
|
// sign in - useful for tracking who a checked-out asset belongs to
|
|
// without needing to create a login account for everyone in a
|
|
// building.
|
|
RoleContact Role = "contact"
|
|
)
|
|
|
|
type User struct {
|
|
ID int64
|
|
Username string
|
|
PasswordHash string
|
|
Role Role
|
|
Enabled bool
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
func (u User) IsAdmin() bool { return u.Role == RoleAdmin }
|
|
|
|
// CanLogin reports whether this account is allowed to sign in at all;
|
|
// contacts exist only to be assigned assets.
|
|
func (u User) CanLogin() bool { return u.Role == RoleAdmin || u.Role == RoleUser }
|
|
|
|
type Folder struct {
|
|
ID int64
|
|
Name string
|
|
ParentID *int64
|
|
Description string
|
|
Icon string
|
|
SortOrder int
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
|
|
// Populated by list/tree queries; not persisted directly on this table.
|
|
FolderCount int
|
|
AssetCount int
|
|
}
|
|
|
|
type Status struct {
|
|
ID int64
|
|
Name string
|
|
Color string
|
|
SortOrder int
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
type FieldType string
|
|
|
|
const (
|
|
FieldTypeText FieldType = "text"
|
|
FieldTypeLongText FieldType = "long_text"
|
|
FieldTypeNumber FieldType = "number"
|
|
FieldTypeDate FieldType = "date"
|
|
FieldTypeBoolean FieldType = "boolean"
|
|
FieldTypeDropdown FieldType = "dropdown"
|
|
FieldTypeURL FieldType = "url"
|
|
FieldTypeIPAddress FieldType = "ip_address"
|
|
)
|
|
|
|
var AllFieldTypes = []FieldType{
|
|
FieldTypeText, FieldTypeLongText, FieldTypeNumber, FieldTypeDate,
|
|
FieldTypeBoolean, FieldTypeDropdown, FieldTypeURL, FieldTypeIPAddress,
|
|
}
|
|
|
|
func (t FieldType) Label() string {
|
|
switch t {
|
|
case FieldTypeText:
|
|
return "Text"
|
|
case FieldTypeLongText:
|
|
return "Long Text"
|
|
case FieldTypeNumber:
|
|
return "Number"
|
|
case FieldTypeDate:
|
|
return "Date"
|
|
case FieldTypeBoolean:
|
|
return "Boolean"
|
|
case FieldTypeDropdown:
|
|
return "Dropdown"
|
|
case FieldTypeURL:
|
|
return "URL"
|
|
case FieldTypeIPAddress:
|
|
return "IP Address"
|
|
}
|
|
return string(t)
|
|
}
|
|
|
|
type ItemType struct {
|
|
ID int64
|
|
Name string
|
|
Description string
|
|
Icon string
|
|
Enabled bool
|
|
SortOrder int
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
|
|
// IsUnique means each asset of this type is its own distinct item
|
|
// (a laptop with its own serial number, tracked as one row per unit).
|
|
// When false, assets of this type are bulk/consumable line items
|
|
// (e.g. "USB-A Cable") tracked by Quantity instead of one row each.
|
|
IsUnique bool
|
|
|
|
Fields []CustomFieldDef
|
|
}
|
|
|
|
type CustomFieldDef struct {
|
|
ID int64
|
|
ItemTypeID int64
|
|
Name string
|
|
FieldKey string
|
|
FieldType FieldType
|
|
Required bool
|
|
DefaultValue string
|
|
Options []string
|
|
SortOrder int
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
type CustomFieldValue struct {
|
|
ID int64
|
|
AssetID int64
|
|
FieldDefID int64
|
|
Value string
|
|
}
|
|
|
|
type Asset struct {
|
|
ID int64
|
|
AssetTag string
|
|
Name string
|
|
ItemTypeID int64
|
|
FolderID *int64
|
|
StatusID int64
|
|
AssignedUserID *int64
|
|
Notes string
|
|
// Quantity is meaningful only when the asset's item type is not
|
|
// IsUnique; unique-type assets are always kept at 1.
|
|
Quantity int
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
|
|
// Populated by joined list/detail queries.
|
|
ItemTypeName string
|
|
ItemTypeIcon string
|
|
ItemTypeIsUnique bool
|
|
StatusName string
|
|
StatusColor string
|
|
AssignedUsername string
|
|
FolderPath []BreadcrumbItem
|
|
CustomFields []AssetFieldValue
|
|
}
|
|
|
|
type AssetFieldValue struct {
|
|
Def CustomFieldDef
|
|
Value string
|
|
}
|
|
|
|
type BreadcrumbItem struct {
|
|
ID int64
|
|
Name string
|
|
}
|
|
|
|
// TreeNode is a folder-or-asset node used to render the inventory tree.
|
|
type TreeNode struct {
|
|
Type string // "folder" or "asset"
|
|
ID int64
|
|
Name string
|
|
Icon string
|
|
ParentID *int64
|
|
HasChildren bool
|
|
AssetTag string
|
|
StatusName string
|
|
StatusColor string
|
|
|
|
// Populated only when the node is pre-expanded for server-side
|
|
// recursive rendering (see web.buildTree); empty otherwise, in which
|
|
// case the client lazy-loads children via /app/tree/children.
|
|
Expanded bool
|
|
Children []TreeNode
|
|
MoreAssets int // count of additional assets beyond the tree display cap, if any
|
|
}
|