feat: cascade-delete hosts when removing a network
When a VLAN/LAN is deleted, all non-gateway, non-livebox devices with an interface in that network are deleted automatically. Gateway and livebox devices are preserved; their interface is unlinked (vlan_id set to NULL). The confirmation dialog now shows the exact count of devices that will be deleted (all three locales: fr/en/es). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -90,7 +90,7 @@ import { ref, reactive } from 'vue'
|
||||
import { vlansApi } from '../api.js'
|
||||
import { t, tFmt } from '../i18n.js'
|
||||
|
||||
const props = defineProps({ vlans: Array })
|
||||
const props = defineProps({ vlans: Array, devices: { type: Array, default: () => [] } })
|
||||
const emit = defineEmits(['refresh'])
|
||||
|
||||
const showForm = ref(false)
|
||||
@@ -145,9 +145,18 @@ async function save() {
|
||||
}
|
||||
}
|
||||
|
||||
function _affectedCount(vlan) {
|
||||
return props.devices.filter(
|
||||
d => !d.is_gateway && !d.is_livebox && d.interfaces.some(i => i.vlan_id === vlan.id)
|
||||
).length
|
||||
}
|
||||
|
||||
async function remove(vlan) {
|
||||
const label = vlan.vlan_id != null ? `VLAN ${vlan.vlan_id} — ${vlan.name}` : `LAN ${vlan.name}`
|
||||
if (!confirm(`Supprimer ${tFmt('confirmDeleteNetwork', label)}`)) return
|
||||
const count = _affectedCount(vlan)
|
||||
let msg = `Supprimer ${tFmt('confirmDeleteNetwork', label)}`
|
||||
if (count > 0) msg += '\n' + tFmt('confirmDeleteNetworkHosts', count)
|
||||
if (!confirm(msg)) return
|
||||
try {
|
||||
await vlansApi.remove(vlan.id)
|
||||
emit('refresh')
|
||||
|
||||
Reference in New Issue
Block a user