Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Vladislav Rykov
THSO.server
Commits
cb9fe380
Commit
cb9fe380
authored
May 13, 2020
by
Vladislav Rykov
Browse files
alerts front end finished
parent
2372612c
Changes
10
Show whitespace changes
Inline
Side-by-side
app/app/__pycache__/views.cpython-37.pyc
View file @
cb9fe380
No preview for this file type
app/app/dao/notification/__pycache__/__init__.cpython-37.pyc
0 → 100644
View file @
cb9fe380
File added
app/app/dao/notification/__pycache__/notification.cpython-37.pyc
0 → 100644
View file @
cb9fe380
File added
app/app/dao/trigger/__pycache__/__init__.cpython-37.pyc
0 → 100644
View file @
cb9fe380
File added
app/app/dao/trigger/__pycache__/trigger.cpython-37.pyc
0 → 100644
View file @
cb9fe380
File added
app/app/dao/trigger/trigger.py
View file @
cb9fe380
...
...
@@ -63,7 +63,7 @@ def create_function(cur, appkey, devid, nfid, expr):
VALUES
({},{},{});
END IF;
"""
.
format
(
expr
[
0
],
get_type
(
expr
[
2
]),
expr
[
1
],
expr
[
2
]
"""
.
format
(
expr
[
0
],
get_type
(
expr
[
2
]),
expr
[
1
],
expr
[
2
]
,
ndif
,
appkey
,
devid
)
query
+=
"""
...
...
app/app/templates/public/al
arm
s.html
→
app/app/templates/public/al
ert
s.html
View file @
cb9fe380
{% extends 'layout.html' %}
{% block title %} Application Al
arm
s: {% endblock %}
{% block title %} Application Al
ert
s: {% endblock %}
{% block content %}
...
...
@@ -21,16 +21,16 @@
<th>
</th>
</thead>
<tbody>
{% for a in al
arm
_list %}
{% for a in al
ert
_list %}
<tr>
<th>
{{ a[3] }}
</th>
<th>
{{ a[4] }}
</th>
<th>
<a
href=
"/al
arm
-rm?id={{
c
[0] }}"
>
<span
class=
"glyphicon glyphicon-remove"
</
span
>
</a>
</th>
<th>
<a
href=
"/al
ert
-rm?id={{
a
[0] }}"
>
<span
class=
"glyphicon glyphicon-remove"
</
span
>
</a>
</th>
</tr>
{% endfor %}
</tbody>
</table>
<a
href=
"/new-al
arm
"
><button
class=
"btn btn-primary"
type=
"submit"
>
Create New Al
arm
</button></a>
<center>
<a
href=
"/new-al
ert
"
><button
class=
"btn btn-primary"
type=
"submit"
>
Create New Al
ert
</button></a>
</center>
</div>
{% else %}
<center>
There are no alarms for given application.
</center>
...
...
app/app/templates/public/app.html
View file @
cb9fe380
...
...
@@ -47,7 +47,7 @@
<center>
<a
href=
"/add-dev"
><button
type=
"submit"
class=
"btn btn-primary"
>
Add Device
</button></a>
<a
href=
"/al
arm
s"
><button
type=
"submit"
class
"
btn
btn-primary
"
>
Al
arm
s
</button></a>
<a
href=
"/al
ert
s"
><button
type=
"submit"
class
=
"btn btn-primary"
>
Al
ert
s
</button></a>
<a
href=
"/delete-app"
><button
type=
"submit"
class=
"btn btn-danger"
onclick=
"return confirm('Are you sure? It will remove all devices and data.');"
>
Delete Application
</button></a>
</center>
<br>
...
...
app/app/templates/public/new-alert.html
0 → 100644
View file @
cb9fe380
{% extends 'layout.html' %}
{% block title %} New Alert {% endblock %}
{% block content %}
<div
class=
"row"
>
<div
class=
"col-md-3"
>
<div
class=
"clickback"
>
<span
class=
"glyphicon glyphicon-arrow-left"
></span>
<p><a
class=
"backlink"
onclick=
"history.back(-1)"
></a></p>
</div>
</div>
<div
class=
"col-md-6"
>
<h2>
Create New Alert
</h2>
<br><br>
<form
id=
"alertform"
action=
"alert"
method=
"post"
>
<div
class=
"form-group"
>
<label>
Name:
</label><br>
<input
type=
"text"
maxlength=
"30"
class=
"form-control"
id=
"alertname"
name=
"alertname"
required
><br>
</div>
<div
class=
"form-group"
>
<label>
Description:
</label><br>
<textarea
id=
"alertdesc"
maxlength=
"300"
class=
"form-control"
name=
"alertdesc"
rows=
"5"
></textarea>
</div>
<h3>
Condition:
</h3>
<h4>
IF
</h4>
<select
class=
"form-control"
id=
"devid"
name=
"devid"
onchange=
"ondev()"
required
>
<option
default
value=
"-"
>
Select Device
</option>
{% for d in devs %}
<option
value=
"{{ d[1] }}"
>
{{ d[0] }}
</option>
{% endfor %}
</select>
<br>
{% if feedback %}
<p
class=
"text-danger float-right"
>
{{ feedback }}
</p>
{% endif %}
</form>
<br>
<h4>
THEN
</h4>
<h5>
Send email to
</h5>
<input
form=
"alertform"
class=
"form-control"
type=
"email"
id=
"email"
name=
"email"
placeholder=
"Type email..."
>
<br>
<div
class=
"form-group"
>
<button
form=
"alertform"
type=
"submit"
class=
"btn btn-primary"
>
Create Alert
</button>
</div>
</div>
</div>
<script
type=
"text/javascript"
>
function
ondev
()
{
var
dev_sel
=
document
.
getElementById
(
"
devid
"
);
var
sel_op
=
dev_sel
.
options
[
dev_sel
.
selectedIndex
].
value
;
if
(
!
document
.
getElementById
(
"
varname
"
))
{
if
(
sel_op
!=
"
-
"
)
{
fetch
(
window
.
origin
+
'
/dev-vars?id=
'
+
sel_op
).
then
(
res
=>
res
.
text
()).
then
(
data
=>
$
(
"
#alertform
"
).
append
(
data
));
}
}
else
{
if
(
sel_op
==
"
-
"
)
{
$
(
"
#varname
"
).
remove
();
}
}
}
function
onvar
()
{
if
(
!
document
.
getElementById
(
"
operation
"
))
{
$
(
"
#alertform
"
).
append
(
"
<br><select class='form-control' name='operaton' id='operation' onchange='onop()' required><option default>CHANGES</option><option>></option><option>>=</option><option><</option><option><=</option><option>==</option></select>
"
);
}
else
{
var
var_sel
=
document
.
getElementById
(
"
varname
"
);
var
sel_var
=
var_sel
.
options
[
var_sel
.
selectedIndex
].
value
;
if
(
sel_var
==
"
-
"
)
{
$
(
"
#operation
"
).
remove
();
}
}
}
function
onop
()
{
if
(
!
document
.
getElementById
(
"
value
"
))
{
var
op_sel
=
document
.
getElementById
(
"
operation
"
);
var
sel_op
=
op_sel
.
options
[
op_sel
.
selectedIndex
].
text
;
if
(
sel_op
!=
"
CHANGES
"
&&
!
document
.
getElementById
(
"
avalue
"
))
{
$
(
"
#alertform
"
).
append
(
"
<br><input type='numeric' class='form-control' name='avalue' id='avalue' placeholder='Value' required>
"
);
}
else
{
if
(
document
.
getElementById
(
"
avalue
"
))
{
$
(
"
#avalue
"
).
remove
();
}
}
}
}
</script>
{% endblock %}
app/app/views.py
View file @
cb9fe380
...
...
@@ -8,6 +8,8 @@ import app.dao.application.application as ad
import
app.dao.device.device
as
dd
import
app.dao.pend.pend
as
pend
import
app.dao.data.data
as
data
import
app.dao.notification.notification
as
nfs
import
app.dao.trigger.trigger
as
tr
import
app.helpers.misc
as
misc
...
...
@@ -281,6 +283,7 @@ def dev_conf_rm():
else
:
return
redirect
(
url_for
(
'index'
))
@
app
.
route
(
'/delete-dev'
)
def
delete_dev
():
if
'name'
in
session
and
'devid'
in
session
:
...
...
@@ -319,6 +322,20 @@ def dev_data_pg():
return
redirect
(
utl_for
(
'index'
))
@
app
.
route
(
'/dev-vars'
)
def
dev_vars
():
if
'name'
in
session
:
last
=
data
.
get_last_n
(
session
[
'appkey'
],
request
.
args
.
get
(
'id'
),
1
)
if
last
[
0
]:
select
=
'<select class="form-control" id="varname" name="varname" onchange="onvar(event)" required>'
select
+=
'<option value="-">Select Variable</option>'
for
k
in
last
[
1
][
0
][
2
]:
select
+=
'<option>'
+
k
+
'</option>'
select
+=
'</select>'
return
select
else
:
return
redirect
(
url_for
(
'index'
))
@
app
.
route
(
'/data-csv'
)
def
data_csv
():
...
...
@@ -441,6 +458,7 @@ def user_delete():
flash
(
'Warning: the user is admin or does not exist.'
,
'warning'
)
return
redirect
(
url_for
(
'index'
))
@
app
.
route
(
'/settings'
,
methods
=
[
'GET'
,
'POST'
])
def
settings
():
if
request
.
method
==
'GET'
:
...
...
@@ -498,11 +516,38 @@ def dev_data(var, dest, page):
return
t
@
app
.
route
(
'/alarms'
)
def
alarms
():
if
name
in
session
:
@
app
.
route
(
'/alerts'
)
def
alerts
():
if
'name'
in
session
:
alerts
=
nfs
.
get_list
(
session
[
'appkey'
])
return
render_template
(
'public/alerts.html'
,
alert_list
=
alerts
[
1
])
else
:
return
redirect
(
url_for
(
'index'
))
return
render_template
(
'public/alarms.html'
)
@
app
.
route
(
'/new-alert'
)
def
new_alert
():
if
'name'
in
session
:
devs
=
dd
.
get_list
(
session
[
'appkey'
])
return
render_template
(
'public/new-alert.html'
,
devs
=
devs
[
1
])
else
:
return
redirect
(
url_for
(
'index'
))
@
app
.
route
(
'/alert'
,
methods
=
[
'POST'
])
def
alert
():
pass
@
app
.
route
(
'/alert-rm'
)
def
alarm_rm
():
if
'name'
in
session
:
res
=
nfs
.
delete
(
session
[
'appkey'
],
request
.
args
.
get
(
'id'
))
if
res
[
0
]:
flash
(
'Alarm removed'
,
'success'
)
return
redirect
(
url_for
(
'alerts'
))
else
:
flash
(
'Alarm cannot be removed : {}'
.
format
(
res
[
1
]),
'danger'
)
return
redirect
(
url_for
(
'alerts'
))
else
:
return
redirect
(
url_for
(
'index'
))
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment