local conversion
This commit is contained in:
@@ -57,6 +57,9 @@ const baseUrl = import.meta.env.BASE_URL ?? '/';
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
<button id="btn-save-local" class="w-full py-2 px-4 rounded-lg text-sm font-medium text-white transition-colors" style="background:#3b82f6">
|
||||
📱 Save to this device
|
||||
</button>
|
||||
<button id="btn-download-json" class="w-full py-2 px-4 rounded-lg text-sm font-medium bg-zinc-700 hover:bg-zinc-600 text-white transition-colors">
|
||||
⬇ Download BAS JSON
|
||||
</button>
|
||||
@@ -64,8 +67,8 @@ const baseUrl = import.meta.env.BASE_URL ?? '/';
|
||||
⬇ Download GeoJSON track
|
||||
</button>
|
||||
{editUrl && (
|
||||
<button id="btn-save" class="w-full py-2 px-4 rounded-lg text-sm font-medium text-white transition-colors" style="background:#3b82f6">
|
||||
☁ Save to my bincio
|
||||
<button id="btn-save" class="w-full py-2 px-4 rounded-lg text-sm font-medium bg-zinc-800 hover:bg-zinc-700 text-white transition-colors border border-zinc-700">
|
||||
☁ Save to cloud instance
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
@@ -85,7 +88,16 @@ const baseUrl = import.meta.env.BASE_URL ?? '/';
|
||||
</div>
|
||||
</Base>
|
||||
|
||||
<script define:vars={{ editUrl, baseUrl }}>
|
||||
<div id="conv-config" data-edit-url={editUrl} data-base-url={baseUrl} style="display:none"></div>
|
||||
|
||||
<script>
|
||||
import { saveActivityLocally } from '../../lib/localstore';
|
||||
|
||||
// ── Config ──────────────────────────────────────────────────────────────────
|
||||
const _cfg = document.getElementById('conv-config') as HTMLElement;
|
||||
const editUrl = _cfg.dataset.editUrl ?? '';
|
||||
const baseUrl = _cfg.dataset.baseUrl ?? '/';
|
||||
|
||||
// ── DOM refs ────────────────────────────────────────────────────────────────
|
||||
const stepPick = document.getElementById('step-pick');
|
||||
const stepLoading = document.getElementById('step-loading');
|
||||
@@ -168,17 +180,17 @@ const baseUrl = import.meta.env.BASE_URL ?? '/';
|
||||
setProgress(20, 'Initialising Python…');
|
||||
pyodide = await window.loadPyodide({ indexURL: 'https://cdn.jsdelivr.net/pyodide/v0.26.4/full/' });
|
||||
|
||||
setProgress(40, 'Loading packages (lxml, pyyaml)…');
|
||||
await pyodide.loadPackage(['lxml', 'pyyaml']);
|
||||
setProgress(40, 'Loading packages (lxml, pyyaml, micropip)…');
|
||||
await pyodide.loadPackage(['lxml', 'pyyaml', 'micropip']);
|
||||
|
||||
setProgress(60, 'Installing fitdecode, gpxpy, rdp…');
|
||||
await pyodide.runPythonAsync(`
|
||||
import micropip
|
||||
await micropip.install(['fitdecode', 'gpxpy', 'rdp'])
|
||||
await micropip.install(['fitdecode', 'gpxpy'])
|
||||
`);
|
||||
|
||||
setProgress(80, 'Loading bincio extract pipeline…');
|
||||
const wheelUrl = new URL('/bincio.whl', window.location.origin).href;
|
||||
const wheelUrl = new URL('/bincio-0.1.0-py3-none-any.whl', window.location.origin).href;
|
||||
await pyodide.runPythonAsync(`
|
||||
import micropip
|
||||
await micropip.install('${wheelUrl}', deps=False)
|
||||
@@ -276,6 +288,27 @@ json.dumps({'id': act_id, 'detail': detail, 'geojson': geojson})
|
||||
showStep('error');
|
||||
}
|
||||
|
||||
// ── Save locally (IndexedDB → service worker serves it in the feed) ─────────
|
||||
document.getElementById('btn-save-local').addEventListener('click', async () => {
|
||||
if (!lastResult) return;
|
||||
const btn = document.getElementById('btn-save-local');
|
||||
btn.disabled = true;
|
||||
btn.textContent = 'Saving…';
|
||||
saveStatus.style.color = 'var(--text-4)';
|
||||
try {
|
||||
await saveActivityLocally(lastResult.detail, lastResult.geojson ?? null);
|
||||
btn.textContent = '✓ Saved to device';
|
||||
btn.style.background = '#16a34a';
|
||||
saveStatus.textContent = 'Activity saved. Visit the feed to see it.';
|
||||
saveStatus.style.color = '#4ade80';
|
||||
} catch (e) {
|
||||
btn.disabled = false;
|
||||
btn.textContent = '📱 Save to this device';
|
||||
saveStatus.textContent = 'Save failed: ' + e.message;
|
||||
saveStatus.style.color = '#f87171';
|
||||
}
|
||||
});
|
||||
|
||||
// ── Downloads ───────────────────────────────────────────────────────────────
|
||||
function downloadJson(data, filename) {
|
||||
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
|
||||
|
||||
Reference in New Issue
Block a user