Feature work from the 2026-07 session: Settings IA - Replace the flat 27-card settings hub with a persistent two-pane shell (SettingsLayout.vue): grouped, searchable left rail + content pane. - Nest all settings/* routes under the shell via router post-processing; shared nav catalog in settingsNav.js. Group by asset class (PCs, Printers, Equipment, Network) so per-type settings stop scattering. Custom fields (core) - customfields + customfieldvalues tables (migration 7d14), CRUD API at /api/customfields, per-asset value get/save. - Settings management page + reusable CustomFieldsSection (detail) and CustomFieldsInputs (form) wired into all four asset types. Warranty (new plugin) - plugins/warranty: warranties + warrantyassets (migration 7d15), derived coverage status, provider abstraction (manual now; Dell/Lenovo/HP stubs). - API CRUD + per-asset panel + report buckets; WarrantyPanel on all four detail pages; Warranties management page; Warranty report + Reports card. - Seed warranty.* permissions. Printer drivers - printerdrivers table (migration 7d13) linked to printer models; drivers now surface on the matching printer's detail page. Other - PCDetail rebalanced (Network + Status + Warranty + custom fields on the right). - Rename PCs list "Features" column to "Remote Access"; fix badge hover underline. - Drop equipment islocationonly field. - Centralize asset-type label/route maps into utils/assetTypes.js. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
92 lines
3.1 KiB
Python
92 lines
3.1 KiB
Python
"""Custom fields: site-defined extra attributes per asset type.
|
|
|
|
A CustomField is a definition scoped to one asset type (equipment, computer,
|
|
printer, network_device). A CustomFieldValue holds one asset's value for one
|
|
field. This is the generic form of the built-in identifier columns - sites add
|
|
their own attributes without a schema change.
|
|
"""
|
|
|
|
from shopdb.extensions import db
|
|
|
|
# Allowed datatypes for a custom field. Values are always stored as text and
|
|
# cast on render/input by the frontend.
|
|
CUSTOM_FIELD_DATATYPES = ('text', 'number', 'date', 'boolean', 'select')
|
|
|
|
|
|
class CustomField(db.Model):
|
|
__tablename__ = 'customfields'
|
|
|
|
fieldid = db.Column(db.Integer, primary_key=True)
|
|
assettypeid = db.Column(
|
|
db.Integer,
|
|
db.ForeignKey('assettypes.assettypeid'),
|
|
nullable=False,
|
|
comment='Which asset category this field applies to'
|
|
)
|
|
# Machine-name key, unique per asset type. Used for stable references.
|
|
fieldkey = db.Column(db.String(50), nullable=False)
|
|
label = db.Column(db.String(150), nullable=False)
|
|
datatype = db.Column(db.String(20), nullable=False, server_default='text')
|
|
# JSON array of options, only meaningful when datatype='select'
|
|
options = db.Column(db.Text)
|
|
showondetail = db.Column(db.Boolean, nullable=False, server_default='1')
|
|
showonform = db.Column(db.Boolean, nullable=False, server_default='1')
|
|
sortorder = db.Column(db.Integer, nullable=False, server_default='0')
|
|
isactive = db.Column(db.Boolean, nullable=False, server_default='1')
|
|
|
|
__table_args__ = (
|
|
db.UniqueConstraint('assettypeid', 'fieldkey', name='uq_customfield_type_key'),
|
|
)
|
|
|
|
def to_dict(self):
|
|
import json
|
|
parsed_options = []
|
|
if self.options:
|
|
try:
|
|
parsed_options = json.loads(self.options)
|
|
except (ValueError, TypeError):
|
|
parsed_options = []
|
|
return {
|
|
'fieldid': self.fieldid,
|
|
'assettypeid': self.assettypeid,
|
|
'fieldkey': self.fieldkey,
|
|
'label': self.label,
|
|
'datatype': self.datatype,
|
|
'options': parsed_options,
|
|
'showondetail': bool(self.showondetail),
|
|
'showonform': bool(self.showonform),
|
|
'sortorder': self.sortorder,
|
|
'isactive': bool(self.isactive),
|
|
}
|
|
|
|
|
|
class CustomFieldValue(db.Model):
|
|
__tablename__ = 'customfieldvalues'
|
|
|
|
valueid = db.Column(db.Integer, primary_key=True)
|
|
fieldid = db.Column(
|
|
db.Integer,
|
|
db.ForeignKey('customfields.fieldid', ondelete='CASCADE'),
|
|
nullable=False
|
|
)
|
|
assetid = db.Column(
|
|
db.Integer,
|
|
db.ForeignKey('assets.assetid', ondelete='CASCADE'),
|
|
nullable=False
|
|
)
|
|
value = db.Column(db.Text)
|
|
|
|
field = db.relationship('CustomField')
|
|
|
|
__table_args__ = (
|
|
db.UniqueConstraint('fieldid', 'assetid', name='uq_customfieldvalue_field_asset'),
|
|
)
|
|
|
|
def to_dict(self):
|
|
return {
|
|
'valueid': self.valueid,
|
|
'fieldid': self.fieldid,
|
|
'assetid': self.assetid,
|
|
'value': self.value,
|
|
}
|