Commit 9652fee5 authored by vertighel's avatar vertighel
Browse files

Fase 5 JS punto 8: rimosso codice morto (noctuaUpdateFromRest, formatValue, export non usati)



- ui.js: cancellata noctuaUpdateFromRest (funzione + JSDoc + shim
  window.noctuaUpdateFromRest) -- zero chiamanti confermato via grep.
  normalizePath era importato solo per lei, rimosso l'import ora
  inutilizzato.
- ui-core.js: formatValue cancellata per intero, zero chiamanti anche
  interni. noctuaMaps e getStatusType restano (usate internamente da
  applyMap/applyVarStatusStyles) ma senza piu' export, mai importate
  altrove.
- Verificato con node --check su tutti i file JS toccati finora nella
  fase 5.
- PLAN.md aggiornato.

Co-Authored-By: default avatarClaude Sonnet 5 <noreply@anthropic.com>
parent 640685b4
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -601,9 +601,20 @@ Working point by point per the user's request, checking in after each
        deleted.
      Verified with `node --check` on all touched JS and a Jinja parse
      check on all touched HTML.
- [ ] Remove dead code: `noctuaUpdateFromRest` + its window shim,
- [x] Remove dead code: `noctuaUpdateFromRest` + its window shim,
      unused `ui-core.js` exports (`formatValue`, `noctuaMaps`,
      confirm `getStatusType`).
      confirm `getStatusType`). Confirmed each via grep before
      touching: `noctuaUpdateFromRest` deleted entirely from `ui.js`
      (function + JSDoc + `window.noctuaUpdateFromRest` shim), which
      left `normalizePath` as an unused import there too (it was only
      ever used inside that function) — removed. `formatValue` in
      `ui-core.js` had zero callers anywhere, not even internal —
      deleted the whole function, not just its export. `noctuaMaps`
      and `getStatusType` are both still used internally in
      `ui-core.js` (by `applyMap`/`applyVarStatusStyles`) but never
      imported elsewhere — dropped `export`, kept the
      const/function. Verified with `node --check` across every JS
      file touched so far this phase, not just this point's files.
- [ ] Add JSDoc to exported functions in the files that have none,
      following the `viewer/` subfolder as the model.

+2 −9
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ export const UI_CONFIG = {
    }
};

export function getStatusType(value, error = null) {
function getStatusType(value, error = null) {
    if (error && (Array.isArray(error) ? error.length > 0 : true)) return 'ERROR';
    if (value === null || value === undefined || String(value).trim() === '') return 'DEFAULT';

@@ -25,13 +25,6 @@ export function getStatusType(value, error = null) {
    return 'DEFAULT';
}

export function formatValue(value) {
    if (value === null || value === undefined) return UI_CONFIG.PLACEHOLDER;
    if (typeof value === 'number') return value.toFixed(1);
    if (Array.isArray(value)) return value.map(v => (typeof v === 'number' ? v.toFixed(2) : v)).join(' / ');
    return String(value);
}

export function normalizePath(path) {
    if (!path) return '';
    let clean = path.replace(/^\/|\/$/g, '').toLowerCase();
@@ -102,7 +95,7 @@ export function resolveValue(data, statusKey) {
 * Each entry is a function (rawValue) → string | null.
 * Return null to fall through to the raw value.
 */
export const noctuaMaps = {
const noctuaMaps = {
    bool_yesno: (v) => v === true  ? "Yes"    : v === false ? "No"     : null,
    bool_onoff: (v) => v === true  ? "On"     : v === false ? "Off"    : null,

+0 −33
Original line number Diff line number Diff line
// ui.js
// Noctua UI Primitives: Unified Toast Notifications and REST-to-Telemetry Bridge.

import { normalizePath } from './ui-core.js';

/**
 * Visualizza una notifica Toast di Bootstrap in basso a destra.
 * Supporta sia parametri booleani (retrocompatibilità) che stringhe semantiche di stile.
@@ -48,35 +46,6 @@ export function showToast(message, type = false) {
    toastEl.addEventListener('hidden.bs.toast', () => toastEl.remove());
}

/**
 * Converte una risposta REST singola (GET/PUT) in un evento di telemetria virtuale.
 * Garantisce che i tasti refresh applichino le stesse logiche, trasformazioni e pulse.
 *
 * @param {string} apiPath - Il percorso dell'API invocata (es. "/telescope/coordinates/offset")
 * @param {object} apiData - La risposta JSON ricevuta dal server (es. {response: [...], raw: ...})
 */
export function noctuaUpdateFromRest(apiPath, apiData) {
    if (!apiPath || !apiData) return;

    const normalizedPath = normalizePath(apiPath);
    const parts = normalizedPath.split('-');
    
    const subsystem = parts[0]; // Es. "telescope"
    
    // Costruisce la chiave del dispositivo unendo i segmenti intermedi (es. "coordinates-offset")
    const endpointKey = parts.slice(1).join('-');

    const telemetryPayload = {
        name: `all-${subsystem}`,
        data: {
            [endpointKey]: apiData
        }
    };

    // Spedisce la risposta nel ciclo di telemetria globale del client
    document.dispatchEvent(new CustomEvent('noctua-telemetry', { detail: telemetryPayload }));
}

/**
 * Applica uno stato di validazione visiva al bordo di un elemento input.
 *
@@ -155,5 +124,3 @@ export async function extractErrorMessage(response, fallback = 'Server error') {
    if (err) return String(err);
    return fallback;
}

window.noctuaUpdateFromRest = noctuaUpdateFromRest;