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
b9d157c6
Commit
b9d157c6
authored
Oct 28, 2020
by
Vladislav Rykov
Browse files
gateway front-end management fully added & tested
parent
70503a0f
Changes
5
Hide whitespace changes
Inline
Side-by-side
app/app/__pycache__/views_admin.cpython-37.pyc
View file @
b9d157c6
No preview for this file type
app/app/dao/gateway/gateway.py
View file @
b9d157c6
from
app.helpers.misc
import
with_psql
from
app.helpers.misc
import
with_psql
from
psycopg2
import
Binary
@
with_psql
@
with_psql
def
create
(
cur
,
name
,
gwid
,
protocol
,
desc
,
secure_key
,
telemetry_send_freq
):
def
create
(
cur
,
name
,
gwid
,
protocol
,
desc
,
secure_key
,
telemetry_send_freq
):
...
@@ -29,7 +28,7 @@ def get_all(cur):
...
@@ -29,7 +28,7 @@ def get_all(cur):
@
with_psql
@
with_psql
def
delete
(
cur
,
gwid
):
def
delete
(
cur
,
gwid
):
cur
.
execute
(
'DELETE FROM gateways WHERE id = %s'
,
gwid
)
cur
.
execute
(
'DELETE FROM gateways WHERE id = %s'
,
(
gwid
,)
)
return
(
True
,)
return
(
True
,)
...
...
app/app/templates/views/admin/gateway-settings.html
View file @
b9d157c6
...
@@ -2,6 +2,10 @@
...
@@ -2,6 +2,10 @@
{% block title %} Administration - Gateway - {{ gw['id'] }} - Settings - HPC
&
A IoT {% endblock %}
{% block title %} Administration - Gateway - {{ gw['id'] }} - Settings - HPC
&
A IoT {% endblock %}
{% block header %}
<script
type=
"text/javascript"
src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"
></script>
{% endblock %}
{% block location %}
{% block location %}
<a
class=
"h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"
href=
"/administration"
>
Administration
</a>
<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>
<p
class=
"h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"
>
-
</p>
...
@@ -73,7 +77,7 @@
...
@@ -73,7 +77,7 @@
</div>
</div>
<div
class=
"modal-footer"
>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-secondary"
data-dismiss=
"modal"
>
Close
</button>
<button
type=
"button"
class=
"btn btn-secondary"
data-dismiss=
"modal"
>
Close
</button>
<
a
href=
"/administration/gateway/{{ gw['id'] }}/delete"
><button
type=
"button
"
class=
"btn btn-danger"
>
Delete Gateway
</button>
</a>
<
button
type=
"button"
onclick=
"gateway_delete({{ gw['id'] }})
"
class=
"btn btn-danger"
>
Delete Gateway
</button>
</div>
</div>
</div>
</div>
</div>
</div>
...
@@ -90,5 +94,16 @@
...
@@ -90,5 +94,16 @@
{% block script %}
{% block script %}
<script
type=
"text/javascript"
>
<script
type=
"text/javascript"
>
document
.
getElementById
(
"
gwdesc
"
).
value
=
"
{{ gw['description'] }}
"
;
document
.
getElementById
(
"
gwdesc
"
).
value
=
"
{{ gw['description'] }}
"
;
function
gateway_delete
(
gwid
)
{
$
.
ajax
({
url
:
"
/administration/gateway/
"
+
gwid
+
"
/delete
"
,
type
:
"
DELETE
"
,
success
:
function
()
{
console
.
log
(
"
success
"
);
window
.
location
.
href
=
"
/administration/gateways
"
;
}
});
}
</script>
</script>
{% endblock %}
{% endblock %}
app/app/views_admin.py
View file @
b9d157c6
...
@@ -650,7 +650,7 @@ def administration_user_delete_account(name):
...
@@ -650,7 +650,7 @@ def administration_user_delete_account(name):
return
redirect
(
url_for
(
'administration_user_settings'
,
name
=
name
))
return
redirect
(
url_for
(
'administration_user_settings'
,
name
=
name
))
@
app
.
route
(
'/administration/gateways'
)
@
app
.
route
(
'/administration/gateways'
,
methods
=
[
"GET"
,
"DELETE"
]
)
@
restricted
(
'admin'
)
@
restricted
(
'admin'
)
def
administration_gateways
():
def
administration_gateways
():
user_cnt
=
ud
.
get_count
()[
1
][
0
]
user_cnt
=
ud
.
get_count
()[
1
][
0
]
...
@@ -663,7 +663,7 @@ def administration_gateways():
...
@@ -663,7 +663,7 @@ def administration_gateways():
return
render_template
(
'views/admin/gateways.html'
,
utcnow
=
misc
.
get_utc
(),
info
=
info
,
gws
=
gws
)
return
render_template
(
'views/admin/gateways.html'
,
utcnow
=
misc
.
get_utc
(),
info
=
info
,
gws
=
gws
)
@
app
.
route
(
'/administration/gateway/<gwid>'
)
@
app
.
route
(
'/administration/gateway/<gwid>'
,
methods
=
[
"GET"
,
"POST"
,
"DELETE"
]
)
@
restricted
(
'admin'
)
@
restricted
(
'admin'
)
def
administration_gateway
(
gwid
):
def
administration_gateway
(
gwid
):
user_cnt
=
ud
.
get_count
()[
1
][
0
]
user_cnt
=
ud
.
get_count
()[
1
][
0
]
...
@@ -710,3 +710,14 @@ def administration_gateway_settings(gwid):
...
@@ -710,3 +710,14 @@ def administration_gateway_settings(gwid):
return
redirect
(
request
.
url
)
return
redirect
(
request
.
url
)
return
redirect
(
url_for
(
'administration_gateway'
,
gwid
=
gwid
))
return
redirect
(
url_for
(
'administration_gateway'
,
gwid
=
gwid
))
@
app
.
route
(
'/administration/gateway/<gwid>/delete'
,
methods
=
[
"DELETE"
])
@
restricted
(
'admin'
)
def
administration_gateway_delete
(
gwid
):
res
=
gd
.
delete
(
gwid
)
if
res
[
0
]:
flash
(
"Gateway '{}' deleted."
.
format
(
gwid
),
'success'
)
return
redirect
(
url_for
(
'administration_gateways'
))
else
:
flash
(
'Error: {}'
.
format
(
res
[
1
]),
'danger'
)
return
redirect
(
url_for
(
'administration_gateway'
,
gwid
=
gwid
))
db.sql
View file @
b9d157c6
...
@@ -95,16 +95,15 @@ CREATE TABLE public.notifications (
...
@@ -95,16 +95,15 @@ CREATE TABLE public.notifications (
action
character
varying
(
200
)
NOT
NULL
action
character
varying
(
200
)
NOT
NULL
);
);
-- ALTER TABLE public.notifications_queue OWNER TO pi;
CREATE
TABLE
public
.
gateways
(
name
character
varying
(
30
)
NOT
NULL
,
--
id
character
varying
(
20
)
NOT
NULL
,
-- Name: users; Type: TABLE; Schema: public; Owner: pi
protocol
character
varying
(
30
)
NOT
NULL
,
--
description
character
varying
(
300
),
CREATE
TABLE
public
.
notifications_queue
(
telemetry_send_freq
numeric
NOT
NULL
,
nf_id
character
varying
(
10
)
NOT
NULL
,
last_keep_alive
numeric
DEFAULT
0
,
app_key
character
varying
(
30
)
NOT
NULL
,
num_errors
numeric
DEFAULT
0
,
dev_id
numeric
(
3
)
NOT
NULL
,
last_report
character
varying
(
1000
)
fired_on
timestamp
(
6
)
NOT
NULL
DEFAULT
now
()
);
);
...
@@ -155,6 +154,12 @@ ALTER TABLE ONLY public.notifications
...
@@ -155,6 +154,12 @@ ALTER TABLE ONLY public.notifications
ADD
CONSTRAINT
notifications_app_key_fkey
FOREIGN
KEY
(
app_key
)
REFERENCES
public
.
applications
(
app_key
);
ADD
CONSTRAINT
notifications_app_key_fkey
FOREIGN
KEY
(
app_key
)
REFERENCES
public
.
applications
(
app_key
);
--
--
-- Name: gateways gateways_id_pkey; Type: CONSTRAINT; Schema: public; Owner: pi
--
ALTER
TABLE
ONLY
public
.
gateways
ADD
CONSTRAINT
gateways_id_pkey
PRIMARY
KEY
(
id
);
--
-- Name: notifications notifications_queue_pkey; Type: CONSTRAINT; Schema: public; Owner: pi
-- Name: notifications notifications_queue_pkey; Type: CONSTRAINT; Schema: public; Owner: pi
--
--
ALTER
TABLE
ONLY
public
.
notifications_queue
ALTER
TABLE
ONLY
public
.
notifications_queue
...
...
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