From: Michael Tremer Date: Thu, 14 Jul 2022 10:35:48 +0000 (+0000) Subject: events: Add some simple UI components X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=550e71947fbcb07723a9bc41f8f552b936748fe5;p=pbs.git events: Add some simple UI components Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 787e3f8e..b1347375 100644 --- a/Makefile.am +++ b/Makefile.am @@ -133,6 +133,7 @@ web_PYTHON = \ src/web/builds.py \ src/web/distributions.py \ src/web/errors.py \ + src/web/events.py \ src/web/handlers.py \ src/web/jobs.py \ src/web/keys.py \ @@ -226,6 +227,15 @@ dist_templates_errors_DATA = \ templates_errorsdir = $(templatesdir)/errors +templates_eventsdir = $(templatesdir)/events + +dist_templates_events_modules_DATA = \ + src/templates/events/modules/list.html \ + src/templates/events/modules/system-message.html \ + src/templates/events/modules/user-message.html + +templates_events_modulesdir = $(templates_eventsdir)/modules + templates_messagesdir = $(templatesdir)/messages dist_templates_messages_builds_DATA = \ diff --git a/src/buildservice/events.py b/src/buildservice/events.py index 16bea543..1be298c7 100644 --- a/src/buildservice/events.py +++ b/src/buildservice/events.py @@ -95,3 +95,19 @@ class Event(base.Object): def __repr__(self): return "<%s %s>" % (self.__class__.__name__, self.type) + + # Make Events accessible as mappings + + def keys(self): + return self.data.keys() + + def __getitem__(self, key): + return self.data[key] + + # Make items accessible as attributes + + def __getattr__(self, key): + try: + return self.data[key] + except KeyError as e: + raise AttributeError(key) from e diff --git a/src/templates/builds/show.html b/src/templates/builds/show.html index 72465bcd..4114c52a 100644 --- a/src/templates/builds/show.html +++ b/src/templates/builds/show.html @@ -93,4 +93,6 @@ {% if build.jobs %} {% module JobsList(build.jobs, show_arch_only=True, show_packages=True) %} {% end %} + + {% module EventsList(build.events) %} {% end block %} diff --git a/src/templates/events/modules/list.html b/src/templates/events/modules/list.html new file mode 100644 index 00000000..0485758e --- /dev/null +++ b/src/templates/events/modules/list.html @@ -0,0 +1,7 @@ +{% for event in events %} + {% if event.by_user %} + {% module EventUserMessage(event) %} + {% else %} + {% module EventSystemMessage(event) %} + {% end %} +{% end %} diff --git a/src/templates/events/modules/system-message.html b/src/templates/events/modules/system-message.html new file mode 100644 index 00000000..18b92668 --- /dev/null +++ b/src/templates/events/modules/system-message.html @@ -0,0 +1,21 @@ +
+ {% block thumbnail %}{% end block %} + +
+ {% if event.type == "build-created" %} +

+ {{ _("Build created") }} +

+ {% else %} +

+ {{ _("- Unknown Event -") }} +

+ {% end %} + + + {% block time %} + {{ locale.format_date(event.t) }} + {% end block %} + +
+
diff --git a/src/templates/events/modules/user-message.html b/src/templates/events/modules/user-message.html new file mode 100644 index 00000000..ddf902e5 --- /dev/null +++ b/src/templates/events/modules/user-message.html @@ -0,0 +1,19 @@ +{% extends "system-message.html" %} + +{% block thumbnail %} +
+
+ {{ event.by_user }} +
+
+{% end block %} + +{% block time %} + {{ locale.format_date(event.t) }} + + ‐ + + + {{ _("by %s") % event.by_user }} + +{% end block %} diff --git a/src/web/__init__.py b/src/web/__init__.py index 798257a1..3f928a72 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -17,6 +17,7 @@ from . import builders from . import builds from . import distributions from . import errors +from . import events from . import jobs from . import keys from . import mirrors @@ -55,6 +56,11 @@ class Application(tornado.web.Application): "BuildOffset" : ui_modules.BuildOffsetModule, "BuildTable" : ui_modules.BuildTableModule, + # Events + "EventsList" : events.ListModule, + "EventSystemMessage" : events.SystemMessageModule, + "EventUserMessage" : events.UserMessageModule, + # Jobs "JobsList" : ui_modules.JobsListModule, "JobsStatus" : ui_modules.JobsStatusModule, diff --git a/src/web/events.py b/src/web/events.py new file mode 100644 index 00000000..79e13185 --- /dev/null +++ b/src/web/events.py @@ -0,0 +1,38 @@ +#!/usr/bin/python3 +############################################################################### +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2022 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +import tornado.web + +from . import ui_modules + +class ListModule(ui_modules.UIModule): + def render(self, events): + return self.render_string("events/modules/list.html", events=events) + + +class UserMessageModule(ui_modules.UIModule): + def render(self, event): + return self.render_string("events/modules/user-message.html", event=event) + + +class SystemMessageModule(ui_modules.UIModule): + def render(self, event): + return self.render_string("events/modules/system-message.html", event=event)