mirror of
https://git.j0bot.ch/admin_j0bot/ploxion-ideas-map.git
synced 2026-11-29 06:32:09 +00:00
synchro du labo (0bf0da65) : app.blade.php, README.md
This commit is contained in:
commit
b230b0260a
21
README.md
Normal file
21
README.md
Normal file
@ -0,0 +1,21 @@
|
||||
# 🗺️ Ideas Map
|
||||
|
||||
La carte des idées géolocalisées — pins, catégories, votes (lecture).
|
||||
|
||||
| | |
|
||||
| --- | --- |
|
||||
| id | `ideas-map` |
|
||||
| fournit | `browse-pins` `map-view` |
|
||||
| bions qu'il nomme | `jOSApps` `jOSPorts` |
|
||||
| fichiers | `app.blade.php` |
|
||||
| dans le labo | `resources/views/ploxions/ideas-map/` (dépôt `my_website2`) |
|
||||
|
||||
## Contribuer
|
||||
|
||||
- **Dans le xer** : https://labo.j0bot.ch/px/atelier?ploxion=ideas-map — prends-le, modifie-le, vois-le tourner, « ⧗ envoyer le tsoin ».
|
||||
- **Dans VS Code** : `xb prendre ideas-map` (ou l'extension xerboxion › ⇩ Prendre), puis ⧗ Envoyer.
|
||||
- Le chemin complet : https://labo.j0bot.ch/px/contribuer
|
||||
|
||||
Ce dépôt est un **miroir** du labo (synchronisé par `bin/ploxions-forge.mjs`, depuis le commit `0bf0da65`) : une modif se propose par un tsoin ou une branche du labo, pas directement ici.
|
||||
|
||||
© 2026 chill-tekk · ne pas nuire
|
||||
309
app.blade.php
Normal file
309
app.blade.php
Normal file
@ -0,0 +1,309 @@
|
||||
{{-- =============================================================
|
||||
PL0XI0N ideas-map — app cliente. S'auto-enregistre dans
|
||||
window.jOSApps['ideas-map'] et se monte comme ÉCRAN dans une fenêtre
|
||||
du window-manager (jOS). « Google Maps, mais pour les idées » : on rend
|
||||
les pins (idées géolocalisées) de l'app ideas_map de RS-7 NATIVEMENT sur
|
||||
une carte Leaflet, dans le style du site (pas un iframe — on est le XER,
|
||||
on rend nous-mêmes).
|
||||
|
||||
100% client-side : tape l'API ideas_map (Rust/Axum) en direct sur ses
|
||||
endpoints PUBLICS de lecture (GET /api/pins, GET /api/stats ; CORS ouvert
|
||||
côté API). base_url vient du manifeste (config/ploxions.php -> __PLOXIONS__).
|
||||
Leaflet est chargé à la demande depuis cdnjs (déjà autorisé par la CSP) ;
|
||||
les tuiles sombres (carto) + l'origine de l'API sont autorisées dans
|
||||
config/csp.php. Si l'API est injoignable, la brique dégrade proprement
|
||||
(« hors ligne », jamais de crash) — standalone, « ne pas nuire ».
|
||||
|
||||
Contrat avec jOS : mount(container, ctx) -> { unmount }
|
||||
(unmount = arrêt propre, droit au silence §4.4 : carte détruite, fetch
|
||||
abandonnés, plus aucun render en vol).
|
||||
============================================================= --}}
|
||||
<style>
|
||||
.im { display: flex; flex-direction: column; height: 100%; color: rgba(220, 240, 235, 0.92);
|
||||
font-family: ui-sans-serif, system-ui, sans-serif; font-size: 0.86rem; background: #060b09; }
|
||||
.im__bar { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
|
||||
padding: 7px 9px; border-bottom: 1px solid rgba(0, 255, 159, 0.16); }
|
||||
.im__cats { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
|
||||
.im__cat { cursor: pointer; padding: 2px 9px; border-radius: 20px; border: 1px solid rgba(0, 255, 159, 0.28);
|
||||
background: none; color: rgba(0, 255, 159, 0.7); font-size: 0.72rem; white-space: nowrap; }
|
||||
.im__cat.is-off { opacity: 0.35; }
|
||||
.im__cat:hover { color: #fff; }
|
||||
.im__refresh { cursor: pointer; padding: 3px 9px; border-radius: 6px; border: 1px solid rgba(0, 255, 159, 0.28);
|
||||
background: none; color: rgba(0, 255, 159, 0.8); font-size: 0.74rem; flex: 0 0 auto; }
|
||||
.im__refresh:hover { background: rgba(0, 255, 159, 0.1); color: #fff; }
|
||||
.im__map { flex: 1; min-height: 0; position: relative; background: #0a0f0d; }
|
||||
.im__map .leaflet-container { width: 100%; height: 100%; background: #0a0f0d; }
|
||||
/* marqueur = pastille glyphe (pas d'image -> rien à autoriser en img-src) */
|
||||
.im__pin { display: flex; align-items: center; justify-content: center; width: 26px; height: 26px;
|
||||
font-size: 16px; line-height: 1; background: rgba(6, 12, 10, 0.92); border: 1px solid rgba(0, 255, 159, 0.55);
|
||||
border-radius: 50% 50% 50% 2px; transform: rotate(-2deg);
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5), 0 0 10px rgba(0, 255, 159, 0.18); }
|
||||
/* popup dans le ton du site (Leaflet par défaut = blanc) */
|
||||
.im__map .leaflet-popup-content-wrapper, .im__map .leaflet-popup-tip {
|
||||
background: #0b1310; color: rgba(225, 245, 238, 0.95); border: 1px solid rgba(0, 255, 159, 0.3);
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6); }
|
||||
.im__map .leaflet-popup-content { margin: 10px 12px; font-size: 0.82rem; }
|
||||
.im__map .leaflet-container a.leaflet-popup-close-button { color: rgba(0, 255, 159, 0.7); }
|
||||
.im__pop-t { font-weight: 700; color: #fff; }
|
||||
.im__pop-c { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em;
|
||||
color: rgba(0, 255, 159, 0.7); margin: 2px 0 4px; }
|
||||
.im__pop-d { color: rgba(200, 225, 215, 0.8); }
|
||||
.im__pop-img { display: block; max-width: 100%; border-radius: 6px; margin-top: 7px; }
|
||||
.im__pop-m { color: rgba(170, 210, 195, 0.55); font-size: 0.68rem; margin-top: 5px;
|
||||
font-family: 'Share Tech Mono', ui-monospace, monospace; }
|
||||
.im__msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
|
||||
text-align: center; padding: 22px 18px; color: rgba(190, 220, 210, 0.7); font-size: 0.84rem;
|
||||
z-index: 500; background: rgba(6, 11, 9, 0.82); }
|
||||
.im__msg div { max-width: 340px; }
|
||||
.im__msg b { color: rgba(0, 255, 159, 0.9); }
|
||||
.im__msg code { font-family: 'Share Tech Mono', ui-monospace, monospace; color: rgba(120, 200, 255, 0.9);
|
||||
background: rgba(0, 0, 0, 0.35); padding: 1px 5px; border-radius: 4px; }
|
||||
.im__foot { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 6px 10px;
|
||||
border-top: 1px solid rgba(0, 255, 159, 0.16); font-size: 0.72rem;
|
||||
font-family: 'Share Tech Mono', ui-monospace, monospace; color: rgba(170, 210, 195, 0.6); }
|
||||
.im__dot { width: 8px; height: 8px; border-radius: 50%; background: rgba(170, 210, 195, 0.4); flex: 0 0 auto; }
|
||||
.im__dot.is-up { background: rgba(39, 201, 63, 0.95); box-shadow: 0 0 8px rgba(39, 201, 63, 0.6); }
|
||||
.im__dot.is-down { background: rgba(255, 95, 86, 0.9); }
|
||||
.im__count { margin-left: auto; }
|
||||
</style>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
// Charge Leaflet (cdnjs, déjà autorisé par la CSP) UNE fois, à la demande
|
||||
// (droit au silence : rien tant qu'aucun ploxion carte n'est ouvert).
|
||||
var LEAFLET = '/vendor/css/';
|
||||
function loadLeaflet() {
|
||||
if (window.L) return Promise.resolve(window.L);
|
||||
if (window.__leafletPromise) return window.__leafletPromise;
|
||||
window.__leafletPromise = new Promise(function (resolve, reject) {
|
||||
var css = document.createElement('link');
|
||||
css.rel = 'stylesheet';
|
||||
css.href = LEAFLET + 'leaflet.min.css';
|
||||
document.head.appendChild(css);
|
||||
var s = document.createElement('script');
|
||||
s.src = '/vendor/js/leaflet.min.js'; // fix RS-3 : le JS est dans /vendor/js/ (LEAFLET=/vendor/css/ ne sert que le .css)
|
||||
s.onload = function () { resolve(window.L); };
|
||||
s.onerror = function () { reject(new Error('leaflet load failed')); };
|
||||
document.head.appendChild(s);
|
||||
});
|
||||
return window.__leafletPromise;
|
||||
}
|
||||
|
||||
// Glyphe par catégorie (valeurs de l'API ideas_map ; défaut 📍).
|
||||
var ICON = {
|
||||
idea: '💡', photo: '📸', cool: '✨', problem: '⚠️', warning: '⚠️',
|
||||
event: '🎉', spot: '📍', view: '🌄', place: '📍'
|
||||
};
|
||||
function catIcon(c) { return ICON[(c || '').toLowerCase()] || '📍'; }
|
||||
|
||||
function manifest() {
|
||||
var all = window.__PLOXIONS__ || [];
|
||||
for (var i = 0; i < all.length; i++) if (all[i].id === 'ideas-map') return all[i];
|
||||
return null;
|
||||
}
|
||||
function baseUrl() {
|
||||
var m = manifest();
|
||||
return (m && m.config && m.config.base_url ? m.config.base_url : 'http://localhost:3009').replace(/\/+$/, '');
|
||||
}
|
||||
function esc(s) { return window.jOSb.esc(s); }
|
||||
function api(path, signal) {
|
||||
return fetch(baseUrl() + path, { headers: { 'Accept': 'application/json' }, mode: 'cors', signal: signal })
|
||||
.then(function (r) { if (!r.ok) throw new Error('http ' + r.status); return r.json(); });
|
||||
}
|
||||
// Résout l'URL d'une photo de pin (relative -> absolue sur l'API).
|
||||
function photoUrl(u) {
|
||||
if (!u) return null;
|
||||
return /^https?:\/\//.test(u) ? u : baseUrl() + (u.charAt(0) === '/' ? '' : '/') + u;
|
||||
}
|
||||
// OUT « select » : pin cliquée -> bus jOSPorts (topic ploxion.ideas-map.select ;
|
||||
// le carnet ideas s'y abonne pour ouvrir la note correspondante). Best-effort.
|
||||
function emitSelect(p) {
|
||||
if (!(window.jOSPorts && window.jOSPorts.emit)) return;
|
||||
try {
|
||||
window.jOSPorts.emit('ideas-map', 'select', {
|
||||
id: (p.id != null ? p.id : null),
|
||||
lat: p.lat, lng: p.lng,
|
||||
title: p.title || '',
|
||||
category: p.category || null
|
||||
});
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
// --- l'app : mount() construit l'UI dans le container, renvoie { unmount }. ---
|
||||
var LIVE = null; // posé au mount : { allPins }
|
||||
function describe() {
|
||||
var pins = LIVE ? LIVE.allPins() : [];
|
||||
return { v: 1, id: 'ideas-map', title: 'Ideas Map', icon: '🗺️', items: [
|
||||
{ p: 1, kind: 'stat', label: 'idées épinglées', value: pins.length }
|
||||
] };
|
||||
}
|
||||
function mount(container, ctx) {
|
||||
var alive = true;
|
||||
var ac = ('AbortController' in window) ? new AbortController() : null;
|
||||
var map = null, layer = null, ro = null;
|
||||
var allPins = [];
|
||||
var off = {}; // catégories désactivées (filtre client-side)
|
||||
|
||||
container.innerHTML =
|
||||
'<div class="im">'
|
||||
+ '<div class="im__bar">'
|
||||
+ '<div class="im__cats" data-cats></div>'
|
||||
+ '<button class="im__refresh" data-refresh title="Recharger">⟳</button>'
|
||||
+ '</div>'
|
||||
+ '<div class="im__map" data-map><div class="im__msg" data-msg><div>chargement de la carte…</div></div></div>'
|
||||
+ '<div class="im__foot">'
|
||||
+ '<span class="im__dot" data-dot></span><span data-status>connexion…</span>'
|
||||
+ '<span class="im__count" data-count></span>'
|
||||
+ '</div>'
|
||||
+ '</div>';
|
||||
|
||||
var elMapHost = container.querySelector('[data-map]');
|
||||
var elCats = container.querySelector('[data-cats]');
|
||||
var elDot = container.querySelector('[data-dot]');
|
||||
var elStatus = container.querySelector('[data-status]');
|
||||
var elCount = container.querySelector('[data-count]');
|
||||
|
||||
function setStatus(state, txt) {
|
||||
elDot.className = 'im__dot' + (state === 'up' ? ' is-up' : state === 'down' ? ' is-down' : '');
|
||||
elStatus.textContent = txt;
|
||||
}
|
||||
function msg(html) {
|
||||
var m = elMapHost.querySelector('[data-msg]');
|
||||
if (!m) { m = document.createElement('div'); m.className = 'im__msg'; m.setAttribute('data-msg', ''); elMapHost.appendChild(m); }
|
||||
m.innerHTML = '<div>' + html + '</div>';
|
||||
m.style.display = '';
|
||||
}
|
||||
function hideMsg() { var m = elMapHost.querySelector('[data-msg]'); if (m) m.style.display = 'none'; }
|
||||
|
||||
function popupHtml(p) {
|
||||
var ph = photoUrl(p.photo_url);
|
||||
var when = (p.created_at || '').slice(0, 10);
|
||||
return '<div class="im__pop-t">' + esc(p.title) + '</div>'
|
||||
+ '<div class="im__pop-c">' + catIcon(p.category) + ' ' + esc(p.category || 'idée') + '</div>'
|
||||
+ (p.description ? '<div class="im__pop-d">' + esc(p.description) + '</div>' : '')
|
||||
+ (ph ? '<img class="im__pop-img" src="' + esc(ph) + '" alt="" loading="lazy">' : '')
|
||||
+ (when ? '<div class="im__pop-m">' + esc(when) + '</div>' : '');
|
||||
}
|
||||
|
||||
// (re)dessine les marqueurs filtrés + recadre sur eux.
|
||||
function draw() {
|
||||
if (!map || !window.L) return;
|
||||
if (layer) { layer.clearLayers(); } else { layer = window.L.layerGroup().addTo(map); }
|
||||
var shown = allPins.filter(function (p) { return !off[(p.category || '').toLowerCase()]; });
|
||||
var pts = [];
|
||||
shown.forEach(function (p) {
|
||||
if (typeof p.lat !== 'number' || typeof p.lng !== 'number') return;
|
||||
var icon = window.L.divIcon({ className: '', html: '<div class="im__pin">' + catIcon(p.category) + '</div>',
|
||||
iconSize: [26, 26], iconAnchor: [13, 24], popupAnchor: [0, -22] });
|
||||
window.L.marker([p.lat, p.lng], { icon: icon }).bindPopup(popupHtml(p))
|
||||
.on('click', function () { emitSelect(p); })
|
||||
.addTo(layer);
|
||||
pts.push([p.lat, p.lng]);
|
||||
});
|
||||
elCount.textContent = shown.length + ' / ' + allPins.length + ' pin' + (allPins.length > 1 ? 's' : '');
|
||||
if (pts.length) {
|
||||
try { map.fitBounds(pts, { padding: [30, 30], maxZoom: 15 }); } catch (e) {}
|
||||
}
|
||||
}
|
||||
|
||||
function renderCats() {
|
||||
var cats = [];
|
||||
allPins.forEach(function (p) { var c = (p.category || 'idée'); if (cats.indexOf(c) < 0) cats.push(c); });
|
||||
cats.sort();
|
||||
elCats.innerHTML = '';
|
||||
cats.forEach(function (c) {
|
||||
var b = document.createElement('button');
|
||||
b.className = 'im__cat' + (off[c.toLowerCase()] ? ' is-off' : '');
|
||||
b.innerHTML = catIcon(c) + ' ' + esc(c);
|
||||
b.addEventListener('click', function () {
|
||||
var k = c.toLowerCase();
|
||||
off[k] = !off[k];
|
||||
b.classList.toggle('is-off', !!off[k]);
|
||||
draw();
|
||||
});
|
||||
elCats.appendChild(b);
|
||||
});
|
||||
}
|
||||
|
||||
function loadPins() {
|
||||
api('/api/pins', ac && ac.signal).then(function (pins) {
|
||||
if (!alive) return;
|
||||
allPins = Array.isArray(pins) ? pins : (pins.pins || []);
|
||||
hideMsg();
|
||||
renderCats();
|
||||
draw();
|
||||
if (!allPins.length) msg('Aucune idée sur la carte pour l\'instant.<br><span style="opacity:.6">Ajoute un pin depuis l\'app ideas_map.</span>');
|
||||
}).catch(function () {
|
||||
if (!alive) return;
|
||||
msg('Impossible de charger les pins.');
|
||||
});
|
||||
}
|
||||
|
||||
function boot() {
|
||||
// health-check via /api/stats : on est franc sur l'état de l'API.
|
||||
setStatus('', 'connexion…');
|
||||
api('/api/stats', ac && ac.signal).then(function (st) {
|
||||
if (!alive) return;
|
||||
setStatus('up', 'ideas_map en ligne · ' + baseUrl().replace(/^https?:\/\//, ''));
|
||||
if (st && st.total_pins != null) elCount.textContent = st.total_pins + ' pins';
|
||||
loadPins();
|
||||
}).catch(function () {
|
||||
if (!alive) return;
|
||||
setStatus('down', 'hors ligne · ' + baseUrl().replace(/^https?:\/\//, ''));
|
||||
msg('<b>ideas_map est hors ligne.</b><br>Lance l\'API en local '
|
||||
+ '(<code>cargo run</code> dans le repo <code>ideas_map/backend</code>, port 3009), '
|
||||
+ 'ou configure <code>PLOXION_IDEAS_MAP_URL</code> vers une instance déployée (HTTPS). '
|
||||
+ '<br><span style="opacity:.6">La brique reste branchée — elle ne casse rien.</span>');
|
||||
});
|
||||
}
|
||||
|
||||
container.querySelector('[data-refresh]').addEventListener('click', function () {
|
||||
if (map) { msg('rechargement…'); loadPins(); }
|
||||
else boot();
|
||||
});
|
||||
|
||||
// Monte la carte (Leaflet chargé à la demande) puis amorce les données.
|
||||
loadLeaflet().then(function (L) {
|
||||
if (!alive) return;
|
||||
hideMsg();
|
||||
map = L.map(elMapHost, { zoomControl: true, attributionControl: true, worldCopyJump: true })
|
||||
.setView([20, 0], 2);
|
||||
L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Dark_Gray_Base/MapServer/tile/{z}/{y}/{x}', {
|
||||
maxZoom: 20, maxNativeZoom: 16,
|
||||
attribution: '© Esri'
|
||||
}).addTo(map);
|
||||
// Quand la fenêtre jOS est redimensionnée/snap, Leaflet doit recalculer.
|
||||
if ('ResizeObserver' in window) {
|
||||
ro = new ResizeObserver(function () { if (map) map.invalidateSize(); });
|
||||
ro.observe(elMapHost);
|
||||
}
|
||||
setTimeout(function () { if (map) map.invalidateSize(); }, 60);
|
||||
boot();
|
||||
}).catch(function () {
|
||||
if (!alive) return;
|
||||
msg('<b>Carte indisponible.</b><br>Leaflet n\'a pas pu se charger (réseau / CSP).');
|
||||
});
|
||||
|
||||
LIVE = { allPins: function () { return allPins; } };
|
||||
return {
|
||||
unmount: function () {
|
||||
LIVE = null;
|
||||
alive = false;
|
||||
if (ac) { try { ac.abort(); } catch (e) {} }
|
||||
if (ro) { try { ro.disconnect(); } catch (e) {} ro = null; }
|
||||
if (map) { try { map.remove(); } catch (e) {} map = null; }
|
||||
container.innerHTML = '';
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
window.jOSApps = window.jOSApps || {};
|
||||
window.jOSApps['ideas-map'] = {
|
||||
manifest: { id: 'ideas-map', name: 'Ideas Map', icon: '🗺️' },
|
||||
mount: mount,
|
||||
describe: describe
|
||||
};
|
||||
})();
|
||||
</script>
|
||||
Loading…
Reference in New Issue
Block a user