277 lines
57 KiB
Vue
277 lines
57 KiB
Vue
<script setup lang="ts">
|
||
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
|
||
import { LGraph, LGraphCanvas, LiteGraph } from 'litegraph.js'
|
||
import { cloneCapabilities, demoLandscape, SYSTEM_PRESETS, systemFromPreset, type CapabilityModel, type ConnectionModel, type DefinitionActionModel, type EndpointModel, type EndpointResponseModel, type EnvironmentContainerModel, type LandscapeModel, type ScenarioModel, type ScenarioStep, type SystemDefinition, type SystemModel, type SystemPreset, uid, validateLandscape } from './model'
|
||
|
||
const STORAGE_KEY = 'dumas-system-landscape-v1'
|
||
const PRESET_STORAGE_KEY = 'dumas-system-presets-v1'
|
||
const landscape = ref<LandscapeModel>(loadLandscape())
|
||
const customPresets = ref<SystemPreset[]>(loadCustomPresets())
|
||
const canvasEl = ref<HTMLCanvasElement | null>(null)
|
||
const selectedSystemId = ref('')
|
||
const selectedConnectionId = ref('')
|
||
const selectedScenarioId = ref(landscape.value.scenarios[0]?.id || '')
|
||
const activeTab = ref<'systems' | 'scenarios' | 'presets' | 'containers'>('scenarios')
|
||
const graph = new LGraph()
|
||
let graphCanvas: any
|
||
let animationFrame = 0
|
||
const playing = ref(false)
|
||
const stepIndex = ref(-1)
|
||
const speed = ref(1)
|
||
const eventLog = ref<string[]>([])
|
||
const packetProgress = ref(0)
|
||
const importError = ref('')
|
||
const fileInput = ref<HTMLInputElement | null>(null)
|
||
const minimapEl = ref<HTMLCanvasElement | null>(null)
|
||
const searchQuery = ref('')
|
||
const categoryFilter = ref('all')
|
||
const dataTypeFilter = ref('all')
|
||
const tagFilter = ref('all')
|
||
const placingPreset = ref<SystemPreset | null>(null)
|
||
const selectedCapabilityIds = ref<string[]>([])
|
||
const presentationMode = ref(false)
|
||
const failureState = ref<'none' | 'rejected' | 'timeout'>('none')
|
||
const retryAttempts = ref<Record<string, number>>({})
|
||
const pendingDecision = ref<ScenarioStep['humanDecision'] | null>(null)
|
||
const runtimeConnectionIds = ref<string[]>([])
|
||
const runtimePayload = ref('')
|
||
const customBuilderOpen = ref(false)
|
||
const customDraft = ref<{ name: string; description: string; category: SystemModel['category']; color: string; definition: SystemDefinition }>({ name: 'Custom system', description: 'Describe this reusable system.', category: 'service', color: '#6d7cff', definition: { actions: [], endpoints: [] } })
|
||
type TransferKind = 'received' | 'sent' | 'stored'
|
||
interface TransferChange { key: string; status: 'added' | 'removed' | 'changed' | 'same'; incoming?: unknown; outgoing?: unknown }
|
||
interface TransferRecord { id: string; kind: TransferKind; scenarioName: string; stepNumber: number; stepExplanation: string; senderId: string; destinationId: string; payload: string; incoming: string; outgoing: string; changes: TransferChange[]; timestamp: string }
|
||
const transferHistory = ref<TransferRecord[]>([])
|
||
const dataTab = ref<TransferKind>('received')
|
||
const selectedContainerId = ref('')
|
||
const selectedContainer = computed(() => landscape.value.containers.find((item) => item.id === selectedContainerId.value))
|
||
const allTags = computed(() => [...new Set(landscape.value.systems.flatMap((system) => system.tags || []))].sort())
|
||
|
||
function loadLandscape(): LandscapeModel {
|
||
try { return validateLandscape(JSON.parse(localStorage.getItem(STORAGE_KEY) || 'null')) } catch { return demoLandscape() }
|
||
}
|
||
function loadCustomPresets(): SystemPreset[] { try { const value = JSON.parse(localStorage.getItem(PRESET_STORAGE_KEY) || '[]'); return Array.isArray(value) ? value : [] } catch { return [] } }
|
||
const selectedSystem = computed(() => landscape.value.systems.find((item) => item.id === selectedSystemId.value))
|
||
const selectedConnection = computed(() => landscape.value.connections.find((item) => item.id === selectedConnectionId.value))
|
||
const selectedScenario = computed(() => landscape.value.scenarios.find((item) => item.id === selectedScenarioId.value))
|
||
const currentStep = computed(() => selectedScenario.value?.steps[stepIndex.value])
|
||
const currentConnections = computed(() => { const ids = runtimeConnectionIds.value.length ? runtimeConnectionIds.value : currentStep.value?.connectionIds || []; return ids.map((id) => landscape.value.connections.find((item) => item.id === id)).filter(Boolean) as ConnectionModel[] })
|
||
const isRunning = computed(() => playing.value || stepIndex.value >= 0)
|
||
|
||
function persist() { localStorage.setItem(STORAGE_KEY, JSON.stringify(landscape.value)) }
|
||
function persistPresets() { localStorage.setItem(PRESET_STORAGE_KEY, JSON.stringify(customPresets.value)) }
|
||
function selectSystem(id: string) { selectedSystemId.value = id; selectedConnectionId.value = '' }
|
||
function selectContainer(id: string) { selectedContainerId.value = id; selectedSystemId.value = ''; selectedConnectionId.value = '' }
|
||
function selectConnection(id: string) { selectedConnectionId.value = id; selectedSystemId.value = ''; const connection = landscape.value.connections.find((item) => item.id === id); if (connection) { connection.transformation ||= { incoming: connection.payload, outgoing: connection.payload, note: '' }; connection.protocol ||= 'HTTPS'; connection.dataType ||= 'JSON'; connection.deliveryMethod ||= 'immediate'; connection.exchangeType ||= 'event-transfer'; connection.responsePayload ||= '{}'; connection.responseStatus ||= 200; connection.showCableLabel ??= true } }
|
||
function addSystem() {
|
||
const id = uid('system'); landscape.value.systems.push({ id, name: 'New system', description: 'Describe this system.', category: 'service', color: '#6d7cff', position: [160, 160], containerId: landscape.value.containers[0]?.id, tags: ['Test'], capabilities: [] }); selectSystem(id); persist(); rebuildGraph()
|
||
}
|
||
function addContainer() { const id = uid('container'); landscape.value.containers.push({ id, name: 'New environment', color: '#2879d0', position: [80, 80], size: [500, 320] }); selectContainer(id); persist(); rebuildGraph() }
|
||
function moveContainer(container: EnvironmentContainerModel, dx: number, dy: number) { container.position = [container.position[0] + dx, container.position[1] + dy]; for (const system of landscape.value.systems.filter((item) => item.containerId === container.id)) system.position = [system.position[0] + dx, system.position[1] + dy]; for (const child of landscape.value.containers.filter((item) => item.parentId === container.id)) child.position = [child.position[0] + dx, child.position[1] + dy]; persist(); rebuildGraph() }
|
||
function deleteContainer(id: string) { landscape.value.systems.forEach((system) => { if (system.containerId === id) delete system.containerId }); landscape.value.containers = landscape.value.containers.filter((item) => item.id !== id && item.parentId !== id); selectedContainerId.value = ''; persist(); rebuildGraph() }
|
||
function openPreset(preset: SystemPreset) { placingPreset.value = preset; selectedCapabilityIds.value = preset.capabilities.map((capability) => capability.id) }
|
||
function placePreset() { if (!placingPreset.value) return; const position: [number, number] = [120 + (landscape.value.systems.length % 3) * 280, 120 + (landscape.value.systems.length % 3) * 150]; const system = systemFromPreset(placingPreset.value, selectedCapabilityIds.value, position); landscape.value.systems.push(system); selectSystem(system.id); placingPreset.value = null; persist(); rebuildGraph() }
|
||
function definitionCapabilities(definition: SystemDefinition): CapabilityModel[] { return definition.actions.map((item) => ({ id: `action-${item.id}`, name: item.name, description: item.description, inputs: item.trigger === 'incoming' ? [{ id: `${item.id}-input`, name: 'Incoming request', description: 'Request handled by this action.' }] : [], outputs: item.outputs.map((output) => ({ id: output.id, name: output.name, description: output.condition || 'Action output.' })), actions: [{ id: item.id, name: item.name, description: item.description, payload: item.outputs[0]?.payload || item.input || '{}' }], payload: item.input || item.outputs[0]?.payload || '{}' })) }
|
||
function saveCustomPreset(preset: SystemPreset) { customPresets.value.push(preset); persistPresets(); activeTab.value = 'presets' }
|
||
function saveSelectedAsPreset() { if (!selectedSystem.value) return; saveCustomPreset({ id: `custom-${uid('preset')}`, name: `${selectedSystem.value.name} custom`, description: selectedSystem.value.description, category: selectedSystem.value.category, color: selectedSystem.value.color, capabilities: cloneCapabilities(selectedSystem.value.capabilities), definition: structuredClone(selectedSystem.value.definition || { actions: [], endpoints: [] }) }) }
|
||
function newCustomAction(): DefinitionActionModel { return { id: uid('action'), name: 'New action', description: 'Describe the simulated action.', trigger: 'button', input: '{}', outputs: [{ id: uid('output'), name: 'Output', payload: '{}', parallel: false }] } }
|
||
function newCustomEndpoint(): EndpointModel { return { id: uid('endpoint'), name: 'New endpoint', protocol: 'HTTPS', method: 'POST', path: '/example', request: '{}', responses: [{ id: uid('response'), status: 200, body: '{}', delayMs: 300 }] } }
|
||
function newCustomResponse(): EndpointResponseModel { return { id: uid('response'), status: 200, body: '{}', delayMs: 300 } }
|
||
function openCustomBuilder() { customDraft.value = { name: 'Custom system', description: 'Describe this reusable system.', category: 'service', color: '#6d7cff', definition: { actions: [newCustomAction()], endpoints: [newCustomEndpoint()] } }; customBuilderOpen.value = true }
|
||
function saveCustomBuilder() { const draft = structuredClone(customDraft.value); const preset: SystemPreset = { id: `custom-${uid('preset')}`, name: draft.name || 'Custom system', description: draft.description, category: draft.category, color: draft.color, capabilities: definitionCapabilities(draft.definition), definition: draft.definition }; saveCustomPreset(preset); customBuilderOpen.value = false }
|
||
function addCustomAction() { customDraft.value.definition.actions.push(newCustomAction()) }
|
||
function addCustomOutput(action: DefinitionActionModel) { action.outputs.push({ id: uid('output'), name: 'Output', payload: '{}', parallel: false }) }
|
||
function addCustomEndpoint() { customDraft.value.definition.endpoints.push(newCustomEndpoint()) }
|
||
function addCustomResponse(endpoint: EndpointModel) { endpoint.responses.push(newCustomResponse()) }
|
||
function deleteSystem(id: string) {
|
||
landscape.value.systems = landscape.value.systems.filter((item) => item.id !== id)
|
||
landscape.value.connections = landscape.value.connections.filter((item) => item.sourceId !== id && item.targetId !== id)
|
||
landscape.value.scenarios.forEach((scenario) => scenario.steps.forEach((step) => step.connectionIds = step.connectionIds.filter((connectionId) => landscape.value.connections.some((item) => item.id === connectionId))))
|
||
selectedSystemId.value = ''; persist(); rebuildGraph()
|
||
}
|
||
function addConnection() {
|
||
if (landscape.value.systems.length < 2) return
|
||
const connection: ConnectionModel = { id: uid('connection'), sourceId: landscape.value.systems[0].id, targetId: landscape.value.systems[1].id, label: 'New connection', description: '', payload: '{}', transformation: { incoming: '{}', outgoing: '{}', note: '' }, protocol: 'HTTPS', dataType: 'JSON', deliveryMethod: 'immediate', exchangeType: 'event-transfer', responsePayload: '{}', responseStatus: 200, showCableLabel: true }
|
||
landscape.value.connections.push(connection); selectConnection(connection.id); persist(); rebuildGraph()
|
||
}
|
||
function deleteConnection(id: string) {
|
||
landscape.value.connections = landscape.value.connections.filter((item) => item.id !== id)
|
||
landscape.value.scenarios.forEach((scenario) => scenario.steps.forEach((step) => step.connectionIds = step.connectionIds.filter((connectionId) => connectionId !== id)))
|
||
selectedConnectionId.value = ''; persist(); rebuildGraph()
|
||
}
|
||
function addScenario() {
|
||
const scenario: ScenarioModel = { id: uid('scenario'), name: 'New scenario', description: 'Describe the journey.', startSystemId: landscape.value.systems[0]?.id || '', steps: [] }
|
||
landscape.value.scenarios.push(scenario); selectedScenarioId.value = scenario.id; activeTab.value = 'scenarios'; persist()
|
||
}
|
||
function actionsForSystem(systemId: string) { return landscape.value.systems.find((system) => system.id === systemId)?.capabilities.flatMap((capability) => capability.actions.map((action) => ({ ...action, capabilityName: capability.name }))) || [] }
|
||
function selectedStartAction() { return actionsForSystem(selectedScenario.value?.startSystemId || '').find((action) => action.id === selectedScenario.value?.startActionId) }
|
||
function addJourneyStep() { if (!selectedScenario.value) return; const connection = landscape.value.connections.find((item) => !selectedScenario.value!.steps.some((step) => step.connectionIds.includes(item.id))) || landscape.value.connections[0]; if (!connection) return; const action = selectedStartAction(); selectedScenario.value.steps.push({ id: uid('step'), connectionIds: [connection.id], explanation: action ? `${action.name} sends data through ${connection.label}.` : `Send data through ${connection.label}.`, payload: action?.payload || connection.payload, delayMs: 1000, outcome: 'success' }); persist() }
|
||
function addParallelBranch() { if (!selectedScenario.value?.steps.length) return addJourneyStep(); const step = selectedScenario.value.steps[selectedScenario.value.steps.length - 1]; const connection = landscape.value.connections.find((item) => !step.connectionIds.includes(item.id)); if (connection) step.connectionIds.push(connection.id); persist() }
|
||
function addStep() {
|
||
if (!selectedScenario.value || !landscape.value.connections[0]) return
|
||
selectedScenario.value.steps.push({ id: uid('step'), connectionIds: [landscape.value.connections[0].id], explanation: 'Explain what happens here.', payload: '{}', delayMs: 1000 }); persist()
|
||
}
|
||
function deleteStep(index: number) { selectedScenario.value?.steps.splice(index, 1); persist() }
|
||
|
||
function resetPlayback() { playing.value = false; stepIndex.value = -1; packetProgress.value = 0; eventLog.value = []; transferHistory.value = []; failureState.value = 'none'; retryAttempts.value = {}; pendingDecision.value = null; runtimeConnectionIds.value = []; runtimePayload.value = ''; stopAnimation() }
|
||
function startScenario(systemId?: string) {
|
||
if (systemId) {
|
||
const candidate = landscape.value.scenarios.find((scenario) => scenario.startSystemId === systemId)
|
||
if (candidate) selectedScenarioId.value = candidate.id
|
||
}
|
||
resetPlayback(); if (selectedScenario.value?.steps.length) { playing.value = true; advanceStep() }
|
||
}
|
||
function advanceStep() {
|
||
if (!selectedScenario.value || stepIndex.value + 1 >= selectedScenario.value.steps.length) { playing.value = false; return }
|
||
stepIndex.value += 1; packetProgress.value = 0
|
||
const step = selectedScenario.value.steps[stepIndex.value]
|
||
runtimeConnectionIds.value = []
|
||
runtimePayload.value = ''
|
||
if (step.humanDecision) { pendingDecision.value = structuredClone(step.humanDecision); playing.value = false; eventLog.value.unshift(`${new Date().toLocaleTimeString()} · Waiting for ${systemName(step.humanDecision.roleSystemId)} decision`); drawPackets(); return }
|
||
recordTransfers(step)
|
||
failureState.value = step.outcome && step.outcome !== 'success' ? step.outcome : 'none'
|
||
if (failureState.value !== 'none') eventLog.value.unshift(`${new Date().toLocaleTimeString()} · ${step.outcome === 'timeout' ? 'TIMEOUT' : 'REJECTED'} · ${step.explanation}`)
|
||
eventLog.value.unshift(`${new Date().toLocaleTimeString()} · ${step.explanation}`)
|
||
animatePacket(step.delayMs / speed.value)
|
||
}
|
||
function recordTransfers(step: ScenarioModel['steps'][number], selectedConnectionIds = step.connectionIds, selectedPayload = '') {
|
||
if (!selectedScenario.value) return
|
||
const now = new Date().toLocaleTimeString()
|
||
for (const connectionId of selectedConnectionIds) {
|
||
const connection = landscape.value.connections.find((item) => item.id === connectionId)
|
||
if (!connection) continue
|
||
const incoming = connection.transformation?.incoming || selectedPayload || step.payload || connection.payload
|
||
const outgoing = selectedPayload || connection.transformation?.outgoing || incoming
|
||
const changes = comparePayloads(incoming, outgoing)
|
||
const payload = outgoing
|
||
transferHistory.value.push(
|
||
...(['sent', 'received', 'stored'] as TransferKind[]).map((kind) => ({ id: uid('transfer'), kind, scenarioName: selectedScenario.value!.name, stepNumber: stepIndex.value + 1, stepExplanation: step.explanation, senderId: connection.sourceId, destinationId: connection.targetId, payload, incoming, outgoing, changes, timestamp: now }))
|
||
)
|
||
if (connection.exchangeType === 'request-response') transferHistory.value.push(...(['sent', 'received'] as TransferKind[]).map((kind) => ({ id: uid('transfer'), kind, scenarioName: selectedScenario.value!.name, stepNumber: stepIndex.value + 1, stepExplanation: `${step.explanation} · Response ${connection.responseStatus || 200}`, senderId: connection.targetId, destinationId: connection.sourceId, payload: connection.responsePayload || '{}', incoming: payload, outgoing: connection.responsePayload || '{}', changes: comparePayloads(payload, connection.responsePayload || '{}'), timestamp: now })))
|
||
}
|
||
}
|
||
function connectionCompatibility(connection: ConnectionModel) { const source = landscape.value.systems.find((item) => item.id === connection.sourceId); const target = landscape.value.systems.find((item) => item.id === connection.targetId); if (!source || !target) return 'Missing endpoint systems.'; const sourcePorts = source.capabilities.flatMap((capability) => capability.outputs).map((port) => port.name.toLowerCase()); const targetPorts = target.capabilities.flatMap((capability) => capability.inputs).map((port) => port.name.toLowerCase()); if (!sourcePorts.length || !targetPorts.length) return 'No declared ports; unusual integration is allowed.'; const match = sourcePorts.some((port) => targetPorts.some((targetPort) => port.includes(targetPort) || targetPort.includes(port))); return match ? 'Compatible declared ports.' : 'Warning: no matching port names; modelling is still allowed.' }
|
||
function chooseHumanAction(action: NonNullable<ScenarioStep['humanDecision']>['actions'][number]) { if (!selectedScenario.value || !pendingDecision.value) return; const step = selectedScenario.value.steps[stepIndex.value]; let payload = action.payload; try { const parsed = JSON.parse(action.payload); Object.assign(parsed, pendingDecision.value.editableFields); payload = JSON.stringify(parsed) } catch { /* Keep non-JSON simulated payloads unchanged. */ } runtimeConnectionIds.value = [action.connectionId]; runtimePayload.value = payload; pendingDecision.value = null; playing.value = true; failureState.value = 'none'; eventLog.value.unshift(`${new Date().toLocaleTimeString()} · ${systemName(step.humanDecision!.roleSystemId)} chose ${action.name}`); recordTransfers(step, [action.connectionId], payload); animatePacket(step.delayMs / speed.value) }
|
||
function comparePayloads(incoming: string, outgoing: string): TransferChange[] { try { const before = JSON.parse(incoming); const after = JSON.parse(outgoing); const keys = new Set([...Object.keys(before || {}), ...Object.keys(after || {})]); return [...keys].sort().map((key) => ({ key, status: !(key in before) ? 'added' : !(key in after) ? 'removed' : JSON.stringify(before[key]) !== JSON.stringify(after[key]) ? 'changed' : 'same', incoming: before[key], outgoing: after[key] })) } catch { return [] } }
|
||
function enableTransformation() { if (selectedConnection.value && !selectedConnection.value.transformation) selectedConnection.value.transformation = { incoming: selectedConnection.value.payload, outgoing: selectedConnection.value.payload, note: '' } }
|
||
function recordsForSelectedSystem(kind: TransferKind) { if (!selectedSystem.value) return []; return transferHistory.value.filter((record) => kind === 'sent' ? record.senderId === selectedSystem.value?.id : record.destinationId === selectedSystem.value?.id) }
|
||
function systemName(id: string) { return landscape.value.systems.find((system) => system.id === id)?.name || id }
|
||
const latestSelectedRecord = computed(() => selectedSystem.value ? transferHistory.value.filter((record) => record.destinationId === selectedSystem.value?.id).slice(-1)[0] : undefined)
|
||
const matchesSystem = (system: SystemModel) => { const query = searchQuery.value.trim().toLowerCase(); const queryMatch = !query || `${system.name} ${system.description}`.toLowerCase().includes(query); const categoryMatch = categoryFilter.value === 'all' || system.category === categoryFilter.value; const dataMatch = dataTypeFilter.value === 'all' || landscape.value.connections.some((connection) => connection.dataType === dataTypeFilter.value && (connection.sourceId === system.id || connection.targetId === system.id)); const tagMatch = tagFilter.value === 'all' || (system.tags || []).includes(tagFilter.value); return queryMatch && categoryMatch && dataMatch && tagMatch }
|
||
function isSystemDimmed(system: SystemModel) { if (!matchesSystem(system)) return true; if (!playing.value || !currentConnections.value.length) return false; return !currentConnections.value.some((connection) => connection.sourceId === system.id || connection.targetId === system.id) }
|
||
function animatePacket(duration: number) {
|
||
stopAnimation(); const started = performance.now()
|
||
const tick = (now: number) => { packetProgress.value = Math.min(1, (now - started) / duration); drawPackets(); if (packetProgress.value < 1) animationFrame = requestAnimationFrame(tick); else if (playing.value) setTimeout(finishStep, 180 / speed.value) }
|
||
animationFrame = requestAnimationFrame(tick)
|
||
}
|
||
function finishStep() {
|
||
const step = currentStep.value
|
||
if (!step || !selectedScenario.value || !step.outcome || step.outcome === 'success') { advanceStep(); return }
|
||
const targetId = step.retryStepId && (retryAttempts.value[step.id] || 0) < 1 ? step.retryStepId : step.recoveryStepId
|
||
if (step.retryStepId && targetId === step.retryStepId) retryAttempts.value[step.id] = (retryAttempts.value[step.id] || 0) + 1
|
||
const targetIndex = targetId ? selectedScenario.value.steps.findIndex((candidate) => candidate.id === targetId) : -1
|
||
if (targetIndex >= 0) { stepIndex.value = targetIndex - 1; failureState.value = 'none'; advanceStep() } else { playing.value = false }
|
||
}
|
||
function stopAnimation() { if (animationFrame) cancelAnimationFrame(animationFrame); animationFrame = 0 }
|
||
function togglePlay() { if (!selectedScenario.value) return; if (playing.value) { playing.value = false; stopAnimation() } else { playing.value = true; if (stepIndex.value < 0) advanceStep(); else animatePacket(currentStep.value?.delayMs || 1000) } }
|
||
|
||
function collapsedContainerFor(systemId: string) { const system = landscape.value.systems.find((item) => item.id === systemId); const container = system?.containerId ? landscape.value.containers.find((item) => item.id === system.containerId) : undefined; return container?.collapsed ? container : undefined }
|
||
function visualNodeId(systemId: string) { return collapsedContainerFor(systemId)?.id || systemId }
|
||
function buildNode(system: SystemModel) {
|
||
if (collapsedContainerFor(system.id)) return null
|
||
const node = LiteGraph.createNode('Landscape/System')
|
||
node.id = system.id; node.title = system.category === 'human' ? `ROLE · ${system.name}` : system.name; node.pos = [...system.position]; node.color = system.color; node.bgcolor = system.category === 'human' ? '#38213b' : '#111827'; node.shape = system.category === 'human' ? LiteGraph.ROUND : LiteGraph.BOX; node.size = [190, 100]
|
||
node.addInput('in', 'SYSTEM'); node.addOutput('out', 'SYSTEM'); node.systemId = system.id; node.showActions = false
|
||
for (const capability of system.capabilities) { for (const input of capability.inputs) node.addInput(`${capability.id}:${input.id}`, input.name); for (const output of capability.outputs) node.addOutput(`${capability.id}:${output.id}`, output.name) }
|
||
if (system.capabilities.length) node.addWidget('button', 'Actions ▸', null, () => { node.showActions = !node.showActions; node.widgets[0].name = node.showActions ? 'Actions ▾' : 'Actions ▸'; graphCanvas?.draw(true, true) })
|
||
node.onDblClick = () => selectSystem(system.id)
|
||
node.onMouseDown = () => selectSystem(system.id)
|
||
node.onDrawForeground = function(ctx: CanvasRenderingContext2D) { const dimmed = isSystemDimmed(system); ctx.save(); ctx.globalAlpha = dimmed ? .28 : 1; ctx.fillStyle = '#8d9bb8'; ctx.font = '11px Inter, sans-serif'; ctx.fillText(system.category.toUpperCase(), 12, 76); if (node.showActions) { ctx.fillStyle = '#c9d3e8'; ctx.font = '10px Inter, sans-serif'; system.capabilities.forEach((capability: CapabilityModel, index: number) => ctx.fillText(`${capability.name}: ${capability.actions.map((item) => item.name).join(', ')}`, 12, 92 + index * 13)) } ctx.restore() }
|
||
graph.add(node); return node
|
||
}
|
||
function connectionLabel(connection: ConnectionModel) { return connection.showCableLabel === false ? '' : `${connection.label} · ${connection.protocol || 'HTTPS'} · ${connection.dataType || 'JSON'} · ${connection.deliveryMethod || 'immediate'}` }
|
||
function rebuildGraph() {
|
||
graph.clear(); for (const container of landscape.value.containers.filter((item) => !item.collapsed)) { const group = new LiteGraph.LGraphGroup(container.name); group.pos = [...container.position]; group.size = [...container.size]; group.color = container.color; group.font_size = 18; group._dumasContainerId = container.id; graph.add(group) }
|
||
for (const container of landscape.value.containers.filter((item) => item.collapsed)) { const node = LiteGraph.createNode('Landscape/Container'); node.id = container.id; node.title = `CONTAINER · ${container.name}`; node.pos = [...container.position]; node.color = container.color; node.bgcolor = '#172a43'; node.size = [210, 90]; node.addOutput('external', 'EXTERNAL'); node.onDblClick = () => { container.collapsed = false; persist(); rebuildGraph() }; graph.add(node) }
|
||
landscape.value.systems.forEach(buildNode)
|
||
for (const connection of landscape.value.connections) {
|
||
const source = graph.getNodeById(visualNodeId(connection.sourceId)); const target = graph.getNodeById(visualNodeId(connection.targetId))
|
||
if (source && target) source.connect(0, target, 0)
|
||
}
|
||
nextTick(() => { graphCanvas?.draw(true, true); drawPackets() })
|
||
}
|
||
function drawPackets() {
|
||
if (!graphCanvas) return
|
||
const original = graphCanvas.onDrawForeground
|
||
graphCanvas.onDrawForeground = undefined
|
||
graphCanvas.draw(true, true)
|
||
graphCanvas.onDrawForeground = original
|
||
if (!currentConnections.value.length || stepIndex.value < 0) return
|
||
const ctx = graphCanvas.ctx as CanvasRenderingContext2D
|
||
for (const connection of landscape.value.connections) {
|
||
if (!connection.showCableLabel) continue
|
||
const from = graph.getNodeById(visualNodeId(connection.sourceId)); const to = graph.getNodeById(visualNodeId(connection.targetId))
|
||
if (!from || !to) continue
|
||
ctx.save(); ctx.fillStyle = '#7887a2'; ctx.font = '10px Inter, sans-serif'; ctx.fillText(connectionLabel(connection), (from.pos[0] + to.pos[0]) / 2, (from.pos[1] + to.pos[1]) / 2 - 8); ctx.restore()
|
||
}
|
||
for (const connection of currentConnections.value) {
|
||
const from = graph.getNodeById(visualNodeId(connection.sourceId)); const to = graph.getNodeById(visualNodeId(connection.targetId))
|
||
if (!from || !to) continue
|
||
const x = from.pos[0] + from.size[0] + (to.pos[0] - from.pos[0] - from.size[0]) * packetProgress.value
|
||
const y = from.pos[1] + 50 + (to.pos[1] + 50 - from.pos[1] - 50) * packetProgress.value
|
||
const packetColor = failureState.value === 'none' ? '#f8c15c' : '#ef627d'; ctx.save(); ctx.fillStyle = packetColor; ctx.shadowColor = packetColor; ctx.shadowBlur = 18; ctx.beginPath(); ctx.arc(x, y, failureState.value === 'none' ? 7 : 9, 0, Math.PI * 2); ctx.fill(); ctx.restore()
|
||
}
|
||
}
|
||
function fitToScreen() { if (!graphCanvas || !canvasEl.value || !landscape.value.systems.length) return; const xs = landscape.value.systems.map((system) => system.position[0]); const ys = landscape.value.systems.map((system) => system.position[1]); const minX = Math.min(...xs); const minY = Math.min(...ys); const maxX = Math.max(...xs) + 220; const maxY = Math.max(...ys) + 130; graphCanvas.ds.scale = Math.min(.95, Math.max(.45, Math.min((canvasEl.value.width - 80) / (maxX - minX), (canvasEl.value.height - 80) / (maxY - minY)))); graphCanvas.ds.offset = [40 - minX * graphCanvas.ds.scale, 40 - minY * graphCanvas.ds.scale]; graphCanvas.draw(true, true); drawMinimap() }
|
||
function drawMinimap() { const canvas = minimapEl.value; if (!canvas) return; const ctx = canvas.getContext('2d'); if (!ctx) return; ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.fillStyle = '#0d121e'; ctx.fillRect(0, 0, canvas.width, canvas.height); const scale = Math.min(canvas.width / 1200, canvas.height / 670); for (const system of landscape.value.systems) { ctx.fillStyle = isSystemDimmed(system) ? '#283248' : system.color; ctx.fillRect(system.position[0] * scale, system.position[1] * scale, 34, 20) } }
|
||
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 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 = ''
|
||
}
|
||
watch(landscape, persist, { deep: true })
|
||
watch([searchQuery, categoryFilter, dataTypeFilter, playing, currentStep], () => { graphCanvas?.draw(true, true); drawMinimap() })
|
||
onMounted(() => { if (!canvasEl.value) return; graphCanvas = new LGraphCanvas(canvasEl.value, graph); graphCanvas.background_image = null; graphCanvas.render_shadows = false; graphCanvas.ds.scale = 0.85; graphCanvas.onDrawForeground = drawPackets; rebuildGraph(); drawMinimap() })
|
||
onUnmounted(stopAnimation)
|
||
</script>
|
||
|
||
<template>
|
||
<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>
|
||
<section v-if="importError" class="import-error">{{ importError }} <button @click="importError = ''">Dismiss</button></section>
|
||
<div class="workspace">
|
||
<aside class="sidebar panel">
|
||
<div class="tabs"><button :class="{active: activeTab === 'scenarios'}" @click="activeTab = 'scenarios'">Scenarios</button><button :class="{active: activeTab === 'systems'}" @click="activeTab = 'systems'">Systems</button><button :class="{active: activeTab === 'containers'}" @click="activeTab = 'containers'">Environments</button><button :class="{active: activeTab === 'presets'}" @click="activeTab = 'presets'">Presets</button></div>
|
||
<div v-if="activeTab === 'scenarios'" class="list-area"><div class="section-heading"><span>Journeys</span><button class="icon-button" @click="addScenario">+</button></div><div v-for="scenario in landscape.scenarios" :key="scenario.id" class="list-item" :class="{selected: selectedScenarioId === scenario.id}" @dblclick="selectedScenarioId = scenario.id; startScenario()"><span class="status-dot"></span><span class="list-copy" @click="selectedScenarioId = scenario.id; resetPlayback()"><strong>{{ scenario.name }}</strong><small>{{ scenario.steps.length }} steps · {{ scenario.description }}</small></span><button class="run-mini" title="Run scenario" @click.stop="selectedScenarioId = scenario.id; startScenario()">▶</button></div></div>
|
||
<div v-else-if="activeTab === 'systems'" class="list-area"><div class="section-heading"><span>Systems</span><button class="icon-button" @click="addSystem">+</button></div><button v-for="system in landscape.systems" :key="system.id" class="list-item" :class="{selected: selectedSystemId === system.id}" @click="selectSystem(system.id)"><span class="system-dot" :style="{background: system.color}"></span><span><strong>{{ system.name }}</strong><small>{{ system.category }} · {{ system.capabilities.length }} capabilities</small></span></button><div class="section-heading connections-heading"><span>Connections</span><button class="icon-button" @click="addConnection">+</button></div><button v-for="connection in landscape.connections" :key="connection.id" class="list-item compact" :class="{selected: selectedConnectionId === connection.id}" @click="selectConnection(connection.id)"><span class="arrow">↗</span><span><strong>{{ connection.label }}</strong><small>{{ landscape.systems.find(s => s.id === connection.sourceId)?.name }} → {{ landscape.systems.find(s => s.id === connection.targetId)?.name }}</small></span></button></div>
|
||
<div v-else class="list-area"><div class="section-heading"><span>Built-in library</span></div><div v-for="preset in SYSTEM_PRESETS" :key="preset.id" class="preset-item" :title="preset.description"><span class="system-dot" :style="{background: preset.color}"></span><span class="list-copy"><strong>{{ preset.name }}</strong><small>{{ preset.capabilities.length }} capabilities</small></span><button class="run-mini" @click="openPreset(preset)">Place</button></div><div class="section-heading connections-heading"><span>Your presets</span></div><div v-if="!customPresets.length" class="muted">Save a customised system from its inspector.</div><div v-for="preset in customPresets" :key="preset.id" class="preset-item" :title="preset.description"><span class="system-dot" :style="{background: preset.color}"></span><span class="list-copy"><strong>{{ preset.name }}</strong><small>{{ preset.capabilities.length }} capabilities</small></span><button class="run-mini" @click="openPreset(preset)">Place</button></div></div>
|
||
<div class="sidebar-foot"><span class="live-dot"></span> Local simulation · auto-saved</div>
|
||
</aside>
|
||
<section class="canvas-panel panel"><div class="canvas-toolbar"><div><span class="eyebrow">LANDSCAPE / LIVE MAP</span><strong>{{ selectedScenario?.name || 'Untitled landscape' }}</strong></div><div class="canvas-hint">Drag nodes to rearrange · scroll to zoom</div></div><canvas ref="canvasEl" width="1200" height="670"></canvas><div class="canvas-legend"><span><i class="legend-node"></i> System</span><span><i class="legend-packet"></i> Active packet</span><span>Pan: drag empty canvas</span></div></section>
|
||
<aside class="inspector panel">
|
||
<div v-if="selectedSystem" class="inspector-content"><div class="inspector-header"><div><span class="eyebrow">SYSTEM</span><h2>{{ selectedSystem.name }}</h2></div><button class="danger-icon" @click="deleteSystem(selectedSystem.id)">×</button></div><label>Name<input v-model="selectedSystem.name" @change="rebuildGraph" /></label><label>Category<select v-model="selectedSystem.category"><option value="application">Application</option><option value="service">Service</option><option value="data">Data</option><option value="human">Human</option><option value="external">External</option></select></label><label>Colour<input v-model="selectedSystem.color" type="color" /></label><label>Description<textarea v-model="selectedSystem.description" rows="4"></textarea></label><button class="primary full" @click="persist">Save system</button><button class="ghost full" @click="saveSelectedAsPreset">Save as my preset</button><div class="capability-list"><div class="steps-head"><span>Capabilities</span></div><article v-for="capability in selectedSystem.capabilities" :key="capability.id" class="capability-card" :title="capability.description"><strong>{{ capability.name }}</strong><small>{{ capability.description }}</small><div class="port-line"><span>Inputs</span>{{ capability.inputs.map((item) => item.name).join(' · ') || 'None' }}</div><div class="port-line"><span>Outputs</span>{{ capability.outputs.map((item) => item.name).join(' · ') || 'None' }}</div><details><summary>Actions & sample payload</summary><div v-for="action in capability.actions" :key="action.id" class="action-row" :title="action.description"><b>{{ action.name }}</b><small>{{ action.description }}</small><textarea v-model="action.payload" rows="2" class="code"></textarea></div><label>Default capability payload<textarea v-model="capability.payload" rows="2" class="code"></textarea></label></details></article></div></div>
|
||
<div v-else-if="selectedConnection" class="inspector-content"><div class="inspector-header"><div><span class="eyebrow">CONNECTION</span><h2>{{ selectedConnection.label }}</h2></div><button class="danger-icon" @click="deleteConnection(selectedConnection.id)">×</button></div><label>Label<input v-model="selectedConnection.label" /></label><label>From<select v-model="selectedConnection.sourceId" @change="rebuildGraph"><option v-for="system in landscape.systems" :key="system.id" :value="system.id">{{ system.name }}</option></select></label><label>To<select v-model="selectedConnection.targetId" @change="rebuildGraph"><option v-for="system in landscape.systems" :key="system.id" :value="system.id">{{ system.name }}</option></select></label><label>Description<textarea v-model="selectedConnection.description" rows="3"></textarea></label><label>Exchange type<select v-model="selectedConnection.exchangeType"><option value="event-transfer">Onward event / transfer</option><option value="request-response">Direct request / response</option></select></label><label>Example request payload<textarea v-model="selectedConnection.payload" rows="4" class="code"></textarea></label><div v-if="selectedConnection.exchangeType === 'request-response'" class="response-box"><b>Simulated response</b><label>Status<input v-model.number="selectedConnection.responseStatus" type="number" /></label><label>Response payload<textarea v-model="selectedConnection.responsePayload" rows="4" class="code"></textarea></label></div><p class="compatibility-note">{{ connectionCompatibility(selectedConnection) }}</p></div>
|
||
<div v-else-if="selectedScenario" class="inspector-content scenario-inspector"><div class="inspector-header"><div><span class="eyebrow">SCENARIO</span><h2>{{ selectedScenario.name }}</h2></div><button class="primary run-button" @click="startScenario()">▶ Run</button></div><label>Name<input v-model="selectedScenario.name" /></label><label>Description<textarea v-model="selectedScenario.description" rows="3"></textarea></label><div class="steps-head"><span>Steps</span><button class="icon-button" @click="addStep">+</button></div><div v-for="(step, index) in selectedScenario.steps" :key="step.id" class="step-editor"><div class="step-number">{{ String(index + 1).padStart(2, '0') }}</div><div class="step-fields"><select v-model="step.connectionIds" multiple><option v-for="connection in landscape.connections" :key="connection.id" :value="connection.id">{{ connection.label }}</option></select><input v-model="step.explanation" placeholder="What happens?" /><textarea v-model="step.payload" rows="2" class="code" placeholder="Payload"></textarea><button class="text-danger" @click="deleteStep(index)">Remove step</button></div></div></div>
|
||
<div v-else class="empty-inspector"><div class="empty-icon">⌘</div><h2>Select an item</h2><p>Choose a system, connection, or scenario to inspect and edit its details.</p></div>
|
||
<div v-if="selectedSystem" class="inspector-content data-inspector"><div class="data-tabs"><button v-for="tab in (['received','sent','stored'] as TransferKind[])" :key="tab" :class="{active: dataTab === tab}" @click="dataTab = tab">{{ tab }}</button></div><div v-if="!recordsForSelectedSystem(dataTab).length" class="muted">No simulated data yet. Run a scenario to populate this history.</div><article v-for="record in recordsForSelectedSystem(dataTab).slice().reverse()" :key="record.id" class="transfer-card"><div class="transfer-meta"><b>Step {{ record.stepNumber }} · {{ record.timestamp }}</b><span>{{ record.scenarioName }}</span></div><div class="transfer-route">{{ systemName(record.senderId) }} → {{ systemName(record.destinationId) }}</div><p>{{ record.stepExplanation }}</p><pre>{{ record.payload }}</pre></article></div>
|
||
</aside>
|
||
</div>
|
||
<footer class="playback panel"><div class="playback-scenario"><span class="eyebrow">SIMULATION</span><strong>{{ selectedScenario?.name || 'No scenario selected' }}</strong></div><button class="control" @click="resetPlayback">↺</button><button class="control play" @click="togglePlay">{{ playing ? 'Ⅱ' : '▶' }}</button><button class="control" @click="advanceStep">›</button><div class="timeline"><div class="timeline-track"><span v-for="(step, index) in (selectedScenario?.steps || [])" :key="step.id" class="timeline-step" :class="{complete: index < stepIndex, current: index === stepIndex}" :style="{width: `${100 / Math.max(1, selectedScenario?.steps.length || 1)}%`}"><i></i><small>{{ index + 1 }}</small></span></div><div class="timeline-label"><span>{{ currentStep?.explanation || 'Ready to run' }}</span><span>{{ stepIndex + 1 < 0 ? 0 : stepIndex + 1 }} / {{ selectedScenario?.steps.length || 0 }}</span></div></div><label class="speed">Speed <select v-model.number="speed"><option :value="0.5">0.5×</option><option :value="1">1×</option><option :value="2">2×</option><option :value="4">4×</option></select></label></footer>
|
||
<section class="event-drawer" v-if="eventLog.length"><span class="eyebrow">EVENT LOG</span><span v-for="event in eventLog.slice(0, 3)" :key="event">{{ event }}</span><span v-if="currentStep" class="payload"><b>Payload</b> {{ currentStep.payload }}</span></section>
|
||
<div v-if="placingPreset" class="modal-backdrop" @click.self="placingPreset = null"><section class="preset-modal panel"><div class="inspector-header"><div><span class="eyebrow">PLACE PRESET</span><h2>{{ placingPreset.name }}</h2><p>{{ placingPreset.description }}</p></div><button class="danger-icon" @click="placingPreset = null">×</button></div><p class="muted">Choose the capabilities to place. The new canvas system will have its own editable copies.</p><label v-for="capability in placingPreset.capabilities" :key="capability.id" class="capability-choice" :title="capability.description"><input v-model="selectedCapabilityIds" type="checkbox" :value="capability.id" /><span><b>{{ capability.name }}</b><small>{{ capability.description }}</small></span></label><div class="modal-actions"><button class="ghost" @click="placingPreset = null">Cancel</button><button class="primary" :disabled="!selectedCapabilityIds.length" @click="placePreset">Place system</button></div></section></div>
|
||
<section v-if="selectedConnection" class="transformation-panel panel"><div><span class="eyebrow">SIMULATED TRANSFORMATION</span><strong>{{ selectedConnection.label }}</strong><p class="muted">Configure the data change explicitly; playback never calls a real service.</p></div><label>Incoming JSON<textarea v-model="selectedConnection.transformation!.incoming" rows="4" class="code" @focus="enableTransformation"></textarea></label><label>Outgoing JSON<textarea v-model="selectedConnection.transformation!.outgoing" rows="4" class="code" @focus="enableTransformation"></textarea></label><label>Explanation<input v-model="selectedConnection.transformation!.note" placeholder="What changed?" @focus="enableTransformation" /></label></section><section v-if="latestSelectedRecord" class="transformation-view panel"><span class="eyebrow">LAST RECEIVED PAYLOAD</span><div class="json-columns"><div><b>Incoming</b><pre>{{ latestSelectedRecord.incoming }}</pre></div><div><b>Outgoing</b><pre>{{ latestSelectedRecord.outgoing }}</pre></div></div><div class="change-list"><span v-for="change in latestSelectedRecord.changes" :key="change.key" :class="`change-${change.status}`"><b>{{ change.status }}</b> {{ change.key }}: {{ change.incoming }} → {{ change.outgoing }}</span></div></section>
|
||
<section v-if="currentStep" class="guided-card panel"><span class="eyebrow">GUIDED STEP {{ stepIndex + 1 }}</span><strong>{{ currentStep.explanation }}</strong><p>{{ selectedScenario?.description }}</p></section><button class="presentation-toggle ghost" @click="presentationMode = !presentationMode">{{ presentationMode ? 'Exit presentation' : 'Presentation mode' }}</button>
|
||
<section v-if="selectedScenario" class="failure-config panel"><div><span class="eyebrow">STEP OUTCOMES</span><strong>Failure and recovery routing</strong><p class="muted">Choose how a simulated step behaves. Retry is limited to one automatic attempt per reset.</p></div><div v-for="(step, index) in selectedScenario.steps" :key="step.id" class="failure-row"><b>{{ index + 1 }}. {{ step.explanation }}</b><select v-model="step.outcome"><option value="success">Success</option><option value="rejected">Reject data</option><option value="timeout">Time out</option></select><select v-model="step.retryStepId"><option value="">No retry</option><option v-for="candidate in selectedScenario.steps" :key="candidate.id" :value="candidate.id" :disabled="candidate.id === step.id">Retry step {{ selectedScenario.steps.indexOf(candidate) + 1 }}</option></select><select v-model="step.recoveryStepId"><option value="">No recovery step</option><option v-for="candidate in selectedScenario.steps" :key="candidate.id" :value="candidate.id" :disabled="candidate.id === step.id">Recover at step {{ selectedScenario.steps.indexOf(candidate) + 1 }}</option></select></div></section>
|
||
<section v-if="selectedConnection" class="connection-properties panel"><span class="eyebrow">CONNECTION PROPERTIES</span><div class="property-grid"><label>Protocol<select v-model="selectedConnection.protocol"><option>HTTPS</option><option>HTTP</option><option>GraphQL</option><option>SMTP</option><option>Webhook</option><option>Message queue</option></select></label><label>Data type<select v-model="selectedConnection.dataType"><option>JSON</option><option>Form data</option><option>CSV</option><option>Event</option><option>Binary</option></select></label><label>Delivery<select v-model="selectedConnection.deliveryMethod"><option value="immediate">Immediate</option><option value="scheduled">Scheduled</option><option value="manual">Manual</option></select></label><label class="checkbox-label"><input v-model="selectedConnection.showCableLabel" type="checkbox" /> Show cable label</label></div></section>
|
||
<section v-if="selectedConnection" class="connection-routing panel"><span class="eyebrow">ENDPOINT ROUTING</span><div class="property-grid"><label>Source endpoint<select v-model="selectedConnection.sourceEndpointId"><option value="">System output / unspecified</option><option v-for="endpoint in (landscape.systems.find((item) => item.id === selectedConnection?.sourceId)?.definition?.endpoints || [])" :key="endpoint.id" :value="endpoint.id">{{ endpoint.name }}</option></select></label><label>Destination input port<select v-model="selectedConnection.targetPortId"><option value="">System input / unspecified</option><option v-for="port in (landscape.systems.find((item) => item.id === selectedConnection?.targetId)?.capabilities.flatMap((capability) => capability.inputs) || [])" :key="port.id" :value="port.id">{{ port.name }}</option></select></label></div><p class="compatibility-note">{{ connectionCompatibility(selectedConnection) }}</p></section>
|
||
<section class="navigation-panel panel"><div class="nav-fields"><label>Search systems<input v-model="searchQuery" placeholder="Name or description" /></label><label>Category<select v-model="categoryFilter"><option value="all">All categories</option><option value="application">Application</option><option value="service">Service</option><option value="data">Data</option><option value="external">External</option></select></label><label>Data type<select v-model="dataTypeFilter"><option value="all">All data types</option><option>JSON</option><option>Form data</option><option>CSV</option><option>Event</option><option>Binary</option></select></label><button class="ghost" @click="fitToScreen">Fit to screen</button></div><div class="minimap-wrap"><span class="eyebrow">MINIMAP</span><canvas ref="minimapEl" width="220" height="120"></canvas></div></section>
|
||
<section v-if="selectedScenario" class="scenario-builder panel"><div><span class="eyebrow">EASY SCENARIO BUILDER</span><strong>Start with an action, then build the journey</strong><p class="muted">Connections remain reusable destinations; parallel branches share one step.</p></div><label>Starting system<select v-model="selectedScenario.startSystemId"><option v-for="system in landscape.systems" :key="system.id" :value="system.id">{{ system.name }}</option></select></label><label>Starting action<select v-model="selectedScenario.startActionId"><option value="">Choose an action</option><option v-for="action in actionsForSystem(selectedScenario.startSystemId)" :key="action.id" :value="action.id">{{ action.capabilityName }} · {{ action.name }}</option></select></label><div class="builder-actions"><button class="ghost" @click="addJourneyStep">+ Sequential step</button><button class="ghost" @click="addParallelBranch">+ Parallel branch</button></div><div class="builder-steps"><article v-for="(step, index) in selectedScenario.steps" :key="step.id"><b>{{ index + 1 }}</b><span>{{ step.explanation }}</span><input v-model="step.payload" class="code" title="Editable sample payload" /></article></div></section>
|
||
<section class="demo-guide panel"><span class="eyebrow">MONDAY DEMO / START HERE</span><strong>Try a journey in three clicks</strong><ol><li>Open <b>Scenarios</b> and choose Contact enquiry, Sample request or Commercial order.</li><li>Press <b>▶</b> in the journey list, then use pause, next or speed controls.</li><li>Try <b>Order retry and recovery</b> to see a rejection, automatic retry and recovery message. Select a system to inspect its data history.</li></ol></section>
|
||
<section v-if="pendingDecision" class="decision-panel panel"><div><span class="eyebrow">HUMAN DECISION REQUIRED</span><strong>{{ systemName(pendingDecision.roleSystemId) }}</strong><p>{{ pendingDecision.task }}</p></div><div class="decision-data"><div><b>Information received</b><pre>{{ pendingDecision.receivedData }}</pre></div><div><b>Editable fields</b><label v-for="(_, key) in pendingDecision.editableFields" :key="key">{{ key }}<input v-model="pendingDecision.editableFields[key]" /></label></div></div><div class="decision-actions"><button v-for="action in pendingDecision.actions" :key="action.id" class="decision-button" :class="action.name.toLowerCase()" :title="action.description" @click="chooseHumanAction(action)"><b>{{ action.name }}</b><small>{{ action.description }}</small></button></div></section>
|
||
<div v-if="customBuilderOpen" class="modal-backdrop" @click.self="customBuilderOpen = false"><section class="custom-builder panel"><div class="inspector-header"><div><span class="eyebrow">CUSTOM SYSTEM BUILDER</span><h2>Reusable system definition</h2><p class="muted">Definitions are saved to the local preset library. Placed instances remain independent.</p></div><button class="danger-icon" @click="customBuilderOpen = false">×</button></div><div class="builder-meta"><label>Name<input v-model="customDraft.name" /></label><label>Category<select v-model="customDraft.category"><option value="application">Application</option><option value="service">Service</option><option value="data">Data</option><option value="human">Human / role</option><option value="external">External</option></select></label><label>Colour<input v-model="customDraft.color" type="color" /></label><label>Description<textarea v-model="customDraft.description" rows="2"></textarea></label></div><div class="builder-section"><div class="steps-head"><span>Actions</span><button class="icon-button" @click="addCustomAction">+</button></div><article v-for="action in customDraft.definition.actions" :key="action.id" class="definition-card"><div class="definition-grid"><label>Name<input v-model="action.name" /></label><label>Trigger<select v-model="action.trigger"><option value="button">Button</option><option value="incoming">Incoming request / event</option><option value="schedule">Simulated schedule</option></select></label></div><label>Description<input v-model="action.description" /></label><label>Example input JSON<textarea v-model="action.input" rows="2" class="code"></textarea></label><div class="steps-head"><span>Outputs</span><button class="icon-button" @click="addCustomOutput(action)">+</button></div><div v-for="output in action.outputs" :key="output.id" class="nested-row"><input v-model="output.name" placeholder="Output name" /><textarea v-model="output.payload" rows="2" class="code" placeholder="Example JSON"></textarea><input v-model="output.condition" placeholder="Outcome condition (optional)" /><label class="checkbox-label"><input v-model="output.parallel" type="checkbox" /> Parallel output</label></div></article></div><div class="builder-section"><div class="steps-head"><span>Endpoints</span><button class="icon-button" @click="addCustomEndpoint">+</button></div><article v-for="endpoint in customDraft.definition.endpoints" :key="endpoint.id" class="definition-card"><div class="definition-grid"><label>Name<input v-model="endpoint.name" /></label><label>Protocol<select v-model="endpoint.protocol"><option>HTTPS</option><option>HTTP</option><option>GraphQL</option><option>Webhook</option><option>Message queue</option></select></label><label>Method<input v-model="endpoint.method" /></label><label>Path<input v-model="endpoint.path" /></label></div><label>Example request JSON<textarea v-model="endpoint.request" rows="2" class="code"></textarea></label><label>Triggers action<select v-model="endpoint.triggersActionId"><option value="">No action</option><option v-for="action in customDraft.definition.actions" :key="action.id" :value="action.id">{{ action.name }}</option></select></label><div class="steps-head"><span>Responses</span><button class="icon-button" @click="addCustomResponse(endpoint)">+</button></div><div v-for="response in endpoint.responses" :key="response.id" class="nested-row response-row"><label>Status<input v-model.number="response.status" type="number" /></label><label>Delay ms<input v-model.number="response.delayMs" type="number" min="0" /></label><textarea v-model="response.body" rows="2" class="code" placeholder="Response body JSON"></textarea></div></article></div><div class="modal-actions"><button class="ghost" @click="customBuilderOpen = false">Cancel</button><button class="primary" @click="saveCustomBuilder">Save reusable preset</button></div></section></div>
|
||
<section v-if="activeTab === 'containers'" class="container-editor panel"><div class="section-heading"><span>Environment containers</span><button class="primary" @click="addContainer">Add container</button></div><div class="container-list"><button v-for="container in landscape.containers" :key="container.id" class="list-item" :class="{selected: selectedContainerId === container.id}" @click="selectContainer(container.id)"><span class="system-dot" :style="{background: container.color}"></span><span><strong>{{ container.name }}</strong><small>{{ container.collapsed ? 'Collapsed' : 'Expanded' }} · {{ landscape.systems.filter((system) => system.containerId === container.id).length }} systems</small></span></button></div><div v-if="selectedContainer" class="container-form"><label>Name<input v-model="selectedContainer.name" @change="rebuildGraph" /></label><label>Colour<input v-model="selectedContainer.color" type="color" @change="rebuildGraph" /></label><label>Parent<select v-model="selectedContainer.parentId" @change="rebuildGraph"><option value="">No parent</option><option v-for="parent in landscape.containers.filter((item) => item.id !== selectedContainer.id)" :key="parent.id" :value="parent.id">{{ parent.name }}</option></select></label><label>Position X<input v-model.number="selectedContainer.position[0]" type="number" @change="rebuildGraph" /></label><label>Position Y<input v-model.number="selectedContainer.position[1]" type="number" @change="rebuildGraph" /></label><label>Width<input v-model.number="selectedContainer.size[0]" type="number" min="180" @change="rebuildGraph" /></label><label>Height<input v-model.number="selectedContainer.size[1]" type="number" min="120" @change="rebuildGraph" /></label><label class="checkbox-label"><input v-model="selectedContainer.collapsed" type="checkbox" @change="rebuildGraph" /> Collapse to summary</label><div class="container-move"><button class="ghost" @click="moveContainer(selectedContainer, -20, 0)">← Move</button><button class="ghost" @click="moveContainer(selectedContainer, 20, 0)">Move →</button><button class="ghost" @click="moveContainer(selectedContainer, 0, -20)">↑ Move</button><button class="ghost" @click="moveContainer(selectedContainer, 0, 20)">↓ Move</button></div><button class="text-danger" @click="deleteContainer(selectedContainer.id)">Delete container</button></div></section>
|
||
<section class="tag-panel panel"><label>Filter by system tag<select v-model="tagFilter"><option value="all">All tags</option><option v-for="tag in allTags" :key="tag">{{ tag }}</option></select></label><label v-if="selectedSystem">Selected system tags<input :value="(selectedSystem.tags || []).join(', ')" @change="selectedSystem.tags = $event.target.value.split(',').map((tag) => tag.trim()).filter(Boolean); persist()" /></label></section>
|
||
</main>
|
||
</template>
|