// Package models defines the core domain types shared across inventree. package models import "time" type Role string const ( RoleAdmin Role = "admin" RoleUser Role = "user" ) 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 } 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 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 CreatedAt time.Time UpdatedAt time.Time // Populated by joined list/detail queries. ItemTypeName string ItemTypeIcon string 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 }