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'}, ], 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: { 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=create`, { ...this.addModalData, parent_network_id: this.currentNetworkData ? this.currentNetworkData.id : null }); if (response.data.status === 'success') { this.addModal = false; window.notify('success', 'Network space created successfully'); await this.$refs.table.fetchData(); } else { window.notify('error', response.data.message); } }, }, })