]> git.giorgioravera.it Git - network-manager.git/commitdiff
renamed visibility and added form to manage it
authorGiorgio Ravera <giorgio.ravera@gmail.com>
Wed, 11 Mar 2026 21:20:40 +0000 (22:20 +0100)
committerGiorgio Ravera <giorgio.ravera@gmail.com>
Wed, 11 Mar 2026 21:20:40 +0000 (22:20 +0100)
backend/db/aliases.py
backend/db/hosts.py
frontend/aliases.html
frontend/css/layout.css
frontend/hosts.html
frontend/js/aliases.js
frontend/js/hosts.js

index 3aa0878bb6cc3c1f6fcd79adb5eed010e7fef9e9..038a770174affcb63144d4a872804990802f124f 100644 (file)
@@ -39,11 +39,16 @@ def validate_data(data: dict) -> dict:
     # Boolean normalization for DB (0/1)
     ssl_enabled = int(bool(data.get("ssl_enabled", 0)))
 
+    # Normalization (0/1/2)
+    v = int(data.get("visibility", 0))
+    visibility = v if v in (0, 1, 2) else 0
+
     return {
         "name": name,
         "target": target,
         "note": note,
         "ssl_enabled": ssl_enabled,
+        "visibility": visibility,
     }
 
 # -----------------------------
@@ -75,12 +80,13 @@ def add_alias(data: dict):
     conn = get_db()
     try:
         cur = conn.execute(
-            "INSERT INTO aliases (name, target, note, ssl_enabled) VALUES (?, ?, ?, ?)",
+            "INSERT INTO aliases (name, target, note, ssl_enabled, visibility) VALUES (?, ?, ?, ?, ?)",
             (
                 cleaned["name"],
                 cleaned["target"],
                 cleaned["note"],
                 cleaned["ssl_enabled"],
+                cleaned["visibility"],
             )
         )
         conn.commit()
@@ -107,7 +113,7 @@ def update_alias(alias_id: int, data: dict) -> bool:
         cur = conn.execute(
             """
             UPDATE aliases
-            SET name=?, target=?, note=?, ssl_enabled=?
+            SET name=?, target=?, note=?, ssl_enabled=?, visibility=?, last_updated=CURRENT_TIMESTAMP
             WHERE id=?
             """,
             (
@@ -115,6 +121,7 @@ def update_alias(alias_id: int, data: dict) -> bool:
                 cleaned["target"],
                 cleaned["note"],
                 cleaned["ssl_enabled"],
+                cleaned["visibility"],
                 alias_id,
             )
         )
@@ -162,7 +169,7 @@ def init_db_alias_table(cur):
             target TEXT NOT NULL,
             note TEXT,
             ssl_enabled INTEGER NOT NULL DEFAULT 0,
-            external_mode INTEGER NOT NULL DEFAULT 0,
+            visibility INTEGER NOT NULL DEFAULT 0,
             last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP
         );
     """)
index ea9c1f01e8174751a6e91c2e12203bc2d5396aea..92c861c1b31fccb6b0df3a75e5dc02a448c344e6 100644 (file)
@@ -55,6 +55,10 @@ def validate_data(data: dict) -> dict:
     # Normalizzazione boolean per DB (0/1)
     ssl_enabled = int(bool(data.get("ssl_enabled", 0)))
 
+    # Normalizzazione (0/1/2)
+    v = int(data.get("visibility", 0))
+    visibility = v if v in (0, 1, 2) else 0
+
     return {
         "name": name,
         "ipv4": ipv4,
@@ -62,6 +66,7 @@ def validate_data(data: dict) -> dict:
         "mac": mac,
         "note": note,
         "ssl_enabled": ssl_enabled,
+        "visibility": visibility,
     }
 
 # -----------------------------
@@ -107,7 +112,7 @@ def add_host(data: dict):
     conn = get_db()
     try:
         cur = conn.execute(
-            "INSERT INTO hosts (name, ipv4, ipv6, mac, note, ssl_enabled) VALUES (?, ?, ?, ?, ?, ?)",
+            "INSERT INTO hosts (name, ipv4, ipv6, mac, note, ssl_enabled, visibility) VALUES (?, ?, ?, ?, ?, ?, ?)",
             (
                 cleaned["name"],
                 cleaned["ipv4"],
@@ -115,6 +120,7 @@ def add_host(data: dict):
                 cleaned["mac"],
                 cleaned["note"],
                 cleaned["ssl_enabled"],
+                cleaned["visibility"],
             )
         )
         conn.commit()
@@ -141,7 +147,7 @@ def update_host(host_id: int, data: dict) -> bool:
         cur = conn.execute(
             """
             UPDATE hosts
-            SET name=?, ipv4=?, ipv6=?, mac=?, note=?, ssl_enabled=?
+            SET name=?, ipv4=?, ipv6=?, mac=?, note=?, ssl_enabled=?, visibility=?, last_updated=CURRENT_TIMESTAMP
             WHERE id=?
             """,
             (
@@ -151,6 +157,7 @@ def update_host(host_id: int, data: dict) -> bool:
                 cleaned["mac"],
                 cleaned["note"],
                 cleaned["ssl_enabled"],
+                cleaned["visibility"],
                 host_id,
             )
         )
@@ -210,7 +217,7 @@ def init_db_hosts_table(cur):
             mac TEXT,
             note TEXT,
             ssl_enabled INTEGER NOT NULL DEFAULT 0,
-            external_mode INTEGER NOT NULL DEFAULT 0,
+            visibility INTEGER NOT NULL DEFAULT 0,
             last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP
         );
     """)
index d30267ca88c08ad119c593da23b1bc653050368c..680baaefeec5263cd2fa7ce9393ded45a4330335 100644 (file)
                             <input class="form-check-input" type="checkbox" id="aliasSSL">
                             <label class="form-check-label" for="aliasSSL">SSL?</label>
                         </div>
+
+                        <div class="mb-2">
+                            <label class="form-label d-block">Visibility</label>
+                            <div class="btn-group" role="group">
+                                <!-- Local -->
+                                <input type="radio" class="btn-check" id="aliasVisibilityLocal" name="aliasVisibility" value="0" checked>
+                                <label class="btn btn-outline-primary" for="aliasVisibilityLocal">Local</label>
+                                <!-- Global -->
+                                <input type="radio" class="btn-check" id="aliasVisibilityGlobal" name="aliasVisibility" value="1">
+                                <label class="btn btn-outline-primary" for="aliasVisibilityGlobal">Global</label>
+                                <!-- Alias -->
+                                <input type="radio" class="btn-check" id="aliasVisibilityAlias" name="aliasVisibility" value="2">
+                                <label class="btn btn-outline-primary" for="aliasVisibilityAlias">Alias</label>
+                            </div>
+                        </div>
                     </form>
                 </div>
 
index 3d59efd9878e6bc32dfa5cbf8019a35604e1507b..a5d730d616d00ee6bf226c593b2471192e5b998b 100644 (file)
@@ -214,7 +214,9 @@ body {
     line-height: 1.1;
 }
 
-.form-label {
+.form-label,
+.form-check-label,
+.form-check-input {
     font-size: 0.80rem;          /* più piccina */
     margin-bottom: 2px;          /* Bootstrap usa 8px; lo riduciamo */
 }
@@ -245,12 +247,6 @@ select.form-select:focus,
     border-color: #198754; /* verde Bootstrap */
 }
 
-.form-check-input:focus {
-    border-color: var(--accent);
-    box-shadow: 0 0 0 1px var(--accent);
-    outline: none;
-}
-
 /* ================================
    Icons
    ================================ */
index 8d8809dc31a8d8c2e25e409548047f4a41598c27..f1a98fa28ca7c2886ce92a450c2185a5a5f189c7 100644 (file)
                             <input class="form-check-input" type="checkbox" id="hostSSL">
                             <label class="form-check-label" for="hostSSL">SSL?</label>
                         </div>
+
+                        <div class="mb-2">
+                            <label class="form-label d-block">Visibility</label>
+                            <div class="btn-group" role="group">
+                                <!-- Local -->
+                                <input type="radio" class="btn-check" id="hostVisibilityLocal" name="hostVisibility" value="0" checked>
+                                <label class="btn btn-outline-primary" for="hostVisibilityLocal">Local</label>
+                                <!-- Global -->
+                                <input type="radio" class="btn-check" id="hostVisibilityGlobal" name="hostVisibility" value="1">
+                                <label class="btn btn-outline-primary" for="hostVisibilityGlobal">Global</label>
+                                <!-- Alias -->
+                                <input type="radio" class="btn-check" id="hostVisibilityAlias" name="hostVisibility" value="2">
+                                <label class="btn btn-outline-primary" for="hostVisibilityAlias">Alias</label>
+                            </div>
+                        </div>
                     </form>
                 </div>
 
index 72d24d5a1d26fd979afbc9374df60135b87f53ca..a2cd9071b6453a53921930db191be6d803b68e12 100644 (file)
@@ -131,9 +131,9 @@ async function loadAliases() {
             td.appendChild(icon);
 
             //
-            // external_mode icon
+            // visibility icon
             //
-            const ext = (h.external_mode ?? "").toString();
+            const ext = (h.visibility ?? "").toString();
             let aria = "";
             let iconClass = "";
             switch (ext) {
@@ -273,6 +273,13 @@ async function editAlias(id) {
     document.getElementById("aliasTarget").value = data.target ?? "";
     document.getElementById("aliasNote").value = data.note ?? "";
     document.getElementById("aliasSSL").checked = !!data.ssl_enabled;
+    if (data.visibility == 0) {
+        document.getElementById("aliasVisibilityLocal").checked = true;
+    } else if (data.visibility == 1){
+        document.getElementById("aliasVisibilityGlobal").checked = true;
+    } else {
+        document.getElementById("aliasVisibilityAlias").checked = true;
+    }
 }
 
 // -----------------------------
@@ -411,7 +418,10 @@ async function handleAddAliasSubmit(e) {
             name:  document.getElementById('aliasName').value.trim(),
             target: document.getElementById('aliasTarget').value.trim(),
             note:   document.getElementById('aliasNote').value.trim(),
-            ssl_enabled: document.getElementById('aliasSSL').checked ? 1 : 0
+            ssl_enabled: document.getElementById('aliasSSL').checked ? 1 : 0,
+            visibility: Number(
+                document.querySelector('input[name="aliasVisibility"]:checked')?.value ?? 0
+            )
         };
 
         const ok = await saveAlias(data);
index 834822c3c9e1e0ce96c299f5647bf4824b798f56..e75f742e5724a485de4580eaed66dedaf6e9c00d 100644 (file)
@@ -150,9 +150,9 @@ async function loadHosts() {
             td.appendChild(icon);
 
             //
-            // external_mode icon
+            // visibility icon
             //
-            const ext = (h.external_mode ?? "").toString();
+            const ext = (h.visibility ?? "").toString();
             let aria = "";
             let iconClass = "";
             switch (ext) {
@@ -294,6 +294,13 @@ async function editHost(id) {
     document.getElementById("hostMAC").value = data.mac ?? "";
     document.getElementById("hostNote").value = data.note ?? "";
     document.getElementById("hostSSL").checked = !!data.ssl_enabled;
+    if (data.visibility == 0) {
+        document.getElementById("hostVisibilityLocal").checked = true;
+    } else if (data.visibility == 1){
+        document.getElementById("hostVisibilityGlobal").checked = true;
+    } else {
+        document.getElementById("hostVisibilityAlias").checked = true;
+    }
 }
 
 // -----------------------------
@@ -444,7 +451,10 @@ async function handleAddHostSubmit(e) {
             ipv6:  document.getElementById('hostIPv6').value.trim(),
             mac:   document.getElementById('hostMAC').value.trim(),
             note:  document.getElementById('hostNote').value.trim(),
-            ssl_enabled: document.getElementById('hostSSL').checked ? 1 : 0
+            ssl_enabled: document.getElementById('hostSSL').checked ? 1 : 0,
+            visibility: Number(
+                document.querySelector('input[name="hostVisibility"]:checked')?.value ?? 0
+            )
         };
 
         const ok = await saveHost(data);