diff --git a/README.md b/README.md index 70f48b5..38eb75d 100644 --- a/README.md +++ b/README.md @@ -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. - 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. +- 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. ```bash diff --git a/src/App.vue b/src/App.vue index 8161e44..15a958e 100644 --- a/src/App.vue +++ b/src/App.vue @@ -21,6 +21,8 @@ const speed = ref(1) const eventLog = ref([]) const packetProgress = ref(0) const importError = ref('') +const jsonUrl = ref('') +const importingUrl = ref(false) const fileInput = ref(null) const minimapEl = ref(null) const searchQuery = ref('') @@ -272,9 +274,24 @@ function drawMinimap() { const canvas = minimapEl.value; if (!canvas) return; co 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) } +function applyImportedLandscape(value: unknown) { landscape.value = validateLandscape(value); selectedScenarioId.value = landscape.value.scenarios[0]?.id || ''; importError.value = ''; persist(); rebuildGraph() } function importJson(event: Event) { 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([searchQuery, categoryFilter, dataTypeFilter, playing, currentStep], () => { graphCanvas?.draw(true, true); drawMinimap() }) @@ -285,7 +302,7 @@ onUnmounted(stopAnimation)