1212                    </div >
1313                </v-col >
1414            </v-row >
15+             <v-row  justify =" center" dense >
16+                 <v-col  cols =10 >
17+                     <div  class =" ma-auto" 
18+                         Current Version: {{ fw_version_old }}
19+                     </div >
20+                 </v-col >
21+             </v-row >
1522            <v-row  justify =" center" 
1623                <v-col  cols =10  >
1724                    <v-file-input 
@@ -78,9 +85,14 @@ export default {
7885        file:  null , 
7986        status:  null , 
8087        alert:  false , 
81-         success:  false  
88+         success:  false , 
89+         fw_version_old:  null , 
90+         fw_version_new:  null  
8291    } 
8392  }, 
93+   mounted () { 
94+       this .fetch_data (" old"  
95+   }, 
8496  computed:  { 
8597      flash_disabled () { 
8698          return  this .disable_flash_btn ; 
@@ -92,13 +104,13 @@ export default {
92104  methods:  { 
93105      upload :  function () { 
94106          this .uploading  =  ! this .uploading ; 
95-           this .disable_upload_btn   =   true  
107+           this .disable ( " upload " )  
96108          var  reader =  new  FileReader (); 
97109          if (! this .file ) { 
98110              this .status  =  " No file selected"  
99-               this .alert   =   true  
111+               this .show_alert ()  
100112              this .uploading  =  ! this .uploading ; 
101-               this .disable_upload_btn   =   false  
113+               this .enable ( " upload " )  
102114              return ; 
103115          } 
104116          reader .readAsArrayBuffer (this .file ); 
@@ -107,44 +119,82 @@ export default {
107119            .post (' api/v1/ota/upload' reader .result ) 
108120            .then (res  =>  { 
109121                this .status  =  " Image upload successfull"  
110-                 this .disable_flash_btn   =   false ; 
111-                 this .disable_upload_btn   =   false  
122+                 this .enable ( " flash " ) ; 
123+                 this .enable ( " upload " )  
112124                this .uploading  =  ! this .uploading ; 
113-                 this .alert = false  
114-                 this .success = true  
125+                 this .show_success () 
115126            }) 
116127            .catch (error  =>  { 
117128                this .status  =  " Could not upload image - Statuscode: " +  error .response .status  
118129                this .uploading  =  ! this .uploading ; 
119-                 this .disable_upload_btn  =  false  
120-                 this .disable_flash_btn  =  true  
121-                 this .alert = true  
122-                 this .success = false  
130+                 this .enable (" upload"  
131+                 this .disable (" flash"  
132+                 this .show_alert () 
123133            }); 
124134          }}, 
125135          flash :  function () { 
126136            this .flashing  =  ! this .flashing ; 
127-             this .disable_flash_btn   =   true  
137+             this .disable ( " flash " )  
128138            let  id =  this .$store .state .active_device_id  
129139            this .$ajax  
130-             .get (' api/v1/ota/' +  ' kk8a4zv '  
140+             .get (' api/v1/ota/' +  id ) 
131141            .then (res  =>  { 
132-                 this .status  =  " Image flashed successfully"  
133-                 this .disable_flash_btn  =  false ; 
134-                 this .disable_upload_btn  =  false  
135-                 this .flashing  =  ! this .uploading ; 
136-                 this .alert = false  
137-                 this .success = true  
142+                 this .disable (" flash"  
143+                 this .enable (" upload"  
144+                 this .flashing  =  ! this .flashing ; 
145+                 this .fetch_data (" new"  
138146            }) 
139147            .catch (error  =>  { 
140148                this .status  =  " Could not be flashed: " +  error .response .status  +  " -" +  error .response .data  
141149                this .flashing  =  ! this .flashing ; 
142-                 this .disable_flash_btn  =  false  
143-                 this .disable_upload_btn  =  false  
144-                 this .success = false  
145-                 this .alert = true  
150+                 this .enable (" flash"  
151+                 this .enable (" upload"  
152+                 this .show_alert () 
146153            }); 
154+           }, 
155+           fetch_data :  function (target ) { 
156+             let  id =  this .$store .state .active_device_id  
157+             this .$ajax  
158+             .get (" api/v1/ts/" +  id +  " /info"  
159+             .then (res  =>  { 
160+                 if  (target ==  " old"  
161+                     this .fw_version_old  =  res .data .FirmwareVersion ; 
162+                 } else  if  (target ==  " new"  
163+                     this .fw_version_new  =  res .data .FirmwareVersion ; 
164+                     this .status  =  " Updated successfully from " +  this .fw_version_old  +  "  --> " +  this .fw_version_new ; 
165+                     this .show_success () 
166+                 } 
167+                 return  
168+             }) 
169+             .catch (error  =>  { 
170+                 this .status  =  " Device Information could not be fetched: " +  error .response .status  +  " -" +  error .response .data  
171+                 this .show_alert () 
172+                 return  
173+             }); 
174+           }, 
175+           enable :  function (btn ) { 
176+               if (btn ==  " flash"  
177+                   this .disable_flash_btn  =  false  
178+               } else  if  (btn ==  " upload"  
179+                   this .disable_upload_btn  =  false  
180+               } 
181+           }, 
182+           disable :  function (btn ) { 
183+               if (btn ==  " flash"  
184+                   this .disable_flash_btn  =  true  
185+               } else  if  (btn ==  " upload"  
186+                   this .disable_upload_btn  =  true  
187+               } 
188+           }, 
189+           show_alert :  function () { 
190+               this .success  =  false  
191+               this .alert  =  true  
192+           }, 
193+           show_success :  function () { 
194+               this .alert  =  false  
195+               this .success  =  true  
147196          } 
197+ 
148198      } 
149199} 
150- script >
200+ script >
0 commit comments