Migrate grateWizard from React/Next.js to native Nuxt integration
- Port all React components to Vue 3 (GwTabs, GwMN, GwCRA, GwCRS, GwMap, GwRelations, GwPerimeterList) - Port hooks to Vue composables (useCesiumProfiles, useSavedPerimeters) - Copy pure TS services and utils (duniter/, ss58, gratewizard utils) - Add Leaflet + Geoman + MarkerCluster dependencies - Serve grateWizard as popup via /gratewizard?popup (layout: false) and info page on /gratewizard (with Librodrome layout) - Remove public/gratewizard-app/ static Next.js export - Refine UI: compact tabs, buttons, inputs, cards, perimeter list - Use Ğ1 breve everywhere, French locale for all dates and amounts - Rename roles: vendeur→offre / acheteur→reçoit le produit ou service - Rename prix→évaluation in all visible text - Add calculated result column in CRA and CRS relation tables - DU/Ğ1 selector uses toggle switch (same as role toggle) - Auto-scroll to monetary data card on polygon selection Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
97
app/composables/useCesiumProfiles.ts
Normal file
97
app/composables/useCesiumProfiles.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
const CESIUM_PODS = [
|
||||
'https://g1.data.brussels.ovh/user/profile/_search',
|
||||
'https://g1.data.le-sou.org/user/profile/_search',
|
||||
'https://g1.data.e-is.pro/user/profile/_search',
|
||||
];
|
||||
const BATCH_SIZE = 500;
|
||||
|
||||
export type GeoMember = {
|
||||
pubkey: string;
|
||||
title: string;
|
||||
city: string;
|
||||
lat: number;
|
||||
lon: number;
|
||||
};
|
||||
|
||||
/** Find the first Cesium+ pod that responds successfully. */
|
||||
async function findWorkingPod(): Promise<string> {
|
||||
for (const url of CESIUM_PODS) {
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ size: 0, query: { match_all: {} } }),
|
||||
});
|
||||
if (res.ok) return url;
|
||||
} catch {
|
||||
// try next pod
|
||||
}
|
||||
}
|
||||
throw new Error('Aucun pod Cesium+ disponible');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch Cesium+ profiles for a given list of v1 pubkeys.
|
||||
* Uses Elasticsearch `ids` query with batches of 500, filtered to geolocated profiles only.
|
||||
* Pass `null` to skip fetching (e.g. while pubkeys are still loading).
|
||||
*/
|
||||
export function useCesiumProfiles(v1Pubkeys: Ref<string[] | null>) {
|
||||
const geoMembers = ref<GeoMember[]>([]);
|
||||
const loading = ref(true);
|
||||
const error = ref<string | null>(null);
|
||||
|
||||
watch(v1Pubkeys, async (pubkeys) => {
|
||||
if (pubkeys === null) return;
|
||||
|
||||
loading.value = true;
|
||||
error.value = null;
|
||||
|
||||
try {
|
||||
const podUrl = await findWorkingPod();
|
||||
const allMembers: GeoMember[] = [];
|
||||
|
||||
for (let i = 0; i < pubkeys.length; i += BATCH_SIZE) {
|
||||
const batch = pubkeys.slice(i, i + BATCH_SIZE);
|
||||
const res = await fetch(podUrl, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
size: batch.length,
|
||||
_source: ['title', 'city', 'geoPoint'],
|
||||
query: {
|
||||
bool: {
|
||||
must: [
|
||||
{ ids: { values: batch } },
|
||||
{ exists: { field: 'geoPoint' } },
|
||||
],
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
if (!res.ok) throw new Error(`Cesium+ HTTP ${res.status}`);
|
||||
const json = await res.json();
|
||||
|
||||
for (const hit of json.hits?.hits ?? []) {
|
||||
const s = hit._source;
|
||||
if (!s?.geoPoint?.lat || !s?.geoPoint?.lon) continue;
|
||||
allMembers.push({
|
||||
pubkey: hit._id,
|
||||
title: s.title || '',
|
||||
city: s.city || '',
|
||||
lat: s.geoPoint.lat,
|
||||
lon: s.geoPoint.lon,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
geoMembers.value = allMembers;
|
||||
} catch (e: any) {
|
||||
error.value = e.message;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}, { immediate: true });
|
||||
|
||||
return { geoMembers, loading, error };
|
||||
}
|
||||
@@ -1,16 +1,17 @@
|
||||
export function useGrateWizard() {
|
||||
const appConfig = useAppConfig()
|
||||
const { url, popup } = appConfig.gratewizard as { url: string; popup: { width: number; height: number } }
|
||||
|
||||
function launch() {
|
||||
const { url, popup } = appConfig.gratewizard as { url: string; popup: { width: number; height: number } }
|
||||
function launch(e?: Event) {
|
||||
const left = Math.round((window.screen.width - popup.width) / 2)
|
||||
const top = Math.round((window.screen.height - popup.height) / 2)
|
||||
window.open(
|
||||
const win = window.open(
|
||||
url,
|
||||
'GrateWizard',
|
||||
'grateWizard',
|
||||
`width=${popup.width},height=${popup.height},left=${left},top=${top},scrollbars=yes,resizable=yes`,
|
||||
)
|
||||
if (win) e?.preventDefault()
|
||||
}
|
||||
|
||||
return { launch }
|
||||
return { url, launch }
|
||||
}
|
||||
|
||||
24
app/composables/useSavedPerimeters.ts
Normal file
24
app/composables/useSavedPerimeters.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
export type SavedPerimeter = {
|
||||
name: string;
|
||||
polygon: [number, number][];
|
||||
createdAt: string;
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'gw-saved-perimeters';
|
||||
|
||||
export function useSavedPerimeters() {
|
||||
const perimeters = useLocalStorage<SavedPerimeter[]>(STORAGE_KEY, []);
|
||||
|
||||
function savePerimeter(name: string, polygon: [number, number][]) {
|
||||
perimeters.value = [
|
||||
...perimeters.value.filter((p) => p.name !== name),
|
||||
{ name, polygon, createdAt: new Date().toISOString() },
|
||||
];
|
||||
}
|
||||
|
||||
function deletePerimeter(name: string) {
|
||||
perimeters.value = perimeters.value.filter((p) => p.name !== name);
|
||||
}
|
||||
|
||||
return { perimeters, savePerimeter, deletePerimeter };
|
||||
}
|
||||
Reference in New Issue
Block a user