11<template >
2-   <v-container >
3-     <v-row  justify =" center" 
4-         <v-col  cols =5 >
5-             <div  class =" ma-auto" 
6-                 Select an image from your PC to upload. Once uploaded, you can start the update process
7-             </div >
8-         </v-col >
9-     </v-row >
10-     <v-row  justify =" center" 
11-       <v-col  cols =2  >
12-         <v-file-input 
13-             v-model =" file" 
14-             label =" File input" 
15-             outlined 
16-             dense 
17-             :show-size =" 1000" 
18-         ></v-file-input >
19-         </v-col >
20-         <v-col  cols =1 >
21-             <v-btn 
22-             :loading =" uploading" 
23-             :disabled =" uploading" 
24-             @click =" upload()" 
25-             Upload</v-btn >
26-         </v-col >
27-       <v-col  cols =1 >
28-           <v-btn 
29-           :loading =" flashing" 
30-           :disabled =" disabled" 
31-           @click =" flash()" 
32-           Start Flashing</v-btn ></v-col >
33-       <v-col  cols =1 ></v-col >
34-     </v-row >
35-     <v-row  justify =" center" 
36-         <v-col  cols =5 >
37-             <div  class =" ma-auto" 
38-                 {{ status }}
39-             </div >
40-         </v-col >
41-     </v-row >
42-   </v-container >
2+     <v-container >
3+         <v-layout  text-xs-center  wrap >
4+       <v-flex  xs12  sm6  offset-sm3 >
5+         <v-card >
6+         <v-card-title  class =" justify-center" v-card-title >
7+         <v-card-text >
8+             <v-row  justify =" center" dense >
9+                 <v-col  cols =10 >
10+                     <div  class =" ma-auto" 
11+                         Select an image from your PC to upload. Once uploaded, you can start the update process
12+                     </div >
13+                 </v-col >
14+             </v-row >
15+             <v-row  justify =" center" 
16+                 <v-col  cols =10  >
17+                     <v-file-input 
18+                         v-model =" file" 
19+                         label =" File input" 
20+                         outlined 
21+                         dense 
22+                         :show-size =" 1000" 
23+                     ></v-file-input >
24+                 </v-col >
25+             </v-row >
26+             <v-row  justify =" center" dense >
27+                 <v-spacer ></v-spacer >
28+                 <v-col  cols =2 >
29+                     <v-btn 
30+                     :loading =" uploading" 
31+                     :disabled =" upload_disabled" 
32+                     @click =" upload()" 
33+                     Upload</v-btn >
34+                 </v-col >
35+                 <v-spacer ></v-spacer >
36+                 <v-col  cols =2 >
37+                     <v-btn 
38+                     :loading =" flashing" 
39+                     :disabled =" flash_disabled" 
40+                     @click =" flash()" 
41+                     Flash</v-btn ></v-col >
42+                 <v-spacer ></v-spacer >
43+             </v-row >
44+             <v-row  justify =" center" 
45+                 <v-alert 
46+                 v-model =" alert" 
47+                 dense 
48+                 outlined 
49+                 type =" error" 
50+                 transition =" scale-transition" 
51+                 dismissible 
52+                 >{{status}}</v-alert >
53+                 <v-alert 
54+                 v-model =" success" 
55+                 dense 
56+                 outlined 
57+                 type =" success" 
58+                 transition =" scale-transition" 
59+                 dismissible 
60+                 >{{status}}</v-alert >
61+             </v-row >
62+         </v-card-text >
63+         </v-card >
64+       </v-flex >
65+         </v-layout >
66+     </v-container >
4367</template >
4468
4569<script >
@@ -49,23 +73,32 @@ export default {
4973    return  { 
5074        uploading:  false , 
5175        flashing:  false , 
52-         start_flash_btn:  true , 
76+         disable_flash_btn:  true , 
77+         disable_upload_btn:  false , 
5378        file:  null , 
54-         status:  null  
79+         status:  null , 
80+         alert:  false , 
81+         success:  false  
5582    } 
5683  }, 
5784  computed:  { 
58-       disabled () { 
59-           return  this .start_flash_btn ; 
85+       flash_disabled () { 
86+           return  this .disable_flash_btn ; 
87+       }, 
88+       upload_disabled () { 
89+           return  this .disable_upload_btn ; 
6090      } 
6191  }, 
6292  methods:  { 
6393      upload :  function () { 
6494          this .uploading  =  ! this .uploading ; 
95+           this .disable_upload_btn  =  true  
6596          var  reader =  new  FileReader (); 
6697          if (! this .file ) { 
6798              this .status  =  " No file selected"  
99+               this .alert  =  true  
68100              this .uploading  =  ! this .uploading ; 
101+               this .disable_upload_btn  =  false  
69102              return ; 
70103          } 
71104          reader .readAsArrayBuffer (this .file ); 
@@ -74,18 +107,44 @@ export default {
74107            .post (' api/v1/ota/upload' reader .result ) 
75108            .then (res  =>  { 
76109                this .status  =  " Image upload successfull"  
77-                 this .start_flash_btn  =  ! this .start_flash_btn ; 
110+                 this .disable_flash_btn  =  false ; 
111+                 this .disable_upload_btn  =  false  
112+                 this .uploading  =  ! this .uploading ; 
113+                 this .alert = false  
114+                 this .success = true  
78115            }) 
79116            .catch (error  =>  { 
80117                this .status  =  " Could not upload image - Statuscode: " +  error .response .status  
81118                this .uploading  =  ! this .uploading ; 
119+                 this .disable_upload_btn  =  false  
120+                 this .disable_flash_btn  =  true  
121+                 this .alert = true  
122+                 this .success = false  
123+             }); 
124+           }}, 
125+           flash :  function () { 
126+             this .flashing  =  ! this .flashing ; 
127+             this .disable_flash_btn  =  true  
128+             let  id =  this .$store .state .active_device_id  
129+             this .$ajax  
130+             .get (' api/v1/ota/' +  ' kk8a4zv'  
131+             .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  
138+             }) 
139+             .catch (error  =>  { 
140+                 this .status  =  " Could not be flashed: " +  error .response .status  +  " -" +  error .response .data  
141+                 this .flashing  =  ! this .flashing ; 
142+                 this .disable_flash_btn  =  false  
143+                 this .disable_upload_btn  =  false  
144+                 this .success = false  
145+                 this .alert = true  
82146            }); 
83147          } 
84-       }, 
85-       flash :  function () { 
86-           this .flashing  =  ! this .flashing  
87-           this .start_flash_btn  =  ! this .start_flash_btn  
88148      } 
89-   } 
90149} 
91150script >
0 commit comments