mirror of
https://git.j0bot.ch/admin_j0bot/ploxion-ports.git
synced 2026-11-29 07:05:06 +00:00
208 lines
13 KiB
PHP
208 lines
13 KiB
PHP
{{-- PL0XION ports — l'INSPECTEUR du bus jOSPorts (RS-7 : « voir les input/output de
|
|
chaque ploxion à la n8n »). Trois choses, toutes RÉELLES :
|
|
1) TOPOLOGIE par type de signal — depuis /ploxion-io.json : pour chaque type
|
|
(son, tsoin, json, event…) on liste les PRODUCTEURS (ploxions qui le
|
|
sortent) et les CONSOMMATEURS (qui le prennent en entrée). C'est le
|
|
câblage n8n calculé automatiquement : une sortie de type T se branche sur
|
|
toute entrée de type T.
|
|
2) LIVE — abonné à jOSPorts.on('*') : le flux réel de ce qui circule sur le
|
|
bus, là, maintenant (topic + payload + heure).
|
|
3) TESTER — émettre un port à la main pour vérifier un câblage.
|
|
100% client-side, composé sur window.jOSb + window.jOSPorts. Droit au silence
|
|
§4.4 (désabonnement + clear au unmount). window.jOSApps['ports'].
|
|
mount(c,ctx)->{unmount}. --}}
|
|
@include('ploxions._bions')
|
|
<style>
|
|
.po { display:flex; flex-direction:column; height:100%; background:#07090e; color:rgba(222,232,242,.92);
|
|
font-family:ui-sans-serif,system-ui,sans-serif; font-size:.82rem; }
|
|
.po__bar { flex:0 0 auto; display:flex; align-items:center; gap:6px; padding:7px 10px; border-bottom:1px solid rgba(120,160,230,.18); }
|
|
.po__t { font-weight:700; color:rgba(165,200,255,.95); }
|
|
.po__t b { color:#fff; }
|
|
.po__sp { flex:1; }
|
|
.po__tab { cursor:pointer; font-size:.72rem; padding:3px 11px; border-radius:20px; border:1px solid rgba(120,160,230,.28);
|
|
background:none; color:rgba(160,195,255,.8); }
|
|
.po__tab.on { background:rgba(120,160,230,.16); color:#fff; border-color:rgba(120,160,230,.5); }
|
|
.po__body { flex:1; min-height:0; overflow-y:auto; padding:10px; }
|
|
.po__hide { display:none; }
|
|
/* topologie */
|
|
.po__type { border:1px solid rgba(120,160,230,.16); border-radius:11px; padding:9px 11px; margin-bottom:9px; background:rgba(16,24,38,.5); }
|
|
.po__th { display:flex; align-items:center; gap:7px; margin-bottom:6px; }
|
|
.po__tn { font-weight:700; color:#fff; font-family:'Share Tech Mono',ui-monospace,monospace; }
|
|
.po__tcnt { font-size:.64rem; color:rgba(150,180,220,.55); }
|
|
.po__rail { display:grid; grid-template-columns:1fr auto 1fr; gap:8px; align-items:start; }
|
|
.po__col h5 { margin:0 0 3px; font-size:.6rem; text-transform:uppercase; letter-spacing:.05em; }
|
|
.po__col.out h5 { color:rgba(255,200,120,.85); }
|
|
.po__col.in h5 { color:rgba(120,220,160,.85); }
|
|
.po__arrow { align-self:center; color:rgba(150,180,220,.5); font-size:1.1rem; }
|
|
.po__chip { display:inline-block; font-size:.68rem; padding:1px 7px; margin:2px 3px 0 0; border-radius:20px;
|
|
border:1px solid rgba(120,160,230,.28); color:rgba(195,215,235,.85); cursor:pointer; }
|
|
.po__chip:hover { background:rgba(120,160,230,.14); color:#fff; }
|
|
.po__empty { font-size:.66rem; color:rgba(150,175,205,.4); font-style:italic; }
|
|
/* live */
|
|
.po__ev { font-family:'Share Tech Mono',ui-monospace,monospace; font-size:.7rem; padding:4px 6px; border-radius:6px;
|
|
margin-bottom:4px; background:rgba(14,22,34,.6); border-left:2px solid rgba(120,220,160,.5); }
|
|
.po__ev .tp { color:rgba(150,200,255,.95); }
|
|
.po__ev .pl { color:rgba(190,205,222,.7); }
|
|
.po__ev .tm { color:rgba(140,165,195,.45); float:right; }
|
|
.po__msg { text-align:center; color:rgba(190,212,228,.55); padding:22px; font-size:.74rem; }
|
|
/* tester */
|
|
.po__form { display:flex; flex-direction:column; gap:8px; max-width:460px; }
|
|
.po__form label { font-size:.66rem; color:rgba(160,185,215,.7); text-transform:uppercase; letter-spacing:.04em; }
|
|
.po__form input, .po__form select { width:100%; box-sizing:border-box; padding:7px 9px; border-radius:7px;
|
|
border:1px solid rgba(120,160,230,.28); background:rgba(12,18,28,.7); color:#e8eef6; font-size:.82rem; }
|
|
.po__fire { cursor:pointer; align-self:flex-start; padding:7px 16px; border-radius:8px; font-weight:700;
|
|
border:1px solid rgba(120,220,160,.55); background:rgba(40,120,80,.35); color:#bfffd6; }
|
|
.po__fire:hover { background:rgba(50,150,100,.5); }
|
|
</style>
|
|
<script>
|
|
(function () {
|
|
'use strict';
|
|
function esc(s) { return window.jOSb.esc(s); }
|
|
|
|
function describe() {
|
|
var n = (window.jOSPorts && typeof window.jOSPorts.list === 'function') ? window.jOSPorts.list().length : 0;
|
|
return { v: 1, id: 'ports', title: 'Ports', icon: '🔌', items: [
|
|
{ p: 1, kind: 'stat', label: 'ploxions câblés', value: n }
|
|
] };
|
|
}
|
|
function mount(container, ctx) {
|
|
var alive = true, unsub = null, IO = null;
|
|
var live = []; // évènements bus récents (max 60)
|
|
|
|
container.innerHTML =
|
|
'<div class="po">'
|
|
+ '<div class="po__bar"><span class="po__t">🔌 <b>PORTS</b> · bus jOSPorts</span><span class="po__sp"></span>'
|
|
+ '<button class="po__tab on" data-tab="topo">topologie</button>'
|
|
+ '<button class="po__tab" data-tab="live">live</button>'
|
|
+ '<button class="po__tab" data-tab="test">tester</button></div>'
|
|
+ '<div class="po__body" data-pane="topo"><div class="po__msg">chargement du registre…</div></div>'
|
|
+ '<div class="po__body po__hide" data-pane="live"><div class="po__msg">en écoute du bus… (rien encore — ouvre/utilise un ploxion)</div></div>'
|
|
+ '<div class="po__body po__hide" data-pane="test"></div>'
|
|
+ '</div>';
|
|
|
|
var panes = {
|
|
topo: container.querySelector('[data-pane="topo"]'),
|
|
live: container.querySelector('[data-pane="live"]'),
|
|
test: container.querySelector('[data-pane="test"]')
|
|
};
|
|
|
|
container.querySelector('.po__bar').addEventListener('click', function (e) {
|
|
var b = e.target.closest('[data-tab]'); if (!b) return;
|
|
var k = b.getAttribute('data-tab');
|
|
container.querySelectorAll('.po__tab').forEach(function (t) { t.classList.toggle('on', t === b); });
|
|
Object.keys(panes).forEach(function (p) { panes[p].classList.toggle('po__hide', p !== k); });
|
|
});
|
|
|
|
// ---- TOPOLOGIE : producteurs/consommateurs par type de signal ----
|
|
function buildTopo() {
|
|
var ids = Object.keys(IO).filter(function (k) { return k[0] !== '_'; });
|
|
var byType = {}; // type -> { out:Set, in:Set }
|
|
function touch(t) { return byType[t] || (byType[t] = { out: {}, in: {} }); }
|
|
ids.forEach(function (id) {
|
|
var e = IO[id]; if (!e) return;
|
|
(e.out || []).forEach(function (o) { if (o && o.t) touch(o.t).out[id] = 1; });
|
|
(e.in || []).forEach(function (i) { if (i && i.t) touch(i.t).in[id] = 1; });
|
|
});
|
|
var types = Object.keys(byType).sort(function (a, b) {
|
|
var ca = Object.keys(byType[a].out).length + Object.keys(byType[a]['in']).length;
|
|
var cb = Object.keys(byType[b].out).length + Object.keys(byType[b]['in']).length;
|
|
return cb - ca;
|
|
});
|
|
if (!types.length) { panes.topo.innerHTML = '<div class="po__msg">aucun type dans le registre.</div>'; return; }
|
|
var html = '';
|
|
types.forEach(function (t) {
|
|
var outs = Object.keys(byType[t].out), ins = Object.keys(byType[t]['in']);
|
|
var wired = outs.length && ins.length;
|
|
html += '<div class="po__type">'
|
|
+ '<div class="po__th"><span class="po__tn">' + esc(t) + '</span>'
|
|
+ '<span class="po__tcnt">' + outs.length + ' prod · ' + ins.length + ' conso'
|
|
+ (wired ? ' · ' + (outs.length * ins.length) + ' liens possibles' : ' · non câblable') + '</span></div>'
|
|
+ '<div class="po__rail">'
|
|
+ '<div class="po__col out"><h5>sortent ' + esc(t) + '</h5>'
|
|
+ (outs.length ? outs.map(chip).join('') : '<span class="po__empty">—</span>') + '</div>'
|
|
+ '<div class="po__arrow">→</div>'
|
|
+ '<div class="po__col in"><h5>prennent ' + esc(t) + '</h5>'
|
|
+ (ins.length ? ins.map(chip).join('') : '<span class="po__empty">—</span>') + '</div>'
|
|
+ '</div></div>';
|
|
});
|
|
panes.topo.innerHTML = html;
|
|
}
|
|
function chip(id) {
|
|
var e = IO[id], title = (e && e.role) ? e.role : id;
|
|
return '<span class="po__chip" data-open="' + esc(id) + '" title="' + esc(title) + '">' + esc(id) + '</span>';
|
|
}
|
|
|
|
// ouvrir un ploxion en cliquant un chip
|
|
panes.topo.addEventListener('click', function (e) {
|
|
var c = e.target.closest('[data-open]'); if (!c) return;
|
|
var id = c.getAttribute('data-open');
|
|
if (window.jOS && typeof window.jOS.openPloxion === 'function') window.jOS.openPloxion(id);
|
|
});
|
|
|
|
// ---- LIVE : abonnement au bus ----
|
|
function onBusEvent(payload, topic) {
|
|
if (!alive) return;
|
|
var d = new Date();
|
|
var hh = ('0' + d.getHours()).slice(-2) + ':' + ('0' + d.getMinutes()).slice(-2) + ':' + ('0' + d.getSeconds()).slice(-2);
|
|
var str = (typeof payload === 'string') ? payload : (function () { try { return JSON.stringify(payload); } catch (e) { return String(payload); } })();
|
|
live.unshift({ topic: topic || '?', pl: (str || '').slice(0, 160), tm: hh });
|
|
if (live.length > 60) live.pop();
|
|
renderLive();
|
|
}
|
|
function renderLive() {
|
|
if (!live.length) { panes.live.innerHTML = '<div class="po__msg">en écoute du bus… (rien encore — ouvre/utilise un ploxion)</div>'; return; }
|
|
panes.live.innerHTML = live.map(function (e) {
|
|
return '<div class="po__ev"><span class="tm">' + esc(e.tm) + '</span>'
|
|
+ '<span class="tp">' + esc(e.topic) + '</span>'
|
|
+ (e.pl ? ' <span class="pl">' + esc(e.pl) + '</span>' : '') + '</div>';
|
|
}).join('');
|
|
}
|
|
|
|
// ---- TESTER : émettre un port à la main ----
|
|
function buildTest() {
|
|
var ids = Object.keys(IO).filter(function (k) { return k[0] !== '_'; }).sort();
|
|
panes.test.innerHTML =
|
|
'<div class="po__form">'
|
|
+ '<div><label>ploxion</label><select data-id>' + ids.map(function (i) { return '<option>' + esc(i) + '</option>'; }).join('') + '</select></div>'
|
|
+ '<div><label>port</label><input data-port placeholder="ex. open, son, tsoin" value="test"></div>'
|
|
+ '<div><label>payload</label><input data-pl placeholder="texte libre" value="ping depuis ports"></div>'
|
|
+ '<button class="po__fire">⚡ émettre sur le bus</button>'
|
|
+ '<div class="po__empty" data-res></div></div>';
|
|
panes.test.querySelector('.po__fire').addEventListener('click', function () {
|
|
var id = panes.test.querySelector('[data-id]').value;
|
|
var port = panes.test.querySelector('[data-port]').value || 'test';
|
|
var pl = panes.test.querySelector('[data-pl]').value;
|
|
var res = panes.test.querySelector('[data-res]');
|
|
if (window.jOSPorts && typeof window.jOSPorts.emit === 'function') {
|
|
var topic = window.jOSPorts.emit(id, port, pl);
|
|
res.textContent = '✓ émis : ' + topic;
|
|
if (window.jOSb) jOSb.toast(container, '⚡ ' + topic);
|
|
} else { res.textContent = '✗ bus jOSPorts indisponible'; }
|
|
});
|
|
}
|
|
|
|
// charge le registre (via le bus si déjà chargé, sinon fetch)
|
|
function withIO(io) {
|
|
IO = io || {}; if (!alive) return;
|
|
buildTopo(); buildTest();
|
|
if (window.jOSPorts && typeof window.jOSPorts.on === 'function') {
|
|
unsub = window.jOSPorts.on('*', onBusEvent);
|
|
}
|
|
}
|
|
if (window.jOSPorts && typeof window.jOSPorts.list === 'function' && window.jOSPorts.list().length) {
|
|
// le bus a déjà le registre en mémoire
|
|
var ids = window.jOSPorts.list(), io = {};
|
|
ids.forEach(function (id) { io[id] = window.jOSPorts.io(id); });
|
|
withIO(io);
|
|
} else {
|
|
fetch('/ploxion-io.json').then(function (r) { return r.json(); }).then(function (d) { withIO(d); })
|
|
.catch(function () { if (alive) panes.topo.innerHTML = '<div class="po__msg">registre injoignable.</div>'; });
|
|
}
|
|
|
|
return { unmount: function () { alive = false; if (typeof unsub === 'function') { try { unsub(); } catch (e) {} } container.innerHTML = ''; } };
|
|
}
|
|
window.jOSApps = window.jOSApps || {};
|
|
window.jOSApps['ports'] = { manifest: { id: 'ports', name: 'Ports', icon: '🔌' }, mount: mount, describe: describe };
|
|
})();
|
|
</script>
|