From f684c389583829050a6b25e7a965122b29e58232 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 15 Jun 2019 17:00:46 -0500 Subject: [PATCH] Refactor tempmon probe graph view per Vue.js --- tailbone/templates/tempmon/probes/graph.mako | 131 ++++++++++++++++++- tailbone/views/tempmon/probes.py | 17 ++- 2 files changed, 142 insertions(+), 6 deletions(-) diff --git a/tailbone/templates/tempmon/probes/graph.mako b/tailbone/templates/tempmon/probes/graph.mako index 5da9717f..9f3bee52 100644 --- a/tailbone/templates/tempmon/probes/graph.mako +++ b/tailbone/templates/tempmon/probes/graph.mako @@ -1,11 +1,12 @@ ## -*- coding: utf-8; -*- -<%inherit file="/base.mako" /> +<%inherit file="/form.mako" /> <%def name="title()">Temperature Graph <%def name="extra_javascript()"> ${parent.extra_javascript()} + % if not use_buefy: + % endif +<%def name="render_form_complete()"> + % if use_buefy: + + + +
+ +
+ + % else: + ## legacy / not buefy +
@@ -84,7 +144,7 @@
-
${probe.location}
+
${probe.location or ""}
@@ -97,3 +157,70 @@
+ % endif + + +<%def name="modify_tailbone_form()"> + + + + +${parent.body()} diff --git a/tailbone/views/tempmon/probes.py b/tailbone/views/tempmon/probes.py index 205d4c52..de0ca42d 100644 --- a/tailbone/views/tempmon/probes.py +++ b/tailbone/views/tempmon/probes.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2018 Lance Edgar +# Copyright © 2010-2019 Lance Edgar # # This file is part of Rattail. # @@ -35,7 +35,7 @@ from rattail_tempmon.db import model as tempmon import colander from deform import widget as dfwidget -from webhelpers2.html import tags +from webhelpers2.html import tags, HTML from tailbone import forms, grids from tailbone.views.tempmon import MasterView @@ -255,6 +255,7 @@ class TempmonProbeView(MasterView): def graph(self): probe = self.get_instance() + use_buefy = self.get_use_buefy() key = 'tempmon.probe.{}.graph_time_range'.format(probe.uuid) selected = self.request.params.get('time-range') @@ -262,18 +263,26 @@ class TempmonProbeView(MasterView): selected = self.request.session.get(key, 'last hour') self.request.session[key] = selected - time_range = tags.select('time-range', selected, tags.Options([ + range_options = tags.Options([ tags.Option("Last Hour", 'last hour'), tags.Option("Last 6 Hours", 'last 6 hours'), tags.Option("Last Day", 'last day'), tags.Option("Last Week", 'last week'), - ])) + ]) + + if use_buefy: + time_range = HTML.tag('b-select', c=[range_options.render()], + **{'v-model': 'currentTimeRange', + '@input': 'timeRangeChanged'}) + else: + time_range = tags.select('time-range', selected, range_options) context = { 'probe': probe, 'parent_title': six.text_type(probe), 'parent_url': self.get_action_url('view', probe), 'time_range': time_range, + 'current_time_range': selected, } return self.render_to_response('graph', context)