mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-10 01:17:42 +01:00
Allow Multiple Dashboards
- Up to 10 Dashboards possible - Config parameter max_dashboard_number added - Default is 4 dashboards - Config parameter will be added automatically via extension if not in config.json
This commit is contained in:
parent
3a75036b19
commit
016c6d1adf
3 changed files with 47 additions and 4 deletions
|
@ -4,6 +4,8 @@ import json
|
||||||
import os
|
import os
|
||||||
from os import listdir
|
from os import listdir
|
||||||
from os.path import isfile, join
|
from os.path import isfile, join
|
||||||
|
from cbpi.api.base import CBPiBase
|
||||||
|
from cbpi.api.config import ConfigType
|
||||||
|
|
||||||
from voluptuous.schema_builder import message
|
from voluptuous.schema_builder import message
|
||||||
|
|
||||||
|
@ -23,24 +25,34 @@ class DashboardController:
|
||||||
|
|
||||||
async def get_content(self, dashboard_id):
|
async def get_content(self, dashboard_id):
|
||||||
try:
|
try:
|
||||||
|
self.path = os.path.join(".", 'config', "cbpi_dashboard_"+ str(dashboard_id) +".json")
|
||||||
|
logging.info(self.path)
|
||||||
with open(self.path) as json_file:
|
with open(self.path) as json_file:
|
||||||
data = json.load(json_file)
|
data = json.load(json_file)
|
||||||
return data
|
return data
|
||||||
except:
|
except:
|
||||||
return {}
|
return {'elements': [], 'pathes': []}
|
||||||
|
|
||||||
async def add_content(self, dashboard_id, data):
|
async def add_content(self, dashboard_id, data):
|
||||||
print(data)
|
print(data)
|
||||||
|
self.path = os.path.join(".", 'config', "cbpi_dashboard_" + str(dashboard_id)+ ".json")
|
||||||
with open(self.path, 'w') as outfile:
|
with open(self.path, 'w') as outfile:
|
||||||
json.dump(data, outfile, indent=4, sort_keys=True)
|
json.dump(data, outfile, indent=4, sort_keys=True)
|
||||||
self.cbpi.notify(title="Dashboard", message="Saved Successfully", type=NotificationType.SUCCESS)
|
self.cbpi.notify(title="Dashboard {}".format(dashboard_id), message="Saved Successfully", type=NotificationType.SUCCESS)
|
||||||
return {"status": "OK"}
|
return {"status": "OK"}
|
||||||
|
|
||||||
async def delete_content(self, dashboard_id):
|
async def delete_content(self, dashboard_id):
|
||||||
|
self.path = os.path.join(".", 'config', "cbpi_dashboard_"+ str(dashboard_id)+ ".json")
|
||||||
if os.path.exists(self.path):
|
if os.path.exists(self.path):
|
||||||
os.remove(self.path)
|
os.remove(self.path)
|
||||||
|
self.cbpi.notify(title="Dashboard {}".format(dashboard_id), message="Deleted Successfully", type=NotificationType.SUCCESS)
|
||||||
|
|
||||||
|
|
||||||
async def get_custom_widgets(self):
|
async def get_custom_widgets(self):
|
||||||
path = os.path.join(".", 'config', "dashboard", "widgets")
|
path = os.path.join(".", 'config', "dashboard", "widgets")
|
||||||
onlyfiles = [os.path.splitext(f)[0] for f in listdir(path) if isfile(join(path, f)) and f.endswith(".svg")]
|
onlyfiles = [os.path.splitext(f)[0] for f in listdir(path) if isfile(join(path, f)) and f.endswith(".svg")]
|
||||||
return onlyfiles
|
return onlyfiles
|
||||||
|
|
||||||
|
async def get_dashboard_numbers(self):
|
||||||
|
max_dashboard_number = self.cbpi.config.get("max_dashboard_number", 4)
|
||||||
|
return max_dashboard_number
|
||||||
|
|
|
@ -33,6 +33,8 @@ class ConfigUpdate(CBPiExtension):
|
||||||
mashout_step = self.cbpi.config.get("steps_mashout", None)
|
mashout_step = self.cbpi.config.get("steps_mashout", None)
|
||||||
boil_step = self.cbpi.config.get("steps_boil", None)
|
boil_step = self.cbpi.config.get("steps_boil", None)
|
||||||
cooldown_step = self.cbpi.config.get("steps_cooldown", None)
|
cooldown_step = self.cbpi.config.get("steps_cooldown", None)
|
||||||
|
max_dashboard_number = self.cbpi.config.get("max_dashboard_number", None)
|
||||||
|
|
||||||
|
|
||||||
if boil_temp is None:
|
if boil_temp is None:
|
||||||
logger.info("INIT Boil Temp Setting")
|
logger.info("INIT Boil Temp Setting")
|
||||||
|
@ -90,6 +92,23 @@ class ConfigUpdate(CBPiExtension):
|
||||||
except:
|
except:
|
||||||
logger.warning('Unable to update database')
|
logger.warning('Unable to update database')
|
||||||
|
|
||||||
|
if max_dashboard_number is None:
|
||||||
|
logger.info("INIT Max Dashboard Numbers for multiple dashboards")
|
||||||
|
try:
|
||||||
|
await self.cbpi.config.add("max_dashboard_number", 4, ConfigType.SELECT, "Max Number of Dashboards",
|
||||||
|
[{"label": "1", "value": 1},
|
||||||
|
{"label": "2", "value": 2},
|
||||||
|
{"label": "3", "value": 3},
|
||||||
|
{"label": "4", "value": 4},
|
||||||
|
{"label": "5", "value": 5},
|
||||||
|
{"label": "6", "value": 6},
|
||||||
|
{"label": "7", "value": 7},
|
||||||
|
{"label": "8", "value": 8},
|
||||||
|
{"label": "9", "value": 9},
|
||||||
|
{"label": "10", "value": 10}])
|
||||||
|
except:
|
||||||
|
logger.warning('Unable to update database')
|
||||||
|
|
||||||
## Check if AtuoMode for Steps is in config
|
## Check if AtuoMode for Steps is in config
|
||||||
AutoMode = self.cbpi.config.get("AutoMode", None)
|
AutoMode = self.cbpi.config.get("AutoMode", None)
|
||||||
if AutoMode is None:
|
if AutoMode is None:
|
||||||
|
|
|
@ -110,3 +110,15 @@ class DashBoardHttpEndpoints:
|
||||||
|
|
||||||
return web.json_response(await self.cbpi.dashboard.get_custom_widgets(), dumps=json_dumps)
|
return web.json_response(await self.cbpi.dashboard.get_custom_widgets(), dumps=json_dumps)
|
||||||
|
|
||||||
|
@request_mapping(path="/numbers", method="GET", auth_required=False)
|
||||||
|
async def get_dashboard_numbers(self, request):
|
||||||
|
"""
|
||||||
|
---
|
||||||
|
description: Get Dashboard Numbers
|
||||||
|
tags:
|
||||||
|
- Dashboard
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: successful operation
|
||||||
|
"""
|
||||||
|
return web.json_response(await self.cbpi.dashboard.get_dashboard_numbers(), dumps=json_dumps)
|
||||||
|
|
Loading…
Reference in a new issue