Commit 02c902f0 authored by Jan Čermák's avatar Jan Čermák

notification dismissing frontend and backend

parent e33cdc48
......@@ -270,6 +270,16 @@ def index():
notifications=notifications.new)
@app.route("/notifications/dismiss", method="POST")
@login_required
def dismiss_notifications():
message_ids = request.POST.getall("message_ids[]")
result = client.dismiss_notifications(message_ids)
if result:
return {'success': True, 'displayedIDs': message_ids}
return {'success': False}
@app.route("/<page_name:re:.+>/", name="config_page")
@login_required
def config_page_get(page_name):
......
......@@ -120,6 +120,16 @@ def get_messages():
return []
def dismiss_notifications(message_ids):
try:
logger.debug(message_ids)
logger.debug(ET.tostring(user_notify.UserNotify.rpc_display(message_ids)))
dispatch(user_notify.UserNotify.rpc_display(message_ids))
return True
except (RPCError, TimeoutExpiredError):
return False
def ntp_update():
get_tag = time.Time.qual_tag("ntp")
element = ET.Element(get_tag)
......
......@@ -4,4 +4,6 @@ Foris.messages.ok = "OK";
Foris.messages.error = "Chyba";
Foris.messages.loading = "Načítám...";
Foris.messages.checkNoForward = "Test připojení se nezdařil, probíhá test připojení s vypnutým forwardováním.";
Foris.messages.lanIpChanged = 'IP adresa Vašeho routeru se změnila. Router by měl nyní být dostupný na adrese <a href="%NEW_LOC%">%IP_ADDR%</a>. Více informací o změně IP adresy najdete výše.';
\ No newline at end of file
Foris.messages.lanIpChanged = 'IP adresa Vašeho routeru se změnila. Router by měl nyní být dostupný na adrese <a href="%NEW_LOC%">%IP_ADDR%</a>. Více informací o změně IP adresy najdete výše.';
Foris.messages.confirmRestart = "Opravdu chcete restartovat router?";
Foris.messages.confirmRestartExtra = "\nZbývající nepřečtené zprávy (%UNREAD%) budou smazány.";
\ No newline at end of file
......@@ -23,7 +23,9 @@ var Foris = {
error: "Error",
loading: "Loading...",
checkNoForward: "Connectivity test failed, testing connection with disabled forwarding.",
lanIpChanged: 'The IP address of your router has been changed. It should be accessible from <a href="%NEW_LOC%">%IP_ADDR%</a>. See the note above for more information about IP address change.'
lanIpChanged: 'The IP address of your router has been changed. It should be accessible from <a href="%NEW_LOC%">%IP_ADDR%</a>. See the note above for more information about IP address change.',
confirmRestart: "Are you sure you want to restart the router?",
confirmRestartExtra: "\nRemaining unread messages (%UNREAD%) will be deleted."
}
};
......@@ -316,6 +318,34 @@ Foris.initWiFiQR = function () {
});
};
Foris.initNotifications = function (csrf_token) {
$(".notification .reboot").on("click", function() {
var unread = $(".notification:visible").length - 1;
var extraMessage = "";
if (unread > 0)
extraMessage = Foris.messages.confirmRestartExtra.replace(/%UNREAD%/g, unread);
return confirm(Foris.messages.confirmRestart + extraMessage);
});
$(".notification .dismiss").on("click", function(e) {
e.preventDefault();
var id = $(this).data("id");
$.post("/config/notifications/dismiss",
{
message_ids: [id],
csrf_token: csrf_token
},
function(data) {
if (data.success) {
for (var i=0; i < data.displayedIDs.length; i++) {
$("#notification_" + data.displayedIDs[i]).fadeOut(800);
}
}
}
);
});
};
$(document).ready(function () {
Foris.initialize();
......
......@@ -273,6 +273,22 @@ button
margin-bottom: 1em
position: relative
.button
background-color: #fff
color: $highlight-color
.buttons
margin-top: 1em
.dismiss
position: absolute
right: 0.2em
top: 0.2em
text-decoration: none
font-weight: bold
font-size: 200%
color: inherit
&.restart
background-color: $message-color-error
color: #fff
......@@ -481,6 +497,9 @@ input[type="checkbox"], input[type="radio"], input[type="file"]
height: 120px
line-height: 120px
a
color: inherit
.logo-turris
display: inline-block
position: absolute
......
......@@ -17,7 +17,7 @@
%if not defined('is_xhr'):
%rebase _layout **locals()
<div id="config-header">
<h1>{{ trans("Settings") }}</h1>
<h1><a href="{{ url("config_index") }}">{{ trans("Settings") }}</a></h1>
<div class="logo-turris"><img src="{{ static("img/logo-turris.png") }}" alt="{{ trans("Project:Turris") }}"></div>
<a id="logout" href="{{ url("logout") }}">{{ trans("Log out") }}</a>
</div>
......
......@@ -23,12 +23,22 @@
%if len(notifications):
%for notification in notifications:
<div class="notification {{ notification.severity }}">
<div class="notification {{ notification.severity }}" id="notification_{{ notification.id }}">
{{! notification.escaped_body }}
%if notification.requires_restart:
<div class="buttons">
<a href="{{ url("config_action", page_name="maintenance", action="reboot") }}" class="button reboot">{{ trans("Reboot now") }}</a>
</div>
%else:
<a href="#" class="dismiss" title="{{ trans("Dismiss") }}" data-id="{{ notification.id }}">&times;</a>
%end
</div>
%end
%else:
<strong>{{ trans("No new messages.") }}</strong>
%end
<script>
Foris.initNotifications("{{ get_csrf_token() }}");
</script>
</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment