Skip to content

Commit c186128

Browse files
committed
wip #92
1 parent 0b73c08 commit c186128

File tree

3 files changed

+67
-25
lines changed

3 files changed

+67
-25
lines changed

src/common/wifi_connect.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ class WifiConnect {
99
}
1010

1111
connect(ssid, conn_type, username, password) {
12-
return this.$axios.post(`${this.CB}/connect`, {
12+
let data = {
1313
ssid: ssid,
1414
conn_type: conn_type,
1515
username: username,
1616
password: password,
17-
});
17+
};
18+
return this.$axios.post(`${this.CB}/connect`, data);
1819
}
1920

2021
disconnect() {
@@ -35,7 +36,7 @@ class WifiConnect {
3536
});
3637
}
3738

38-
connection_status() {
39+
status() {
3940
return this.$axios.get(`${this.CB}/connection_status`);
4041
}
4142
}

src/components/Settings.vue

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -376,18 +376,23 @@
376376
<v-card-title>
377377
<h3 class="text-xs-left">{{ $t('message.settings_network_title') }}</h3>
378378
</v-card-title>
379+
<div>
380+
<v-chip v-if="wifi_status.wifi" prepend-icon="mdi-wifi">Wifi</v-chip>
381+
<v-chip v-if="wifi_status.internet" prepend-icon="mdi-web">Internet</v-chip>
382+
</div>
379383
<div class="cardContent">
380384
<v-radio-group v-model="settings.wifiMode" column
381385
@change="v$.settings.wifiMode.$touch"
382386
>
387+
<v-radio v-bind:label="$t('message.settings_network_mode_ap')" value="ap"></v-radio>
383388
<v-radio v-bind:label="$t('message.settings_network_mode_client')" value="client"></v-radio>
384-
<v-radio v-bind:label="$t('message.settings_network_mode_ap')" value="ap">
385-
</v-radio>
389+
386390
</v-radio-group>
387391
<div v-if="settings.wifiMode=='client'">
388392
<v-select
389393
:disabled="settings.wifiMode!='client'"
390394
v-model="settings.wifiSSID"
395+
@change="v$.settings.wifiSSID.$touch"
391396
:items="networks"
392397
item-title="ssid"
393398
item-value="ssid"
@@ -396,18 +401,19 @@
396401
>
397402
</v-select>
398403
<v-text-field
399-
v-if="network_require_user()"
404+
v-if="network_require_user"
400405
:disabled="settings.wifiMode!='client'"
401406
v-model="settings.wifiUser"
402-
:type="text"
403-
v-bind:label="$t('message.settings_network_user')"></v-text-field>
407+
@change="v$.settings.wifiUser.$touch"
408+
v-bind:label="$t('message.settings_network_username')"></v-text-field>
404409
<v-text-field
405410
:disabled="settings.wifiMode!='client'"
406411
v-model="settings.wifiPsw"
412+
@change="v$.settings.wifiPsw.$touch"
407413
:append-icon="wifi_pwd_show ? 'mdi-eye' : 'mdi-eye-off'"
408414
:type="wifi_pwd_show ? 'text' : 'password'"
409415
@click:append="wifi_pwd_show = !wifi_pwd_show"
410-
v-bind:label="$t('message.settings_network_password')"></v-text-field>
416+
v-bind:label="$t('message.settings_network_password')"></v-text-field>
411417
</div>
412418
<!--v-card-actions>
413419
<v-btn color="primary" @click.stop="dialog = true" block>Salva</v-btn>
@@ -432,6 +438,22 @@
432438
</v-dialog>
433439
</v-card-actions-->
434440
</div>
441+
<template>
442+
<div class="text-center">
443+
<v-dialog
444+
v-model="wifi_overlay"
445+
persistent
446+
>
447+
<v-card>
448+
<v-card-text>
449+
<div class="text-center">
450+
{{ $t('message.settings_network_wait') }}
451+
</div>
452+
</v-card-text>
453+
</v-card>
454+
</v-dialog>
455+
</div>
456+
</template>
435457
</v-card>
436458
</v-col>
437459
</v-layout>
@@ -760,7 +782,7 @@ export default {
760782
this.cb.status = this.$store.getters.status;
761783
this.adminPassword_dialog = this.settings.adminPassword != null && this.settings.adminPassword != '';
762784
this.$wifi_connect.networks().then((result) => {
763-
this.networks = result.data;
785+
this.networks = result.data.ssids;
764786
});
765787
},
766788
beforeRouteLeave(to, from, next) {
@@ -773,8 +795,8 @@ export default {
773795
},
774796
computed: {
775797
network_require_user() {
776-
const network = this.networks.find(item => { return item.ssid==this.v$.settings.wifiSSID });
777-
return network.conn_type == "ENTERPRISE";
798+
const network = this.networks.find(item => { return item.ssid==this.settings.wifiSSID });
799+
return network && network.conn_type == "ENTERPRISE";
778800
}
779801
},
780802
methods: {
@@ -914,6 +936,9 @@ export default {
914936
}
915937
this.status = 0;
916938
});
939+
this.$wifi_connect.status().then((result) => {
940+
this.wifi_status = result.data;
941+
});
917942
},
918943
deletePkg(pkgNameID) {
919944
this.$coderbot.deleteMusicPackage(pkgNameID).then(() => {
@@ -949,21 +974,31 @@ export default {
949974
});
950975
if (this.v$.settings.wifiMode.$dirty || this.v$.settings.wifiSSID.$dirty || this.v$.settings.wifiPsw.$dirty) {
951976
if(this.settings.wifiMode=="client") {
952-
const network = this.networks.find(item => { return item.ssid==this.v$.settings.wifiSSID });
953-
this.$wifi_connect.connect(network.ssid, network.conn_type, this.settings.wifiUser, this.settings.wifiPsw)
954-
.then(() => {
955-
console.log('connect Sent');
956-
this.snackText = this.$i18n.t('message.settings_network_updated');
957-
this.snackbar = true;
958-
});
959-
} else {
960-
this.$wifi_connect.disconnect()
961-
.then(() => {
962-
console.log('disconnect Sent');
963-
this.snackText = this.$i18n.t('message.settings_network_updated');
964-
this.snackbar = true;
977+
const network = this.networks.find(item => { return item.ssid==this.settings.wifiSSID });
978+
if(network != null) {
979+
this.wifi_overlay = true;
980+
this.$wifi_connect.disconnect().then((result) => {
981+
setTimeout(() => {
982+
this.$wifi_connect.connect(network.ssid, network.conn_type, this.settings.wifiUser, this.settings.wifiPsw)
983+
.then((result) => {
984+
this.snackText = this.$i18n.t('message.settings_network_updated');
985+
this.snackbar = true;
986+
this.wifi_overlay = false;
987+
})
988+
.catch((error) => {
989+
console.error(error);
990+
this.wifi_overlay = false;
991+
});
992+
}, 10000);
993+
})
994+
.catch((error) => {
995+
console.error(error);
996+
this.wifi_overlay = false;
965997
});
998+
}
966999
}
1000+
} else {
1001+
this.$wifi_connect.disconnect().then((result) => {});
9671002
}
9681003
}
9691004
},
@@ -1095,7 +1130,9 @@ export default {
10951130
this.$i18n.t('message.settings_tabs_music_packages')
10961131
],
10971132
networks: [],
1133+
wifi_status: null,
10981134
wifi_pwd_show: false,
1135+
wifi_overlay: false,
10991136
};
11001137
},
11011138
validations() {
@@ -1156,6 +1193,8 @@ export default {
11561193
wifiSSID: {
11571194
required,
11581195
},
1196+
wifiUser: {
1197+
},
11591198
wifiPsw: {
11601199
required,
11611200
},

src/i18n/locales/it/messages.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,11 @@
201201
"settings_network_mode_client": "Connetti ad una rete WiFi già esistente (client)",
202202
"settings_network_mode_ap": "Lascia che CoderBot configuri la propria rete WiFi locale (ad-hoc)",
203203
"settings_network_ssid": "Nome rete WiFi (SSID)",
204+
"settings_network_username": "Nome utente",
204205
"settings_network_password": "Password rete WiFi",
205206
"settings_network_save_title": "Attenzione!",
206207
"settings_network_save_text_1": "Questa operazione cambierà la configurazione di CoderBot che sarà poi riavviato.",
208+
"settings_network_wait": "Prego attendere la connessione.",
207209
"settings_component_test_title": "Test componenti",
208210
"settings_component_test_passed": "Passato",
209211
"settings_component_test_failed": "Fallito",

0 commit comments

Comments
 (0)