444444 </v-layout >
445445 </v-container >
446446 </v-tab-item >
447+
448+ <!-- PACKAGE MANAGER -->
449+ <v-tab-item >
450+ <v-container grid-list-md text-xs-center >
451+ <v-layout row wrap align-center >
452+ <v-flex xs12 md6 offset-md3 >
453+ <h3 class =" text-xs-left" >Gestione Pacchetti</h3 >
454+ <br >
455+ <v-card >
456+ <div class =" cardContent" >
457+ <h3 class =" text-xs-left" > Pacchetti installati:</h3 >
458+
459+ <div v-for =" pkgnames in settings.packagesInstalled" >
460+ <ul >
461+ <li > nome: {{pkgnames[0][0]}} tipo: {{pkgnames[1]}} <span align =" right" ><v-btn @click =" deletePkg(pkgnames[0][1])" color =" red" dark >
462+ <v-icon >fas fa-trash</v-icon > Rimuovi
463+ </v-btn ></span >
464+ </li >
465+ </ul >
466+ </div >
467+
468+ </v-card >
469+ <h3 class =" text-xs-left" > Aggiungi Pacchetto ssh with python</h3 >
470+ <v-card >
471+ <div class =" cardContent" >
472+ <template v-if =" updateStatus == 1 " >
473+ Caricamento del file:
474+ <h3 >{{ counter }} %</h3 >
475+ <br >
476+ {{ updateStatusText }}
477+ </template >
478+ <template v-if =" updateStatus == 2 " >
479+ </template >
480+ <template v-if =" updateStatus == 0 " >
481+ <v-text-field label =" Seleziona il pacchetto da installare" @click =' pickFile' v-model =' fileName' prepend-icon =' attach_file' ></v-text-field >
482+ <input type =" file" style =" display : none " ref =" file" @change =" onFilePicked" >
483+ <template v-if =" this .fileObj " >Clicca "CONFERMA" per installare il pacchetto<br ></template >
484+ <v-btn v-if =" this.fileObj" @click =" uploadPackage" color =" error" >Conferma</v-btn >
485+ </template >
486+ </div >
487+ </v-card >
488+ </v-flex >
489+ </v-layout >
490+ </v-container >
491+ </v-tab-item >
492+
447493 </v-tabs-items >
448494 <!-- </template>
449495 <template v-else>
466512<script >
467513import sidebar from " ../components/Sidebar"
468514
515+ function readTextFile (file , callback ) {
516+ var rawFile = new XMLHttpRequest ();
517+ rawFile .overrideMimeType (" application/json" );
518+ rawFile .open (" GET" , file, true );
519+ rawFile .onreadystatechange = function () {
520+ if (rawFile .readyState === 4 && rawFile .status == " 200" ) {
521+ callback (rawFile .responseText );
522+ }
523+ }
524+ rawFile .send (null );
525+ }
526+ var packageList = [];// ["pianoooo","pianoo"], ["chitarra","guiitar"], ["flauto","fluute"]];
527+ var datapkg = readTextFile ( " ./static/music_package.json" , function (text ){
528+ var datas = JSON .parse (text);
529+
530+
531+ Object .keys (datas[' packages' ]).forEach (function (key ) {
532+ console .table (' Key : ' + key + ' , Value : ' + datas[' packages' ][key])
533+ console .table (' Key : name_IT, Value : ' + datas[' packages' ][key][' name_IT' ])
534+ var names = [datas[' packages' ][key][' name_IT' ], key];
535+ if (datas[' packages' ][key][' category' ] == ' instrument' ){
536+ packageList[packageList .length ] = [names, ' instrument' ];
537+ }
538+ else if (datas[' packages' ][key][' category' ] == ' animal' ){
539+ packageList[packageList .length ] = [names, ' animal' ];
540+ }
541+ })
542+ return packageList;
543+ });
544+
469545export default {
470546
471547 components: { sidebar },
@@ -493,6 +569,32 @@ export default {
493569 this .formdata .append (' file_to_upload' , files[0 ], files[0 ].name );
494570
495571 },
572+
573+ uploadPackage () {
574+ let qs = this .$qs
575+ var pkgName = qs .stringify ({
576+ ' nameID' : this .fileName ,
577+ })
578+
579+ const config = {
580+ headers: { ' Content-Type' : ' multipart/form-data' },
581+ onUploadProgress : progressEvent => {
582+ this .counter = Math .floor ((progressEvent .loaded * 100 ) / progressEvent .total );
583+ }
584+ }
585+ this .updateStatus = 1
586+
587+ this .$axios .post (this .CB + ' /updatePackages' , this .formdata ).then (function (result ) {
588+ this .uploadCompleted = true ;
589+ this .uploadInProgress = false ;
590+ console .dir (result .data );
591+
592+ this .updateStatusText = ' Upload completato. Riavvio in corso.'
593+
594+ }.bind (this ))
595+
596+ },
597+
496598 upload () {
497599 const config = {
498600 headers: { ' Content-Type' : ' multipart/form-data' },
@@ -512,6 +614,20 @@ export default {
512614 }.bind (this ))
513615
514616 },
617+
618+ /* readTextFile(file, callback) {
619+ var rawFile = new XMLHttpRequest();
620+ rawFile.overrideMimeType("application/json");
621+ rawFile.open("GET", file, true);
622+ rawFile.onreadystatechange = function() {
623+ if (rawFile.readyState === 4 && rawFile.status == "200") {
624+ callback(rawFile.responseText);
625+ }
626+ }
627+
628+ rawFile.send(null);
629+ },
630+ */
515631 restoreConfig () {
516632 let axios = this .$axios
517633 let CB = this .CB
@@ -577,7 +693,7 @@ export default {
577693 this .cb .status = response .data
578694 this .cb .logs .log = response .data .log
579695 }.bind (this ))
580- axios .get (this .CB + ' /info' )
696+ axioks .get (this .CB + ' /info' )
581697 .then (function (response ) {
582698 this .cb .info = response .data
583699 }.bind (this ))
@@ -586,7 +702,7 @@ export default {
586702 let axios = this .$axios
587703 let CB = this .CB
588704 let status = this .status
589- axios .get (CB + ' /status' )
705+ axios .kkget (CB + ' /status' )
590706 .then (function (response ) {
591707 if (this .status == 0 && response .status ) {
592708 this .snackText = ' CoderBot è tornato online'
@@ -610,6 +726,22 @@ export default {
610726 this .status = 0
611727 }.bind (this ))
612728 },
729+
730+ deletePkg (pkgNameID ){
731+ let CBv1 = this .CBv1
732+ let axios = this .$axios
733+ let qs = this .$qs
734+ var pkgName = qs .stringify ({
735+ ' nameID' : pkgNameID,
736+ })
737+ axios .post (CBv1 + ' /deletepkg' , pkgName)
738+ .then (function () {
739+ console .log (' Pacchetto rimosso' )
740+ this .snackText = " Pacchetto rimosso"
741+ this .snackbar = true
742+ }.bind (this ))
743+ },
744+
613745 prepopulate : function () {
614746 let axios = this .$axios
615747 let settings = this .settings
@@ -687,8 +819,28 @@ export default {
687819 data .ctrlTurnSpeed = remoteConfig .ctrl_tr_speed
688820
689821 data .audioLevel = remoteConfig .audio_volume_level
822+ // data.packagesInstalled = remoteConfig.packageList
823+ data .packagesInstalled = remoteConfig .packages_installed
824+ /* this.readTextFile( "./static/music_package.json" , function(text){
825+ var datas = JSON.parse(text);
826+ Object.keys(datas['packages']).forEach(function(key) {
827+ console.table('Key : ' + key + ', Value : ' + datas['packages'][key])
828+ console.table('Key : name_IT, Value : ' + datas['packages'][key]['name_IT'])
829+ var names = [datas['packages'][key]['name_IT'], key];
830+
831+ if (datas['packages'][key]['category'] == 'instrument'){
832+ instrumentlist[instrumentlist.length] = names;
833+ }
834+ else if (datas['packages'][key]['category'] == 'animal'){
835+ animalist[animalist.length] = names;
836+ }
837+ })
838+ return instrumentlist;
839+ })
840+ */
690841 }.bind (this ))
691842 },
843+
692844 save : function () {
693845 let qs = this .$qs
694846 let selectedTab = this .tab
@@ -738,6 +890,7 @@ export default {
738890 ' ctrl_tr_speed' : data .ctrlTurnSpeed ,
739891
740892 ' audio_volume_level' : data .audioLevel ,
893+ ' packages_installed' : data .packagesInstalled
741894 })
742895 axios .post (CBv1 + ' /config' , legacySettings)
743896 .then (function () {
@@ -784,7 +937,7 @@ export default {
784937 wifiPsw: null ,
785938
786939 audioLevel: null ,
787-
940+ packagesInstalled : packageList,
788941 moveFwdElapse: null ,
789942 moveFwdSpeed: null ,
790943 moveTurnElapse: null ,
@@ -834,7 +987,7 @@ export default {
834987 drawer: null ,
835988 tab: null ,
836989 // tabs: ['Generali', 'Rete', 'Movimento', 'Suoni', 'Avanzate'],
837- tabs: [' Generali' , ' Movimento' , ' Suoni' , ' Avanzate' , ' Test' ,' Audio' ]
990+ tabs: [' Generali' , ' Movimento' , ' Suoni' , ' Avanzate' , ' Test' ,' Audio' , ' Gestione Pacchetti ' ]
838991 }
839992 }
840993}
0 commit comments