Fix node creation: proper angle routing, axios refresh, thema form

Root causes fixed:
1. branchAngle routing only matched 0° — now uses isExtendAngle()
   for all extend angles (0/180/45/315), vertical (90/270) = fork
2. handleForkBranch did nothing at dim 1 — now opens thema form
3. After form submit, Inertia reloaded entire page losing canvas
   dimension state — now uses axios + refreshMapData() via API
4. Custom metro node form used dead Inertia useForm refs

Changes:
- All creation flows now use axios POST + refreshMapData() which
  fetches /api/map/strategy or /api/map/project/{id} without page
  reload, preserving the canvas dimension and zoom state
- New thema creation modal (for ↑↓ fork at dim 1)
- Track creation modal updated to use axios (for ↑↓ fork in dim 2)
- Metro node creation modal updated to use axios
- CommitmentForm @close now triggers refreshMapData()
- CommitmentForm eigenaar_id now has required validation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
znetsixe
2026-04-08 17:50:55 +02:00
parent e4f040657f
commit 8dc6e65e28

View File

@@ -1,6 +1,7 @@
<script setup>
import { ref, computed } from 'vue'
import { usePage, router, useForm } from '@inertiajs/vue3'
import axios from 'axios'
import MetroCanvas from '@/Components/MetroMap/MetroCanvas.vue'
import Breadcrumb from '@/Components/MetroMap/Breadcrumb.vue'
import NodePreview from '@/Components/MetroMap/NodePreview.vue'
@@ -88,13 +89,29 @@ const handleDimensionChange = (event) => {
selectedNode.value = null
}
// --- Refresh map data without full page reload ---
const refreshMapData = async () => {
try {
const url = currentProjectId.value
? `/api/map/project/${currentProjectId.value}`
: '/api/map/strategy'
const { data } = await axios.get(url)
// Update the reactive props — Inertia page props are mutable
Object.assign(props.mapData, data)
} catch (e) {
// Fallback: full page reload
router.reload()
}
}
// --- Branch handle node creation ---
const isExtendAngle = (angle) => [0, 180, 45, 315].includes(angle)
const handleCreateNode = (event) => {
if (event.branchAngle === 0) {
// Extend existing line — determine entity type from lineId
if (isExtendAngle(event.branchAngle)) {
handleExtendLine(event)
} else {
// Fork — create a new track + first node
// Vertical (90°, 270°) = new track
handleForkBranch(event)
}
}
@@ -105,101 +122,124 @@ const handleExtendLine = (event) => {
// In dim 2 (project level): determine what type of entity to create
if (event.depth > 1 && event.parentEntityType === 'project') {
if (lineId.startsWith('lifecycle-') || lineId === 'lifecycle') {
// Can't manually add lifecycle phases — they advance via transition
return
return // Lifecycle phases advance via transition, not manual creation
}
if (lineId.startsWith('commitments-') || lineId === 'commitments') {
pendingCreatePosition.value = { x: event.x, y: event.y }
pendingCreateEvent.value = event
showCommitmentForm.value = true
return
}
if (lineId.startsWith('documents-') || lineId === 'documents') {
// Future: document upload
console.log('Document creation at', event.x, event.y)
pendingCreateEvent.value = event
showMetroNodeForm.value = true
return
}
// Custom line — create a metro node
createMetroNode(event)
// Custom line
pendingCreateEvent.value = event
showMetroNodeForm.value = true
return
}
// In dim 1 (strategy level): extend = add project to theme
// In dim 1 (strategy level): extend = add project
editingProject.value = null
showProjectForm.value = true
}
const handleForkBranch = (event) => {
// Fork creates a new track (metro line), then the first node on it
if (event.parentEntityType === 'project' && event.parentEntityId) {
pendingForkEvent.value = event
if (event.depth > 1 && event.parentEntityType === 'project' && event.parentEntityId) {
// Inside a project → create new metro line
pendingCreateEvent.value = event
showTrackForm.value = true
} else {
// At dim 1 → create new thema (= new metro line at root)
pendingCreateEvent.value = event
showThemaForm.value = true
}
}
const pendingCreatePosition = ref(null)
const pendingForkEvent = ref(null)
const pendingCreateEvent = ref(null)
// --- Track creation form (for fork branches) ---
// --- Track creation form (for fork branches in dim 2) ---
const showTrackForm = ref(false)
const trackForm = useForm({
project_id: null,
naam: '',
})
const trackFormData = ref({ naam: '' })
const trackFormProcessing = ref(false)
const submitTrackForm = () => {
trackForm.project_id = currentProjectId.value
trackForm.post('/metro-lines', {
onSuccess: () => {
showTrackForm.value = false
trackForm.reset()
pendingForkEvent.value = null
},
})
const submitTrackForm = async () => {
trackFormProcessing.value = true
try {
await axios.post('/metro-lines', {
project_id: currentProjectId.value,
naam: trackFormData.value.naam,
})
showTrackForm.value = false
trackFormData.value.naam = ''
pendingCreateEvent.value = null
await refreshMapData()
} catch (e) {
console.error('Track creation failed:', e.response?.data || e.message)
} finally {
trackFormProcessing.value = false
}
}
// --- Metro node creation form (for custom line extend) ---
// --- Thema creation form (for fork branches at dim 1) ---
const showThemaForm = ref(false)
const themaFormData = ref({ naam: '', beschrijving: '' })
const themaFormProcessing = ref(false)
const submitThemaForm = async () => {
themaFormProcessing.value = true
try {
await axios.post('/themas', {
naam: themaFormData.value.naam,
beschrijving: themaFormData.value.beschrijving,
})
showThemaForm.value = false
themaFormData.value = { naam: '', beschrijving: '' }
pendingCreateEvent.value = null
await refreshMapData()
} catch (e) {
console.error('Thema creation failed:', e.response?.data || e.message)
} finally {
themaFormProcessing.value = false
}
}
// --- Metro node / generic item creation form ---
const showMetroNodeForm = ref(false)
const pendingMetroNodeEvent = ref(null)
const metroNodeForm = useForm({
metro_line_id: '',
naam: '',
beschrijving: '',
x: 0,
y: 0,
})
const nodeFormData = ref({ naam: '', beschrijving: '' })
const nodeFormProcessing = ref(false)
const createMetroNode = (event) => {
pendingMetroNodeEvent.value = event
// Extract metro_line_id from lineId (format: "custom-{id}" or similar)
metroNodeForm.x = event.x
metroNodeForm.y = event.y
metroNodeForm.naam = ''
metroNodeForm.beschrijving = ''
showMetroNodeForm.value = true
}
const submitMetroNodeForm = async () => {
const event = pendingCreateEvent.value
if (!event) return
const submitMetroNodeForm = () => {
const event = pendingMetroNodeEvent.value
// The lineId from the canvas might be something like "custom-5" — extract the DB id
// For now, try to find the metro_line by matching
const lineId = event?.lineId ?? ''
const match = lineId.match(/\d+$/)
metroNodeForm.metro_line_id = match ? match[0] : ''
nodeFormProcessing.value = true
try {
const lineId = event.lineId ?? ''
const match = lineId.match(/\d+$/)
metroNodeForm.post('/metro-nodes', {
onSuccess: () => {
showMetroNodeForm.value = false
metroNodeForm.reset()
pendingMetroNodeEvent.value = null
},
})
await axios.post('/metro-nodes', {
metro_line_id: match ? parseInt(match[0]) : null,
naam: nodeFormData.value.naam,
beschrijving: nodeFormData.value.beschrijving,
x: event.x,
y: event.y,
})
showMetroNodeForm.value = false
nodeFormData.value = { naam: '', beschrijving: '' }
pendingCreateEvent.value = null
await refreshMapData()
} catch (e) {
console.error('Node creation failed:', e.response?.data || e.message)
} finally {
nodeFormProcessing.value = false
}
}
// --- FAB handlers ---
const handleCreateTheme = () => {
// Future: thema creation form
editingProject.value = null
showProjectForm.value = true
showThemaForm.value = true
}
const handleCreateTrack = () => {
@@ -293,10 +333,10 @@ const editingProject = ref(null)
:show="showCommitmentForm"
:project-id="currentProjectId"
:users="users"
@close="showCommitmentForm = false; pendingCreatePosition = null"
@close="showCommitmentForm = false; pendingCreateEvent = null; refreshMapData()"
/>
<!-- Track creation modal (for fork branches and FAB) -->
<!-- Track creation modal (fork in dim 2) -->
<Teleport to="body">
<Transition name="modal-fade">
<div v-if="showTrackForm" class="modal-backdrop" @click="showTrackForm = false">
@@ -305,19 +345,13 @@ const editingProject = ref(null)
<form @submit.prevent="submitTrackForm">
<div class="form-group">
<label class="form-label">Naam</label>
<input
v-model="trackForm.naam"
type="text"
class="form-input"
placeholder="bijv. Risico's, Acties..."
required
autofocus
/>
<input v-model="trackFormData.naam" type="text" class="form-input"
placeholder="bijv. Risico's, Acties..." required autofocus />
</div>
<div class="form-actions">
<button type="button" class="btn-cancel" @click="showTrackForm = false">Annuleren</button>
<button type="submit" class="btn-submit" :disabled="trackForm.processing">
{{ trackForm.processing ? 'Bezig...' : 'Aanmaken' }}
<button type="submit" class="btn-submit" :disabled="trackFormProcessing">
{{ trackFormProcessing ? 'Bezig...' : 'Aanmaken' }}
</button>
</div>
</form>
@@ -326,7 +360,36 @@ const editingProject = ref(null)
</Transition>
</Teleport>
<!-- Metro node creation modal (for custom line extend) -->
<!-- Thema creation modal (fork at dim 1) -->
<Teleport to="body">
<Transition name="modal-fade">
<div v-if="showThemaForm" class="modal-backdrop" @click="showThemaForm = false">
<div class="modal-content" @click.stop>
<div class="modal-header">NIEUW THEMA</div>
<form @submit.prevent="submitThemaForm">
<div class="form-group">
<label class="form-label">Naam</label>
<input v-model="themaFormData.naam" type="text" class="form-input"
placeholder="Naam van het thema..." required autofocus />
</div>
<div class="form-group">
<label class="form-label">Beschrijving</label>
<textarea v-model="themaFormData.beschrijving" class="form-input form-textarea"
placeholder="Omschrijving..." rows="3"></textarea>
</div>
<div class="form-actions">
<button type="button" class="btn-cancel" @click="showThemaForm = false">Annuleren</button>
<button type="submit" class="btn-submit" :disabled="themaFormProcessing">
{{ themaFormProcessing ? 'Bezig...' : 'Aanmaken' }}
</button>
</div>
</form>
</div>
</div>
</Transition>
</Teleport>
<!-- Metro node creation modal (extend on custom/document lines) -->
<Teleport to="body">
<Transition name="modal-fade">
<div v-if="showMetroNodeForm" class="modal-backdrop" @click="showMetroNodeForm = false">
@@ -335,28 +398,18 @@ const editingProject = ref(null)
<form @submit.prevent="submitMetroNodeForm">
<div class="form-group">
<label class="form-label">Naam</label>
<input
v-model="metroNodeForm.naam"
type="text"
class="form-input"
placeholder="Naam van het punt..."
required
autofocus
/>
<input v-model="nodeFormData.naam" type="text" class="form-input"
placeholder="Naam..." required autofocus />
</div>
<div class="form-group">
<label class="form-label">Beschrijving</label>
<textarea
v-model="metroNodeForm.beschrijving"
class="form-input form-textarea"
placeholder="Optionele beschrijving..."
rows="3"
></textarea>
<textarea v-model="nodeFormData.beschrijving" class="form-input form-textarea"
placeholder="Optioneel..." rows="3"></textarea>
</div>
<div class="form-actions">
<button type="button" class="btn-cancel" @click="showMetroNodeForm = false">Annuleren</button>
<button type="submit" class="btn-submit" :disabled="metroNodeForm.processing">
{{ metroNodeForm.processing ? 'Bezig...' : 'Aanmaken' }}
<button type="submit" class="btn-submit" :disabled="nodeFormProcessing">
{{ nodeFormProcessing ? 'Bezig...' : 'Aanmaken' }}
</button>
</div>
</form>