clean from dirty code in network transport subsystem

This commit is contained in:
Bogdan Pilyugin 2023-08-20 15:29:54 +02:00
parent b89a78c0a4
commit 68d085bb67
11 changed files with 31 additions and 49 deletions

View File

@ -1,13 +1,17 @@
<template>
<q-card-actions>
<q-btn color="green" v-on:click="SendAndRequest(senddata, 1, 0, 'mykey', true)">Apply</q-btn>
<q-btn color="orange" v-on:click="SendAndRequest(senddata, 1, 1, 'mykey', true)">Save</q-btn>
<q-btn color="red" v-on:click="SendAndRequest(senddata, 1, 2, 'mykey', true)">Save & Reboot</q-btn>
<q-btn color="green"
v-on:click="PostData(senddata, 1, 0, ShowDelayDialog('Data applying...', 1000, null))">Apply</q-btn>
<q-btn color="orange"
v-on:click="PostData(senddata, 1, 1, ShowDelayDialog('Data saving...', 1000, null))">Save</q-btn>
<q-btn color="red"
v-on:click="PostData(senddata, 1, 2, ShowDelayDialog('Data saving and reboot...', 10000, null))">Save &
Reboot</q-btn>
</q-card-actions>
</template>
<script setup>
import { SendAndRequest } from "components/webguicomp/network";
//import { defineProps } from "vue";
import { PostData } from "components/webguicomp/network";
import { ShowDelayDialog } from "./helpers";
const props = defineProps(['senddata']);
</script>

View File

@ -24,7 +24,7 @@
</template>
<script setup>
import { reactive } from "vue";
import { SendAndRequest } from "components/webguicomp/network";
import { PostData } from "components/webguicomp/network";
import CardActions from "components/webguicomp/CardActions.vue"
defineOptions({
@ -37,5 +37,5 @@ const init = {
eth_gw: "", eth_dns1: "", eth_dns2: "", eth_dns3: "", eth_mac: ""
}
const data = reactive(init);
SendAndRequest(data, 2, 0, 'mykey', false);
PostData(data, 2, 0, null);
</script>

View File

@ -21,7 +21,7 @@
<script setup>
import { reactive } from "vue";
import { SendAndRequest } from "components/webguicomp/network";
import { PostData } from "components/webguicomp/network";
import CardActions from "components/webguicomp/CardActions.vue"
defineOptions({
@ -33,6 +33,6 @@ const init = {
}
const data = reactive(init);
SendAndRequest(data, 2, 0, 'mykey', false);
PostData(data, 2, 0, null);
</script>

View File

@ -16,7 +16,7 @@
<script setup>
import { computed, onUnmounted, reactive, onMounted } from "vue";
import { SendAndRequest } from "components/webguicomp//network";
import { PostData } from "components/webguicomp//network";
import { secondsToHms } from "components/webguicomp/helpers"
defineOptions({
@ -29,12 +29,12 @@ const init = {
}
const data = reactive(init);
SendAndRequest(data, 2, 0, 'mykey', false);
PostData(data, 2, 0, null);
let intervalId
onMounted(() => {
intervalId = setInterval(() => {
SendAndRequest(data, 2, 0, 'mykey', false);
PostData(data, 2, 0, null);
}, 1000)
})
onUnmounted(() => clearInterval(intervalId))

View File

@ -23,7 +23,7 @@
<script setup>
import { reactive } from "vue";
import { SendAndRequest } from "components/webguicomp//network";
import { PostData } from "components/webguicomp//network";
import CardActions from "components/webguicomp/CardActions.vue"
@ -39,5 +39,5 @@ const init = {
}
const data = reactive(init);
SendAndRequest(data, 2, 0, 'mykey', false);
PostData(data, 2, 0, null);
</script>

View File

@ -23,7 +23,7 @@
<script setup>
import { reactive } from "vue";
import { SendAndRequest } from "components/webguicomp//network";
import { PostData } from "components/webguicomp//network";
import CardActions from "components/webguicomp/CardActions.vue"
const init = {
@ -38,5 +38,5 @@ const init = {
}
const data = reactive(init);
SendAndRequest(data, 2, 0, 'mykey', false);
PostData(data, 2, 0, null);
</script>

View File

@ -19,7 +19,7 @@
<script setup>
import { reactive } from "vue";
import { SendAndRequest } from "components/webguicomp/network";
import { PostData } from "components/webguicomp/network";
import CardActions from "components/webguicomp/CardActions.vue"
@ -31,5 +31,5 @@ const init = {
}
const data = reactive(init);
SendAndRequest(data, 2, 0, 'mykey', false);
PostData(data, 2, 0, null);
</script>

View File

@ -30,7 +30,7 @@
<script setup>
import { computed, onUnmounted, reactive, onMounted } from "vue";
import { SendAndRequest } from "components/webguicomp/network";
import { PostData } from "components/webguicomp/network";
import { secondsToHms } from "components/webguicomp/helpers"
defineOptions({
@ -50,12 +50,12 @@ const init = {
free_ram_min: 0
}
const data = reactive(init);
SendAndRequest(data, 2, 0, 'mykey', false);
PostData(data, 2, 0, null);
let intervalId
onMounted(() => {
intervalId = setInterval(() => {
SendAndRequest(data, 2, 0, 'mykey', false);
PostData(data, 2, 0, null);
}, 1000)
})
onUnmounted(() => clearInterval(intervalId))

View File

@ -24,7 +24,7 @@
<script setup>
import { reactive } from "vue";
import { SendAndRequest } from "components/webguicomp/network"
import { PostData } from "components/webguicomp/network"
import CardActions from "components/webguicomp/CardActions.vue"
defineOptions({
@ -35,5 +35,5 @@ const init = {
model_name: "", hw_rev: 0, fw_rev: "", idf_rev: "", build_date: "", ser_num: ""
}
const data = reactive(init);
SendAndRequest(data, 2, 0, 'mykey', false);
PostData(data, 2, 0, null);
</script>

View File

@ -35,7 +35,7 @@
<script setup>
import { computed, reactive } from "vue";
import { SendAndRequest } from "components/webguicomp/network";
import { PostData } from "components/webguicomp/network";
import { useQuasar } from 'quasar'
import SelectWiFiDialog from 'components/webguicomp/SelectWiFiDialog.vue'
import CardActions from "components/webguicomp/CardActions.vue"
@ -74,7 +74,7 @@ function OpenScanDialog() {
});
};
SendAndRequest(data, 2, 0, 'mykey', false);
PostData(data, 2, 0, null);
</script>

View File

@ -1,27 +1,10 @@
import { api } from "boot/axios";
import { sha256 } from "js-sha256";
import { Notify, Dialog } from "quasar";
import { Notify } from "quasar";
const API_URL = "/api";
const SHA256_HMAC_KEY = "mykey";
function ShowSaveDialog(apltype) {
const opername = ['Data applying...', 'Data saving...', 'Data saving and reboot...'];
let step = (apltype == 2) ? 1 : 10;
let percentage = 0;
const dialog = Dialog.create({ message: opername[apltype], progress: true, persistent: true, ok: false })
const interval = setInterval(() => {
percentage = Math.min(100, percentage + step);
dialog.update({
message: `${opername[apltype]} ${percentage}%`
})
if (percentage === 100) {
clearInterval(interval);
setTimeout(() => { dialog.hide() }, 350)
}
}, 100)
}
function PostData(varlist, messtype, applytype, onfinished) {
var pld = {};
var data = {};
@ -50,12 +33,7 @@ function PostData(varlist, messtype, applytype, onfinished) {
}
function SendAndRequest(varlist, mstp, apltp, shakey, okreport) {
var onfinish = (okreport) ? () => { ShowSaveDialog(apltp) } : null;
PostData(varlist, mstp, apltp, onfinish);
}
export { SendAndRequest, PostData };
export { PostData };