Refactor tempmon dashboard view, for buefy themes
This commit is contained in:
parent
0753e956f9
commit
f18f24962e
|
@ -8,5 +8,14 @@
|
|||
% endif
|
||||
</%def>
|
||||
|
||||
<%def name="modify_this_page_vars()">
|
||||
${parent.modify_this_page_vars()}
|
||||
<script type="text/javascript">
|
||||
|
||||
${form.component_studly}Data.probesData = ${json.dumps(probes_data)|n}
|
||||
|
||||
</script>
|
||||
</%def>
|
||||
|
||||
|
||||
${parent.body()}
|
||||
|
|
|
@ -40,4 +40,14 @@
|
|||
% endif
|
||||
</%def>
|
||||
|
||||
<%def name="modify_this_page_vars()">
|
||||
${parent.modify_this_page_vars()}
|
||||
<script type="text/javascript">
|
||||
|
||||
${form.component_studly}Data.probesData = ${json.dumps(probes_data)|n}
|
||||
|
||||
</script>
|
||||
</%def>
|
||||
|
||||
|
||||
${parent.body()}
|
||||
|
|
|
@ -83,6 +83,57 @@
|
|||
</%def>
|
||||
|
||||
<%def name="render_this_page()">
|
||||
% if use_buefy:
|
||||
|
||||
${h.form(request.current_route_url(), ref='applianceForm')}
|
||||
${h.csrf_token(request)}
|
||||
<div class="level-left">
|
||||
|
||||
<div class="level-item">
|
||||
<b-field label="Appliance" horizontal>
|
||||
<b-select name="appliance_uuid"
|
||||
v-model="applianceUUID"
|
||||
@input="$refs.applianceForm.submit()">
|
||||
<option v-for="appliance in appliances"
|
||||
:key="appliance.uuid"
|
||||
:value="appliance.uuid">
|
||||
{{ appliance.name }}
|
||||
</option>
|
||||
</b-select>
|
||||
</b-field>
|
||||
</div>
|
||||
|
||||
% if appliance:
|
||||
<div class="level-item">
|
||||
<a href="${url('tempmon.appliances.view', uuid=appliance.uuid)}">
|
||||
${h.image(url('tempmon.appliances.thumbnail', uuid=appliance.uuid), "")}
|
||||
</a>
|
||||
</div>
|
||||
% endif
|
||||
|
||||
</div>
|
||||
${h.end_form()}
|
||||
|
||||
% if appliance and appliance.probes:
|
||||
% for probe in appliance.probes:
|
||||
<h4 class="is-size-4">
|
||||
Probe: ${h.link_to(probe.description, url('tempmon.probes.graph', uuid=probe.uuid))}
|
||||
(status: ${enum.TEMPMON_PROBE_STATUS[probe.status]})
|
||||
</h4>
|
||||
% if probe.enabled:
|
||||
<canvas ref="tempchart-${probe.uuid}" width="400" height="60"></canvas>
|
||||
% else:
|
||||
<p>This probe is not enabled.</p>
|
||||
% endif
|
||||
% endfor
|
||||
% elif appliance:
|
||||
<h3>This appliance has no probes configured!</h3>
|
||||
% else:
|
||||
<h3>Please choose an appliance.</h3>
|
||||
% endif
|
||||
|
||||
% else:
|
||||
## not buefy
|
||||
<div style="display: flex;">
|
||||
|
||||
<div class="form-wrapper">
|
||||
|
@ -129,6 +180,67 @@
|
|||
% else:
|
||||
<h3>This appliance has no probes configured!</h3>
|
||||
% endif
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
<%def name="modify_this_page_vars()">
|
||||
${parent.modify_this_page_vars()}
|
||||
<script type="text/javascript">
|
||||
|
||||
ThisPageData.appliances = ${json.dumps(appliances_data)|n}
|
||||
ThisPageData.applianceUUID = ${json.dumps(appliance.uuid if appliance else None)|n}
|
||||
ThisPageData.charts = {}
|
||||
|
||||
ThisPage.methods.fetchReadings = function(uuid) {
|
||||
|
||||
if (!uuid) {
|
||||
uuid = this.applianceUUID
|
||||
}
|
||||
|
||||
for (let chart in this.charts) {
|
||||
chart.destroy()
|
||||
}
|
||||
this.charts = []
|
||||
|
||||
let url = '${url('tempmon.dashboard.readings')}'
|
||||
let params = {appliance_uuid: uuid}
|
||||
this.$http.get(url, {params: params}).then(response => {
|
||||
if (response.data.probes) {
|
||||
|
||||
for (let probe of response.data.probes) {
|
||||
|
||||
let context = this.$refs[`tempchart-${'$'}{probe.uuid}`]
|
||||
this.charts[probe.uuid] = new Chart(context, {
|
||||
type: 'scatter',
|
||||
data: {
|
||||
datasets: [{
|
||||
label: probe.description,
|
||||
data: probe.readings
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
scales: {
|
||||
xAxes: [{
|
||||
type: 'time',
|
||||
time: {unit: 'minute'},
|
||||
position: 'bottom'
|
||||
}]
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
} else {
|
||||
alert(response.data.error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
ThisPage.mounted = function() {
|
||||
this.fetchReadings()
|
||||
}
|
||||
|
||||
</script>
|
||||
</%def>
|
||||
|
||||
|
||||
|
|
|
@ -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…
Reference in a new issue