From 758f9b5aa5486103a5c3c2fdb7097351c9ae1a59 Mon Sep 17 00:00:00 2001 From: Viktor Lofgren Date: Sun, 22 Oct 2023 14:24:52 +0200 Subject: [PATCH] (converter) Get UUID pips out of the models Rendering concerns shouldn't be in the models, it's poor separation of concerns and very difficult to follow. --- .../marginalia/renderer/MustacheRenderer.java | 15 ++++++++++++++ .../control/sys/model/EventLogEntry.java | 9 --------- .../control/sys/model/MessageQueueEntry.java | 20 ------------------- .../control/sys/model/ProcessHeartbeat.java | 9 --------- .../control/sys/model/ServiceHeartbeat.java | 9 --------- .../control/partials/events-table-summary.hdb | 5 +---- .../control/partials/events-table.hdb | 5 +---- .../control/partials/message-queue-table.hdb | 4 +--- .../control/partials/processes-table.hdb | 4 +--- .../control/partials/services-table.hdb | 5 +---- 10 files changed, 20 insertions(+), 65 deletions(-) diff --git a/code/common/renderer/src/main/java/nu/marginalia/renderer/MustacheRenderer.java b/code/common/renderer/src/main/java/nu/marginalia/renderer/MustacheRenderer.java index 4060a15b..2cd98a23 100644 --- a/code/common/renderer/src/main/java/nu/marginalia/renderer/MustacheRenderer.java +++ b/code/common/renderer/src/main/java/nu/marginalia/renderer/MustacheRenderer.java @@ -26,6 +26,21 @@ public class MustacheRenderer { var handlebars = new Handlebars(loader); handlebars.registerHelpers(ConditionalHelpers.class); handlebars.registerHelper("md", new MarkdownHelper()); + handlebars.registerHelper("readableUUID", (context, options) -> { + if (context == null) return ""; + String instance = context.toString(); + if (instance.length() < 31) return ""; + + String color1 = "#"+instance.substring(0, 6); + String color2 = "#"+instance.substring(25, 31); + String shortName = instance.substring(0, 8); + + String ret = "".formatted(instance) + + " ".formatted(color1) + + " ".formatted(color2) + + " " + shortName + ""; + return ret; + }); try { template = handlebars.compile(templateFile); diff --git a/code/services-core/control-service/src/main/java/nu/marginalia/control/sys/model/EventLogEntry.java b/code/services-core/control-service/src/main/java/nu/marginalia/control/sys/model/EventLogEntry.java index b16d01f0..4ca34b71 100644 --- a/code/services-core/control-service/src/main/java/nu/marginalia/control/sys/model/EventLogEntry.java +++ b/code/services-core/control-service/src/main/java/nu/marginalia/control/sys/model/EventLogEntry.java @@ -9,13 +9,4 @@ public record EventLogEntry( String eventType, String eventMessage) { - public String instance() { - return instanceFull.substring(0, 8); - } - public String instanceColor() { - return '#' + instanceFull.substring(0, 6); - } - public String instanceColor2() { - return '#' + instanceFull.substring(25, 31); - } } diff --git a/code/services-core/control-service/src/main/java/nu/marginalia/control/sys/model/MessageQueueEntry.java b/code/services-core/control-service/src/main/java/nu/marginalia/control/sys/model/MessageQueueEntry.java index dd0146bd..1ff87387 100644 --- a/code/services-core/control-service/src/main/java/nu/marginalia/control/sys/model/MessageQueueEntry.java +++ b/code/services-core/control-service/src/main/java/nu/marginalia/control/sys/model/MessageQueueEntry.java @@ -18,26 +18,6 @@ public record MessageQueueEntry ( public boolean hasRelatedMessage() { return relatedId > 0; } - public String ownerInstance() { - if (ownerInstanceFull == null) { - return ""; - } - - return ownerInstanceFull.substring(0, 8); - } - public String ownerInstanceColor() { - if (ownerInstanceFull == null) { - return "#000000"; - } - return '#' + ownerInstanceFull.substring(0, 6); - } - public String ownerInstanceColor2() { - if (ownerInstanceFull == null) { - return "#000000"; - } - - return '#' + ownerInstanceFull.substring(25, 31); - } public String stateCode() { if (state == null) { diff --git a/code/services-core/control-service/src/main/java/nu/marginalia/control/sys/model/ProcessHeartbeat.java b/code/services-core/control-service/src/main/java/nu/marginalia/control/sys/model/ProcessHeartbeat.java index 0f789aee..7cf5205d 100644 --- a/code/services-core/control-service/src/main/java/nu/marginalia/control/sys/model/ProcessHeartbeat.java +++ b/code/services-core/control-service/src/main/java/nu/marginalia/control/sys/model/ProcessHeartbeat.java @@ -9,15 +9,6 @@ public record ProcessHeartbeat( Integer progress, String status ) { - public String uuid() { - return uuidFull.substring(0, 8); - } - public String uuidColor() { - return '#' + uuidFull.substring(0, 6); - } - public String uuidColor2() { - return '#' + uuidFull.substring(25, 31); - } public boolean isMissing() { return lastSeenMillis > 10000; } diff --git a/code/services-core/control-service/src/main/java/nu/marginalia/control/sys/model/ServiceHeartbeat.java b/code/services-core/control-service/src/main/java/nu/marginalia/control/sys/model/ServiceHeartbeat.java index f1d6c705..b056e154 100644 --- a/code/services-core/control-service/src/main/java/nu/marginalia/control/sys/model/ServiceHeartbeat.java +++ b/code/services-core/control-service/src/main/java/nu/marginalia/control/sys/model/ServiceHeartbeat.java @@ -10,13 +10,4 @@ public record ServiceHeartbeat( public boolean isMissing() { return lastSeenMillis > 10000; } - public String uuid() { - return uuidFull.substring(0, 8); - } - public String uuidColor() { - return '#' + uuidFull.substring(0, 6); - } - public String uuidColor2() { - return '#' + uuidFull.substring(25, 31); - } } diff --git a/code/services-core/control-service/src/main/resources/templates/control/partials/events-table-summary.hdb b/code/services-core/control-service/src/main/resources/templates/control/partials/events-table-summary.hdb index cd9f5e0c..66e68d3a 100644 --- a/code/services-core/control-service/src/main/resources/templates/control/partials/events-table-summary.hdb +++ b/code/services-core/control-service/src/main/resources/templates/control/partials/events-table-summary.hdb @@ -11,10 +11,7 @@ {{#each events}} {{serviceName}} - -    - {{instance}} - + {{{readableUUID instanceFull}}} {{eventTime}} {{eventType}} {{eventMessage}} diff --git a/code/services-core/control-service/src/main/resources/templates/control/partials/events-table.hdb b/code/services-core/control-service/src/main/resources/templates/control/partials/events-table.hdb index 57570b00..96bb898d 100644 --- a/code/services-core/control-service/src/main/resources/templates/control/partials/events-table.hdb +++ b/code/services-core/control-service/src/main/resources/templates/control/partials/events-table.hdb @@ -31,10 +31,7 @@ {{#each events}} {{serviceName}} - -    - {{instance}} - + {{{readableUUID instanceFull}}} {{eventTime}} {{eventType}} {{eventMessage}} diff --git a/code/services-core/control-service/src/main/resources/templates/control/partials/message-queue-table.hdb b/code/services-core/control-service/src/main/resources/templates/control/partials/message-queue-table.hdb index 5f3abe7d..62ece47a 100644 --- a/code/services-core/control-service/src/main/resources/templates/control/partials/message-queue-table.hdb +++ b/code/services-core/control-service/src/main/resources/templates/control/partials/message-queue-table.hdb @@ -27,9 +27,7 @@ {{id}} {{recipientInbox}} {{function}} - -    {{ownerInstance}} - + {{{readableUUID ownerInstanceFull}}} {{createdTime}} diff --git a/code/services-core/control-service/src/main/resources/templates/control/partials/processes-table.hdb b/code/services-core/control-service/src/main/resources/templates/control/partials/processes-table.hdb index e1687e4c..a3e3e5e8 100644 --- a/code/services-core/control-service/src/main/resources/templates/control/partials/processes-table.hdb +++ b/code/services-core/control-service/src/main/resources/templates/control/partials/processes-table.hdb @@ -12,9 +12,7 @@ {{#each processes}} {{displayName}} - -   {{uuid}} - + {{{readableUUID uuidFull}}} {{status}} {{#if progress}}{{progress}}%{{/if}} {{#unless isStopped}}{{lastSeenMillis}}{{/unless}} diff --git a/code/services-core/control-service/src/main/resources/templates/control/partials/services-table.hdb b/code/services-core/control-service/src/main/resources/templates/control/partials/services-table.hdb index 0ae14bd5..fff6c535 100644 --- a/code/services-core/control-service/src/main/resources/templates/control/partials/services-table.hdb +++ b/code/services-core/control-service/src/main/resources/templates/control/partials/services-table.hdb @@ -8,10 +8,7 @@ {{#each services}} {{serviceId}} - -    - {{uuid}} - + {{{readableUUID uuidFull}}} {{lastSeenMillis}} {{/each}}