Files
wled-screen-controller-mixed/server/src/wled_controller/templates/modals/value-source-editor.html
alexei.dolgolyov bd8d7a019f Codebase review: stability, performance, usability, and i18n fixes
Stability:
- Fix race condition: set _is_running before create_task in target processors
- Await probe task after cancel in wled_target_processor
- Replace raw fetch() with fetchWithAuth() across devices, kc-targets, pattern-templates
- Add try/catch to showTestTemplateModal in streams.js
- Wrap blocking I/O in asyncio.to_thread (picture_targets, system restore)
- Fix dashboardStopAll to filter only running targets with ok guard

Performance:
- Vectorize fire effect spark loop with numpy in effect_stream
- Vectorize FFT band binning with cumulative sum in analysis.py
- Rewrite pixel_processor with vectorized numpy (accept ndarray or list)
- Add httpx.AsyncClient connection pooling with lock in wled_provider
- Optimize _send_pixels_http to avoid np.hstack allocation in wled_client
- Mutate chart arrays in-place in dashboard, perf-charts, targets
- Merge dashboard 2-batch fetch into single Promise.all
- Hoist frame_time outside loop in mapped_stream

Usability:
- Fix health check interval load/save in device settings
- Swap confirm modal button classes (No=secondary, Yes=danger)
- Add aria-modal to audio/value source editors, fix close button aria-labels
- Add modal footer close button to settings modal
- Add dedicated calibration LED count validation error keys

i18n:
- Replace ~50 hardcoded English strings with t() calls across 12 JS files
- Add 50 new keys to en.json, ru.json, zh.json
- Localize inline toasts in index.html with window.t fallback
- Add data-i18n to command palette footer
- Add localization policy to CLAUDE.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 12:12:37 +03:00

278 lines
22 KiB
HTML

<!-- Value Source Editor Modal -->
<div id="value-source-modal" class="modal" role="dialog" aria-modal="true" aria-labelledby="value-source-modal-title">
<div class="modal-content">
<div class="modal-header">
<h2 id="value-source-modal-title" data-i18n="value_source.add">Add Value Source</h2>
<button class="modal-close-btn" onclick="closeValueSourceModal()" data-i18n-aria-label="aria.close">&#x2715;</button>
</div>
<div class="modal-body">
<form id="value-source-form" onsubmit="return false;">
<input type="hidden" id="value-source-id">
<div id="value-source-error" class="error-message" style="display: none;"></div>
<!-- Name -->
<div class="form-group">
<div class="label-row">
<label for="value-source-name" data-i18n="value_source.name">Name:</label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.name.hint">A descriptive name for this value source</small>
<input type="text" id="value-source-name" data-i18n-placeholder="value_source.name.placeholder" placeholder="Brightness Pulse" required>
</div>
<!-- Type (hidden in edit mode since type is immutable) -->
<div id="value-source-type-group" class="form-group">
<div class="label-row">
<label for="value-source-type" data-i18n="value_source.type">Type:</label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.type.hint">Static outputs a constant value. Animated cycles through a waveform. Audio reacts to sound input.</small>
<select id="value-source-type" onchange="onValueSourceTypeChange()">
<option value="static" data-i18n="value_source.type.static">Static</option>
<option value="animated" data-i18n="value_source.type.animated">Animated</option>
<option value="audio" data-i18n="value_source.type.audio">Audio</option>
<option value="adaptive_time" data-i18n="value_source.type.adaptive_time">Adaptive (Time of Day)</option>
<option value="adaptive_scene" data-i18n="value_source.type.adaptive_scene">Adaptive (Scene)</option>
</select>
</div>
<!-- Static fields -->
<div id="value-source-static-section">
<div class="form-group">
<div class="label-row">
<label for="value-source-value"><span data-i18n="value_source.value">Value:</span> <span id="value-source-value-display">1.0</span></label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.value.hint">Constant output value (0.0 = off, 1.0 = full brightness)</small>
<input type="range" id="value-source-value" min="0" max="1" step="0.01" value="1.0"
oninput="document.getElementById('value-source-value-display').textContent = this.value">
</div>
</div>
<!-- Animated fields -->
<div id="value-source-animated-section" style="display:none">
<div class="form-group">
<div class="label-row">
<label for="value-source-waveform" data-i18n="value_source.waveform">Waveform:</label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.waveform.hint">Shape of the brightness animation cycle</small>
<select id="value-source-waveform">
<option value="sine" data-i18n="value_source.waveform.sine">Sine</option>
<option value="triangle" data-i18n="value_source.waveform.triangle">Triangle</option>
<option value="square" data-i18n="value_source.waveform.square">Square</option>
<option value="sawtooth" data-i18n="value_source.waveform.sawtooth">Sawtooth</option>
</select>
</div>
<div class="form-group">
<div class="label-row">
<label for="value-source-speed"><span data-i18n="value_source.speed">Speed (cpm):</span> <span id="value-source-speed-display">10</span></label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.speed.hint">Cycles per minute — how fast the waveform repeats (1 = very slow, 120 = very fast)</small>
<input type="range" id="value-source-speed" min="1" max="120" step="1" value="10"
oninput="document.getElementById('value-source-speed-display').textContent = this.value">
</div>
<div class="form-group">
<div class="label-row">
<label for="value-source-min-value"><span data-i18n="value_source.min_value">Min Value:</span> <span id="value-source-min-value-display">0</span></label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.min_value.hint">Minimum output of the waveform cycle</small>
<input type="range" id="value-source-min-value" min="0" max="1" step="0.01" value="0"
oninput="document.getElementById('value-source-min-value-display').textContent = this.value">
</div>
<div class="form-group">
<div class="label-row">
<label for="value-source-max-value"><span data-i18n="value_source.max_value">Max Value:</span> <span id="value-source-max-value-display">1</span></label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.max_value.hint">Maximum output of the waveform cycle</small>
<input type="range" id="value-source-max-value" min="0" max="1" step="0.01" value="1"
oninput="document.getElementById('value-source-max-value-display').textContent = this.value">
</div>
</div>
<!-- Audio fields -->
<div id="value-source-audio-section" style="display:none">
<div class="form-group">
<div class="label-row">
<label for="value-source-audio-source" data-i18n="value_source.audio_source">Audio Source:</label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.audio_source.hint">Mono audio source to read audio levels from</small>
<select id="value-source-audio-source">
<!-- populated dynamically with mono audio sources -->
</select>
</div>
<div class="form-group">
<div class="label-row">
<label for="value-source-mode" data-i18n="value_source.mode">Mode:</label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.mode.hint">RMS measures average volume. Peak tracks loudest moments. Beat triggers on rhythm.</small>
<select id="value-source-mode">
<option value="rms" data-i18n="value_source.mode.rms">RMS (Volume)</option>
<option value="peak" data-i18n="value_source.mode.peak">Peak</option>
<option value="beat" data-i18n="value_source.mode.beat">Beat</option>
</select>
</div>
<div class="form-group">
<div class="label-row">
<label for="value-source-auto-gain" data-i18n="value_source.auto_gain">Auto Gain:</label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.auto_gain.hint">Automatically normalize audio levels so output uses the full range, regardless of input volume</small>
<label class="toggle-label">
<input type="checkbox" id="value-source-auto-gain">
<span data-i18n="value_source.auto_gain.enable">Enable auto-gain</span>
</label>
</div>
<div class="form-group">
<div class="label-row">
<label for="value-source-sensitivity"><span data-i18n="value_source.sensitivity">Sensitivity:</span> <span id="value-source-sensitivity-display">1.0</span></label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.sensitivity.hint">Gain multiplier for the audio signal (higher = more reactive)</small>
<input type="range" id="value-source-sensitivity" min="0.1" max="20" step="0.1" value="1.0"
oninput="document.getElementById('value-source-sensitivity-display').textContent = this.value">
</div>
<div class="form-group">
<div class="label-row">
<label for="value-source-smoothing"><span data-i18n="value_source.smoothing">Smoothing:</span> <span id="value-source-smoothing-display">0.3</span></label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.smoothing.hint">Temporal smoothing (0 = instant response, 1 = very smooth/slow)</small>
<input type="range" id="value-source-smoothing" min="0" max="1" step="0.05" value="0.3"
oninput="document.getElementById('value-source-smoothing-display').textContent = this.value">
</div>
<div class="form-group">
<div class="label-row">
<label for="value-source-audio-min-value"><span data-i18n="value_source.audio_min_value">Min Value:</span> <span id="value-source-audio-min-value-display">0</span></label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.audio_min_value.hint">Output when audio is silent (e.g. 0.3 = 30% brightness floor)</small>
<input type="range" id="value-source-audio-min-value" min="0" max="1" step="0.01" value="0"
oninput="document.getElementById('value-source-audio-min-value-display').textContent = this.value">
</div>
<div class="form-group">
<div class="label-row">
<label for="value-source-audio-max-value"><span data-i18n="value_source.audio_max_value">Max Value:</span> <span id="value-source-audio-max-value-display">1</span></label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.audio_max_value.hint">Output at maximum audio level</small>
<input type="range" id="value-source-audio-max-value" min="0" max="1" step="0.01" value="1"
oninput="document.getElementById('value-source-audio-max-value-display').textContent = this.value">
</div>
</div>
<!-- Adaptive Time of Day fields -->
<div id="value-source-adaptive-time-section" style="display:none">
<div class="form-group">
<div class="label-row">
<label data-i18n="value_source.schedule">Schedule:</label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.schedule.hint">Define at least 2 time points. Brightness interpolates linearly between them, wrapping at midnight.</small>
<div id="value-source-schedule-list" class="schedule-list"></div>
<button type="button" class="btn btn-secondary btn-sm" onclick="addSchedulePoint()" data-i18n="value_source.schedule.add">+ Add Point</button>
</div>
</div>
<!-- Adaptive Scene fields -->
<div id="value-source-adaptive-scene-section" style="display:none">
<div class="form-group">
<div class="label-row">
<label for="value-source-picture-source" data-i18n="value_source.picture_source">Picture Source:</label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.picture_source.hint">The picture source whose frames will be analyzed for average brightness.</small>
<select id="value-source-picture-source">
<!-- populated dynamically -->
</select>
</div>
<div class="form-group">
<div class="label-row">
<label for="value-source-scene-behavior" data-i18n="value_source.scene_behavior">Behavior:</label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.scene_behavior.hint">Complement: dark scene = high brightness (ideal for ambient backlight). Match: bright scene = high brightness.</small>
<select id="value-source-scene-behavior">
<option value="complement" data-i18n="value_source.scene_behavior.complement">Complement (dark → bright)</option>
<option value="match" data-i18n="value_source.scene_behavior.match">Match (bright → bright)</option>
</select>
</div>
<div class="form-group">
<div class="label-row">
<label for="value-source-scene-sensitivity"><span data-i18n="value_source.sensitivity">Sensitivity:</span> <span id="value-source-scene-sensitivity-display">1.0</span></label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.scene_sensitivity.hint">Gain multiplier for the luminance signal (higher = more reactive to brightness changes)</small>
<input type="range" id="value-source-scene-sensitivity" min="0.1" max="5" step="0.1" value="1.0"
oninput="document.getElementById('value-source-scene-sensitivity-display').textContent = this.value">
</div>
<div class="form-group">
<div class="label-row">
<label for="value-source-scene-smoothing"><span data-i18n="value_source.smoothing">Smoothing:</span> <span id="value-source-scene-smoothing-display">0.3</span></label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.smoothing.hint">Temporal smoothing (0 = instant response, 1 = very smooth transitions)</small>
<input type="range" id="value-source-scene-smoothing" min="0" max="1" step="0.05" value="0.3"
oninput="document.getElementById('value-source-scene-smoothing-display').textContent = this.value">
</div>
</div>
<!-- Shared adaptive output range (shown for both adaptive types) -->
<div id="value-source-adaptive-range-section" style="display:none">
<div class="form-group">
<div class="label-row">
<label for="value-source-adaptive-min-value"><span data-i18n="value_source.adaptive_min_value">Min Value:</span> <span id="value-source-adaptive-min-value-display">0</span></label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.adaptive_min_value.hint">Minimum output brightness</small>
<input type="range" id="value-source-adaptive-min-value" min="0" max="1" step="0.01" value="0"
oninput="document.getElementById('value-source-adaptive-min-value-display').textContent = this.value">
</div>
<div class="form-group">
<div class="label-row">
<label for="value-source-adaptive-max-value"><span data-i18n="value_source.adaptive_max_value">Max Value:</span> <span id="value-source-adaptive-max-value-display">1</span></label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.adaptive_max_value.hint">Maximum output brightness</small>
<input type="range" id="value-source-adaptive-max-value" min="0" max="1" step="0.01" value="1"
oninput="document.getElementById('value-source-adaptive-max-value-display').textContent = this.value">
</div>
</div>
<!-- Description -->
<div class="form-group">
<div class="label-row">
<label for="value-source-description" data-i18n="value_source.description">Description (optional):</label>
<button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
</div>
<small class="input-hint" style="display:none" data-i18n="value_source.description.hint">Optional notes about this value source</small>
<input type="text" id="value-source-description" data-i18n-placeholder="value_source.description.placeholder" placeholder="Describe this value source...">
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-icon btn-secondary" onclick="closeValueSourceModal()" title="Cancel" data-i18n-title="settings.button.cancel" data-i18n-aria-label="aria.cancel">&#x2715;</button>
<button class="btn btn-icon btn-primary" onclick="saveValueSource()" title="Save" data-i18n-title="settings.button.save" data-i18n-aria-label="aria.save">&#x2713;</button>
</div>
</div>
</div>