Vue.component('IpNetwork', { //language=Vue template: ` `, data() { return { window: window, apiUrl: window['TT_CONFIG']['IPNETWORK_API_URL'], IpNetworkTableConfig: { defaultPageSize: 50, customRowClass: function (row) { return row.cidr !== '32' ? 'tt-pointer' : ''; }, expandCondition: function (row) { return !!row.description; }, headers: [ {text: 'Network Address', key: 'network_address_str'}, {text: 'Name', key: 'name'}, { text: 'Status', key: 'status', filter: 'iconSelect', filterOptions: [{value: 'active', text: 'Active', icon: 'fas fa-check text-success'}, {value: 'inactive', text: 'Inactive', icon: 'fas fa-times text-danger'}, {value: 'reserved', text: 'Reserved', icon: 'fas fa-lock text-warning'}] }, {text: 'Children', key: 'children', filter: 'numberRange'}, {text: 'Aktionen', key: 'actions', sortable: false}, ], tableHeader: 'IPAM', key: 'IpNetwork' }, currentNetworkData: null, addModal: false, addModalData: { network_address: '', cidr: '', parent_network_id: '', status: 'active', name: '', description: '', location: '', }, } }, async mounted() { function popstateFunction() { const parentNetworkId = new URLSearchParams(window.location.search).get('parent_network_id'); this.switchCurrentNetwork(parentNetworkId).then(); } window.onpopstate = popstateFunction.bind(this); window.onpopstate.call(this) }, methods: { openModal(row = false) { if (row) { const data = JSON.parse(JSON.stringify(row)); this.addModalData = { id: data.id, network_address: data.network_address_str.split('/')[0], cidr: data.cidr, parent_network_id: this.currentNetworkData ? this.currentNetworkData.id : '', status: data.status, name: data.name, description: data.description, location: data.location, } } else { this.addModalData = { network_address: '', cidr: '', parent_network_id: this.currentNetworkData ? this.currentNetworkData.id : '', status: 'active', name: '', description: '', location: '', }; } this.addModal = true; }, async switchCurrentNetwork(networkId = null) { if (!networkId) { this.$refs.table.$set(this.$refs.table.filters, 'parent_network_id', undefined); this.currentNetworkData = null; this.IpNetworkTableConfig.tableHeader = 'IPAM'; this.$refs.table.disableDebounce = true; window.history.pushState({}, '', `?`); } else { this.$refs.table.disableDebounce = true; this.$refs.table.$set(this.$refs.table.filters, 'parent_network_id', networkId); window.history.pushState({}, '', `?parent_network_id=${networkId}`); const response = await axios.post(`${this.apiUrl}?do=getById`, {id: networkId}); this.currentNetworkData = response.data.network; this.IpNetworkTableConfig.tableHeader = `IPAM - ${this.currentNetworkData.network_address_str}/${this.currentNetworkData.cidr} - ${this.currentNetworkData.name}`; } await this.$refs.table.fetchData(); }, async addSubmit() { const response = await axios.post(`${this.apiUrl}?do=${this.addModalData.id ? 'update' : 'create'}`, { ...this.addModalData, parent_network_id: this.currentNetworkData ? this.currentNetworkData.id : null }); if (response.data.status === 'success') { this.addModal = false; this.addModalData = {}; window.notify('success', 'Network space created successfully'); await this.$refs.table.fetchData(); } else { window.notify('error', response.data.message); } }, async deleteSubmit() { const response = await axios.post(`${this.apiUrl}?do=delete`, {id: this.addModalData.id}); if (response.data.status === 'success') { this.addModal = false; this.addModalData = {}; window.notify('success', 'Network space deleted successfully'); await this.$refs.table.fetchData(); } else { window.notify('error', response.data.message); } } }, })