Fixes for webgui and more native gui development

This commit is contained in:
2026-09-16 19:07:10 +02:00
parent 9b45fd3700
commit 2fc74c0677
31 changed files with 2143 additions and 417 deletions
+130
View File
@@ -0,0 +1,130 @@
# SPDX-License-Identifier: WTFPL
"""
Dropdowns and database enums
dropdowns can change
enums are static
"""
class Dropdown:
HULL_TYPE = 1
COMPANY_TYPE = 2
STORAGE_TYPE = 3
EQUIPMENT_CATEGORY = 4
PROVISION_CATEGORY = 5
PROVISION_UNIT = 6
FUSE_TYPE = 7
UNIT = 8
BOX_TYPE = 9
FUSE_BLOCK = 10
CABLE_TYPE = 11
CABLE_TECHNAME = 12
class Lookup:
def __init__(self, db):
self.db = db
self._enums = {}
self._dropdowns = {}
def load(self):
self._load_enums()
self._load_dropdowns()
def _load_enums(self):
"""
TODO translation via gettext needed
"""
db_enums = {
'user.role': ('user', 'role'),
'dropdown.flags': ('dropdown', 'flags'),
'vessel.vtype': ('vessel', 'vtype'),
'storage.capaunit': ('storage', 'capaunit'),
'tagref.objtype': ('tagref', 'objtype'),
'inventory.conttype': ('inventory', 'conttype'),
'inventory.invcond': ('inventory', 'invcond'),
'cable.cablecond': ('cable', 'cablecond'),
'measurement.accuracy': ('measurement', 'accuracy'),
'document.doctype': ('document', 'doctype'),
'document.roleaccess': ('document', 'roleaccess'),
'docref.reftype': ('docref', 'reftype'),
'maintenance.maintstate': ('maintenance', 'maintstate'),
'project.projstate': ('project', 'projstate'),
'task.priority': ('task', 'priority'),
'task.taskstate': ('task', 'taskstate'),
'note.notetype': ('note', 'notetype'),
'checklist.clstate': ('checklist', 'clstate'),
'checkitem.checkresult': ('checkitem', 'checkresult'),
'signalk.objtype': ('signalk', 'objtype'),
'signalk.datatype': ('signalk', 'datatype')
}
for key, (table, column) in db_enums.items():
self._enums[key] = self.db.load_enum(table, column)
def _load_dropdowns(self):
self._dropdowns.clear()
sql = (
"SELECT ddid, ddval, ddtext "
"FROM dropdown "
"WHERE ddid>0 "
"ORDER BY ddid, sort, ddval"
)
self.db.cur.execute(sql)
for ddid, ddval, ddtext in self.db.cur.fetchall():
if ddid not in self._dropdowns:
self._dropdowns[ddid] = {}
self._dropdowns[ddid][ddval] = ddtext
def enum(self, name):
return self._enums[name]
def dropdown(self, ddid):
return self._dropdowns[ddid]
def refresh(self):
# TODO ugly hack please improve
self._load_dropdowns()
class ListDefinition:
pass
"""
EQUIPMENT_LIST = ListDefinition(
name="equipment",
query=
"SELECT
e.eid,
e.ename,
c.name AS manufacturer,
e.model,
e.ecat,
e.weight
FROM equipment e
LEFT JOIN company c
ON c.cid = e.manufacturer"
,
columns=[
Column("ename", _("Name")),
Column("manufacturer", _("Manufacturer")),
Column(
"model",
_("Model")
),
Column(
"ecat",
_("Category"),
formatter=dropdown(Dropdown.EQUIPMENT_CATEGORY)
),
Column(
"weight",
_("Weight"),
formatter=weight()
),
]
)
"""