74 lines
5.1 KiB
PHP
74 lines
5.1 KiB
PHP
<?php
|
|
/**
|
|
* UX Drill-Down Universal Enricher v1
|
|
* Doctrine 14 STRICT : Additive only, zero page modification.
|
|
* Returns a JS bundle that pages can optionally include via <script src="/api/ux-drill-enricher.php"></script>
|
|
* On any tile without onclick/cursor:pointer, adds contextual drill-down opening WEVIA chat with tile text as msg.
|
|
*/
|
|
header('Content-Type: application/javascript; charset=utf-8');
|
|
header('Cache-Control: public, max-age=300');
|
|
?>
|
|
// WEVAL UX Drill-Down Universal Enricher v1 (additif, doctrine 14)
|
|
(function(){
|
|
if (window.__WEVAL_UX_DRILL_DONE__) return; window.__WEVAL_UX_DRILL_DONE__ = true;
|
|
|
|
// Only enrich if not already interactive; zero override of existing onclick
|
|
function enrichTile(el) {
|
|
if (el.onclick || el.getAttribute('onclick') || el.getAttribute('data-drill-wired')) return;
|
|
var cs = window.getComputedStyle(el);
|
|
if (cs.cursor === 'pointer') return;
|
|
|
|
// Find tile text label for WEVIA context
|
|
var label = (el.querySelector('.label, .kpi-label, h3, h4, .title, [class*="title"]') || {}).innerText || el.innerText || '';
|
|
label = label.trim().toLowerCase().split('\n')[0].slice(0, 60);
|
|
if (!label || label.length < 3) return;
|
|
|
|
el.setAttribute('data-drill-wired', 'true');
|
|
el.style.cursor = 'pointer';
|
|
el.style.transition = 'transform .15s ease, box-shadow .15s ease';
|
|
el.addEventListener('mouseenter', function(){ el.style.transform = 'translateY(-2px)'; el.style.boxShadow = '0 4px 20px rgba(98,143,255,.25)'; });
|
|
el.addEventListener('mouseleave', function(){ el.style.transform = ''; el.style.boxShadow = ''; });
|
|
el.addEventListener('click', function(e){
|
|
if (e.target.tagName === 'A' || e.target.tagName === 'BUTTON' || e.target.closest('a,button')) return;
|
|
openDrillPanel(label);
|
|
});
|
|
}
|
|
|
|
function openDrillPanel(label) {
|
|
var overlay = document.getElementById('__weval_drill_overlay');
|
|
if (!overlay) {
|
|
overlay = document.createElement('div');
|
|
overlay.id = '__weval_drill_overlay';
|
|
overlay.style.cssText = 'position:fixed;top:0;right:0;bottom:0;width:480px;max-width:100vw;background:#0a0f1e;border-left:1px solid rgba(98,143,255,.3);box-shadow:-8px 0 40px rgba(0,0,0,.5);z-index:99998;padding:24px;overflow:auto;transform:translateX(100%);transition:transform .3s ease;color:#e5edff;font:14px/1.6 Inter,sans-serif;';
|
|
document.body.appendChild(overlay);
|
|
}
|
|
overlay.innerHTML = '<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:20px;padding-bottom:16px;border-bottom:1px solid rgba(255,255,255,.1)"><h3 style="margin:0;font-size:15px;color:#628fff;letter-spacing:.5px;text-transform:uppercase">▸ Drill-Down · ' + label + '</h3><button onclick="document.getElementById(\'__weval_drill_overlay\').style.transform=\'translateX(100%)\'" style="background:transparent;border:none;color:#8ca6cc;font-size:20px;cursor:pointer;padding:4px 12px">✕</button></div><div id="__weval_drill_body" style="color:#b8c5db">⟳ Chargement via WEVIA...</div>';
|
|
setTimeout(function(){ overlay.style.transform = 'translateX(0)'; }, 10);
|
|
|
|
fetch('/api/wevia-sse-orchestrator.php?msg=' + encodeURIComponent(label), {cache:'no-store'})
|
|
.then(function(r){ return r.text(); })
|
|
.then(function(txt){
|
|
var body = document.getElementById('__weval_drill_body');
|
|
if (!body) return;
|
|
// Extract text/content/output/answer
|
|
var m = txt.match(/"output":"([^"]+)"/) || txt.match(/"content":"([^"]+)"/) || txt.match(/"text":"([^"]+)"/) || txt.match(/"answer":"([^"]+)"/);
|
|
var intentMatch = txt.match(/"intent":"([^"]+)"/);
|
|
var intent = intentMatch ? intentMatch[1] : 'wevia';
|
|
var content = m ? m[1].replace(/\\n/g,'\n').replace(/\\"/g,'"').replace(/\\u([0-9a-f]{4})/gi, function(_,h){return String.fromCharCode(parseInt(h,16));}) : '(pas de détails disponibles — demander plus précisément)';
|
|
body.innerHTML = '<div style="padding:12px 14px;background:rgba(98,143,255,.08);border-left:3px solid #628fff;border-radius:4px;margin-bottom:16px"><div style="font-size:11px;color:#628fff;letter-spacing:.5px;margin-bottom:6px;text-transform:uppercase">Intent · ' + intent + '</div><div style="color:#e5edff;white-space:pre-wrap">' + content + '</div></div><a href="/wevia-master.html?q=' + encodeURIComponent(label) + '" style="display:inline-block;padding:8px 16px;background:linear-gradient(135deg,#628fff,#8b5cf6);color:white;text-decoration:none;border-radius:6px;font-size:13px">→ Ouvrir dans WEVIA Master</a>';
|
|
})
|
|
.catch(function(){ var body=document.getElementById('__weval_drill_body'); if(body) body.innerHTML='<div style="color:#ff6b6b">Erreur chargement WEVIA</div>'; });
|
|
}
|
|
|
|
function scan() {
|
|
var selectors = '.card, .tile, .kpi, .stat, [class*="gauge"], [class*="widget"], [class*="metric"], .module-card';
|
|
document.querySelectorAll(selectors).forEach(enrichTile);
|
|
}
|
|
|
|
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', scan);
|
|
else scan();
|
|
// Also re-scan after 2s for dynamic tiles
|
|
setTimeout(scan, 2000);
|
|
setTimeout(scan, 5000);
|
|
})();
|