changed notify icon - added code to grab remote json from craftycontrol.com for announcements and such - icon turns red if update available

This commit is contained in:
Phillip Tarrant 2020-09-22 21:42:41 -04:00
parent 09a74ef188
commit 7f090b928f
6 changed files with 57 additions and 32 deletions

View File

@ -13,11 +13,13 @@ import logging
from datetime import datetime from datetime import datetime
from socket import gethostname from socket import gethostname
from app.classes.shared.console import console from app.classes.shared.console import console
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
try: try:
import requests
from OpenSSL import crypto from OpenSSL import crypto
from argon2 import PasswordHasher from argon2 import PasswordHasher
@ -96,6 +98,21 @@ class Helpers:
return version_data return version_data
@staticmethod
def get_announcements():
r = requests.get('https://craftycontrol.com/notify.json', timeout=2)
data = '[{"id":"1","date":"Unknown","title":"Error getting Announcements","desc":"Error getting ' \
'Announcements","link":""}] '
if r.status_code in [200, 201]:
try:
data = json.loads(r.content)
except:
pass
return data
def get_version_string(self): def get_version_string(self):
version_data = self.get_version() version_data = self.get_version()

View File

@ -74,6 +74,12 @@ class AjaxHandler(BaseHandler):
logger.warning("Skipping Log Line due to error: {}".format(e)) logger.warning("Skipping Log Line due to error: {}".format(e))
pass pass
elif page == "announcements":
data = helper.get_announcements()
page_data['notify_data'] = data
self.render_page('ajax/notify.html', page_data)
def post(self, page): def post(self, page):
user_data = json.loads(self.get_secure_cookie("user_data")) user_data = json.loads(self.get_secure_cookie("user_data"))
error = bleach.clean(self.get_argument('error', "WTF Error!")) error = bleach.clean(self.get_argument('error', "WTF Error!"))

View File

@ -26,6 +26,7 @@ class PanelHandler(BaseHandler):
defined_servers = controller.list_defined_servers() defined_servers = controller.list_defined_servers()
page_data = { page_data = {
'update_available': False,
'version_data': helper.get_version_string(), 'version_data': helper.get_version_string(),
'user_data': user_data, 'user_data': user_data,
'server_stats': { 'server_stats': {

View File

@ -0,0 +1,14 @@
{% for item in data['notify_data'] %}
<!-- <div class="hidden">{{ item['id'] }}</div>-->
<div class="event">
<p class="font-weight-medium">{{ item['title'] }}</p>
<a class="d-flex align-items-center">
<div class="badge badge-primary">{{ item['date'] }}</div>
<span class="text-muted ml-2">{{ item['desc'] }}</span>
</a>
</div>
{% end %}

View File

@ -45,7 +45,6 @@
<span class="mdi mdi-menu"></span> <span class="mdi mdi-menu"></span>
</button> </button>
{% include notify.html %} {% include notify.html %}
<button class="navbar-toggler navbar-toggler-right d-lg-none align-self-center" type="button" data-toggle="offcanvas"> <button class="navbar-toggler navbar-toggler-right d-lg-none align-self-center" type="button" data-toggle="offcanvas">
@ -88,6 +87,20 @@
$(function () { $(function () {
$('[data-toggle="tooltip"]').tooltip() $('[data-toggle="tooltip"]').tooltip()
}) })
<!-- Notify-->
$(document).ready(function(){
$("#notificationDropdown").click(function(){
$.get("/ajax/announcements", function(data){
console.log(data);
bootbox.alert({
title: "Notifications",
message: data,
});
});
});
});
</script> </script>
{% block js %} {% block js %}

View File

@ -1,39 +1,13 @@
<ul class="navbar-nav ml-auto"> <ul class="navbar-nav ml-auto">
<li class="nav-item dropdown"> <li class="nav-item dropdown">
<a class="nav-link count-indicator" id="notificationDropdown" href="#" data-toggle="dropdown"> <a class="nav-link count-indicator" id="notificationDropdown" href="#" data-toggle="dropdown">
<i class="mdi mdi-email-outline"></i> <i class="fas fa-broadcast-tower
{% if data.get('update_available') %}
text-danger
{% end %}
"></i>
<!-- <span class="count bg-success">3</span>--> <!-- <span class="count bg-success">3</span>-->
</a> </a>
<div class="dropdown-menu dropdown-menu-right navbar-dropdown preview-list pb-0" aria-labelledby="notificationDropdown">
<a class="dropdown-item preview-item py-3">
<div class="preview-thumbnail">
<i class="mdi mdi-alert m-auto text-primary"></i>
</div>
<div class="preview-item-content">
<h6 class="preview-subject font-weight-normal mb-1">Application Error</h6>
<p class="font-weight-light small-text mb-0"> Just now </p>
</div>
</a>
<a class="dropdown-item preview-item py-3">
<div class="preview-thumbnail">
<i class="mdi mdi-settings m-auto text-primary"></i>
</div>
<div class="preview-item-content">
<h6 class="preview-subject font-weight-normal mb-1">Settings</h6>
<p class="font-weight-light small-text mb-0"> Private message </p>
</div>
</a>
<a class="dropdown-item preview-item py-3">
<div class="preview-thumbnail">
<i class="mdi mdi-airballoon m-auto text-primary"></i>
</div>
<div class="preview-item-content">
<h6 class="preview-subject font-weight-normal mb-1">New user registration</h6>
<p class="font-weight-light small-text mb-0"> 2 days ago </p>
</div>
</a>
</div>
</li> </li>
<li class="nav-item dropdown user-dropdown"> <li class="nav-item dropdown user-dropdown">
<a class="nav-link dropdown-toggle" id="UserDropdown" href="#" data-toggle="dropdown" aria-expanded="false"> <a class="nav-link dropdown-toggle" id="UserDropdown" href="#" data-toggle="dropdown" aria-expanded="false">