mirror of
https://github.com/myronblair/jarvis
synced 2026-06-30 17:50:23 -05:00
HA tab: add ALL / ON ONLY toggle filter
This commit is contained in:
@@ -572,6 +572,8 @@ select.filter-sel:focus{border-color:var(--cyan)}
|
||||
<div class="filters">
|
||||
<span class="lbl">DOMAIN:</span>
|
||||
<select class="filter-sel" id="ha-domain" onchange="loadHA()"><option value="">ALL</option></select>
|
||||
<button class="filter-btn active" id="ha-all-btn" onclick="setHAOnlyOn(false,this)">ALL</button>
|
||||
<button class="filter-btn" id="ha-on-btn" onclick="setHAOnlyOn(true,this)">ON ONLY</button>
|
||||
<input id="ha-search" placeholder="search name or entity_id..." style="background:#060a0e;border:1px solid var(--border2);color:var(--text);padding:4px 8px;font-family:var(--font);font-size:0.65rem;width:220px;outline:none" oninput="filterHATable()" onchange="filterHATable()">
|
||||
<span class="lbl" id="ha-count" style="color:var(--cyan)"></span>
|
||||
</div>
|
||||
@@ -1132,9 +1134,22 @@ async function loadHA() {
|
||||
renderHATable(_haEntities);
|
||||
}
|
||||
|
||||
let _haOnlyOn = false;
|
||||
|
||||
function setHAOnlyOn(onlyOn, btn) {
|
||||
_haOnlyOn = onlyOn;
|
||||
document.getElementById('ha-all-btn').classList.toggle('active', !onlyOn);
|
||||
document.getElementById('ha-on-btn').classList.toggle('active', onlyOn);
|
||||
filterHATable();
|
||||
}
|
||||
|
||||
function filterHATable() {
|
||||
const q = document.getElementById('ha-search')?.value.toLowerCase() || '';
|
||||
renderHATable(q ? _haEntities.filter(e => (e.name||'').toLowerCase().includes(q)||(e.entity_id||'').toLowerCase().includes(q)) : _haEntities);
|
||||
const ON_STATES = ['on','home','open','playing','mowing','active','idle'];
|
||||
let list = _haEntities;
|
||||
if (_haOnlyOn) list = list.filter(e => ON_STATES.includes(e.state));
|
||||
if (q) list = list.filter(e => (e.name||'').toLowerCase().includes(q)||(e.entity_id||'').toLowerCase().includes(q));
|
||||
renderHATable(list);
|
||||
}
|
||||
|
||||
function renderHATable(entities) {
|
||||
|
||||
Reference in New Issue
Block a user