def show(self): html.open_div(class_="notify_users") with table_element("notify_users", sortable=False, searchable=False, omit_if_empty=True) as table: for entry in sorted(notify.get_gui_messages(), key=lambda e: e["time"], reverse=True): if "dashlet" not in entry["methods"]: continue table.row() msg_id = entry["id"] datetime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(entry['time'])) message = entry["text"].replace("\n", " ") table.cell(_("Actions"), css="buttons", sortable=False) html.icon_button( "", _("Delete"), "delete", onclick="delete_user_notification('%s', this);" % msg_id) table.text_cell(_("Message"), message) table.text_cell(_("Date"), datetime) html.close_div()
def render_user_notification_table(what: str) -> None: html.open_div(class_="notify_users") with table_element("notify_users", sortable=False, searchable=False, omit_if_empty=True) as table: for entry in sorted(notify.get_gui_messages(), key=lambda e: e["time"], reverse=True): if what not in entry["methods"]: continue table.row() msg_id = entry["id"] datetime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(entry['time'])) message = entry["text"].replace("\n", " ") table.cell(_("Actions"), css="buttons", sortable=False) onclick = "cmk.utils.delete_user_notification('%s', this);cmk.utils.reload_whole_page();" % msg_id \ if what == "gui_hint" else "cmk.utils.delete_user_notification('%s', this);" % msg_id html.icon_button( "", _("Delete"), "delete", onclick=onclick, ) table.text_cell(_("Message"), message) table.text_cell(_("Date"), datetime) html.close_div()
def render_messages(self): for msg in notify.get_gui_messages(): if 'gui_hint' in msg['methods']: html.open_div(id_="message-%s" % msg['id'], class_=["popup_msg"]) html.a("x", href="javascript:void(0)", class_=["close"], onclick="cmk.sidebar.message_close(\'%s\')" % msg['id']) html.write_text(msg['text'].replace('\n', '<br>\n')) html.close_div() if 'gui_popup' in msg['methods']: html.javascript('alert(\'%s\'); cmk.sidebar.mark_message_read("%s")' % (html.attrencode(msg['text']).replace('\n', '\\n'), msg['id']))
def page(self): popup_msg: List = [] hint_msg: int = 0 for msg in notify.get_gui_messages(): if 'gui_hint' in msg['methods']: hint_msg += 1 if 'gui_popup' in msg['methods']: popup_msg.append({"id": msg["id"], "text": msg['text']}) return { "popup_messages": popup_msg, "hint_messages": { "text": ungettext("message", "messages", hint_msg), "count": hint_msg, }, }