Explorar o código

fix calculate remaining time of test

ali %!s(int64=2) %!d(string=hai) anos
pai
achega
b5990eed6e

+ 8 - 10
src/components/Widgets/Test/TestParticipation/TestParticipation.vue

@@ -119,9 +119,6 @@ export default {
       return formattedHours + ':' + formattedMinutes + ':' + formattedSeconds
     }
   },
-  beforeUnmount() {
-    this.$store.commit('Test/updateAnswerBook', null)
-  },
   mounted () {
     // this.getAnswerBook()
     this.getTestQuestions()
@@ -177,6 +174,8 @@ export default {
           this.stopTimer()
         } else {
           this.remainingTime--
+          this.answerBook.remainingTime = this.remainingTime
+          this.$store.commit('Test/updateAnswerBook', this.answerBook)
         }
       }, 1000)
     },
@@ -209,21 +208,20 @@ export default {
           this.backToClassList()
         })
     },
-    initPageFromAnswerBook (answerBook) {
+    initPageFromAnswerBook (answerBook, setRemainingTime = true) {
       this.answerBook = new AnswerBook(answerBook)
       this.answerBook.loading = false
-      // this.answerBook.server_time = '2023-12-15T23:57:46.909211'
-      // this.answerBook.server_time = '2023-12-20T07:08:42.923512'
-      // this.answerBook.attending_start_time = '2023-12-15T23:27:46.909211'
-      // this.answerBook.attending_start_time = '2023-12-19T21:22:14.384151'
-      this.remainingTime = this.getRemainingTimeInSeconds(this.answerBook.server_time, this.answerBook.attending_start_time, this.answerBook.duration)
+      if (this.answerBook.remainingTime === null) {
+        this.answerBook.remainingTime = this.getRemainingTimeInSeconds(this.answerBook.server_time, this.answerBook.attending_start_time, this.answerBook.duration)
+      }
+      this.remainingTime = this.answerBook.remainingTime
       this.$store.commit('Test/updateAnswerBook', this.answerBook)
       this.startTimer()
     },
     getTestQuestions () {
       this.loadAnswerBookFromStore()
       if (this.storeAnswerBook && this.storeAnswerBook.id) {
-        this.initPageFromAnswerBook(this.storeAnswerBook)
+        this.initPageFromAnswerBook(this.storeAnswerBook, false)
         return
       }
       this.answerBook.loading = true

+ 1 - 0
src/models/AnswerBook.js

@@ -47,6 +47,7 @@ class AnswerBook extends Model {
       { key: 'server_time' },
       { key: 'attending_start_time' },
       { key: 'status' },
+      { key: 'remainingTime' },
       {
         key: 'is_enabled_attending',
         default: false