summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/web_kbn.py67
1 files changed, 39 insertions, 28 deletions
diff --git a/bin/web_kbn.py b/bin/web_kbn.py
index 96b6461..f891675 100755
--- a/bin/web_kbn.py
+++ b/bin/web_kbn.py
@@ -39,51 +39,52 @@ class WebKbnConfig(AppConfigUnit):
}
-common_static_files = [
- 'bootstrap.min.css',
- 'bootstrap.bundle.min.js',
- 'polyfills.js',
- 'app.js',
- 'app.css'
-]
-static_version = 4
+# files marked with + at the beginning are included by default
+common_static_files = {
+ '+bootstrap.min.css': 1,
+ '+bootstrap.bundle.min.js': 1,
+ '+polyfills.js': 1,
+ '+app.js': 6,
+ '+app.css': 6,
+ 'hls.js': 1
+}
routes = web.RouteTableDef()
logger = logging.getLogger(__name__)
lang_context_var = ContextVar('lang', default=Translation.DEFAULT_LANGUAGE)
-def get_js_link(file, version=static_version) -> str:
+def get_js_link(file, version) -> str:
if is_development_mode():
version = int(time.time())
- if version:
- file += f'?version={version}'
+ file += f'?version={version}'
return f'<script src="{config.app_config["assets_public_path"]}/{file}" type="text/javascript"></script>'
-def get_css_link(file, version=static_version) -> str:
+def get_css_link(file, version) -> str:
if is_development_mode():
version = int(time.time())
- if version:
- file += f'?version={version}'
+ file += f'?version={version}'
return f'<link rel="stylesheet" type="text/css" href="{config.app_config["assets_public_path"]}/{file}">'
-def get_head_static(files=None) -> str:
+def get_head_static(additional_files=None) -> str:
buf = StringIO()
- if files is None:
- files = []
- for file in common_static_files + files:
- try:
- q_ind = file.index('?')
- v = file[q_ind+1:]
- file = file[:file.index('?')]
- except ValueError:
- pass
+ if additional_files is None:
+ additional_files = []
+
+ for file, version in common_static_files.items():
+ enabled_by_default = file.startswith('+')
+ if not enabled_by_default and file not in additional_files:
+ continue
+
+ if enabled_by_default:
+ file = file[1:]
if file.endswith('.js'):
- buf.write(get_js_link(file))
+ buf.write(get_js_link(file, version))
else:
- buf.write(get_css_link(file))
+ buf.write(get_css_link(file, version))
+
return buf.getvalue()
@@ -252,6 +253,13 @@ async def index0(req: web.Request):
@routes.get('/main.cgi')
async def index(req: web.Request):
+ tabs = ['zones', 'list']
+ tab = req.query.get('tab', None)
+ if tab and (tab not in tabs or tab == tabs[0]):
+ raise web.HTTPFound('/main.cgi')
+ if tab is None:
+ tab = tabs[0]
+
ctx = {}
for k in 'inverter', 'sensors':
ctx[f'{k}_grafana_url'] = config.app_config[f'{k}_grafana_url']
@@ -261,6 +269,8 @@ async def index(req: web.Request):
ctx['allcams'] = cc.get_all_cam_names()
ctx['lang_enum'] = Language
ctx['lang_selected'] = lang_context_var.get()
+ ctx['tab_selected'] = tab
+ ctx['tabs'] = tabs
return await render(req, 'index',
title=lang('sitename'),
@@ -419,7 +429,7 @@ async def cams(req: web.Request):
if not cc.has_camera(int(cam)):
raise ValueError('invalid camera id')
cams = [int(cam)]
- mode = {'type': 'single', 'cam': cam}
+ mode = {'type': 'single', 'cam': int(cam)}
elif zone is not None:
if not cc.has_zone(zone):
@@ -428,7 +438,8 @@ async def cams(req: web.Request):
mode = {'type': 'zone', 'zone': zone}
else:
- raise web.HTTPBadRequest(text='no camera id or zone found')
+ cams = cc.get_all_cam_names()
+ mode = {'type': 'all'}
js_config = {
'host': config.app_config['cam_hls_host'],