Skip to content

Commit 5eefc97

Browse files
committed
fix add music packaged, onboard tests
1 parent 6454bef commit 5eefc97

File tree

2 files changed

+93
-192
lines changed

2 files changed

+93
-192
lines changed

src/common/coderbot.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ class CoderBot {
129129
this.$store.commit('setMusicAnimals', musicAnimals);
130130
}
131131

132+
async uploadMusicPackage(formdata) {
133+
const config = {
134+
headers: {
135+
'Content-Type': 'multipart/form-data'
136+
},
137+
};
138+
return await this.$axios.post(`${this.CB}/music/packages`, formdata, config);
139+
}
140+
132141
async loadCNNModels() {
133142
const result = await this.$axios.get(`${this.CB}/cnnmodels`);
134143
const cnnModels = [];
@@ -288,9 +297,7 @@ class CoderBot {
288297
}
289298

290299
deleteMusicPackage(pkgNameID) {
291-
return this.$axios.post(`${this.CB}/deleteMusicPackage`, {
292-
package_name: pkgNameID,
293-
});
300+
return this.$axios.delete(`${this.CB}/music/packages/${pkgNameID}`);
294301
}
295302

296303
restoreSettings() {
@@ -302,8 +309,9 @@ class CoderBot {
302309
}
303310

304311
test(checkedTests) {
305-
return this.$axios.post(`${this.CB}/testCoderbot`, {
306-
params: checkedTests
312+
console.log(checkedTests);
313+
return this.$axios.post(`${this.CB}/system/test`, {
314+
tests: checkedTests
307315
});
308316
}
309317

src/components/Settings.vue

Lines changed: 80 additions & 187 deletions
Original file line numberDiff line numberDiff line change
@@ -628,148 +628,31 @@
628628
<v-row row wrap align-center>
629629
<v-col >
630630
<v-card>
631-
<v-card-title>
632-
{{ $t('message.settings_component_test_title') }}
633-
</v-card-title>
631+
<v-card-title>
632+
{{ $t('message.settings_component_test_title') }}
633+
</v-card-title>
634634
<v-card-text>
635-
<div id='test_array'>
636-
<!-- SONAR -->
637-
<v-row row wrap justify-center>
638-
<!-- switch -->
639-
<v-col xs12 offset-md2 md5>
640-
<v-switch v-bind:label="$t('message.settings_component_test_sonar')" value="sonar" v-model="checkedTests" color="orange"></v-switch>
641-
</v-col>
642-
<!-- button state -->
643-
<v-col xs12 md4>
644-
<span v-if="cb.logs != null && cb.logs.test != null && cb.logs.test.sonar != 0">
645-
<!-- passed -->
646-
<span v-if="cb.logs.test.sonar == 1">
647-
<v-btn @click="runTests" slot="activator" color="green" dark>
648-
<v-icon icon="mdi-check"></v-icon> {{ $t('message.settings_component_test_passed') }}
649-
</v-btn>
650-
</span>
651-
<!-- failed -->
652-
<span v-else>
653-
<v-btn @click="runTests" slot="activator" color="red" dark>
654-
<v-icon icon="mdi-exclamation"></v-icon> {{ $t('message.settings_component_test_failed') }}
655-
</v-btn>
656-
</span>
657-
</span>
658-
<!-- not tested -->
659-
<span v-else>
660-
<v-btn @click="runTests" slot="activator" color="grey" dark>
661-
<v-icon icon="mdi-help"></v-icon> {{ $t('message.settings_component_test_not_tested') }}
662-
</v-btn>
663-
</span>
664-
</v-col>
665-
</v-row>
666-
<!-- MOTORS -->
635+
<div id='test_array' v-for="test in tests">
667636
<v-row row wrap justify-center>
668-
<!-- switch -->
669637
<v-col xs12 offset-md2 md5>
670-
<v-switch v-bind:label="$t('message.settings_component_test_motors')" value="motors" v-model="checkedTests" color="orange">
671-
</v-switch>
638+
<v-switch :label="test.title" :value="test.name" v-model="checkedTests[test.name]" color="orange"></v-switch>
672639
</v-col>
673-
<!-- button state -->
674640
<v-col xs12 md4>
675-
<span v-if="cb.logs != null && cb.logs.test != null && cb.logs.test.motors != 0">
676-
<!-- passed -->
677-
<span v-if="cb.logs.test.motors== 1">
678-
<v-btn @click="runTests" slot="activator" color="green" dark>
679-
<v-icon icon="mdi-check"></v-icon> {{ $t('message.settings_component_test_passed') }}
680-
</v-btn>
681-
</span>
682-
<!-- failed -->
683-
<span v-else>
684-
<v-btn @click="runTests" slot="activator" color="red" dark>
685-
<v-icon icon="mdi-exclamation"></v-icon> {{ $t('message.settings_component_test_failed') }}
686-
</v-btn>
687-
</span>
688-
</span>
689-
<!-- not tested -->
690-
<span v-else>
691-
<v-btn @click="runTests" slot="activator" color="grey" dark>
692-
<v-icon icon="mdi-help"></v-icon> {{ $t('message.settings_component_test_not_tested') }}
693-
</v-btn>
694-
</span>
695-
</v-col>
696-
</v-row>
697-
698-
<!-- SPEAKER -->
699-
<v-row row wrap justify-center>
700-
<!-- switch -->
701-
<v-col xs12 offset-md2 md5>
702-
<v-switch v-bind:label="$t('message.settings_component_test_speaker')" value="speaker" v-model="checkedTests" color="orange">
703-
</v-switch>
704-
</v-col>
705-
<!-- button state -->
706-
<v-col xs12 md4>
707-
<span v-if="cb.logs != null && cb.logs.test != null && cb.logs.test.speaker != 0">
708-
<!-- passed -->
709-
<span v-if="cb.logs.test.speaker== 1">
710-
<v-btn @click="runTests" slot="activator" color="green" dark>
711-
<v-icon icon="mdi-check"></v-icon> {{ $t('message.settings_component_test_passed') }}
712-
</v-btn>
713-
</span>
714-
<!-- failed -->
715-
<span v-else>
716-
<v-btn @click="runTests" slot="activator" color="red" dark>
717-
<v-icon icon="mdi-exclamation"></v-icon> {{ $t('message.settings_component_test_not_failed') }}
718-
</v-btn>
719-
</span>
720-
</span>
721-
<!-- not tested -->
722-
<span v-else>
723-
<v-btn @click="runTests" slot="activator" color="grey" dark>
724-
<v-icon icon="mdi-help"></v-icon> {{ $t('message.settings_component_test_not_tested') }}
725-
</v-btn>
726-
</span>
727-
</v-col>
728-
</v-row>
729-
730-
<!-- OCR -->
731-
<v-row row wrap justify-center>
732-
<!-- switch -->
733-
<v-col xs12 offset-md2 md5>
734-
<v-switch v-bind:label="$t('message.settings_component_test_ocr')" value="ocr" v-model="checkedTests" color="orange">
735-
</v-switch>
736-
</v-col>
737-
<!-- button state -->
738-
<v-col xs12 md4>
739-
<span v-if="cb.logs != null && cb.logs.test != null && cb.logs.test.ocr != 0">
740-
<!-- passed -->
741-
<span v-if="cb.logs.test.ocr== 1">
742-
<v-btn @click="runTests" slot="activator" color="green" dark>
743-
<v-icon icon="mdi-check"></v-icon> {{ $t('message.settings_component_test_passed') }}
744-
</v-btn>
745-
</span>
746-
<!-- failed -->
747-
<span v-else>
748-
<v-btn @click="runTests" slot="activator" color="red" dark>
749-
<v-icon icon="mdi-exclamation"></v-icon> {{ $t('message.settings_component_test_failed') }}
750-
</v-btn>
751-
</span>
752-
</span>
753-
<!-- not tested -->
754-
<span v-else>
755-
<v-btn @click="runTests" slot="activator" color="grey" dark>
756-
<v-icon icon="mdi-help"></v-icon> {{ $t('message.settings_component_test_not_tested') }}
757-
</v-btn>
758-
</span>
641+
<v-chip slot="activator" :color="testStatusColor(test.name)" dark>
642+
<v-icon icon="mdi-check"></v-icon> {{ testStatusLabel(test.name) }}
643+
</v-chip>
759644
</v-col>
760645
</v-row>
761646
</div>
762-
<br>
763-
<v-card-actions>
764-
765-
<v-btn v-if="cb.logs != null && !cb.logs.runningTest" block @click="runTests" slot="activator" color="orange" dark>
766-
<v-icon icon="mdi-animation-play"></v-icon> {{ $t('message.settings_component_test_run') }}
767-
</v-btn>
768-
<v-btn v-else block disabled>
769-
<v-icon icon="mdi-clock-outline"></v-icon> {{ $t('message.settings_component_test_text_1') }}
770-
</v-btn>
771-
</v-card-actions>
772647
</v-card-text>
648+
<v-card-actions>
649+
<v-btn v-if="!testsRunning" block @click="runTests" slot="activator" color="orange" dark>
650+
<v-icon icon="mdi-animation-play"></v-icon> {{ $t('message.settings_component_test_run') }}
651+
</v-btn>
652+
<v-btn v-else block>
653+
<v-icon icon="mdi-clock-outline"></v-icon> {{ $t('message.settings_component_test_text_1') }}
654+
</v-btn>
655+
</v-card-actions>
773656
</v-card>
774657
</v-col>
775658
</v-row>
@@ -821,20 +704,8 @@
821704
{{ $t('message.settings_music_packages_add') }}
822705
</v-card-title>
823706
<v-card-text>
824-
<template v-if="updateStatus==1">
825-
<b>{{ $t('message.settings_music_package_installed') }}</b>
826-
<br>
827-
{{ updateStatusText }}
828-
<v-btn @click="refresh" color="error">{{ $t('message.settings_music_packages_update') }}</v-btn>
829-
</template>
830-
<template v-if="updateStatus==2 || updateStatus==3">
831-
<b>{{ $t('message.settings_music_packages_installation_failed') }}</b>
832-
<br>
833-
{{ updateStatusText }}
834-
<v-btn @click="refresh" color="error">{{ $t('message.settings_music_packages_update') }}</v-btn>
835-
</template>
836707
<template v-if="updateStatus==0">
837-
<v-text-field label="$t('message.settings_music_packages_select')" @click='pickFile' v-model='fileName'
708+
<v-text-field :label="$t('message.settings_music_packages_select')" @click='pickFile' v-model='fileName'
838709
prepend-icon='attach_file'></v-text-field>
839710
<input type="file" style="display: none" ref="file" @change="onFilePicked">
840711
<template v-if="this.fileObj">{{ $t('message.settings_music_packages_install_confirm_text') }}<br></template>
@@ -907,6 +778,7 @@ import useVuelidate from '@vuelidate/core';
907778
import {
908779
required, alpha, integer, decimal, between, minValue, maxValue
909780
} from '@vuelidate/validators';
781+
import i18n from '../i18n';
910782
911783
import sidebar from './Sidebar.vue';
912784
@@ -964,8 +836,7 @@ export default {
964836
},
965837
requirePassword() {
966838
return this.settings.adminPassword != null && this.settings.adminPassword != '' && !this.passwordVerified;
967-
}
968-
839+
},
969840
},
970841
methods: {
971842
pickFile() {
@@ -981,23 +852,25 @@ export default {
981852
this.formdata.append('file_to_upload', files[0], files[0].name);
982853
},
983854
uploadPackage() {
984-
/*
985-
const qs = this.$qs;
986-
const pkgName = qs.stringify({
987-
nameID: this.fileName,
988-
});
989-
*/
990-
this.$coderbot.updatePackages(this.formData).then((result) => {
991-
this.updateStatus = result.data;
855+
this.$coderbot.uploadMusicPackage(this.formdata).then((result) => {
856+
console.log(result);
857+
this.updateStatus = 0;
992858
this.uploadCompleted = true;
993859
this.uploadInProgress = false;
860+
this.fileObj = null;
861+
this.fileName = null;
994862
this.updateStatusText = this.$i18n.t('message.settings_music_packages_text_1');
995-
if (this.updateStatus == 2) {
996-
this.updateStatusText = this.$i18n.t('message.settings_music_packages_text_2');
997-
}
998-
if (this.updateStatus == 3) {
999-
this.updateStatusText = this.$i18n.t('message.settings_music_packages_text_3');
1000-
}
863+
this.$coderbot.loadMusicPackages().then(() => {
864+
this.musicPackages = this.$store.getters.musicPackages;
865+
});
866+
}).catch((result) => {
867+
console.log(result);
868+
this.updateStatus = 0;
869+
this.uploadCompleted = true;
870+
this.uploadInProgress = false;
871+
this.fileObj = null;
872+
this.fileName = null;
873+
this.updateStatusText = this.$i18n.t('message.settings_music_packages_text_3');
1001874
});
1002875
},
1003876
upload() {
@@ -1017,27 +890,8 @@ export default {
1017890
});
1018891
},
1019892
refresh() {
1020-
window.location.reload();
1021-
/*
1022-
readTextFile
1023-
this.musicPackages = packageList
1024-
this.$http.get('vue/index.html#/settings').then((results) => {
1025-
console.log(results.data.data);
1026-
}, (results) => {
1027-
console.log('ERROR');
1028-
console.log(results);
1029-
});
1030-
readTextFile(file, callback) {
1031-
var rawFile = new XMLHttpRequest();
1032-
rawFile.overrideMimeType("application/json");
1033-
rawFile.open("GET", file, true);
1034-
rawFile.onreadystatechange = function() {
1035-
if (rawFile.readyState === 4 && rawFile.status == "200") {
1036-
callback(rawFile.responseText);
1037-
}
1038-
}
1039-
rawFile.send(null);
1040-
*/
893+
this.$coderbot.loadMusicPackages();
894+
this.musicPackages = this.$store.getters.musicPackages;
1041895
},
1042896
pollWifiStatus() {
1043897
this.$wifi_connect.status().then((result) => {
@@ -1058,12 +912,14 @@ export default {
1058912
});
1059913
},
1060914
runTests() {
1061-
this.cb.logs.runningTest = true;
1062-
this.$coderbot.test(this.checkedTests).then((response) => {
1063-
this.cb.logs.test = response.data;
915+
this.runningTest = true;
916+
let tests = Object.values(this.checkedTests);
917+
this.$coderbot.test(tests).then((response) => {
918+
console.log(response.data);
919+
this.testResults = response.data;
1064920
this.snackText = 'Running tests';
1065921
this.snackbar = true;
1066-
this.cb.logs.runningTest = false;
922+
this.testsRunning = false;
1067923
});
1068924
},
1069925
reset() {
@@ -1093,6 +949,9 @@ export default {
1093949
console.log('Pacchetto rimosso');
1094950
this.snackText = this.$i18n.t('message.settings_music_package_removed');
1095951
this.snackbar = true;
952+
this.$coderbot.loadMusicPackages().then(() => {
953+
this.musicPackages = this.$store.getters.musicPackages;
954+
});
1096955
});
1097956
},
1098957
save() {
@@ -1141,6 +1000,26 @@ export default {
11411000
}
11421001
}
11431002
},
1003+
testStatusColor(name) {
1004+
switch (this.testResults[name]) {
1005+
case 1:
1006+
return "green";
1007+
case -1:
1008+
return "red";
1009+
case 0:
1010+
return "default";
1011+
}
1012+
},
1013+
testStatusLabel(name) {
1014+
switch (this.testResults[name]) {
1015+
case 1:
1016+
return this.$i18n.t('message.settings_component_test_passed');
1017+
case -1:
1018+
return this.$i18n.t('message.settings_component_test_failed');
1019+
case 0:
1020+
return this.$i18n.t('message.settings_component_test_not_tested');
1021+
}
1022+
},
11441023
toggleSidebar() {
11451024
const currentStatus = this.$store.getters.drawerStatus;
11461025
this.$store.commit('toggleDrawer', !currentStatus);
@@ -1264,6 +1143,7 @@ export default {
12641143
cb: {
12651144
info: {},
12661145
status: {},
1146+
logs: {},
12671147
},
12681148
drawer: null,
12691149
tab: null,
@@ -1284,6 +1164,19 @@ export default {
12841164
this.$i18n.t('message.settings_tabs_audio'),
12851165
this.$i18n.t('message.settings_tabs_music_packages')
12861166
],
1167+
tests: [
1168+
{ name: "sonar", title: this.$i18n.t('message.settings_component_test_sonar') },
1169+
{ name: "motors", title: this.$i18n.t('message.settings_component_test_motors') },
1170+
{ name: "speaker", title: this.$i18n.t('message.settings_component_test_speaker') },
1171+
{ name: "OCR", title: this.$i18n.t('message.settings_component_test_ocr') },
1172+
],
1173+
testResults: {
1174+
sonar: null,
1175+
motors: null,
1176+
speaker: null,
1177+
OCR: null,
1178+
},
1179+
testsRunning: false,
12871180
networks: [],
12881181
wifi_status: null,
12891182
wifi_pwd_show: false,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy