Add URL landscape JSON import
This commit is contained in:
@@ -44,6 +44,7 @@ The initial landscape contains Website, API, ERP, CRM and Email Platform plus tw
|
|||||||
- Adjust playback speed and inspect the active payload.
|
- Adjust playback speed and inspect the active payload.
|
||||||
- Persist the complete landscape, including node positions, in browser local storage.
|
- Persist the complete landscape, including node positions, in browser local storage.
|
||||||
- Export and import the landscape as JSON. Invalid imports and deleted connection references are rejected with actionable errors.
|
- Export and import the landscape as JSON. Invalid imports and deleted connection references are rejected with actionable errors.
|
||||||
|
- Load a landscape JSON document from an HTTP(S) URL through the URL import control. The remote server must return JSON and allow browser CORS requests; the same version and reference validation as file imports is applied.
|
||||||
- Use the Monday Demo guide at the bottom of the app to walk through playback, data inspection and failure recovery.
|
- Use the Monday Demo guide at the bottom of the app to walk through playback, data inspection and failure recovery.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
+19
-2
@@ -21,6 +21,8 @@ const speed = ref(1)
|
|||||||
const eventLog = ref<string[]>([])
|
const eventLog = ref<string[]>([])
|
||||||
const packetProgress = ref(0)
|
const packetProgress = ref(0)
|
||||||
const importError = ref('')
|
const importError = ref('')
|
||||||
|
const jsonUrl = ref('')
|
||||||
|
const importingUrl = ref(false)
|
||||||
const fileInput = ref<HTMLInputElement | null>(null)
|
const fileInput = ref<HTMLInputElement | null>(null)
|
||||||
const minimapEl = ref<HTMLCanvasElement | null>(null)
|
const minimapEl = ref<HTMLCanvasElement | null>(null)
|
||||||
const searchQuery = ref('')
|
const searchQuery = ref('')
|
||||||
@@ -272,9 +274,24 @@ function drawMinimap() { const canvas = minimapEl.value; if (!canvas) return; co
|
|||||||
function exportJson() {
|
function exportJson() {
|
||||||
const blob = new Blob([JSON.stringify(landscape.value, null, 2)], { type: 'application/json' }); const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = 'system-landscape.json'; link.click(); URL.revokeObjectURL(url)
|
const blob = new Blob([JSON.stringify(landscape.value, null, 2)], { type: 'application/json' }); const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = 'system-landscape.json'; link.click(); URL.revokeObjectURL(url)
|
||||||
}
|
}
|
||||||
|
function applyImportedLandscape(value: unknown) { landscape.value = validateLandscape(value); selectedScenarioId.value = landscape.value.scenarios[0]?.id || ''; importError.value = ''; persist(); rebuildGraph() }
|
||||||
function importJson(event: Event) {
|
function importJson(event: Event) {
|
||||||
const input = event.target as HTMLInputElement; const file = input.files?.[0]; if (!file) return
|
const input = event.target as HTMLInputElement; const file = input.files?.[0]; if (!file) return
|
||||||
const reader = new FileReader(); reader.onload = () => { try { landscape.value = validateLandscape(JSON.parse(String(reader.result))); selectedScenarioId.value = landscape.value.scenarios[0]?.id || ''; importError.value = ''; persist(); rebuildGraph() } catch (error) { importError.value = error instanceof Error ? error.message : 'Invalid landscape file.' } }; reader.readAsText(file); input.value = ''
|
const reader = new FileReader(); reader.onload = () => { try { applyImportedLandscape(JSON.parse(String(reader.result))) } catch (error) { importError.value = error instanceof Error ? error.message : 'Invalid landscape file.' } }; reader.readAsText(file); input.value = ''
|
||||||
|
}
|
||||||
|
async function importJsonFromUrl() {
|
||||||
|
const value = jsonUrl.value.trim()
|
||||||
|
if (!value) { importError.value = 'Enter a JSON URL first.'; return }
|
||||||
|
let url: URL
|
||||||
|
try { url = new URL(value); if (!['http:', 'https:'].includes(url.protocol)) throw new Error('Only HTTP and HTTPS URLs are supported.') } catch (error) { importError.value = error instanceof Error ? error.message : 'Enter a valid HTTP(S) URL.'; return }
|
||||||
|
importingUrl.value = true; importError.value = ''
|
||||||
|
try {
|
||||||
|
const response = await fetch(url.toString(), { headers: { Accept: 'application/json' } })
|
||||||
|
if (!response.ok) throw new Error(`The URL returned HTTP ${response.status}.`)
|
||||||
|
applyImportedLandscape(JSON.parse(await response.text()))
|
||||||
|
} catch (error) {
|
||||||
|
importError.value = error instanceof Error && error.message.includes('Failed to fetch') ? 'Could not fetch that URL. The server may be unavailable or may not allow browser CORS requests.' : error instanceof Error ? error.message : 'URL import failed.'
|
||||||
|
} finally { importingUrl.value = false }
|
||||||
}
|
}
|
||||||
watch(landscape, persist, { deep: true })
|
watch(landscape, persist, { deep: true })
|
||||||
watch([searchQuery, categoryFilter, dataTypeFilter, playing, currentStep], () => { graphCanvas?.draw(true, true); drawMinimap() })
|
watch([searchQuery, categoryFilter, dataTypeFilter, playing, currentStep], () => { graphCanvas?.draw(true, true); drawMinimap() })
|
||||||
@@ -285,7 +302,7 @@ onUnmounted(stopAnimation)
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<main class="app-shell" :class="{presentation: presentationMode}">
|
<main class="app-shell" :class="{presentation: presentationMode}">
|
||||||
<header class="topbar"><div><span class="eyebrow">DUMAS LABS / SIMULATION</span><h1>System Landscape <em>Simulator</em></h1></div><div class="top-actions"><button class="ghost" @click="openCustomBuilder">Build system</button><button class="ghost" @click="exportJson">Export JSON</button><button class="ghost" @click="fileInput?.click()">Import JSON</button><input ref="fileInput" type="file" accept="application/json" hidden @change="importJson" /></div></header>
|
<header class="topbar"><div><span class="eyebrow">DUMAS LABS / SIMULATION</span><h1>System Landscape <em>Simulator</em></h1></div><div class="top-actions"><button class="ghost" @click="openCustomBuilder">Build system</button><button class="ghost" @click="exportJson">Export JSON</button><button class="ghost" @click="fileInput?.click()">Import JSON</button><input ref="fileInput" type="file" accept="application/json" hidden @change="importJson" /><div class="url-import"><input v-model="jsonUrl" type="url" placeholder="https://example.test/landscape.json" @keyup.enter="importJsonFromUrl" /><button class="ghost" :disabled="importingUrl" @click="importJsonFromUrl">{{ importingUrl ? 'Loading…' : 'Load URL' }}</button></div></div></header>
|
||||||
<section v-if="importError" class="import-error">{{ importError }} <button @click="importError = ''">Dismiss</button></section>
|
<section v-if="importError" class="import-error">{{ importError }} <button @click="importError = ''">Dismiss</button></section>
|
||||||
<div class="workspace">
|
<div class="workspace">
|
||||||
<aside class="sidebar panel">
|
<aside class="sidebar panel">
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user