PIGWay Pi Control
@@ -69,7 +71,7 @@ async function pluginAction(id,operation){try{await pluginPut('/api/v1/plugins',
function capabilityField(section,key,value,spec){const unit=LANG==='zh'?({s:'秒',ms:'毫秒'}[spec.unit]||spec.unit):spec.unit,label=spec.label?.[LANG]||spec.label?.en||key,id=`${section}.${key}`,vis=spec.visible?` data-cap-visible="${esc(JSON.stringify(spec.visible))}"`:'';return ``}
function pluginChoice(x){const zh={off:'全灭',solid:'自定义常亮',flash:'自定义闪烁(实验性)',breathe:'内置呼吸',flow:'流水灯',marquee:'跑马灯',rainbow:'彩虹灯',colorful:'炫彩灯',red:'红色',green:'绿色',blue:'蓝色',yellow:'黄色',purple:'紫色',cyan:'青色',white:'白色'};return LANG==='zh'?(zh[x]||x):x}
function capabilityFields(section,fields,values){const seen=new Set();return Object.entries(fields).map(([key,spec])=>{if(!spec.color_group)return capabilityField(section,key,values[key],spec);if(seen.has(spec.color_group))return '';seen.add(spec.color_group);const members=Object.entries(fields).filter(([,v])=>v.color_group===spec.color_group),hex='#'+['r','g','b'].map(c=>Number(values[members.find(([,v])=>v.channel===c)[0]]).toString(16).padStart(2,'0')).join('');return `
`;editor.oninput=e=>{if(e.target.dataset.capColor){const group=e.target.dataset.capColor,hex=e.target.value;['r','g','b'].forEach((c,i)=>{editor.querySelector(`[data-cap-key="${group}_${c}"]`).value=parseInt(hex.slice(1+2*i,3+2*i),16)})}for(const picker of editor.querySelectorAll('[data-cap-color]')){picker.value='#'+['r','g','b'].map(c=>Math.max(0,Math.min(255,Number(editor.querySelector(`[data-cap-key="${picker.dataset.capColor}_${c}"]`).value))).toString(16).padStart(2,'0')).join('')}updatePluginVisibility()};updatePluginVisibility();$('savePlugin').onclick=savePluginConfig}catch(e){$('pluginEditor').textContent=e.message}}
+async function editPlugin(id){try{pluginSelected=id;pluginDraft=await get('/api/v1/plugin/config?host='+encodeURIComponent(currentConfigHost)+'&id='+encodeURIComponent(id));const data=pluginDraft,editor=$('pluginEditor');editor.innerHTML=`
${esc(id)}
${pluginText('配置由插件保存并立即应用,不重启监控。','Settings are saved and applied by the plugin without restarting monitoring.')}
`;editor.oninput=e=>{if(e.target.dataset.capColor){const group=e.target.dataset.capColor,hex=e.target.value;['r','g','b'].forEach((c,i)=>{editor.querySelector(`[data-cap-key="${group}_${c}"]`).value=parseInt(hex.slice(1+2*i,3+2*i),16)})}for(const picker of editor.querySelectorAll('[data-cap-color]')){picker.value='#'+['r','g','b'].map(c=>Math.max(0,Math.min(255,Number(editor.querySelector(`[data-cap-key="${picker.dataset.capColor}_${c}"]`).value))).toString(16).padStart(2,'0')).join('')}updatePluginVisibility()};updatePluginVisibility();$('savePlugin').onclick=savePluginConfig}catch(e){$('pluginEditor').textContent=e.message}}
function updatePluginVisibility(){document.querySelectorAll('[data-cap-visible]').forEach(el=>{const rules=JSON.parse(el.dataset.capVisible);el.classList.toggle('hidden',!Object.entries(rules).every(([key,values])=>values.includes(document.querySelector(`[data-cap-key="${key}"]`)?.value)))})}
async function savePluginConfig(){const updates={};for(const el of document.querySelectorAll('[data-cap-key]')){if(!el.reportValidity())return;const s=el.dataset.capSection,k=el.dataset.capKey;(updates[s]??={})[k]=el.value}try{await pluginPut('/api/v1/plugin/config',{id:pluginSelected,updates});$('pluginSaveState').textContent=pluginText('保存成功','Saved')}catch(e){$('pluginSaveState').textContent=e.message}}
document.addEventListener('click',async e=>{const b=e.target.closest('[data-manage-plugin-host]');if(!b)return;currentConfigHost=b.dataset.managePluginHost;await ensureHosts();$('configHost').value=currentConfigHost;document.querySelector('[data-tab="config"]').click();await loadConfig();document.querySelector('[data-config-section="plugins"]')?.click()});