diff --git a/baps_types/alert.py b/baps_types/alert.py new file mode 100644 index 0000000..493a544 --- /dev/null +++ b/baps_types/alert.py @@ -0,0 +1,65 @@ +from typing import Any, Dict +from datetime import datetime + +CRITICAL = "Critical" +WARNING = "Warning" + +class Alert: + start_time: int = 0 + last_time: int = 0 + end_time: int = -1 + id: str + title: str + description: str + module: str + severity: str + + + @property + def ui_class(self) -> str: + if self.severity == CRITICAL: + return "danger" + if self.severity == WARNING: + return "warning" + return "info" + + # return self._weight + + # weight.setter + # def weight(self, value: int): + # self._weight = value + + + @property + def __dict__(self): + attrs = ["start_time", "last_time", "end_time", "id", "title", "description", "module", "severity"] + out = {} + for attr in attrs: + out[attr] = self.__getattribute__(attr) + + return out + + def __init__(self, new_data: Dict[str,Any]): + required_vars = [ + "start_time", # Just in case an alert wants to show starting earlier than it is reported. + "id", + "title", + "description", + "module", + "severity" + ] + + for key in required_vars: + if key not in new_data.keys(): + raise KeyError("Key {} is missing from data to create Alert.".format(key)) + + #if type(new_data[key]) != type(getattr(self,key)): + # raise TypeError("Key {} has type {}, was expecting {}.".format(key, type(new_data[key]), type(getattr(self,key)))) + + # Account for if the creator didn't want to set a custom time. + if key == "start_time" and new_data[key] == -1: + new_data[key] = datetime.now() + + setattr(self,key,new_data[key]) + + self.last_time = self.start_time diff --git a/helpers/alert_manager.py b/helpers/alert_manager.py new file mode 100644 index 0000000..820f45d --- /dev/null +++ b/helpers/alert_manager.py @@ -0,0 +1,29 @@ +from typing import List +from baps_types.alert import CRITICAL, Alert + +class AlertManager(): + _alerts: List[Alert] + + def __init__(self): + self._alerts = [Alert( + { + "start_time": -1, + "id": "test", + "title": "Test Alert", + "description": "This is a test alert.", + "module": "Test", + "severity": CRITICAL + } + )] + + @property + def alerts_current(self): + return self._alerts + + @property + def alert_count_current(self): + return len(self._alerts) + + @property + def alert_count_previous(self): + return len(self._alerts) diff --git a/ui-templates/alerts.html b/ui-templates/alerts.html new file mode 100644 index 0000000..edf1b7e --- /dev/null +++ b/ui-templates/alerts.html @@ -0,0 +1,41 @@ +{% extends 'base.html' %} +{% block head %} + +{% endblock %} +{% block content_inner %} + {% if data %} +

Current Alerts: {{ data.alert_count_current }}

+ +
+ {% for alert in data.alerts_current %} +
+
+

+ + {{ alert.severity }} +

+ Since {{ alert.start_time }} + Last Seen {{ alert.last_time }} + {% if alert.end_time > -1 %} + Ended {{ alert.end_time }} + {% endif %} +
+ +
+
+ Module: {{ alert.module }}
+ {{ alert.description }} +
+
+
+ {% endfor %} +
+
+

Previous Alerts: {{ data.alert_count_previous }}

+
+ +
+ {% endif %} +{% endblock %} diff --git a/ui-templates/index.html b/ui-templates/index.html index 53c5aa4..bb8b21b 100644 --- a/ui-templates/index.html +++ b/ui-templates/index.html @@ -1,4 +1,7 @@ {% extends 'base.html' %} +{% block head %} + +{% endblock %} {% block content %}
@@ -16,6 +19,23 @@ Open BAPS Presenter + +
+ {% if data.alert_count > 0 %} +