| 1 | <!DOCTYPE html> |
| 2 | <html lang="en"><head><meta charset="utf-8"> |
| 3 | <meta name="viewport" content="width=device-width,initial-scale=1"> |
| 4 | <title>services</title> |
| 5 | <!--TOKENS--> |
| 6 | <style> |
| 7 | *{box-sizing:border-box} |
| 8 | html,body{margin:0;min-height:100%} |
| 9 | body{background:var(--bg);color:var(--tx,var(--text));font-family:var(--font); |
| 10 | font-size:14px;line-height:1.5;-webkit-font-smoothing:antialiased} |
| 11 | .wrap{max-width:1180px;margin:0 auto;padding:18px 18px 40px} |
| 12 | .top{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-bottom:14px} |
| 13 | .brand{font-size:11px;font-weight:700;letter-spacing:.09em;text-transform:uppercase; |
| 14 | color:var(--mu,var(--text-2))} |
| 15 | .title{font-size:19px;font-weight:680;margin:0;letter-spacing:-.01em} |
| 16 | .sp{flex:1 1 auto} |
| 17 | .pill{font-size:11px;font-weight:600;padding:3px 9px;border-radius:999px; |
| 18 | background:var(--sf2,var(--surface-2));color:var(--mu,var(--text-2)); |
| 19 | border:1px solid var(--ln,var(--line));white-space:nowrap} |
| 20 | .icon-btn{display:inline-flex;align-items:center;justify-content:center;gap:6px; |
| 21 | background:var(--sf2,var(--surface-2));border:1px solid var(--ln,var(--line)); |
| 22 | color:var(--text);border-radius:9px;height:30px;padding:0 11px;cursor:pointer; |
| 23 | font-family:inherit;font-size:12px;font-weight:600} |
| 24 | .icon-btn:hover{background:var(--surface-hover);border-color:var(--line-2)} |
| 25 | .icon-btn:active{transform:scale(.97)} |
| 26 | .icon-btn svg{width:14px;height:14px;fill:none;stroke:currentColor;stroke-width:1.9; |
| 27 | stroke-linecap:round;stroke-linejoin:round} |
| 28 | |
| 29 | .chips{display:grid;grid-template-columns:repeat(auto-fit,minmax(130px,1fr));gap:10px; |
| 30 | margin-bottom:14px} |
| 31 | .chip{background:var(--sf,var(--bg-card));border:1px solid var(--ln,var(--line)); |
| 32 | border-radius:12px;padding:11px 13px;cursor:pointer;font-family:inherit; |
| 33 | text-align:left;color:var(--text)} |
| 34 | .chip:hover{border-color:var(--line-2)} |
| 35 | .chip.sel{box-shadow:inset 0 0 0 1.5px var(--ac,var(--blue))} |
| 36 | .chip .k{display:flex;align-items:center;gap:6px;font-size:10.5px;font-weight:700; |
| 37 | letter-spacing:.07em;text-transform:uppercase;color:var(--mu,var(--text-2))} |
| 38 | .chip .k svg{width:12px;height:12px;fill:none;stroke:currentColor;stroke-width:2; |
| 39 | stroke-linecap:round;stroke-linejoin:round} |
| 40 | .chip .v{font-family:var(--mono);font-size:23px;font-weight:700;margin-top:3px; |
| 41 | letter-spacing:-.02em} |
| 42 | .chip.ok .v{color:var(--green)} |
| 43 | .chip.bad .v{color:var(--red)} |
| 44 | .chip.none .v{color:var(--mu,var(--text-2))} |
| 45 | |
| 46 | .bar{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-bottom:10px} |
| 47 | .search{flex:1 1 240px;min-width:0;padding:9px 12px;border-radius:10px; |
| 48 | border:1px solid var(--ln,var(--line));background:var(--input-bg);color:var(--text); |
| 49 | font-family:inherit;font-size:13px} |
| 50 | .search:focus{outline:2px solid var(--ac,var(--blue));outline-offset:-1px} |
| 51 | select{padding:9px 11px;border-radius:10px;border:1px solid var(--ln,var(--line)); |
| 52 | background:var(--input-bg);color:var(--text);font-family:inherit;font-size:13px} |
| 53 | |
| 54 | .panel{background:var(--sf,var(--bg-card));border:1px solid var(--ln,var(--line)); |
| 55 | border-radius:14px;overflow:hidden} |
| 56 | .tb{width:100%;overflow-x:auto} |
| 57 | table{width:100%;border-collapse:collapse;font-size:13px} |
| 58 | th{text-align:left;font-size:10.5px;letter-spacing:.07em;text-transform:uppercase; |
| 59 | color:var(--mu,var(--text-2));font-weight:700;padding:9px 12px; |
| 60 | border-bottom:1px solid var(--ln,var(--line));white-space:nowrap; |
| 61 | background:var(--sf2,var(--surface-2))} |
| 62 | td{padding:9px 12px;border-bottom:1px solid var(--ln,var(--line)); |
| 63 | vertical-align:middle;white-space:nowrap} |
| 64 | tr.row{cursor:pointer} |
| 65 | tr.row:hover td{background:var(--surface-hover)} |
| 66 | tr.row:last-child td{border-bottom:0} |
| 67 | tr.row.sel td{background:var(--sf2,var(--surface-2))} |
| 68 | .mo{font-family:var(--mono);font-size:12.5px} |
| 69 | .name{font-weight:600;max-width:340px;overflow:hidden;text-overflow:ellipsis} |
| 70 | .desc{font-size:11.5px;color:var(--mu,var(--text-2));max-width:340px; |
| 71 | overflow:hidden;text-overflow:ellipsis;margin-top:1px} |
| 72 | .tag{font-size:10px;font-weight:700;padding:2px 8px;border-radius:6px; |
| 73 | white-space:nowrap;letter-spacing:.03em} |
| 74 | .t-run{background:rgba(48,209,88,.16);color:var(--green)} |
| 75 | .t-fail{background:rgba(255,69,58,.16);color:var(--red)} |
| 76 | .t-off{background:var(--sf2,var(--surface-2));color:var(--mu,var(--text-2)); |
| 77 | border:1px solid var(--ln,var(--line))} |
| 78 | .t-warn{background:rgba(255,159,10,.16);color:var(--orange)} |
| 79 | .dot{display:inline-block;width:7px;height:7px;border-radius:50%;margin-right:6px; |
| 80 | vertical-align:1px} |
| 81 | .d-run{background:var(--green)}.d-fail{background:var(--red)} |
| 82 | .d-off{background:var(--gray)}.d-warn{background:var(--orange)} |
| 83 | .empty{padding:26px 14px;text-align:center;color:var(--mu,var(--text-2));font-size:13px} |
| 84 | .hide{display:none!important} |
| 85 | |
| 86 | /* detail drawer */ |
| 87 | .scrim{position:fixed;inset:0;background:rgba(0,0,0,.38);opacity:0;pointer-events:none; |
| 88 | transition:opacity .18s var(--ease);z-index:40} |
| 89 | .scrim.open{opacity:1;pointer-events:auto} |
| 90 | .drawer{position:fixed;top:0;right:0;bottom:0;width:min(430px,100%);z-index:41; |
| 91 | background:var(--bg-2,var(--bg-card));border-left:1px solid var(--ln,var(--line)); |
| 92 | box-shadow:var(--shadow-lg);transform:translateX(102%); |
| 93 | transition:transform .22s var(--ease);display:flex;flex-direction:column; |
| 94 | max-width:100%} |
| 95 | .drawer.open{transform:none} |
| 96 | .dh{display:flex;align-items:flex-start;gap:10px;padding:16px 16px 12px; |
| 97 | border-bottom:1px solid var(--ln,var(--line))} |
| 98 | .dh .t{flex:1 1 auto;min-width:0} |
| 99 | .dh .n{font-size:15px;font-weight:680;word-break:break-all} |
| 100 | .dh .s{font-size:11.5px;color:var(--mu,var(--text-2));margin-top:3px; |
| 101 | word-break:break-word} |
| 102 | .dbody{flex:1 1 auto;overflow-y:auto;padding:14px 16px 24px} |
| 103 | .kv{display:grid;grid-template-columns:110px minmax(0,1fr);gap:8px 12px; |
| 104 | font-size:12.5px;margin-bottom:16px} |
| 105 | .kv .k{color:var(--mu,var(--text-2))} |
| 106 | .kv .v{font-family:var(--mono);word-break:break-all} |
| 107 | .ctl{display:flex;gap:8px;flex-wrap:wrap;border-top:1px solid var(--ln,var(--line)); |
| 108 | padding-top:14px;margin-top:4px} |
| 109 | .btn{background:var(--ac,var(--blue));color:#fff;border:0;border-radius:999px; |
| 110 | padding:8px 16px;font-weight:650;font-size:12.5px;cursor:pointer;font-family:inherit} |
| 111 | .btn:active{transform:scale(.98)} |
| 112 | .btn.gh{background:transparent;color:var(--text);border:1px solid var(--ln,var(--line))} |
| 113 | .btn.warn{background:var(--orange)} |
| 114 | .btn.bad{background:var(--red)} |
| 115 | .note{font-size:11.5px;color:var(--mu,var(--text-2));margin-top:10px} |
| 116 | .out{margin-top:12px;padding:10px 12px;border-radius:10px;font-size:12.5px; |
| 117 | background:var(--sf2,var(--surface-2));border:1px solid var(--ln,var(--line)); |
| 118 | word-break:break-word} |
| 119 | .out.err{color:var(--red);border-color:rgba(255,69,58,.4)} |
| 120 | .out.ok{color:var(--green);border-color:rgba(48,209,88,.35)} |
| 121 | |
| 122 | @media(max-width:860px){ |
| 123 | .wrap{padding:14px 12px 32px} |
| 124 | .name,.desc{max-width:200px} |
| 125 | th.h-opt,td.h-opt{display:none} |
| 126 | } |
| 127 | @media(max-width:600px){ |
| 128 | .wrap{padding:12px 10px 28px} |
| 129 | .title{font-size:17px} |
| 130 | .chips{grid-template-columns:repeat(2,minmax(0,1fr));gap:8px} |
| 131 | .chip .v{font-size:20px} |
| 132 | .name,.desc{max-width:150px} |
| 133 | th.h-since,td.h-since{display:none} |
| 134 | .drawer{width:100%} |
| 135 | } |
| 136 | </style></head><body> |
| 137 | <div class="wrap"> |
| 138 | <div class="top"> |
| 139 | <div> |
| 140 | <div class="brand">SCORPIOX BOT</div> |
| 141 | <h1 class="title">Services</h1> |
| 142 | </div> |
| 143 | <span class="sp"></span> |
| 144 | <span class="pill" id="initPill">init: —</span> |
| 145 | <button class="icon-btn embed-hide" id="btnRefresh" type="button" title="Reload"> |
| 146 | <svg viewBox="0 0 24 24"><path d="M20 12a8 8 0 1 1-2.3-5.7"/><path d="M20 4v5h-5"/></svg> |
| 147 | Refresh |
| 148 | </button> |
| 149 | <button class="icon-btn embed-hide" id="btnTheme" type="button" title="Toggle appearance"> |
| 150 | <svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="4.2"/><path d="M12 2v2M12 20v2M2 12h2M20 12h2M5 5l1.4 1.4M17.6 17.6L19 19M19 5l-1.4 1.4M6.4 17.6L5 19"/></svg> |
| 151 | </button> |
| 152 | </div> |
| 153 | |
| 154 | <div class="chips"> |
| 155 | <button class="chip" id="cAll" type="button"><div class="k">All</div><div class="v" id="vAll">—</div></button> |
| 156 | <button class="chip ok" id="cRun" type="button"><div class="k"><span class="dot d-run"></span>Running</div><div class="v" id="vRun">—</div></button> |
| 157 | <button class="chip bad" id="cFail" type="button"><div class="k"><span class="dot d-fail"></span>Failed</div><div class="v" id="vFail">—</div></button> |
| 158 | <button class="chip none" id="cOff" type="button"><div class="k"><span class="dot d-off"></span>Inactive</div><div class="v" id="vOff">—</div></button> |
| 159 | </div> |
| 160 | |
| 161 | <div class="bar"> |
| 162 | <input class="search" id="q" type="search" placeholder="Search name or description" autocomplete="off" spellcheck="false"> |
| 163 | <select id="sort" title="Sort"> |
| 164 | <option value="failed">Sort: failed first</option> |
| 165 | <option value="name">Sort: name</option> |
| 166 | <option value="state">Sort: state</option> |
| 167 | </select> |
| 168 | </div> |
| 169 | |
| 170 | <div class="panel"> |
| 171 | <div class="tb"> |
| 172 | <table> |
| 173 | <thead><tr> |
| 174 | <th>Service</th> |
| 175 | <th>State</th> |
| 176 | <th class="h-opt">Enabled</th> |
| 177 | <th class="h-opt">PID</th> |
| 178 | <th class="h-opt">Memory</th> |
| 179 | <th class="h-since">Since</th> |
| 180 | </tr></thead> |
| 181 | <tbody id="rows"></tbody> |
| 182 | </table> |
| 183 | </div> |
| 184 | <div id="empty" class="empty hide">No services matched this filter.</div> |
| 185 | </div> |
| 186 | </div> |
| 187 | |
| 188 | <div class="scrim" id="scrim"></div> |
| 189 | <aside class="drawer" id="drawer" aria-hidden="true"> |
| 190 | <div class="dh"> |
| 191 | <div class="t"><div class="n" id="dName">—</div><div class="s" id="dDesc"></div></div> |
| 192 | <button class="icon-btn" id="dClose" type="button" title="Close"> |
| 193 | <svg viewBox="0 0 24 24"><path d="M6 6l12 12M18 6L6 18"/></svg> |
| 194 | </button> |
| 195 | </div> |
| 196 | <div class="dbody"> |
| 197 | <div class="kv"> |
| 198 | <div class="k">State</div><div class="v" id="dState">—</div> |
| 199 | <div class="k">Sub-state</div><div class="v" id="dSub">—</div> |
| 200 | <div class="k">Enabled</div><div class="v" id="dEnabled">—</div> |
| 201 | <div class="k">PID</div><div class="v" id="dPid">—</div> |
| 202 | <div class="k">Memory</div><div class="v" id="dMem">—</div> |
| 203 | <div class="k">Since</div><div class="v" id="dSince">—</div> |
| 204 | </div> |
| 205 | <div class="ctl hide" id="dCtl"> |
| 206 | <button class="btn" id="opStart" type="button">Start</button> |
| 207 | <button class="btn warn" id="opRestart" type="button">Restart</button> |
| 208 | <button class="btn bad" id="opStop" type="button">Stop</button> |
| 209 | </div> |
| 210 | <div class="note hide" id="dNote"></div> |
| 211 | <div class="out hide" id="dOut"></div> |
| 212 | </div> |
| 213 | </aside> |
| 214 | |
| 215 | <script> |
| 216 | (function(){ |
| 217 | "use strict"; |
| 218 | var q=new URLSearchParams(location.search); |
| 219 | var node=q.get('node')||''; |
| 220 | var sid=q.get('id')||''; |
| 221 | var pwd=q.get('pwd')||(node&&localStorage.getItem('bot_pwd_'+node))|| |
| 222 | localStorage.getItem('bot_active_pwd')||''; |
| 223 | var HUB=q.get('plugin')||''; |
| 224 | |
| 225 | /* Two call routes. Through the hub -> call the hub proxy back. Opened directly |
| 226 | * on the node -> the plugin itself is the route. Calling /plugins?plugin= on the |
| 227 | * node returns the discovery list, not this plugin. */ |
| 228 | function api(action,extra,method){ |
| 229 | var u=(HUB?'/plugins?plugin='+encodeURIComponent(HUB):'/plugin_services')+ |
| 230 | '?action='+encodeURIComponent(action)+(extra?('&'+extra):'')+ |
| 231 | (node?'&node='+encodeURIComponent(node):'')+ |
| 232 | (sid?'&id='+encodeURIComponent(sid):'')+ |
| 233 | (pwd?'&pwd='+encodeURIComponent(pwd):''); |
| 234 | return fetch(u,{method:method||'GET',headers:pwd?{'X-Bot-Password':pwd}:{}}) |
| 235 | .then(function(r){return r.json();}); |
| 236 | } |
| 237 | function $(id){return document.getElementById(id);} |
| 238 | function esc(v){return String(v==null?'':v).replace(/[&<>"']/g,function(c){ |
| 239 | return({'&':'&','<':'<','>':'>','"':'"',"'":'''})[c];});} |
| 240 | function bytes(n){ |
| 241 | if(n==null||n===0) return '—'; |
| 242 | var u=['B','KiB','MiB','GiB','TiB'],i=0,v=n; |
| 243 | while(v>=1024&&i<u.length-1){v/=1024;i++;} |
| 244 | return (v>=100?Math.round(v):(Math.round(v*10)/10))+' '+u[i]; |
| 245 | } |
| 246 | var DATA=[],CTL=false,FILTER='',SORT='failed',SEL=null; |
| 247 | |
| 248 | function stateCls(s){ |
| 249 | if(s.failed||s.active==='failed') return 'fail'; |
| 250 | if(s.active==='running'||s.active==='active'||s.sub==='running') return 'run'; |
| 251 | if(s.active==='paused'||s.active==='starting'||s.active==='stopping') return 'warn'; |
| 252 | return 'off'; |
| 253 | } |
| 254 | function stateLabel(s){ |
| 255 | var c=stateCls(s); |
| 256 | if(c==='run') return 'running'; |
| 257 | if(c==='fail') return 'failed'; |
| 258 | if(c==='warn') return s.active||'pending'; |
| 259 | return s.active==='inactive'?'inactive':(s.active||'inactive'); |
| 260 | } |
| 261 | /* unused helper removed: stateLabel(s) already returns the visible label */ |
| 262 | |
| 263 | function visible(){ |
| 264 | var f=FILTER, needle=($('q').value||'').toLowerCase(); |
| 265 | var out=DATA.filter(function(s){ |
| 266 | if(f==='running'&&stateCls(s)!=='run') return false; |
| 267 | if(f==='failed'&&stateCls(s)!=='fail') return false; |
| 268 | if(f==='inactive'&&stateCls(s)!=='off') return false; |
| 269 | if(needle){ |
| 270 | var hay=(s.name+' '+(s.description||'')).toLowerCase(); |
| 271 | if(hay.indexOf(needle)<0) return false; |
| 272 | } |
| 273 | return true; |
| 274 | }); |
| 275 | if(SORT==='name') out.sort(function(a,b){return a.name<b.name?-1:a.name>b.name?1:0;}); |
| 276 | else if(SORT==='state') out.sort(function(a,b){ |
| 277 | var x=stateCls(a),y=stateCls(b); |
| 278 | if(x!==y) return x<y?-1:1; |
| 279 | return a.name<b.name?-1:1;}); |
| 280 | return out; |
| 281 | } |
| 282 | |
| 283 | function render(){ |
| 284 | var rows=visible(); |
| 285 | var h=''; |
| 286 | for(var i=0;i<rows.length;i++){ |
| 287 | var s=rows[i],c=stateCls(s); |
| 288 | h+='<tr class="row'+(SEL&&SEL===s.name?' sel':'')+'" data-n="'+esc(s.name)+'">'+ |
| 289 | '<td><div class="name" title="'+esc(s.name)+'">'+esc(s.name)+'</div>'+ |
| 290 | (s.description?'<div class="desc" title="'+esc(s.description)+'">'+esc(s.description)+'</div>':'')+ |
| 291 | '</td>'+ |
| 292 | '<td><span class="tag t-'+c+'"><span class="dot d-'+c+'"></span>'+ |
| 293 | esc(stateLabel(s))+'</span></td>'+ |
| 294 | '<td class="mo h-opt">'+esc(s.enabled||'-')+'</td>'+ |
| 295 | '<td class="mo h-opt">'+(s.pid>0?esc(s.pid):'—')+'</td>'+ |
| 296 | '<td class="mo h-opt">'+bytes(s.memory_bytes)+'</td>'+ |
| 297 | '<td class="mo h-since">'+esc(s.since||'—')+'</td></tr>'; |
| 298 | } |
| 299 | $('rows').innerHTML=h; |
| 300 | $('empty').className=rows.length?'empty hide':'empty'; |
| 301 | var trs=$('rows').querySelectorAll('tr.row'); |
| 302 | for(var k=0;k<trs.length;k++){ |
| 303 | trs[k].onclick=function(){open(this.getAttribute('data-n'));}; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | function load(){ |
| 308 | return api('list','filter=all').then(function(d){ |
| 309 | if(!d||!d.ok){ throw new Error((d&&d.error)||'load failed'); } |
| 310 | DATA=d.services||[]; |
| 311 | CTL=!!d.control_enabled; |
| 312 | var sum=d.summary||{}; |
| 313 | $('vAll').textContent=DATA.length; |
| 314 | $('vRun').textContent=sum.running||0; |
| 315 | $('vFail').textContent=sum.failed||0; |
| 316 | $('vOff').textContent=sum.inactive||0; |
| 317 | $('initPill').textContent='init: '+(d.init_system||'unknown')+ |
| 318 | (CTL?' · control on':' · read-only'); |
| 319 | render(); |
| 320 | }); |
| 321 | } |
| 322 | |
| 323 | function open(name){ |
| 324 | var s=null; |
| 325 | for(var i=0;i<DATA.length;i++) if(DATA[i].name===name){s=DATA[i];break;} |
| 326 | if(!s) return; |
| 327 | SEL=name; |
| 328 | $('dName').textContent=s.name; |
| 329 | $('dDesc').textContent=s.description||''; |
| 330 | $('dState').textContent=stateLabel(s); |
| 331 | $('dSub').textContent=s.sub||'—'; |
| 332 | $('dEnabled').textContent=s.enabled||'-'; |
| 333 | $('dPid').textContent=s.pid>0?s.pid:'—'; |
| 334 | $('dMem').textContent=bytes(s.memory_bytes); |
| 335 | $('dSince').textContent=s.since||'—'; |
| 336 | $('dOut').className='out hide'; |
| 337 | $('dOut').textContent=''; |
| 338 | if(CTL){ |
| 339 | $('dCtl').className='ctl'; |
| 340 | $('dNote').className='note'; |
| 341 | $('dNote').textContent='Control is enabled on this node (SERVICES_ALLOW_CONTROL=1). Every action is sent as a separate argv element, never through a shell.'; |
| 342 | }else{ |
| 343 | $('dCtl').className='ctl hide'; |
| 344 | $('dNote').className='note'; |
| 345 | $('dNote').textContent='Read-only: set SERVICES_ALLOW_CONTROL=1 in this node\'s plugin environment to enable start, stop and restart.'; |
| 346 | } |
| 347 | $('drawer').className='drawer open'; |
| 348 | $('drawer').setAttribute('aria-hidden','false'); |
| 349 | $('scrim').className='scrim open'; |
| 350 | render(); |
| 351 | } |
| 352 | function close(){ |
| 353 | SEL=null; |
| 354 | $('drawer').className='drawer'; |
| 355 | $('drawer').setAttribute('aria-hidden','true'); |
| 356 | $('scrim').className='scrim'; |
| 357 | render(); |
| 358 | } |
| 359 | |
| 360 | function control(op){ |
| 361 | if(!SEL) return; |
| 362 | var label={start:'start',stop:'stop',restart:'restart'}[op]; |
| 363 | if(!window.confirm(label+' '+SEL+'?\n\nThis runs '+label+' on the node\'s service manager.')) return; |
| 364 | var o=$('dOut'); |
| 365 | o.className='out'; |
| 366 | o.textContent='Sending '+label+' '+SEL+' ...'; |
| 367 | api('control','unit='+encodeURIComponent(SEL)+'&op='+encodeURIComponent(op),'POST') |
| 368 | .then(function(d){ |
| 369 | if(d&&d.ok){ |
| 370 | o.className='out ok'; |
| 371 | o.textContent=label+' requested for '+SEL+'.'; |
| 372 | setTimeout(function(){load().then(function(){ |
| 373 | for(var i=0;i<DATA.length;i++) if(DATA[i].name===SEL){ show(DATA[i]); break; } |
| 374 | });},700); |
| 375 | }else{ |
| 376 | o.className='out err'; |
| 377 | o.textContent=(d&&(d.error||('HTTP error')))+''; |
| 378 | } |
| 379 | }).catch(function(e){ |
| 380 | o.className='out err'; |
| 381 | o.textContent='Request failed: '+e.message; |
| 382 | }); |
| 383 | } |
| 384 | function show(s){ |
| 385 | $('dState').textContent=stateLabel(s); |
| 386 | $('dSub').textContent=s.sub||'—'; |
| 387 | $('dEnabled').textContent=s.enabled||'-'; |
| 388 | $('dPid').textContent=s.pid>0?s.pid:'—'; |
| 389 | $('dMem').textContent=bytes(s.memory_bytes); |
| 390 | $('dSince').textContent=s.since||'—'; |
| 391 | render(); |
| 392 | } |
| 393 | |
| 394 | function setFilter(f){ |
| 395 | FILTER=f; |
| 396 | var ids={all:'cAll',running:'cRun',failed:'cFail',inactive:'cOff'}; |
| 397 | for(var k in ids) $(ids[k]).className='chip'+(k===f?' sel':'')+ |
| 398 | (k==='running'?' ok':k==='failed'?' bad':k==='inactive'?' none':''); |
| 399 | render(); |
| 400 | } |
| 401 | |
| 402 | $('cAll').onclick=function(){setFilter('');}; |
| 403 | $('cRun').onclick=function(){setFilter('running');}; |
| 404 | $('cFail').onclick=function(){setFilter('failed');}; |
| 405 | $('cOff').onclick=function(){setFilter('inactive');}; |
| 406 | $('q').oninput=render; |
| 407 | $('sort').onchange=function(){SORT=this.value;render();}; |
| 408 | $('btnRefresh').onclick=function(){load();}; |
| 409 | $('dClose').onclick=close; |
| 410 | $('scrim').onclick=close; |
| 411 | $('opStart').onclick=function(){control('start');}; |
| 412 | $('opStop').onclick=function(){control('stop');}; |
| 413 | $('opRestart').onclick=function(){control('restart');}; |
| 414 | if(window.sxApplyTheme){ |
| 415 | $('btnTheme').onclick=function(){ |
| 416 | window.sxApplyTheme(window.sxTheme&&window.sxTheme()==='dark'?'light':'dark'); |
| 417 | }; |
| 418 | }else{ |
| 419 | $('btnTheme').className='icon-btn embed-hide hide'; |
| 420 | } |
| 421 | document.addEventListener('keydown',function(e){ |
| 422 | if(e.key==='Escape'&&SEL) close(); |
| 423 | }); |
| 424 | setFilter(''); |
| 425 | load().catch(function(e){ |
| 426 | $('empty').className='empty'; |
| 427 | $('empty').textContent='Could not load services: '+e.message; |
| 428 | }); |
| 429 | })(); |
| 430 | </script> |
| 431 | </body></html> |