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
58c52665
Commit
58c52665
authored
Jun 02, 2020
by
Vladislav Rykov
Browse files
admin:user app dev configuration view completely integrated
parent
e5e3d2e9
Changes
5
Hide whitespace changes
Inline
Side-by-side
app/app/__pycache__/views.cpython-37.pyc
View file @
58c52665
No preview for this file type
app/app/__pycache__/views_admin.cpython-37.pyc
View file @
58c52665
No preview for this file type
app/app/templates/new/admin/user-application-device-configuration.html
0 → 100644
View file @
58c52665
{% extends 'logged_layout.html' %}
{% block title %} HPC
&
A IoT - Device Configuration {% endblock %}
{% block header %}
<link
href=
"https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
rel=
"stylesheet"
>
<script
type=
"text/javascript"
src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"
></script>
{% endblock %}
{% block location %}
<a
class=
"h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"
href=
"/administration"
>
Administration
</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=
"/administration/users"
>
Users
</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=
"/administration/users/{{ user }}"
>
{{ user }}
</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=
"/administration/users/{{ user }}/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=
"/administration/users/{{ user }}/application/{{ app[1] }}"
>
{{ app[0] }}
</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=
"/administration/users/{{ user }}/application/{{ app[1] }}/device/{{ dev[1] }}"
>
{{ dev[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"
>
Device Configuration
</h3>
</div>
<div
class=
"card-body"
>
<form
id=
"confform"
onsubmit=
"onsub()"
>
<div
class=
"form-group"
>
<label>
Config ID:
</label><br>
<input
type=
"number"
min=
"0"
max=
"255"
size=
"3"
class=
"form-control"
id=
"confid"
name=
"confid"
required
><br>
</div>
<div
class=
"form-group"
>
<label>
Argument:
</label><br>
<textarea
id=
"arg"
name=
"arg"
class=
"form-control"
maxlength=
"50"
name=
"appdesc"
rows=
"2"
required
></textarea>
</div>
<br>
<div
class=
"form-group"
>
<button
type=
"submit"
class=
"btn btn-primary"
>
Configure
</button>
</div>
<br>
</form>
<div
class=
"card-header bg-transparent"
>
<h3
class=
"mb-0"
id=
"confhistory"
>
Configuration history
</h3>
</div>
{% if config_list %}
<table
class=
"table"
>
<thead>
<th>
Config ID
</th>
<th>
Arguments
</th>
<th>
Status
</th>
<th>
</th>
</thead>
<tbody>
{% for c in config_list %}
<td>
{{ c[0] }}
</td>
<td>
{{ c[1] }}
</td>
<td>
<span
class=
"badge badge-dot"
>
{% if c[2] %}
<i
class=
"bg-success"
></i>
Completed
{% else %}
<i
class=
"bg-warning"
></i>
Pending
{% endif %}
</span>
</td>
<td>
<a
href=
"javascript:void(0)"
onclick=
"return remove_configuration('{{ c[3][0:-1] }}')"
>
<span
class=
"fa fa-remove"
>
</span>
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<div
class=
"col-lg-12"
>
<center><p
style=
"margin-top: 35px;"
>
No configuration messages.
</p></center>
</div>
{% endif %}
</div>
</div>
</div>
</div>
{% endblock %}
{% block script %}
<script
type=
"text/javascript"
>
function
onsub
()
{
$
.
ajax
({
url
:
"
/administration/users/{{ user }}/application/{{ app[1] }}/device/{{ dev[1] }}/configure
"
,
type
:
"
post
"
,
data
:
$
(
"
#confform
"
).
serialize
(),
success
:
function
()
{
location
.
reload
();
}
});
}
function
remove_configuration
(
b64
)
{
$
.
ajax
({
url
:
"
/administration/users/{{ user }}/application/{{ app[1] }}/device/{{ dev[1] }}/remove-configuration?conf=
"
+
b64
,
type
:
"
get
"
,
success
:
function
()
{
location
.
reload
();
}
});
}
</script>
{% endblock %}
app/app/views.py
View file @
58c52665
...
...
@@ -488,7 +488,7 @@ def dev_conf():
return
redirect
(
url_for
(
'index'
))
@
app
.
route
(
'/application/<appkey>/device/<devid>/remove-configuration'
)
def
dev_conf_rm
(
appkey
,
devid
):
def
application_device_configuration_remove
(
appkey
,
devid
):
if
'name'
in
session
:
res
=
pend
.
delete
(
appkey
,
devid
,
request
.
args
.
get
(
'conf'
)
+
'_'
)
...
...
app/app/views_admin.py
View file @
58c52665
...
...
@@ -16,7 +16,7 @@ import app.dao.misc.misc as md
from
app.helpers.misc
import
restricted
import
app.helpers.misc
as
misc
#
import binascii
import
binascii
MAX_PG
=
5
...
...
@@ -342,6 +342,45 @@ def administration_users_user_application_device_data(name, appkey, devid, var,
return
t
@
app
.
route
(
'/administration/users/<name>/application/<appkey>/device/<devid>/configure'
,
methods
=
[
'GET'
,
'POST'
])
@
restricted
(
access_level
=
'admin'
)
def
administration_users_user_application_device_configuration
(
name
,
appkey
,
devid
):
if
request
.
method
==
'GET'
:
pend_msgs
=
pend
.
get_list
(
appkey
,
devid
)
ap
=
ad
.
get
(
appkey
)[
1
]
dev
=
dd
.
get
(
appkey
,
devid
)[
1
]
if
pend_msgs
[
0
]:
config_list
=
[]
for
pm
in
pend_msgs
[
1
]:
cntt
=
binascii
.
a2b_base64
(
pm
[
2
])
config_id
=
int
(
cntt
[
0
])
config_args
=
cntt
[
2
:(
len
(
cntt
)
-
1
)].
decode
(
'utf-8'
)
ack
=
pm
[
3
]
config_list
.
append
((
config_id
,
config_args
,
ack
,
pm
[
2
]))
return
render_template
(
'new/admin/user-application-device-configuration.html'
,
dev
=
dev
,
app
=
ap
,
config_list
=
config_list
,
user
=
name
)
elif
request
.
method
==
'POST'
:
base64_args
=
misc
.
pend_base64_encode
(
request
.
form
[
'arg'
],
request
.
form
[
'confid'
])
pend
.
create
(
appkey
,
devid
,
base64_args
)
flash
(
'Message enqueued'
,
'success'
)
return
''
,
201
@
app
.
route
(
'/administration/users/<name>/application/<appkey>/device/<devid>/remove-configuration'
)
@
restricted
(
access_level
=
'admin'
)
def
administration_users_user_application_device_configuration_remove
(
name
,
appkey
,
devid
):
res
=
pend
.
delete
(
appkey
,
devid
,
request
.
args
.
get
(
'conf'
)
+
'_'
)
if
res
[
0
]:
flash
(
'Configuration message successfully removed.'
,
'success'
)
else
:
flash
(
'Error removing configuration message: {}'
.
format
(
res
[
1
]),
'danger'
)
return
''
,
200
@
app
.
route
(
'/administration/users/<name>/chart-update'
)
@
restricted
(
access_level
=
'admin'
)
def
administration_users_user_chart_update
(
name
):
...
...
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