147
147
id =" file"
148
148
show-size
149
149
accept =" .tar"
150
+ :rules =" [is_file_input_not_empty]"
151
+ :error-messages =" file_input_error"
150
152
label =" File input"
151
153
/>
152
154
<v-progress-linear
158
160
v-if =" !disable_upload_controls"
159
161
color =" primary"
160
162
class =" mr-2 mb-4"
161
- @click =" upload()"
163
+ @click =" validateInputFileForm() && upload()"
162
164
v-text =" 'Upload'"
163
165
/>
164
166
@@ -253,6 +255,7 @@ export default Vue.extend({
253
255
default_repository ,
254
256
selected_image: default_repository ,
255
257
deleting: ' ' , // image currently being deleted, if any
258
+ file_input_error: ' ' ,
256
259
}
257
260
},
258
261
computed: {
@@ -262,6 +265,9 @@ export default Vue.extend({
262
265
totalPages(): number {
263
266
return Math .ceil (this .available_versions .remote .length / 10 )
264
267
},
268
+ input_file_required_message(): string {
269
+ return ' File is required'
270
+ },
265
271
},
266
272
mounted() {
267
273
this .loadCurrentVersion ()
@@ -430,14 +436,14 @@ export default Vue.extend({
430
436
return remote_counterpart .sha !== image .sha && remote_counterpart .sha !== null
431
437
},
432
438
async upload() {
433
- this . disable_upload_controls = true
434
- const { files } = document . getElementById ( ' file ' ) as HTMLInputElement
435
- if ( files !== null ) {
439
+ const file = this . get_input_file ()
440
+ if ( file !== null ) {
441
+ this . disable_upload_controls = true
436
442
await back_axios ({
437
443
method: ' POST' ,
438
444
url: ' /version-chooser/v1.0/version/load/' ,
439
445
timeout: 15 * 60 * 1000 , // Wait for 15min
440
- data: files [ 0 ] ,
446
+ data: file ,
441
447
headers: { ' Content-Type' : ' undefined' },
442
448
onUploadProgress : (event ) => {
443
449
this .upload_percentage = Math .round (100 * (event .loaded / event .total ))
@@ -596,6 +602,28 @@ export default Vue.extend({
596
602
}
597
603
return this .available_versions .local .some ((image ) => image .sha === sha )
598
604
},
605
+ get_input_file(): File | null {
606
+ const { files } = document .getElementById (' file' ) as HTMLInputElement
607
+
608
+ if (files !== null && files .length > 0 ) {
609
+ return files [0 ]
610
+ }
611
+
612
+ return null
613
+ },
614
+ is_file_input_not_empty(v : File | null ): true | string {
615
+ this .file_input_error = ' '
616
+ return !! v || this .input_file_required_message
617
+ },
618
+ validateInputFileForm(): boolean {
619
+ const valid = this .get_input_file () != null
620
+
621
+ if (! valid ) {
622
+ this .file_input_error = this .input_file_required_message
623
+ }
624
+
625
+ return valid
626
+ },
599
627
},
600
628
})
601
629
</script >
0 commit comments