|
|
@@ -9,14 +9,18 @@ import java.util.function.Function;
|
|
|
@Service
|
|
|
public class HtmlRenderingService {
|
|
|
|
|
|
- public String buildPersonFieldHtml(JsonNode rightPerson, JsonNode leftPerson, Function<JsonNode, String> extractor, boolean hasChanges) {
|
|
|
- if (!hasChanges || rightPerson == null) {
|
|
|
- JsonNode primary = rightPerson != null ? rightPerson : leftPerson;
|
|
|
+ /**
|
|
|
+ * Generic method to build field HTML for any type of node comparison.
|
|
|
+ * This replaces all the specific build*FieldHtml methods which were identical.
|
|
|
+ */
|
|
|
+ public String buildFieldHtml(JsonNode rightNode, JsonNode leftNode, Function<JsonNode, String> extractor, boolean hasChanges) {
|
|
|
+ if (!hasChanges || rightNode == null) {
|
|
|
+ JsonNode primary = rightNode != null ? rightNode : leftNode;
|
|
|
return primary != null ? escape(extractor.apply(primary)) : "";
|
|
|
}
|
|
|
|
|
|
- String rightVal = rightPerson != null ? extractor.apply(rightPerson) : "";
|
|
|
- String leftVal = leftPerson != null ? extractor.apply(leftPerson) : "";
|
|
|
+ String rightVal = rightNode != null ? extractor.apply(rightNode) : "";
|
|
|
+ String leftVal = leftNode != null ? extractor.apply(leftNode) : "";
|
|
|
|
|
|
if (!Objects.equals(rightVal, leftVal)) {
|
|
|
return cellHtml(rightVal, leftVal, true);
|
|
|
@@ -24,85 +28,30 @@ public class HtmlRenderingService {
|
|
|
return escape(rightVal);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // Legacy methods for backward compatibility - delegate to the generic method
|
|
|
+ public String buildPersonFieldHtml(JsonNode rightPerson, JsonNode leftPerson, Function<JsonNode, String> extractor, boolean hasChanges) {
|
|
|
+ return buildFieldHtml(rightPerson, leftPerson, extractor, hasChanges);
|
|
|
+ }
|
|
|
|
|
|
public String buildItemFieldHtml(JsonNode rightItem, JsonNode leftItem, Function<JsonNode, String> extractor, boolean hasChanges) {
|
|
|
- if (!hasChanges || rightItem == null) {
|
|
|
- JsonNode primary = rightItem != null ? rightItem : leftItem;
|
|
|
- return primary != null ? escape(extractor.apply(primary)) : "";
|
|
|
- }
|
|
|
-
|
|
|
- String rightVal = rightItem != null ? extractor.apply(rightItem) : "";
|
|
|
- String leftVal = leftItem != null ? extractor.apply(leftItem) : "";
|
|
|
-
|
|
|
- if (!Objects.equals(rightVal, leftVal)) {
|
|
|
- return cellHtml(rightVal, leftVal, true);
|
|
|
- } else {
|
|
|
- return escape(rightVal);
|
|
|
- }
|
|
|
+ return buildFieldHtml(rightItem, leftItem, extractor, hasChanges);
|
|
|
}
|
|
|
|
|
|
public String buildEinkommenFieldHtml(JsonNode rightItem, JsonNode leftItem, Function<JsonNode, String> extractor, boolean hasChanges) {
|
|
|
- if (!hasChanges || rightItem == null) {
|
|
|
- JsonNode primary = rightItem != null ? rightItem : leftItem;
|
|
|
- return primary != null ? escape(extractor.apply(primary)) : "";
|
|
|
- }
|
|
|
-
|
|
|
- String rightVal = rightItem != null ? extractor.apply(rightItem) : "";
|
|
|
- String leftVal = leftItem != null ? extractor.apply(leftItem) : "";
|
|
|
-
|
|
|
- if (!Objects.equals(rightVal, leftVal)) {
|
|
|
- return cellHtml(rightVal, leftVal, true);
|
|
|
- } else {
|
|
|
- return escape(rightVal);
|
|
|
- }
|
|
|
+ return buildFieldHtml(rightItem, leftItem, extractor, hasChanges);
|
|
|
}
|
|
|
|
|
|
public String buildFreibetragFieldHtml(JsonNode rightItem, JsonNode leftItem, Function<JsonNode, String> extractor, boolean hasChanges) {
|
|
|
- if (!hasChanges || rightItem == null) {
|
|
|
- JsonNode primary = rightItem != null ? rightItem : leftItem;
|
|
|
- return primary != null ? escape(extractor.apply(primary)) : "";
|
|
|
- }
|
|
|
-
|
|
|
- String rightVal = rightItem != null ? extractor.apply(rightItem) : "";
|
|
|
- String leftVal = leftItem != null ? extractor.apply(leftItem) : "";
|
|
|
-
|
|
|
- if (!Objects.equals(rightVal, leftVal)) {
|
|
|
- return cellHtml(rightVal, leftVal, true);
|
|
|
- } else {
|
|
|
- return escape(rightVal);
|
|
|
- }
|
|
|
+ return buildFieldHtml(rightItem, leftItem, extractor, hasChanges);
|
|
|
}
|
|
|
|
|
|
public String buildKitaFieldHtml(JsonNode rightItem, JsonNode leftItem, Function<JsonNode, String> extractor, boolean hasChanges) {
|
|
|
- if (!hasChanges || rightItem == null) {
|
|
|
- JsonNode primary = rightItem != null ? rightItem : leftItem;
|
|
|
- return primary != null ? escape(extractor.apply(primary)) : "";
|
|
|
- }
|
|
|
-
|
|
|
- String rightVal = rightItem != null ? extractor.apply(rightItem) : "";
|
|
|
- String leftVal = leftItem != null ? extractor.apply(leftItem) : "";
|
|
|
-
|
|
|
- if (!Objects.equals(rightVal, leftVal)) {
|
|
|
- return cellHtml(rightVal, leftVal, true);
|
|
|
- } else {
|
|
|
- return escape(rightVal);
|
|
|
- }
|
|
|
+ return buildFieldHtml(rightItem, leftItem, extractor, hasChanges);
|
|
|
}
|
|
|
|
|
|
public String buildAusstattungFieldHtml(JsonNode rightAusstattung, JsonNode leftAusstattung, Function<JsonNode, String> extractor, boolean hasChanges) {
|
|
|
- if (!hasChanges || rightAusstattung == null) {
|
|
|
- JsonNode primary = rightAusstattung != null ? rightAusstattung : leftAusstattung;
|
|
|
- return primary != null ? escape(extractor.apply(primary)) : "";
|
|
|
- }
|
|
|
-
|
|
|
- String rightVal = rightAusstattung != null ? extractor.apply(rightAusstattung) : "";
|
|
|
- String leftVal = leftAusstattung != null ? extractor.apply(leftAusstattung) : "";
|
|
|
-
|
|
|
- if (!Objects.equals(rightVal, leftVal)) {
|
|
|
- return cellHtml(rightVal, leftVal, true);
|
|
|
- } else {
|
|
|
- return escape(rightVal);
|
|
|
- }
|
|
|
+ return buildFieldHtml(rightAusstattung, leftAusstattung, extractor, hasChanges);
|
|
|
}
|
|
|
|
|
|
public String cellHtml(String newVal, String oldVal, boolean changed) {
|
|
|
@@ -110,12 +59,28 @@ public class HtmlRenderingService {
|
|
|
return escape(newVal);
|
|
|
}
|
|
|
|
|
|
- // Handle empty old values
|
|
|
- String displayOldVal = (oldVal == null || oldVal.trim().isEmpty()) ? "leer" : oldVal;
|
|
|
+ // Check if this is an addition (alt was empty/null, now has value)
|
|
|
+ boolean isAddition = (oldVal == null || oldVal.trim().isEmpty()) &&
|
|
|
+ (newVal != null && !newVal.trim().isEmpty());
|
|
|
+
|
|
|
+ // Check if this is a deletion (alt had value, now is empty/null)
|
|
|
+ boolean isDeletion = (oldVal != null && !oldVal.trim().isEmpty()) &&
|
|
|
+ (newVal == null || newVal.trim().isEmpty());
|
|
|
|
|
|
- // Return with cell-changed class and proper old value display
|
|
|
- return "<span class='cell-changed'>" + escape(newVal) +
|
|
|
- "<div class='old'>Alt: " + escape(displayOldVal) + "</div></span>";
|
|
|
+ if (isAddition) {
|
|
|
+ // Field was added (alt was empty, now has value)
|
|
|
+ return "<span class='cell-added'>" + escape(newVal) +
|
|
|
+ "<div class='old'>hinzugefügt</div></span>";
|
|
|
+ } else if (isDeletion) {
|
|
|
+ // Field was deleted (alt had value, now is empty)
|
|
|
+ return "<span class='cell-deleted'>leer" +
|
|
|
+ "<div class='old'>gelöscht (war: " + escape(oldVal) + ")</div></span>";
|
|
|
+ } else {
|
|
|
+ // Field was changed (both old and new have values)
|
|
|
+ String displayOldVal = (oldVal == null || oldVal.trim().isEmpty()) ? "leer" : oldVal;
|
|
|
+ return "<span class='cell-changed'>" + escape(newVal) +
|
|
|
+ "<div class='old'>geändert (war: " + escape(displayOldVal) + ")</div></span>";
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public String escape(String s) {
|
|
|
@@ -126,50 +91,14 @@ public class HtmlRenderingService {
|
|
|
}
|
|
|
|
|
|
public String buildUntermieterFieldHtml(JsonNode rightItem, JsonNode leftItem, Function<JsonNode, String> extractor, boolean hasChanges) {
|
|
|
- if (!hasChanges || rightItem == null) {
|
|
|
- JsonNode primary = rightItem != null ? rightItem : leftItem;
|
|
|
- return primary != null ? escape(extractor.apply(primary)) : "";
|
|
|
- }
|
|
|
-
|
|
|
- String rightVal = rightItem != null ? extractor.apply(rightItem) : "";
|
|
|
- String leftVal = leftItem != null ? extractor.apply(leftItem) : "";
|
|
|
-
|
|
|
- if (!Objects.equals(rightVal, leftVal)) {
|
|
|
- return cellHtml(rightVal, leftVal, true);
|
|
|
- } else {
|
|
|
- return escape(rightVal);
|
|
|
- }
|
|
|
+ return buildFieldHtml(rightItem, leftItem, extractor, hasChanges);
|
|
|
}
|
|
|
|
|
|
public String buildMitbewohnerFieldHtml(JsonNode rightItem, JsonNode leftItem, Function<JsonNode, String> extractor, boolean hasChanges) {
|
|
|
- if (!hasChanges || rightItem == null) {
|
|
|
- JsonNode primary = rightItem != null ? rightItem : leftItem;
|
|
|
- return primary != null ? escape(extractor.apply(primary)) : "";
|
|
|
- }
|
|
|
-
|
|
|
- String rightVal = rightItem != null ? extractor.apply(rightItem) : "";
|
|
|
- String leftVal = leftItem != null ? extractor.apply(leftItem) : "";
|
|
|
-
|
|
|
- if (!Objects.equals(rightVal, leftVal)) {
|
|
|
- return cellHtml(rightVal, leftVal, true);
|
|
|
- } else {
|
|
|
- return escape(rightVal);
|
|
|
- }
|
|
|
+ return buildFieldHtml(rightItem, leftItem, extractor, hasChanges);
|
|
|
}
|
|
|
|
|
|
public String buildMieteFieldHtml(JsonNode rightMiete, JsonNode leftMiete, Function<JsonNode, String> extractor, boolean hasChanges) {
|
|
|
- if (!hasChanges || rightMiete == null) {
|
|
|
- JsonNode primary = rightMiete != null ? rightMiete : leftMiete;
|
|
|
- return primary != null ? escape(extractor.apply(primary)) : "";
|
|
|
- }
|
|
|
-
|
|
|
- String rightVal = rightMiete != null ? extractor.apply(rightMiete) : "";
|
|
|
- String leftVal = leftMiete != null ? extractor.apply(leftMiete) : "";
|
|
|
-
|
|
|
- if (!Objects.equals(rightVal, leftVal)) {
|
|
|
- return cellHtml(rightVal, leftVal, true);
|
|
|
- } else {
|
|
|
- return escape(rightVal);
|
|
|
- }
|
|
|
+ return buildFieldHtml(rightMiete, leftMiete, extractor, hasChanges);
|
|
|
}
|
|
|
}
|