labels and automatizations

This commit is contained in:
Mateusz Gruszczyński
2026-05-06 22:13:52 +02:00
parent e2017b8344
commit a72b6eb364
5 changed files with 70 additions and 34 deletions

View File

@@ -528,10 +528,10 @@
// Note: Builder queues allow many conditions and many ordered actions in one automation without changing old single-step saves.
let automationConditionQueue=[];
let automationEffectQueue=[];
function automationCondition(){ const type=$('autoConditionType')?.value||'completed'; const cond={type}; if(type==='no_seeds'){cond.seeds=Number($('autoCondSeeds')?.value||0);cond.minutes=Number($('autoCondMinutes')?.value||0);} if(type==='ratio_gte')cond.ratio=Number($('autoCondRatio')?.value||1); if(type==='label_missing'||type==='label_has')cond.label=$('autoCondLabel')?.value||''; if(type==='status')cond.status=$('autoCondStatus')?.value||'Seeding'; if(type==='path_contains')cond.text=$('autoCondText')?.value||''; return cond; }
function automationCondition(){ const type=$('autoConditionType')?.value||'completed'; const cond={type}; if($('autoCondNegate')?.checked) cond.negate=true; if(type==='no_seeds'){cond.seeds=Number($('autoCondSeeds')?.value||0);cond.minutes=Number($('autoCondMinutes')?.value||0);} if(type==='ratio_gte')cond.ratio=Number($('autoCondRatio')?.value||1); if(type==='label_missing'||type==='label_has')cond.label=$('autoCondLabel')?.value||''; if(type==='status')cond.status=$('autoCondStatus')?.value||'Seeding'; if(type==='path_contains')cond.text=$('autoCondText')?.value||''; return cond; }
function automationEffect(){ const type=$('autoEffectType')?.value||'add_label'; const eff={type}; if(type==='move'){eff.path=$('autoEffectPath')?.value||''; eff.move_data=!!($('autoMoveDataPhysical')?.checked); eff.recheck=!!($('autoMoveRecheck')?.checked); eff.keep_seeding=!!($('autoMoveKeepSeeding')?.checked);} if(type==='add_label'||type==='remove_label')eff.label=$('autoEffectLabel')?.value||''; if(type==='set_labels')eff.labels=$('autoEffectLabels')?.value||''; return eff; }
function updateAutomationForm(){ const ct=$('autoConditionType')?.value||''; document.querySelectorAll('[data-auto-cond]').forEach(el=>el.classList.toggle('d-none', !el.dataset.autoCond.split(',').includes(ct))); const et=$('autoEffectType')?.value||''; document.querySelectorAll('[data-auto-effect]').forEach(el=>el.classList.toggle('d-none', !el.dataset.autoEffect.split(',').includes(et))); }
function conditionSummary(c){ return c.type==='no_seeds'?`no seeds <=${c.seeds||0} for ${c.minutes||0} min`:c.type==='ratio_gte'?`ratio >= ${c.ratio}`:c.type==='label_missing'?`missing label ${c.label||''}`:c.type==='label_has'?`has label ${c.label||''}`:c.type==='status'?`status ${c.status||''}`:c.type==='path_contains'?`path contains ${c.text||''}`:'completed'; }
function conditionSummary(c){ const base=c.type==='no_seeds'?`no seeds <=${c.seeds||0} for ${c.minutes||0} min`:c.type==='ratio_gte'?`ratio >= ${c.ratio}`:c.type==='label_missing'?`missing label ${c.label||''}`:c.type==='label_has'?`has label ${c.label||''}`:c.type==='status'?`status ${c.status||''}`:c.type==='path_contains'?`path contains ${c.text||''}`:'completed'; return c.negate?`NOT (${base})`:base; }
function effectSummary(e){ return e.type==='move'?`move to ${e.path||'default path'}${e.move_data?' + data move':''}${e.keep_seeding?' + keep seeding':''}${e.recheck?' + recheck':''}`:e.type==='add_label'?`add label ${e.label||''}`:e.type==='remove_label'?`remove label ${e.label||''}`:e.type==='set_labels'?`set labels ${e.labels||''}`:e.type; }
function renderAutomationBuilder(){ const cbox=$('autoConditionsList'), ebox=$('autoEffectsList'); if(cbox) cbox.innerHTML=automationConditionQueue.length?automationConditionQueue.map((c,i)=>`<div class="automation-chip"><span>${esc(i+1)}. ${esc(conditionSummary(c))}</span><button class="btn btn-xs btn-outline-secondary auto-remove-condition" data-index="${i}" type="button">×</button></div>`).join(''):'<div class="small text-muted">No extra conditions added; current condition will be used on save.</div>'; if(ebox) ebox.innerHTML=automationEffectQueue.length?automationEffectQueue.map((e,i)=>`<div class="automation-chip"><span>${esc(i+1)}. ${esc(effectSummary(e))}</span><button class="btn btn-xs btn-outline-secondary auto-remove-effect" data-index="${i}" type="button">×</button></div>`).join(''):'<div class="small text-muted">No action sequence added; current action will be used on save.</div>'; }
function addAutomationCondition(){ automationConditionQueue.push(automationCondition()); renderAutomationBuilder(); }

View File

@@ -1245,7 +1245,8 @@ body.mobile-mode .mobile-card {
align-items: center;
}
.auto-move-option {
.auto-move-option,
.auto-condition-option {
gap: 0.45rem;
margin: 0;
}