diff --git a/src/components/Modal/components/device.vue b/src/components/Modal/components/device.vue index 8d17d08..e524d83 100644 --- a/src/components/Modal/components/device.vue +++ b/src/components/Modal/components/device.vue @@ -6,6 +6,7 @@ placeholder="Name" v-model="newDeviceForm.name" > +

Listen Port

+

Firewall Mark

import { Component, Vue } from 'vue-property-decorator' import { deviceApi } from '@/api/interface' +import {DeviceCreateOrUpdateRequest} from "wgrest/models/device-create-or-update-request"; +import {emitter} from "@/utils/emmiter"; @Component({ name: 'DeviceModal' }) export default class DeviceModal extends Vue { - private newDeviceForm = { - name: '', - listen_port: 0, - private_key: '', - firewall_mark: 0, - networks: '' + private newDeviceForm: DeviceCreateOrUpdateRequest = { + name: null, + listen_port: null, + private_key: null, + firewall_mark: null, + networks: null } public async createDevice(): Promise { - console.log(this.newDeviceForm) - const newDevice = { - ...this.newDeviceForm, - networks: this.newDeviceForm.networks.split(',') + const savedItem = JSON.parse(JSON.stringify(this.newDeviceForm)) + + Object.keys(savedItem).forEach(key => { + if (!savedItem[key]) { + delete savedItem[key] + } + }) + + if(Object.keys(savedItem).includes('networks')) { + savedItem.networks = savedItem.networks.split(',') } - console.log(newDevice) - await deviceApi.createDevice(newDevice) + await deviceApi.createDevice(savedItem) + + this.$emit('close') + + emitter.emit('updateDevice') + + this.$message({ + type: 'success', + message: 'New device create' + }) } } diff --git a/src/components/Modal/components/peer.vue b/src/components/Modal/components/peer.vue index affcca6..0626b58 100644 --- a/src/components/Modal/components/peer.vue +++ b/src/components/Modal/components/peer.vue @@ -75,6 +75,10 @@ export default class DeviceModal extends Vue { await deviceApi.createDevicePeer(this.$route.params.id, newPeer) this.$emit('close') emitter.emit('updatePeer') + this.$message({ + type: 'success', + message: 'New peer create' + }) } } diff --git a/src/styles/index.scss b/src/styles/index.scss index 96329df..6c3bc0e 100644 --- a/src/styles/index.scss +++ b/src/styles/index.scss @@ -65,3 +65,9 @@ div:focus { width: 100% !important; } } + +.el-message-box { + @media (max-width: 850px) { + width: 100%; + } +} diff --git a/src/views/dashboard/peerItem.vue b/src/views/dashboard/peerItem.vue index a5ce517..eca5436 100644 --- a/src/views/dashboard/peerItem.vue +++ b/src/views/dashboard/peerItem.vue @@ -126,9 +126,14 @@ export default class peerItem extends Vue { } private async savePeer(): Promise { + const savedItem = JSON.parse(JSON.stringify(this.editedPeer)) + if (!savedItem.private_key) { + delete savedItem.private_key + } + await deviceApi.updateDevicePeer(this.$route.params.id, this.item.url_safe_public_key, { - ...this.editedPeer, - allowed_ips: peerItem.prepareAllowedIps(this.editedPeer.allowed_ips) + ...savedItem, + allowed_ips: peerItem.prepareAllowedIps(savedItem.allowed_ips) }) this.$message({