alarms can be edited from WebUI

refs #21
This commit is contained in:
boyska 2016-09-14 16:15:14 +02:00
parent d7fcdd3f09
commit 4e2e93b43c
5 changed files with 53 additions and 7 deletions

View file

@ -13,6 +13,10 @@ from larigira import forms
db = Blueprint('db', __name__, url_prefix='/db', template_folder='templates')
def get_model():
return current_app.larigira.controller.monitor.model
@db.route('/')
def home():
return render_template('dbadmin_base.html')
@ -33,17 +37,37 @@ def addtime():
return render_template('add_time.html', kinds=kinds)
@db.route('/edit/time/<int:alarmid>', methods=['GET', 'POST'])
def edit_time(alarmid):
model = get_model()
timespec = model.get_alarm_by_id(alarmid)
kind = timespec['kind']
Form, receiver = tuple(forms.get_timeform(kind))
form = Form()
if request.method == 'GET':
form.populate_from_timespec(timespec)
if request.method == 'POST' and form.validate():
data = receiver(form)
model.update_alarm(alarmid, data)
model.reload()
return redirect(url_for('db.list', _anchor='event-%d' % alarmid))
return render_template('add_time_kind.html',
form=form,
kind=kind,
mode='edit',
)
@db.route('/add/time/<kind>', methods=['GET', 'POST'])
def addtime_kind(kind):
Form, receiver = tuple(forms.get_timeform(kind))
form = Form()
if request.method == 'POST' and form.validate():
data = receiver(form)
model = current_app.larigira.controller.monitor.model
eid = model.add_alarm(data)
eid = get_model().add_alarm(data)
return redirect(url_for('db.edit_event', alarmid=eid))
return render_template('add_time_kind.html', form=form, kind=kind)
return render_template('add_time_kind.html', form=form, kind=kind, mode='add')
@db.route('/add/audio')

View file

@ -10,6 +10,11 @@
resubmit
</div>
{% endif %}
{% if mode == 'edit' %}
<div class="alert alert-info">
<strong>Note:</strong> You can change parameters, but you cannot change the <em>kind</em> of this alarm (yet)
</div>
{% endif %}
<div class="container-fluid">
{{wtf.quick_form(form)}}

View file

@ -17,17 +17,19 @@ $(function() {
{% block content %}
<div class="container-fluid">
{% for e, actions in events %}
<div class="event row">
<div class="event row" id="event-{{e.eid}}">
<h2>Event {{e.eid}} <small>{{e.nick if 'nick'}}</small> </h2>
<div class="col-md-8">
<h3>Time</h3>
<a class="button" href="{{url_for('db.edit_time', alarmid=e.eid)}}">
Change time for this event</a>
{{dict_table(e, ['nick', 'actions'])}}
</div>
<div class="actions col-md-4">
<h3>Audio</h3>
<a class="button" href="{{url_for('db.edit_event', alarmid=e.eid)}}">
Change audio for this event</a>
Change audios for this event</a>
<ol>
{% for a in actions %}
<li>

View file

@ -1,4 +1,4 @@
from __future__ import print_function
from datetime import datetime
from pytimeparse.timeparse import timeparse
from flask_wtf import Form
@ -23,6 +23,15 @@ class FrequencyAlarmForm(Form):
'(like 9w3d12h)')
submit = SubmitField(u'Submit')
def populate_from_timespec(self, timespec):
if 'nick' in timespec:
self.nick.data = timespec['nick']
if 'start' in timespec:
self.start.data = datetime.fromtimestamp(timespec['start'])
if 'end' in timespec:
self.end.data = datetime.fromtimestamp(timespec['end'])
self.interval.data = timespec['interval']
def validate_interval(form, field):
try:
int(field.data)

View file

@ -1,4 +1,4 @@
from __future__ import print_function
from datetime import datetime
from flask_wtf import Form
from wtforms import StringField, DateTimeField, validators, SubmitField
@ -12,6 +12,12 @@ class SingleAlarmForm(Form):
'YYYY-MM-DD HH:MM:SS')
submit = SubmitField(u'Submit')
def populate_from_timespec(self, timespec):
if 'nick' in timespec:
self.nick.data = timespec['nick']
if 'timestamp' in timespec:
self.dt.data = datetime.fromtimestamp(timespec['timestamp'])
def singlealarm_receive(form):
return {