(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.
This commit is contained in:
Viktor Lofgren 2023-10-22 14:24:52 +02:00
parent e06a8c1de2
commit 758f9b5aa5
10 changed files with 20 additions and 65 deletions

View File

@ -26,6 +26,21 @@ public class MustacheRenderer<T> {
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 = "<span title=\"%s\">".formatted(instance) +
"<span style=\"background-color: %s\" class=\"uuidPip\">&nbsp;</span>".formatted(color1) +
"<span style=\"background-color: %s\" class=\"uuidPip\">&nbsp;</span>".formatted(color2) +
"&nbsp;" + shortName + "</span>";
return ret;
});
try {
template = handlebars.compile(templateFile);

View File

@ -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);
}
}

View File

@ -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) {

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -11,10 +11,7 @@
{{#each events}}
<tr>
<td>{{serviceName}}</td>
<td title="{{instanceFull}}">
<span style="background-color: {{instanceColor}}" class="uuidPip">&nbsp;</span><span style="background-color: {{instanceColor2}}" class="uuidPip">&nbsp;</span>
{{instance}}
</td>
<td>{{{readableUUID instanceFull}}}</td>
<td title="{{eventDateTime}}">{{eventTime}}</td>
<td>{{eventType}}</td>
<td>{{eventMessage}}</td>

View File

@ -31,10 +31,7 @@
{{#each events}}
<tr>
<td>{{serviceName}}</td>
<td title="{{instanceFull}}">
<span style="background-color: {{instanceColor}}" class="uuidPip">&nbsp;</span><span style="background-color: {{instanceColor2}}" class="uuidPip">&nbsp;</span>
{{instance}}
</td>
<td>{{{readableUUID instanceFull}}}</td>
<td title="{{eventDateTime}}">{{eventTime}}</td>
<td>{{eventType}}</td>
<td>{{eventMessage}}</td>

View File

@ -27,9 +27,7 @@
<td><a href="/message-queue/{{id}}">{{id}}</a></td>
<td><a href="/message-queue?inbox={{recipientInbox}}">{{recipientInbox}}</a></td>
<td>{{function}}</td>
<td title="{{ownerInstanceFull}}">
<span style="background-color: {{ownerInstanceColor}}" class="uuidPip">&nbsp;</span><span style="background-color: {{ownerInstanceColor2}}" class="uuidPip">&nbsp;</span>&nbsp;<a href="/message-queue?instance={{ownerInstanceFull}}">{{ownerInstance}}</a>
</td>
<td>{{{readableUUID ownerInstanceFull}}}</td>
<td>{{createdTime}}</td>
</tr>
<tr>

View File

@ -12,9 +12,7 @@
{{#each processes}}
<tr class="{{#if isMissing}}missing{{/if}}">
<td>{{displayName}}</td>
<td title="{{uuidFull}}">
<span style="background-color: {{uuidColor}}" class="uuidPip">&nbsp;</span><span style="background-color: {{uuidColor2}}" class="uuidPip">&nbsp;</span>{{uuid}}
</td>
<td>{{{readableUUID uuidFull}}}</td>
<td>{{status}}</td>
<td style="{{progressStyle}}">{{#if progress}}{{progress}}%{{/if}}</td>
<td>{{#unless isStopped}}{{lastSeenMillis}}{{/unless}}</td>

View File

@ -8,10 +8,7 @@
{{#each services}}
<tr class="{{#if isMissing}}missing{{/if}} {{#unless alive}}terminated{{/unless}}">
<td><a href="/services/{{serviceId}}">{{serviceId}}</a></td>
<td title="{{uuidFull}}">
<span style="background-color: {{uuidColor}}" class="uuidPip">&nbsp;</span><span style="background-color: {{uuidColor2}}" class="uuidPip">&nbsp;</span>
{{uuid}}
</td>
<td>{{{readableUUID uuidFull}}}</td>
<td>{{lastSeenMillis}}</td>
</tr>
{{/each}}