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
b90bf1e4
Commit
b90bf1e4
authored
May 26, 2020
by
Vladislav Rykov
Browse files
application settings integrated & tested
parent
ac18fafa
Changes
5
Hide whitespace changes
Inline
Side-by-side
app/.gitignore
deleted
100644 → 0
View file @
ac18fafa
*.swp
app/app/__pycache__/views.cpython-37.pyc
View file @
b90bf1e4
No preview for this file type
app/app/templates/new/public/application-settings.html
0 → 100644
View file @
b90bf1e4
{% extends 'logged_layout.html' %}
{% block title %} HPC
&
A IoT - Application Settings {% endblock %}
{% block location %}
<a
class=
"h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"
href=
"/applications"
>
Applications
</a>
<p
class=
"h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"
>
-
</p>
<a
class=
"h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"
href=
"/application/{{ app[1] }}"
>
{{ app[0] }}
</a>
{% endblock %}
{% block body %}
<!-- Page content -->
<div
class=
"container-fluid mt--7"
>
<!-- Table -->
<div
class=
"row"
>
<div
class=
"col"
>
<div
class=
"card shadow"
>
<div
class=
"card-header bg-transparent"
>
<h3
class=
"mb-0"
>
Application Settings
</h3>
</div>
<div
class=
"card-body"
>
<form
action=
"/application/{{ app[1] }}/settings"
method=
"post"
id=
"appsettings"
>
<div
class=
"form-group"
>
<label>
Name:
</label><br>
<input
type=
"text"
maxlength=
"30"
class=
"form-control"
id=
"appname"
name=
"appname"
value=
"{{ app[0] }}"
required
><br>
</div>
<div
class=
"form-group"
>
<label>
Description:
</label><br>
<textarea
id=
"appdesc"
maxlength=
"200"
class=
"form-control"
name=
"appdesc"
rows=
"5"
></textarea>
</div>
<br>
<div
class=
"custom-control custom-control-alternative custom-checkbox"
>
<input
class=
"custom-control-input"
id=
"secure"
type=
"checkbox"
name=
"secure"
{%
if
app
[4]
%}
checked
{%
endif
%}
>
<label
class=
"custom-control-label"
for=
"secure"
>
<span
class=
"text-muted"
>
Secure
</span>
</label>
</div>
<br>
<p>
Note, if you use secure option, make sure your device uses aes128 ctr with the corresponding key.
</p>
<br>
</form>
<div
class=
"row"
style=
"margin-top: 30px;"
>
<div
class=
"col-lg-3"
>
<button
type=
"submit"
form=
"appsettings"
class=
"btn btn-primary btn-block"
>
Save
</button>
</div>
<div
class=
"col-lg-3"
>
</div>
<div
class=
"col-lg-3"
>
</div>
<div
class=
"col-lg-3"
>
<button
type=
"button"
class=
"btn btn-danger btn-block"
data-toggle=
"modal"
data-target=
"#exampleModal"
>
Delete
</button>
<div
class=
"modal fade"
id=
"exampleModal"
tabindex=
"-1"
role=
"dialog"
aria-labelledby=
"exampleModalLabel"
aria-hidden=
"true"
>
<div
class=
"modal-dialog"
>
<div
class=
"modal-content"
>
<div
class=
"modal-header"
>
<h5
class=
"modal-title"
id=
"exampleModalLabel"
>
Are you sure?
</h5>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-label=
"Close"
>
<span
aria-hidden=
"true"
>
×
</span>
</button>
</div>
<div
class=
"modal-body"
>
This action will remove permanently the application and all its devices with their corresponding data.
</div>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-secondary"
data-dismiss=
"modal"
>
Close
</button>
<a
href=
"/application/{{ app[1] }}/delete"
><button
type=
"button"
class=
"btn btn-danger"
>
Delete Application
</button></a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block script %}
<script
type=
"text/javascript"
>
document
.
getElementById
(
"
appdesc
"
).
value
=
"
{{ app[3] }}
"
;
</script>
{% endblock %}
app/app/templates/new/public/new-application.html
View file @
b90bf1e4
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
<div
class=
"col"
>
<div
class=
"col"
>
<div
class=
"card shadow"
>
<div
class=
"card shadow"
>
<div
class=
"card-header bg-transparent"
>
<div
class=
"card-header bg-transparent"
>
<h3
class=
"mb-0"
>
Application
s
</h3>
<h3
class=
"mb-0"
>
New
Application
</h3>
</div>
</div>
<div
class=
"card-body"
>
<div
class=
"card-body"
>
<form
action=
"new-application"
method=
"post"
>
<form
action=
"new-application"
method=
"post"
>
...
...
app/app/views.py
View file @
b90bf1e4
...
@@ -137,7 +137,7 @@ def application(appkey):
...
@@ -137,7 +137,7 @@ def application(appkey):
@
app
.
route
(
'/new-application'
,
methods
=
[
'GET'
,
'POST'
])
@
app
.
route
(
'/new-application'
,
methods
=
[
'GET'
,
'POST'
])
def
new_
application
():
def
application
_create
():
if
'name'
in
session
:
if
'name'
in
session
:
if
request
.
method
==
'GET'
:
if
request
.
method
==
'GET'
:
return
render_template
(
'new/public/new-application.html'
)
return
render_template
(
'new/public/new-application.html'
)
...
@@ -145,7 +145,7 @@ def new_application():
...
@@ -145,7 +145,7 @@ def new_application():
if
request
.
form
[
'appname'
]
==
''
:
if
request
.
form
[
'appname'
]
==
''
:
flash
(
'Application name cannot be empty.'
,
'danger'
)
flash
(
'Application name cannot be empty.'
,
'danger'
)
return
render_template
(
request
.
url
)
return
render_template
(
request
.
url
)
el
se
:
el
if
request
.
method
==
'POST'
:
appkey
=
misc
.
rand_str
(
app
.
config
[
'APPKEY_LENGTH'
]).
decode
(
'utf-8'
)
appkey
=
misc
.
rand_str
(
app
.
config
[
'APPKEY_LENGTH'
]).
decode
(
'utf-8'
)
secure_key
=
misc
.
gen_skey_b64
(
16
)
secure_key
=
misc
.
gen_skey_b64
(
16
)
secure
=
False
secure
=
False
...
@@ -171,6 +171,28 @@ def new_application():
...
@@ -171,6 +171,28 @@ def new_application():
return
redirect
(
url_for
(
'login'
,
users_signup
=
app
.
config
[
'USERS_SIGNUP'
]))
return
redirect
(
url_for
(
'login'
,
users_signup
=
app
.
config
[
'USERS_SIGNUP'
]))
@
app
.
route
(
'/application/<appkey>/delete'
)
def
application_delete
(
appkey
):
if
'name'
in
session
:
devs
=
dd
.
get_list
(
appkey
)
for
dev
in
devs
[
1
]:
data
.
delete_table
(
appkey
,
dev
[
1
])
dd
.
delete_table
(
appkey
)
res
=
ad
.
delete
(
appkey
)
if
not
res
[
0
]:
flash
(
'Error deleting application: {}'
.
format
(
res
[
1
]),
'danger'
)
return
redirect
(
url_for
(
'application'
,
appkey
=
appkey
))
else
:
flash
(
'Application deleted.'
,
'success'
)
return
redirect
(
url_for
(
'applications'
))
else
:
return
redirect
(
url_for
(
'login'
))
@
app
.
route
(
'/application/<appkey>/device/<devid>'
)
@
app
.
route
(
'/application/<appkey>/device/<devid>'
)
def
application_device
(
appkey
,
devid
):
def
application_device
(
appkey
,
devid
):
if
'name'
in
session
:
if
'name'
in
session
:
...
@@ -842,6 +864,30 @@ def application_new_automation(appkey):
...
@@ -842,6 +864,30 @@ def application_new_automation(appkey):
return
redirect
(
url_for
(
'login'
))
return
redirect
(
url_for
(
'login'
))
@
app
.
route
(
'/application/<appkey>/settings'
,
methods
=
[
'GET'
,
'POST'
])
def
application_settings
(
appkey
):
if
'name'
in
session
:
if
request
.
method
==
'GET'
:
ap
=
ad
.
get
(
appkey
)
return
render_template
(
'new/public/application-settings.html'
,
app
=
ap
[
1
])
elif
request
.
method
==
'POST'
:
if
request
.
form
.
getlist
(
'secure'
)
and
request
.
form
.
getlist
(
'secure'
)[
0
]
==
'on'
:
secure
=
True
else
:
secure
=
False
res
=
ad
.
update
(
appkey
,
request
.
form
[
'appname'
],
request
.
form
[
'appdesc'
],
secure
)
if
not
res
[
0
]:
flash
(
'Error: {}'
.
format
(
res
[
1
]),
'danger'
)
return
render_template
(
request
.
url
)
return
redirect
(
request
.
url
)
else
:
return
redirect
(
url_for
(
'login'
))
@
app
.
route
(
'/alerts'
)
@
app
.
route
(
'/alerts'
)
def
alerts
():
def
alerts
():
if
'name'
in
session
:
if
'name'
in
session
:
...
@@ -850,6 +896,7 @@ def alerts():
...
@@ -850,6 +896,7 @@ def alerts():
else
:
else
:
return
redirect
(
url_for
(
'index'
))
return
redirect
(
url_for
(
'index'
))
@
app
.
route
(
'/new-alert'
)
@
app
.
route
(
'/new-alert'
)
def
new_alert
():
def
new_alert
():
if
'name'
in
session
:
if
'name'
in
session
:
...
...
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