From 0da5aa171d322e688b6e77f02c63deb9ce666d12 Mon Sep 17 00:00:00 2001 From: Benjamin Braatz Date: Tue, 9 Mar 2021 20:13:22 +0100 Subject: [PATCH] Add plugin name to bus registration and debug app --- controlpi-plugins/wsserver.py | 18 +++++++++++------- web/controlpi-debug.css | 14 +++++++++++++- web/controlpi-debug.js | 16 +++++++++++----- web/index.css | 12 ++++++------ 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/controlpi-plugins/wsserver.py b/controlpi-plugins/wsserver.py index 0dcc015..c19126b 100644 --- a/controlpi-plugins/wsserver.py +++ b/controlpi-plugins/wsserver.py @@ -24,7 +24,8 @@ class Connection: self._name = f"{self._address}:{self._port}" if path != '/': self._name = path[1:] - self._bus.register(self._name, [{}], [{}], self._receive) + self._bus.register(self._name, 'WSServer-Connection', + [{}], [{}], self._receive) async def _receive(self, message: Message) -> None: json_message = json.dumps(message) @@ -89,17 +90,20 @@ class WSServer(BasePlugin): return HTTPStatus.OK, response_headers, body def _process_conf(self, conf: PluginConfiguration) -> None: - if 'port' not in conf: + self._port = 80 + if 'port' in conf: + self._port = conf['port'] + else: print(f"'port' not configured for WSServer '{self._name}'." " Using 80.") - conf['port'] = 80 - self._port = conf['port'] - if 'web root' not in conf: + web_root = 'web' + if 'web root' in conf: + web_root = conf['web root'] + else: print(f"'web root' not configured for WSServer '{self._name}'." " Using 'web'.") - conf['web root'] = 'web' self._web_root = os.path.realpath(os.path.join(os.getcwd(), - conf['web root'])) + web_root)) super()._process_conf(conf) async def run(self) -> None: diff --git a/web/controlpi-debug.css b/web/controlpi-debug.css index 959ac31..1fca3c6 100644 --- a/web/controlpi-debug.css +++ b/web/controlpi-debug.css @@ -14,11 +14,23 @@ background-color: #bcdaf8; } -.client > h2 { +.client > header { + display: flex; + justify-content: space-between; +} + +.client > header > h2 { + vertical-align: top; font-size: 1.2rem; font-weight: bold; } +.client > header > h3 { + vertical-align: top; + font-size: 0.8rem; + font-weight: bold; +} + .interfacecontainer { white-space: nowrap; } diff --git a/web/controlpi-debug.js b/web/controlpi-debug.js index 5ae170a..9c4dd77 100644 --- a/web/controlpi-debug.js +++ b/web/controlpi-debug.js @@ -1,10 +1,15 @@ // Create section for client: -function createForClient(client) { +function createForClient(client, plugin) { const section = document.createElement('section') section.setAttribute('id', client) section.setAttribute('class', 'client') - const heading = document.createElement('h2') - heading.appendChild(document.createTextNode(client)) + const heading = document.createElement('header') + const headingH2 = document.createElement('h2') + headingH2.appendChild(document.createTextNode(client)) + heading.appendChild(headingH2) + const headingH3 = document.createElement('h3') + headingH3.appendChild(document.createTextNode(plugin)) + heading.appendChild(headingH3) section.appendChild(heading) const receiveOuter = document.createElement('div') receiveOuter.setAttribute('class', 'interfacecontainer') @@ -247,7 +252,8 @@ function processBusMessage(message) { if (clientElement == null) { // Create element for client if not existent: const main = document.getElementById('ControlPi Debug') - main.appendChild(createForClient(message['client'])) + main.appendChild(createForClient(message['client'], + message['plugin'])) } // Crate message elements for receives interface: const receiveContainer = document.getElementById(message['client'] + ' Receives') @@ -316,7 +322,7 @@ function processClientMessage(message) { if (clientElement == null) { // Create section for client if not existent: const main = document.getElementById('ControlPi Debug') - main.appendChild(createForClient(message.sender)) + main.appendChild(createForClient(message.sender, '')) } // Update last received message: const lastContainer = document.getElementById(message['sender'] + ' Last') diff --git a/web/index.css b/web/index.css index e33bc74..e0f29d1 100644 --- a/web/index.css +++ b/web/index.css @@ -22,32 +22,32 @@ body { color: black; } -header { +body > header { padding: 10px; background-color: #2c343b; } -header * { +body > header * { vertical-align: middle; } -header svg { +body > header svg { height: 40px; } -header span { +body > header span { font-family: "Michroma", sans-serif; font-weight: bold; font-size: 20px; text-transform: uppercase; } -header span.Graph { +body > header span.Graph { margin-left: 10px; color: white; } -header span.IT { +body > header span.IT { margin-right: 10px; color: #83a1b4; } -- 2.34.1