Commit 2598c4ad authored by Patrick Godwin's avatar Patrick Godwin

serve.py: clean up + refactor dashboard()

parent 08290805
Pipeline #75166 failed with stages
in 1 minute and 43 seconds
......@@ -77,56 +77,49 @@ def dashboard(page='index'):
"""
config = dict(app.config)
page_config = config['pages'][page]
static_dir = '../' if config['use_cgi'] else ''
if page != 'index':
static_dir += '../'
### determine if querying for online or historical data
if 'type' in bottle.request.query:
config['pages'][page]['type'] = bottle.request.query['type']
page_config['type'] = bottle.request.query['type']
else:
config['pages'][page]['type'] = 'online'
if config['pages'][page]['type'] == 'online':
page_config['type'] = 'online'
### process online/historical query settings
if page_config['type'] == 'online':
if 'lookback' in bottle.request.query:
config['pages'][page]['lookback'] = int(bottle.request.query['lookback'])
page_config['lookback'] = int(bottle.request.query['lookback'])
if 'delay' in bottle.request.query:
config['pages'][page]['delay'] = int(bottle.request.query['delay'])
else:
config['pages'][page]['start'] = int(bottle.request.query['start'])
config['pages'][page]['end'] = int(bottle.request.query['end'])
### find out whether query is for realtime or historical data
if config['pages'][page]['type'] == 'online':
stop = int(utils.gps_now() - config['pages'][page]['delay'])
start = stop - config['pages'][page]['lookback']
refresh = 2000
page_config['delay'] = int(bottle.request.query['delay'])
page_config['stop'] = int(utils.gps_now() - page_config['delay'])
page_config['start'] = page_config['stop'] - page_config['lookback']
page_config['refresh'] = 2000
else:
start = config['pages'][page]['start']
stop = config['pages'][page]['end']
refresh = -1
page_config['stop'] = int(bottle.request.query['end'])
page_config['start'] = int(bottle.request.query['start'])
page_config['refresh'] = -1
### fill in plot section for page with plot/schema info
plots = config['pages'][page]['plots']
plots = page_config['plots']
for plot in plots:
plot_name = plot['plot']
plot.update(config['plots'][plot_name])
plot['schema'] = config['schemas'][plot['schema']]
### generate html
### generate dashboard
yield bottle.template(
'dashboard.html',
static_dir=static_dir,
script_name=config['script_name'],
plot_defaults=config['plotly'] if 'plotly' in config else {},
plots=plots,
start=start,
stop=stop,
refresh=refresh,
lookback=config['pages'][page]['lookback'],
delay=config['pages'][page]['delay'],
query_type=config['pages'][page]['type'],
dashboard_config=config['navbar'],
page_config=config['pages'],
current_page=page,
plots=plots,
plot_defaults=config['plotly'] if 'plotly' in config else {},
)
......
......@@ -46,10 +46,10 @@
% end
<div id='plots'>
% include('navbar.html', **dashboard_config)
% include('navbar.html', **page_config[current_page])
% include('plots.html')
</div>
</body>
% include('scripts.js', **dashboard_config)
% include('scripts.js', **page_config[current_page])
</html>
......@@ -19,7 +19,7 @@
% if current_page != 'index':
% script_name = '../' + script_name
% end
% for page in pages:
% for page in dashboard_config['pages']:
% if page == 'index':
% url = script_name if script_name[-1] != '/' else script_name[:-1]
% else:
......@@ -30,7 +30,7 @@
% end
<!-- add tabs -->
% for tab in tabs:
% for tab in dashboard_config['tabs']:
<li><a class="nav-link mt-0" href="{{ tab['url'] }}">{{ tab['name'] }}</a></li>
% end
......
......@@ -52,7 +52,7 @@
delay: {{ delay }},
start: {{ start }},
end: {{ stop }},
type: '{{ query_type }}'
type: '{{ type }}'
},
selected: {{ lookback }},
options: [
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment