@@ -14,6 +14,7 @@ export default {
1414 ballotsProcessed : null ,
1515 ballotsTotal : null ,
1616 success : false ,
17+ duplicateCount : 0 ,
1718 } ;
1819 } ,
1920 methods : {
@@ -27,7 +28,7 @@ export default {
2728 const ballotFiles = document . getElementById ( "ballotsFolder" ) . files ;
2829 this . ballotsTotal = ballotFiles . length ;
2930
30- const uploadId = await this . uploadDeviceFile ( this . ballotsTotal ) ;
31+ const uploadId = await this . uploadDeviceFile ( ) ;
3132 await this . uploadBallotFiles ( uploadId , ballotFiles ) ;
3233 this . success = true ;
3334 }
@@ -39,15 +40,14 @@ export default {
3940 this . loading = false ;
4041 }
4142 } ,
42- async uploadDeviceFile ( ballotCount ) {
43+ async uploadDeviceFile ( ) {
4344 const [ deviceFile ] = document . getElementById ( "deviceFile" ) . files ;
4445 const deviceContents = await deviceFile . text ( ) ;
4546 console . log ( "Creating election" , deviceFile . name ) ;
4647 const result = await eel . create_ballot_upload (
4748 this . electionId ,
4849 deviceFile . name ,
49- deviceContents ,
50- ballotCount
50+ deviceContents
5151 ) ( ) ;
5252 if ( ! result . success ) {
5353 throw new Error ( result . message ) ;
@@ -69,17 +69,44 @@ export default {
6969 if ( ! result . success ) {
7070 throw new Error ( result . message ) ;
7171 }
72+ if ( result . result . is_duplicate ) {
73+ this . duplicateCount ++ ;
74+ }
7275 this . ballotsProcessed ++ ;
7376 }
7477 } ,
7578 getElectionUrl : function ( ) {
7679 return RouterService . getElectionUrl ( this . electionId ) ;
7780 } ,
81+ uploadMore : function ( ) {
82+ this . success = false ;
83+ this . duplicateCount = 0 ;
84+ this . election = null ;
85+ this . loading = false ;
86+ this . alert = null ;
87+ this . ballotsProcessed = null ;
88+ this . ballotsTotal = null ;
89+ this . success = false ;
90+ this . duplicateCount = 0 ;
91+ this . $nextTick ( ( ) => {
92+ this . resetFiles ( ) ;
93+ } ) ;
94+ } ,
95+ resetFiles : function ( ) {
96+ document . getElementById ( "deviceFile" ) . value = null ;
97+ document . getElementById ( "ballotsFolder" ) . value = null ;
98+ } ,
99+ } ,
100+ mounted ( ) {
101+ this . resetFiles ( ) ;
78102 } ,
79103 template : /*html*/ `
80104 <div v-if="alert" class="alert alert-danger" role="alert">
81105 {{ alert }}
82106 </div>
107+ <div v-if="duplicateCount" class="alert alert-warning" role="alert">
108+ {{ duplicateCount }} ballots were skipped because their object_ids had already been uploaded for this election.
109+ </div>
83110 <form id="mainForm" class="needs-validation" novalidate @submit.prevent="uploadBallots" v-if="!success">
84111 <div class="row g-3 align-items-center">
85112 <div class="col-12">
@@ -107,15 +134,17 @@ export default {
107134 <div class="invalid-feedback">Please provide a ballot folder.</div>
108135 </div>
109136 <div class="col-12 mt-4">
110- <button type="submit" :disabled="loading" class="btn btn-primary">Upload Ballots</button>
137+ <button type="submit" :disabled="loading" class="btn btn-primary me-2">Upload Ballots</button>
138+ <a :href="getElectionUrl()" class="btn btn-secondary me-2">Cancel</a>
111139 <spinner :visible="loading"></spinner>
112140 <p v-if="loading && ballotsProcessed">{{ ballotsProcessed }} of {{ ballotsTotal }} files processed.</p>
113141 </div>
114142 </form>
115143 <div v-if="success" class="text-center">
116144 <img src="/images/check.svg" width="200" height="200" class="mt-4 mb-2"></img>
117- <p>Successfully uploaded {{ballotsTotal}} ballots.</p>
118- <a :href="getElectionUrl()" class="btn btn-primary">Continue</a>
145+ <p>Successfully uploaded {{ballotsTotal-duplicateCount}} ballots.</p>
146+ <a :href="getElectionUrl()" class="btn btn-primary me-2">Done Uploading</a>
147+ <button type="button" @click="uploadMore()" class="btn btn-secondary">Upload More Ballots</button>
119148 </div>
120149 ` ,
121150} ;
0 commit comments