2019-02-18 09:18:32 +00:00
|
|
|
<template>
|
2019-03-01 13:29:00 +00:00
|
|
|
<NetworkForm
|
2019-10-28 13:48:13 +00:00
|
|
|
v-if="networkData"
|
2019-03-01 13:29:00 +00:00
|
|
|
:handle-submit="handleSubmit"
|
2019-10-28 13:48:13 +00:00
|
|
|
:defaults="networkData"
|
2019-03-01 13:29:00 +00:00
|
|
|
:disabled="disabled"
|
|
|
|
/>
|
2019-02-18 09:18:32 +00:00
|
|
|
</template>
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import {defineComponent, onMounted, ref, watch} from "vue";
|
|
|
|
import {useRoute} from "vue-router";
|
|
|
|
import {switchToChannel} from "../../js/router";
|
2019-11-16 17:24:03 +00:00
|
|
|
import socket from "../../js/socket";
|
2022-06-19 00:25:21 +00:00
|
|
|
import {useStore} from "../../js/store";
|
|
|
|
import NetworkForm, {NetworkFormDefaults} from "../NetworkForm.vue";
|
2019-02-18 09:18:32 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
export default defineComponent({
|
2019-02-18 09:18:32 +00:00
|
|
|
name: "NetworkEdit",
|
|
|
|
components: {
|
2019-03-01 13:29:00 +00:00
|
|
|
NetworkForm,
|
2019-02-18 09:18:32 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
setup() {
|
|
|
|
const route = useRoute();
|
|
|
|
const store = useStore();
|
|
|
|
|
|
|
|
const disabled = ref(false);
|
|
|
|
const networkData = ref<NetworkFormDefaults | null>(null);
|
|
|
|
|
|
|
|
const setNetworkData = () => {
|
|
|
|
socket.emit("network:get", String(route.params.uuid || ""));
|
|
|
|
networkData.value = store.getters.findNetwork(String(route.params.uuid || ""));
|
2019-02-18 09:18:32 +00:00
|
|
|
};
|
2022-06-19 00:25:21 +00:00
|
|
|
|
|
|
|
const handleSubmit = (data: {uuid: string; name: string}) => {
|
|
|
|
disabled.value = true;
|
2019-03-01 13:29:00 +00:00
|
|
|
socket.emit("network:edit", data);
|
2019-02-18 09:18:32 +00:00
|
|
|
|
2019-03-01 13:29:00 +00:00
|
|
|
// TODO: move networks to vuex and update state when the network info comes in
|
2022-06-19 00:25:21 +00:00
|
|
|
const network = store.getters.findNetwork(data.uuid);
|
2019-11-07 09:29:04 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
if (network) {
|
|
|
|
network.name = network.channels[0].name = data.name;
|
|
|
|
|
|
|
|
switchToChannel(network.channels[0]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
watch(
|
|
|
|
() => route.params.uuid,
|
|
|
|
(newValue) => {
|
|
|
|
setNetworkData();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
setNetworkData();
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
disabled,
|
|
|
|
networkData,
|
|
|
|
handleSubmit,
|
|
|
|
};
|
2019-02-18 09:18:32 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
});
|
2019-02-18 09:18:32 +00:00
|
|
|
</script>
|