Refactor tempmon dashboard view, for buefy themes
This commit is contained in:
parent
0753e956f9
commit
f18f24962e
7 changed files with 225 additions and 19 deletions
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
# Copyright © 2010-2023 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -121,6 +121,14 @@ class TempmonApplianceView(MasterView):
|
|||
elif self.creating or self.editing:
|
||||
f.remove_field('probes')
|
||||
|
||||
def template_kwargs_view(self, **kwargs):
|
||||
kwargs = super(TempmonApplianceView, self).template_kwargs_view(**kwargs)
|
||||
appliance = kwargs['instance']
|
||||
|
||||
kwargs['probes_data'] = self.normalize_probes(appliance.probes)
|
||||
|
||||
return kwargs
|
||||
|
||||
def unique_name(self, node, value):
|
||||
query = self.Session.query(tempmon.Appliance)\
|
||||
.filter(tempmon.Appliance.name == value)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
# Copyright © 2010-2023 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -159,6 +159,14 @@ class TempmonClientView(MasterView):
|
|||
# archived
|
||||
f.set_helptext('archived', tempmon.Client.archived.__doc__)
|
||||
|
||||
def template_kwargs_view(self, **kwargs):
|
||||
kwargs = super(TempmonClientView, self).template_kwargs_view(**kwargs)
|
||||
client = kwargs['instance']
|
||||
|
||||
kwargs['probes_data'] = self.normalize_probes(client.probes)
|
||||
|
||||
return kwargs
|
||||
|
||||
def objectify(self, form, data=None):
|
||||
|
||||
# this is a hack to prevent updates to the 'enabled' timestamp, when
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2020 Lance Edgar
|
||||
# Copyright © 2010-2023 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -42,6 +42,28 @@ class MasterView(views.MasterView):
|
|||
from rattail_tempmon.db import Session
|
||||
return Session()
|
||||
|
||||
def normalize_probes(self, probes):
|
||||
data = []
|
||||
for probe in probes:
|
||||
view_url = self.request.route_url('tempmon.probes.view', uuid=probe.uuid)
|
||||
edit_url = self.request.route_url('tempmon.probes.edit', uuid=probe.uuid)
|
||||
data.append({
|
||||
'uuid': probe.uuid,
|
||||
'url': view_url,
|
||||
'_action_url_view': view_url,
|
||||
'_action_url_edit': edit_url,
|
||||
'description': probe.description,
|
||||
'critical_temp_min': probe.critical_temp_min,
|
||||
'good_temp_min': probe.good_temp_min,
|
||||
'good_temp_max': probe.good_temp_max,
|
||||
'critical_temp_max': probe.critical_temp_max,
|
||||
'status': self.enum.TEMPMON_PROBE_STATUS[probe.status],
|
||||
'enabled': "Yes" if probe.enabled else "No",
|
||||
})
|
||||
app = self.get_rattail_app()
|
||||
data = app.json_friendly(data)
|
||||
return data
|
||||
|
||||
def render_probes(self, obj, field):
|
||||
"""
|
||||
This method is used by Appliance and Client views.
|
||||
|
@ -50,6 +72,39 @@ class MasterView(views.MasterView):
|
|||
return ""
|
||||
|
||||
route_prefix = self.get_route_prefix()
|
||||
use_buefy = self.get_use_buefy()
|
||||
if use_buefy:
|
||||
|
||||
actions = [self.make_grid_action_view()]
|
||||
if self.request.has_perm('tempmon.probes.edit'):
|
||||
actions.append(self.make_grid_action_edit())
|
||||
|
||||
factory = self.get_grid_factory()
|
||||
g = factory(
|
||||
key='{}.probes'.format(route_prefix),
|
||||
data=[],
|
||||
columns=[
|
||||
'description',
|
||||
'critical_temp_min',
|
||||
'good_temp_min',
|
||||
'good_temp_max',
|
||||
'critical_temp_max',
|
||||
'status',
|
||||
'enabled',
|
||||
],
|
||||
labels={
|
||||
'critical_temp_min': "Crit. Min",
|
||||
'good_temp_min': "Good Min",
|
||||
'good_temp_max': "Good Max",
|
||||
'critical_temp_max': "Crit. Max",
|
||||
},
|
||||
linked_columns=['description'],
|
||||
main_actions=actions,
|
||||
)
|
||||
return HTML.literal(
|
||||
g.render_buefy_table_element(data_prop='probesData'))
|
||||
|
||||
# not buefy!
|
||||
view_url = lambda p, i: self.request.route_url('tempmon.probes.view', uuid=p.uuid)
|
||||
actions = [
|
||||
grids.GridAction('view', icon='zoomin', url=view_url),
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
# Copyright © 2010-2023 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -74,27 +74,31 @@ class TempmonDashboardView(View):
|
|||
selected_appliance = TempmonSession.query(tempmon.Appliance)\
|
||||
.get(selected_uuid)
|
||||
|
||||
appliances = TempmonSession.query(tempmon.Appliance)\
|
||||
.order_by(tempmon.Appliance.name)\
|
||||
.all()
|
||||
appliance_options = tags.Options([
|
||||
tags.Option(appliance.name, appliance.uuid)
|
||||
for appliance in appliances])
|
||||
|
||||
if use_buefy:
|
||||
appliance_select = None
|
||||
raise NotImplementedError
|
||||
else:
|
||||
appliance_select = tags.select('appliance_uuid', selected_uuid, appliance_options)
|
||||
|
||||
return {
|
||||
context = {
|
||||
'index_url': self.request.route_url('tempmon.appliances'),
|
||||
'index_title': "TempMon Appliances",
|
||||
'use_buefy': use_buefy,
|
||||
'appliance_select': appliance_select,
|
||||
'appliance': selected_appliance,
|
||||
}
|
||||
|
||||
appliances = TempmonSession.query(tempmon.Appliance)\
|
||||
.order_by(tempmon.Appliance.name)\
|
||||
.all()
|
||||
|
||||
if use_buefy:
|
||||
context['appliances_data'] = [{'uuid': a.uuid,
|
||||
'name': a.name}
|
||||
for a in appliances]
|
||||
|
||||
else:
|
||||
appliance_options = tags.Options([
|
||||
tags.Option(appliance.name, appliance.uuid)
|
||||
for appliance in appliances])
|
||||
context['appliance_select'] = tags.select(
|
||||
'appliance_uuid', selected_uuid, appliance_options)
|
||||
|
||||
return context
|
||||
|
||||
def readings(self):
|
||||
|
||||
# track down the requested appliance
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue