-UI Adjustment for small screens. Brew Steps are displayed above the kettles. -tags/3.1_alpha
| @@ -14,6 +14,7 @@ class ActorView(BaseView): | |||||
| @classmethod | @classmethod | ||||
| def post_init_callback(self, obj): | def post_init_callback(self, obj): | ||||
| obj.state = 0 | obj.state = 0 | ||||
| obj.power = 100 | obj.power = 100 | ||||
| @@ -9,10 +9,17 @@ class Dummy(Step): | |||||
| @cbpi.addon.step.action("WOHOO") | @cbpi.addon.step.action("WOHOO") | ||||
| def myaction(self): | def myaction(self): | ||||
| self.stop_timer() | |||||
| self.start_timer(10) | |||||
| print "HALLO" | print "HALLO" | ||||
| text = Property.Text(label="Text", configurable=True, description="WOHOOO") | text = Property.Text(label="Text", configurable=True, description="WOHOOO") | ||||
| time = Property.Text(label="Text", configurable=True, description="WOHOOO") | |||||
| def execute(self): | def execute(self): | ||||
| #print self.text | #print self.text | ||||
| pass | |||||
| pass | |||||
| def reset(self): | |||||
| print "RESET STEP!!!" | |||||
| self.stop_timer() | |||||
| @@ -1,3 +1,5 @@ | |||||
| from modules.core.proptypes import Property | |||||
| import time | |||||
| class Base(object): | class Base(object): | ||||
| @@ -192,8 +194,40 @@ class FermenterController(ControllerBase): | |||||
| return self.get_sensor_value(int(self.api.cache.get("fermenter").get(id).sensor)) | return self.get_sensor_value(int(self.api.cache.get("fermenter").get(id).sensor)) | ||||
| class Timer(object): | |||||
| timer_end = Property.Number("TIMER_END", configurable=False) | |||||
| class Step(Base): | |||||
| def start_timer(self, timer): | |||||
| if self.timer_end is not None: | |||||
| return | |||||
| self.timer_end = int(time.time()) + timer | |||||
| def stop_timer(self): | |||||
| if self.timer_end is not None: | |||||
| self.timer_end = None | |||||
| def is_timer_running(self): | |||||
| if self.timer_end is not None: | |||||
| return True | |||||
| else: | |||||
| return False | |||||
| def timer_remaining(self): | |||||
| if self.timer_end is not None: | |||||
| return self.timer_end - int(time.time()) | |||||
| else: | |||||
| return None | |||||
| def is_timer_finished(self): | |||||
| if self.timer_end is None: | |||||
| return None | |||||
| if self.timer_end <= int(time.time()): | |||||
| return True | |||||
| else: | |||||
| return False | |||||
| class Step(Base, Timer): | |||||
| @classmethod | @classmethod | ||||
| @@ -226,7 +260,6 @@ class Step(Base): | |||||
| for a in kwds: | for a in kwds: | ||||
| super(Step, self).__setattr__(a, kwds.get(a)) | super(Step, self).__setattr__(a, kwds.get(a)) | ||||
| self.api = kwds.get("api") | self.api = kwds.get("api") | ||||
| self.id = kwds.get("id") | self.id = kwds.get("id") | ||||
| self.name = kwds.get("name") | self.name = kwds.get("name") | ||||
| @@ -72,11 +72,14 @@ class ActorCore(object): | |||||
| def init_one(self, id): | def init_one(self, id): | ||||
| try: | try: | ||||
| print "INIT ONE ACTOR", id | |||||
| actor = self.cbpi.cache["actors"][id] | actor = self.cbpi.cache["actors"][id] | ||||
| clazz = self.cbpi.cache[self.key].get(actor.type)["class"] | clazz = self.cbpi.cache[self.key].get(actor.type)["class"] | ||||
| cfg = actor.config.copy() | cfg = actor.config.copy() | ||||
| cfg.update(dict(cbpi=self.cbpi, id=id)) | cfg.update(dict(cbpi=self.cbpi, id=id)) | ||||
| self.cbpi.cache["actors"][id].instance = clazz(**cfg) | self.cbpi.cache["actors"][id].instance = clazz(**cfg) | ||||
| actor.state = 0 | |||||
| actor.power = 100 | |||||
| self.cbpi.emit("INIT_ACTOR", id=id) | self.cbpi.emit("INIT_ACTOR", id=id) | ||||
| except Exception as e: | except Exception as e: | ||||
| print e | print e | ||||
| @@ -277,6 +280,7 @@ class CraftBeerPI(object): | |||||
| FORMAT = '%(asctime)-15s - %(levelname)s - %(message)s' | FORMAT = '%(asctime)-15s - %(levelname)s - %(message)s' | ||||
| logging.basicConfig(filename='./logs/app.log', level=logging.INFO, format=FORMAT) | logging.basicConfig(filename='./logs/app.log', level=logging.INFO, format=FORMAT) | ||||
| self.cache["messages"] = [] | self.cache["messages"] = [] | ||||
| self.cache["version"] = "3.1" | |||||
| self.modules = {} | self.modules = {} | ||||
| self.cache["users"] = {'manuel': {'pw': 'secret'}} | self.cache["users"] = {'manuel': {'pw': 'secret'}} | ||||
| self.addon = Addon(self) | self.addon = Addon(self) | ||||
| @@ -1,5 +1,5 @@ | |||||
| from modules.core.db import DBModel, get_db | from modules.core.db import DBModel, get_db | ||||
| from flask import json | |||||
| class Kettle(DBModel): | class Kettle(DBModel): | ||||
| __fields__ = ["name","sensor", "heater", "automatic", "logic", "config", "agitator", "target_temp"] | __fields__ = ["name","sensor", "heater", "automatic", "logic", "config", "agitator", "target_temp"] | ||||
| @@ -0,0 +1,19 @@ | |||||
| from flask import Blueprint | |||||
| from modules.core.core import cbpi, addon | |||||
| from flask_swagger import swagger | |||||
| from flask import json | |||||
| from flask import Blueprint | |||||
| @addon.core.initializer(order=22) | |||||
| def web(cbpi): | |||||
| s = Blueprint('web_view', __name__, template_folder='templates', static_folder='static') | |||||
| @s.route('/', methods=["GET"]) | |||||
| def index(): | |||||
| return s.send_static_file("index.html") | |||||
| print "REGISTER" | |||||
| cbpi.addon.core.add_menu_link("JQuery View", "/web_view") | |||||
| cbpi._app.register_blueprint(s, url_prefix='/web_view') | |||||
| @@ -0,0 +1,32 @@ | |||||
| <!doctype html> | |||||
| <html lang="en"> | |||||
| <head> | |||||
| <meta charset="utf-8"> | |||||
| <title>CraftBeerPi WebView</title> | |||||
| </head> | |||||
| <body> | |||||
| <div id="root" > | |||||
| <div id="kettle"> | |||||
| </div> | |||||
| </div> | |||||
| <!--script src="static/bundle.js" type="text/javascript"></script--> | |||||
| <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> | |||||
| <script> | |||||
| $(document).ready(function() { | |||||
| $.ajax({ | |||||
| url: "/api/system/dump", | |||||
| dataType: "json" | |||||
| }).then(function(data) { | |||||
| $.each(data.actors, function (i, val) { | |||||
| $( "#kettle" ).append("<div>"+ val.name +"</div>") | |||||
| }); | |||||
| }); | |||||
| }); | |||||
| </script> | |||||
| </body> | |||||
| </html> | |||||
| @@ -0,0 +1,3 @@ | |||||
| { | |||||
| "presets" : ["es2015", "stage-0", "react"] | |||||
| } | |||||
| @@ -0,0 +1,19 @@ | |||||
| from flask import Blueprint | |||||
| from modules.core.core import cbpi, addon | |||||
| from flask_swagger import swagger | |||||
| from flask import json | |||||
| from flask import Blueprint | |||||
| @addon.core.initializer(order=22) | |||||
| def web(cbpi): | |||||
| s = Blueprint('webviewreact', __name__, template_folder='templates', static_folder='static') | |||||
| @s.route('/', methods=["GET"]) | |||||
| def index(): | |||||
| return s.send_static_file("index.html") | |||||
| print "REGISTER" | |||||
| cbpi.addon.core.add_menu_link("ReactJS View", "/webviewreact") | |||||
| cbpi._app.register_blueprint(s, url_prefix='/webviewreact') | |||||
| @@ -0,0 +1,44 @@ | |||||
| { | |||||
| "name": "react-app2", | |||||
| "version": "0.1.0", | |||||
| "private": true, | |||||
| "devDependencies": { | |||||
| "react-scripts": "0.9.5" | |||||
| }, | |||||
| "dependencies": { | |||||
| "axios": "^0.16.1", | |||||
| "babel-core": "^6.18.2", | |||||
| "babel-loader": "^6.2.8", | |||||
| "babel-preset-es2015": "^6.18.0", | |||||
| "babel-preset-react": "^6.16.0", | |||||
| "babel-preset-stage-0": "^6.22.0", | |||||
| "classnames": "^2.2.5", | |||||
| "highcharts-boost": "^0.1.2", | |||||
| "highcharts-exporting": "^0.1.2", | |||||
| "highcharts-more": "^0.1.2", | |||||
| "immutability-helper": "^2.1.2", | |||||
| "rc-slider": "^7.0.8", | |||||
| "react": "^15.5.4", | |||||
| "react-bootstrap": "^0.30.10", | |||||
| "react-bs-notifier": "^4.3.2", | |||||
| "react-dom": "^15.5.4", | |||||
| "react-fileupload-progress": "^0.4.0", | |||||
| "react-highcharts": "^12.0.0", | |||||
| "react-js-diagrams": "^3.1.2", | |||||
| "react-jsonschema-form": "^0.50.1", | |||||
| "react-redux": "^5.0.4", | |||||
| "react-router-dom": "^4.1.1", | |||||
| "react-sortable-hoc": "^0.6.3", | |||||
| "redux": "^3.6.0", | |||||
| "redux-logger": "^3.0.1", | |||||
| "redux-thunk": "^2.2.0", | |||||
| "socket.io-client": "^1.7.3", | |||||
| "webpack": "^1.13.3" | |||||
| }, | |||||
| "scripts": { | |||||
| "start": "react-scripts start", | |||||
| "build": "react-scripts build", | |||||
| "test": "react-scripts test --env=jsdom", | |||||
| "eject": "react-scripts eject" | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,15 @@ | |||||
| <!doctype html> | |||||
| <html lang="en"> | |||||
| <head> | |||||
| <meta charset="utf-8"> | |||||
| <title>CraftBeerPi WebView</title> | |||||
| </head> | |||||
| <body> | |||||
| <div id="root" > | |||||
| </div> | |||||
| <script src="static/bundle.js" type="text/javascript"></script> | |||||
| </body> | |||||
| </html> | |||||
| @@ -0,0 +1,23 @@ | |||||
| from modules.core.core import cbpi, addon | |||||
| from flask_swagger import swagger | |||||
| from flask import json | |||||
| from flask import Blueprint | |||||
| @addon.core.initializer(order=22) | |||||
| def hello(cbpi): | |||||
| s = Blueprint('react', __name__, template_folder='templates', static_folder='static') | |||||
| @s.route('/', methods=["GET"]) | |||||
| def index(): | |||||
| return s.send_static_file("index.html") | |||||
| @s.route('/swagger.json', methods=["GET"]) | |||||
| def spec(): | |||||
| swag = swagger(cbpi._app) | |||||
| swag['info']['version'] = "3.0" | |||||
| swag['info']['title'] = "CraftBeerPi" | |||||
| return json.dumps(swag) | |||||
| cbpi.addon.core.add_menu_link("Swagger API", "/swagger") | |||||
| cbpi._app.register_blueprint(s, url_prefix='/swagger') | |||||
| @@ -0,0 +1,95 @@ | |||||
| <!-- HTML for static distribution bundle build --> | |||||
| <!DOCTYPE html> | |||||
| <html lang="en"> | |||||
| <head> | |||||
| <meta charset="UTF-8"> | |||||
| <title>Swagger UI</title> | |||||
| <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet"> | |||||
| <link rel="stylesheet" type="text/css" href="./static/swagger-ui.css" > | |||||
| <link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" /> | |||||
| <link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" /> | |||||
| <style> | |||||
| html | |||||
| { | |||||
| box-sizing: border-box; | |||||
| overflow: -moz-scrollbars-vertical; | |||||
| overflow-y: scroll; | |||||
| } | |||||
| *, | |||||
| *:before, | |||||
| *:after | |||||
| { | |||||
| box-sizing: inherit; | |||||
| } | |||||
| body { | |||||
| margin:0; | |||||
| background: #fafafa; | |||||
| } | |||||
| </style> | |||||
| </head> | |||||
| <body> | |||||
| <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position:absolute;width:0;height:0"> | |||||
| <defs> | |||||
| <symbol viewBox="0 0 20 20" id="unlocked"> | |||||
| <path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path> | |||||
| </symbol> | |||||
| <symbol viewBox="0 0 20 20" id="locked"> | |||||
| <path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"/> | |||||
| </symbol> | |||||
| <symbol viewBox="0 0 20 20" id="close"> | |||||
| <path d="M14.348 14.849c-.469.469-1.229.469-1.697 0L10 11.819l-2.651 3.029c-.469.469-1.229.469-1.697 0-.469-.469-.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-.469-.469-.469-1.228 0-1.697.469-.469 1.228-.469 1.697 0L10 8.183l2.651-3.031c.469-.469 1.228-.469 1.697 0 .469.469.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c.469.469.469 1.229 0 1.698z"/> | |||||
| </symbol> | |||||
| <symbol viewBox="0 0 20 20" id="large-arrow"> | |||||
| <path d="M13.25 10L6.109 2.58c-.268-.27-.268-.707 0-.979.268-.27.701-.27.969 0l7.83 7.908c.268.271.268.709 0 .979l-7.83 7.908c-.268.271-.701.27-.969 0-.268-.269-.268-.707 0-.979L13.25 10z"/> | |||||
| </symbol> | |||||
| <symbol viewBox="0 0 20 20" id="large-arrow-down"> | |||||
| <path d="M17.418 6.109c.272-.268.709-.268.979 0s.271.701 0 .969l-7.908 7.83c-.27.268-.707.268-.979 0l-7.908-7.83c-.27-.268-.27-.701 0-.969.271-.268.709-.268.979 0L10 13.25l7.418-7.141z"/> | |||||
| </symbol> | |||||
| <symbol viewBox="0 0 24 24" id="jump-to"> | |||||
| <path d="M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z"/> | |||||
| </symbol> | |||||
| <symbol viewBox="0 0 24 24" id="expand"> | |||||
| <path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z"/> | |||||
| </symbol> | |||||
| </defs> | |||||
| </svg> | |||||
| <div id="swagger-ui"></div> | |||||
| <script src="./static/swagger-ui-bundle.js"> </script> | |||||
| <script src="./static/swagger-ui-standalone-preset.js"> </script> | |||||
| <script> | |||||
| window.onload = function() { | |||||
| // Build a system | |||||
| const ui = SwaggerUIBundle({ | |||||
| url: "http://" + window.location.hostname + ":" + window.location.port + "/swagger/swagger.json", | |||||
| dom_id: '#swagger-ui', | |||||
| deepLinking: true, | |||||
| presets: [ | |||||
| SwaggerUIBundle.presets.apis, | |||||
| SwaggerUIStandalonePreset | |||||
| ], | |||||
| plugins: [ | |||||
| SwaggerUIBundle.plugins.DownloadUrl | |||||
| ], | |||||
| layout: "StandaloneLayout" | |||||
| }) | |||||
| window.ui = ui | |||||
| } | |||||
| </script> | |||||
| </body> | |||||
| </html> | |||||
| @@ -0,0 +1,57 @@ | |||||
| <!doctype html> | |||||
| <html lang="en-US"> | |||||
| <body onload="run()"> | |||||
| </body> | |||||
| </html> | |||||
| <script> | |||||
| 'use strict'; | |||||
| function run () { | |||||
| var oauth2 = window.opener.swaggerUIRedirectOauth2; | |||||
| var sentState = oauth2.state; | |||||
| var redirectUrl = oauth2.redirectUrl; | |||||
| var isValid, qp, arr; | |||||
| if (/code|token|error/.test(window.location.hash)) { | |||||
| qp = window.location.hash.substring(1); | |||||
| } else { | |||||
| qp = location.search.substring(1); | |||||
| } | |||||
| arr = qp.split("&") | |||||
| arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';}) | |||||
| qp = qp ? JSON.parse('{' + arr.join() + '}', | |||||
| function (key, value) { | |||||
| return key === "" ? value : decodeURIComponent(value) | |||||
| } | |||||
| ) : {} | |||||
| isValid = qp.state === sentState | |||||
| if (oauth2.auth.schema.get("flow") === "accessCode" && !oauth2.auth.code) { | |||||
| if (!isValid) { | |||||
| oauth2.errCb({ | |||||
| authId: oauth2.auth.name, | |||||
| source: "auth", | |||||
| level: "warning", | |||||
| message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server" | |||||
| }); | |||||
| } | |||||
| if (qp.code) { | |||||
| delete oauth2.state; | |||||
| oauth2.auth.code = qp.code; | |||||
| oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl}); | |||||
| } else { | |||||
| oauth2.errCb({ | |||||
| authId: oauth2.auth.name, | |||||
| source: "auth", | |||||
| level: "error", | |||||
| message: "Authorization failed: no accessCode received from the server" | |||||
| }); | |||||
| } | |||||
| } else { | |||||
| oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl}); | |||||
| } | |||||
| window.close(); | |||||
| } | |||||
| </script> | |||||
| @@ -0,0 +1 @@ | |||||
| {"version":3,"file":"swagger-ui-bundle.js","sources":["webpack:///swagger-ui-bundle.js"],"mappings":"AAAA;;;;;AAu7LA;;;;;;AA65DA;;;;;;;;;;;;;;;;;;;;;;;;;;AA68TA;;;;;;;;;;;;;;AAs8JA;;;;;;;;;AA69pBA;;;;;AA81QA;AAm4DA;;;;;;AAo4YA;;;;;;AA0iaA;AA4lvBA","sourceRoot":""} | |||||
| @@ -0,0 +1 @@ | |||||
| {"version":3,"file":"swagger-ui-standalone-preset.js","sources":["webpack:///swagger-ui-standalone-preset.js"],"mappings":"AAAA;;;;;AA80CA;;;;;;AAqpFA","sourceRoot":""} | |||||
| @@ -0,0 +1 @@ | |||||
| {"version":3,"file":"swagger-ui.css","sources":[],"mappings":"","sourceRoot":""} | |||||
| @@ -0,0 +1 @@ | |||||
| {"version":3,"file":"swagger-ui.js","sources":["webpack:///swagger-ui.js"],"mappings":"AAAA;;;;;;AAokeA","sourceRoot":""} | |||||
| @@ -227,10 +227,13 @@ def execute_step(api): | |||||
| step = cbpi.cache.get("active_step") | step = cbpi.cache.get("active_step") | ||||
| if step is not None: | if step is not None: | ||||
| step.execute() | step.execute() | ||||
| if step.is_dirty(): | if step.is_dirty(): | ||||
| state = {} | state = {} | ||||
| for field in step.managed_fields: | for field in step.managed_fields: | ||||
| state[field] = step.__getattribute__(field) | state[field] = step.__getattribute__(field) | ||||
| Step.update_step_state(step.id, state) | Step.update_step_state(step.id, state) | ||||
| step.reset_dirty() | step.reset_dirty() | ||||
| cbpi.ws_emit("UPDATE_ALL_STEPS", Step.get_all()) | cbpi.ws_emit("UPDATE_ALL_STEPS", Step.get_all()) | ||||
| @@ -1,3 +1,4 @@ | |||||
| import flask_login | |||||
| import yaml | import yaml | ||||
| from flask import json, url_for, Response | from flask import json, url_for, Response | ||||
| from flask_classy import FlaskView, route | from flask_classy import FlaskView, route | ||||
| @@ -7,6 +8,8 @@ from modules.core.core import cbpi | |||||
| import pprint | import pprint | ||||
| import time | import time | ||||
| from modules.login import User | |||||
| class SystemView(FlaskView): | class SystemView(FlaskView): | ||||
| def doShutdown(self): | def doShutdown(self): | ||||
| @@ -149,6 +152,10 @@ class SystemView(FlaskView): | |||||
| 200: | 200: | ||||
| description: CraftBeerPi System Cache | description: CraftBeerPi System Cache | ||||
| """ | """ | ||||
| if cbpi.get_config_parameter("password_security", "NO") == "NO": | |||||
| user = User() | |||||
| user.id = "craftbeerpi" | |||||
| flask_login.login_user(user) | |||||
| if self.api.get_config_parameter("setup", "YES") == "YES": | if self.api.get_config_parameter("setup", "YES") == "YES": | ||||
| return json.dumps(dict(setup=True, loggedin= current_user.is_authenticated )) | return json.dumps(dict(setup=True, loggedin= current_user.is_authenticated )) | ||||
| @@ -26,5 +26,8 @@ from modules.action import * | |||||
| from modules.base_plugins.actor import * | from modules.base_plugins.actor import * | ||||
| from modules.base_plugins.sensor import * | from modules.base_plugins.sensor import * | ||||
| from modules.base_plugins.steps import * | from modules.base_plugins.steps import * | ||||
| from modules.example_plugins.WebViewJquery import * | |||||
| from modules.example_plugins.WebViewReactJs import * | |||||
| from modules.example_plugins.swagger import * | |||||
| cbpi.run() | cbpi.run() | ||||
| @@ -1 +1,2 @@ | |||||
| INSERT OR IGNORE INTO config VALUES ('password', 'beer', 'text', 'LoginPassword', NULL ); | INSERT OR IGNORE INTO config VALUES ('password', 'beer', 'text', 'LoginPassword', NULL ); | ||||
| INSERT OR IGNORE INTO config VALUES ('password_security', 'NO', 'select', 'Show Login Dialog', '["YES","NO"]'); | |||||