-Ui Changes

-Brew Steps added
-Clean AddOn Dialog
This commit is contained in:
Manuel83
2017-06-25 21:29:45 +02:00
parent f0b7c6e640
commit 00739ea38f
21 changed files with 297 additions and 75 deletions
+24 -6
View File
@@ -1,5 +1,5 @@
import time
from flask import json
from flask import json, request
from flask_classy import route
from modules import DBModel, cbpi, get_db
@@ -21,9 +21,9 @@ class Step(DBModel):
return r.get("order")
@classmethod
def get_by_state(cls, state):
def get_by_state(cls, state, order=True):
cur = get_db().cursor()
cur.execute("SELECT * FROM %s WHERE state = ?" % cls.__table_name__, state)
cur.execute("SELECT * FROM %s WHERE state = ? ORDER BY %s.'order'" % (cls.__table_name__,cls.__table_name__,), state)
r = cur.fetchone()
if r is not None:
return cls(r)
@@ -54,6 +54,16 @@ class Step(DBModel):
cur.execute("UPDATE %s SET stepstate = ? WHERE id =?" % cls.__table_name__, (json.dumps(state),id))
get_db().commit()
@classmethod
def sort(cls, new_order):
cur = get_db().cursor()
for e in new_order:
cur.execute("UPDATE %s SET '%s' = ? WHERE id = ?" % (cls.__table_name__, "order"), (e[1], e[0]))
get_db().commit()
class StepView(BaseView):
model = Step
def pre_post_callback(self, data):
@@ -61,6 +71,14 @@ class StepView(BaseView):
data["order"] = 1 if order is None else order + 1
data["state"] = "I"
@route('/sort', methods=["POST"])
def sort_steps(self):
Step.sort(request.json)
cbpi.emit("UPDATE_ALL_STEPS", self.model.get_all())
return ('', 204)
@route('/', methods=["DELETE"])
def deleteAll(self):
self.model.delete_all()
@@ -185,8 +203,10 @@ def init_after_startup():
if type_cfg is None:
# step type not found. cant restart step
return
print "STEP SATE......", step.stepstate
cfg = step.stepstate.copy()
cfg.update(dict(api=cbpi, id=step.id, timer_end=None, managed_fields=get_manged_fields_as_array(type_cfg)))
cfg.update(dict(api=cbpi, id=step.id, managed_fields=get_manged_fields_as_array(type_cfg)))
instance = type_cfg.get("class")(**cfg)
instance.init()
cbpi.cache["active_step"] = instance
@@ -214,9 +234,7 @@ def execute_step():
step = cbpi.cache.get("active_step")
if step is not None:
step.execute()
if step.is_dirty():
state = {}
for field in step.managed_fields:
state[field] = step.__getattribute__(field)