Эх сурвалжийг харах

Verbesserung anzeige geändert, gelöschte und hinzugefügte Felder werden jetzt angezeigt.

Leonard Schulz 1 жил өмнө
parent
commit
dcc1a3b073

+ 43 - 114
src/main/java/com/tsystems/inwo/vgl/service/HtmlRenderingService.java

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

+ 26 - 1
src/main/resources/static/css/global.css

@@ -27,7 +27,6 @@
   --schwarz: #000000;
   --grau-hell: #f7f9fa;
   --grau-stark: #d7d8d9;
-  --berlin-rot: #e20613;
   --diwo-blau: #145c9e;
   --diwo-blau-hell: #cfe8fc;
   
@@ -241,6 +240,32 @@ td:has(.cell-changed) {
   margin-right: 4px;
 }
 
+.cell-added,
+td:has(.cell-added) {
+  background: var(--gruen-hell);
+}
+
+.cell-added:not(.sym)::before {
+  content: "+ ";
+  color: var(--gruen);
+  font-weight: bold;
+  font-size: 0.9em;
+  margin-right: 4px;
+}
+
+.cell-deleted,
+td:has(.cell-deleted) {
+  background: var(--rot-hell);
+}
+
+.cell-deleted:not(.sym)::before {
+  content: "− ";
+  color: var(--rot);
+  font-weight: bold;
+  font-size: 0.9em;
+  margin-right: 4px;
+}
+
 .old {
   display: block;
   font-size: 0.85em;

+ 43 - 1
src/main/resources/static/css/miete.css

@@ -125,6 +125,30 @@
   background: var(--gelb-hell) !important;
 }
 
+/* Hinzugefügte Zellen in Miete-Tabellen sollen grün hervorgehoben werden */
+.miete-grid-table .cell-added,
+.miete-grid-table td:has(.cell-added) {
+  background: var(--gruen-hell) !important;
+}
+
+.miete-grid-table .value-cell.cell-added,
+.miete-grid-table .pauschale-cell.cell-added,
+.miete-grid-table .gewerbefläche-cell.cell-added {
+  background: var(--gruen-hell) !important;
+}
+
+/* Gelöschte Zellen in Miete-Tabellen sollen rot hervorgehoben werden */
+.miete-grid-table .cell-deleted,
+.miete-grid-table td:has(.cell-deleted) {
+  background: var(--rot-hell) !important;
+}
+
+.miete-grid-table .value-cell.cell-deleted,
+.miete-grid-table .pauschale-cell.cell-deleted,
+.miete-grid-table .gewerbefläche-cell.cell-deleted {
+  background: var(--rot-hell) !important;
+}
+
 /* Wohnung-Tabelle Highlighting */
 .wohnung-grid-table .cell-changed,
 .wohnung-grid-table td:has(.cell-changed) {
@@ -133,4 +157,22 @@
 
 .wohnung-grid-table .value-cell.cell-changed {
   background: var(--gelb-hell) !important;
-}
+}
+
+.wohnung-grid-table .cell-added,
+.wohnung-grid-table td:has(.cell-added) {
+  background: var(--gruen-hell) !important;
+}
+
+.wohnung-grid-table .value-cell.cell-added {
+  background: var(--gruen-hell) !important;
+}
+
+.wohnung-grid-table .cell-deleted,
+.wohnung-grid-table td:has(.cell-deleted) {
+  background: var(--rot-hell) !important;
+}
+
+.wohnung-grid-table .value-cell.cell-deleted {
+  background: var(--rot-hell) !important;
+}