ali 2 лет назад
Родитель
Сommit
91a78bea2f

+ 15 - 0
src/api/models/AnswerBook.js

@@ -8,6 +8,7 @@ export default class AnswerBookAPI extends APIRepository {
     this.APIAdresses = {
       base: '/lma/answer_books',
       byId: (id) => '/lma/answer_books/' + id,
+      confirmAnswers: (id) => '/lma/answer_books/' + id + '/confirm_answers',
       getTestQuestions: (id) => '/lma/answer_books/' + id + '/get_test_questions',
       submitOverallAnswer: (id) => '/lma/answer_books/' + id + '/submit_overall_answer'
     }
@@ -87,4 +88,18 @@ export default class AnswerBookAPI extends APIRepository {
       }
     })
   }
+
+  confirmAnswers (id) {
+    return this.sendRequest({
+      apiMethod: 'put',
+      api: this.api,
+      request: this.APIAdresses.confirmAnswers(id),
+      resolveCallback: (response) => {
+        return new AnswerBook(response.data)
+      },
+      rejectCallback: (error) => {
+        return error
+      }
+    })
+  }
 }

+ 2 - 3
src/components/Widgets/Test/TestParticipation/TestParticipation.vue

@@ -30,9 +30,9 @@
       <template v-if="mounted">
         <all-questions v-if="$route.name === 'UserPanel.Test.AnswerBook.Participate.AllQuestions'"
                        :answer-book="answerBook"
+                       @sentsuccess="onAllQuestionsSentSuccess"
                        @sending="onAllQuestionsSending"
-                       @sentSuccess="onAllQuestionsSentSuccess"
-                       @sentFailed="onAllQuestionsSentFailed" />
+                       @sentfailed="onAllQuestionsSentFailed" />
         <single-question v-else-if="$route.name === 'UserPanel.Test.AnswerBook.Participate.SingleQuestion'"
                          :answer-book="answerBook"
                          :question-number="parseInt($route.params.question_number)"
@@ -133,7 +133,6 @@ export default {
     },
     onAllQuestionsSentSuccess () {
       this.answerBook.loading = false
-      this.backToClassList()
     },
     onAllQuestionsSentFailed () {
       this.answerBook.loading = false

+ 17 - 3
src/components/Widgets/Test/TestParticipation/components/AllQuestions.vue

@@ -48,7 +48,7 @@ export default {
       default: new AnswerBook()
     }
   },
-  emits: ['sending', 'sentSuccess', 'sentFailed'],
+  emits: ['sending', 'sentsuccess', 'sentfailed'],
   data () {
     return {
       mounted: false,
@@ -84,10 +84,24 @@ export default {
       this.$emit('sending')
       this.$refs.entityCreate.createEntity(false)
         .then(() => {
-          this.$emit('sentSuccess')
+          APIGateway.answerBook.confirmAnswers(this.answerBook.id)
+            .then(() => {
+              this.$emit('sentsuccess')
+              this.$router.push({
+                name: 'UserPanel.Test.AnswerBook.Participate.SingleQuestion',
+                params: {
+                  test_id: this.$route.params.test_id,
+                  answer_book_id: this.$route.params.answer_book_id,
+                  question_number: 'complete'
+                }
+              })
+            })
+            .catch(() => {
+              this.$emit('sentfailed')
+            })
         })
         .catch(() => {
-          this.$emit('sentFailed')
+          this.$emit('sentfailed')
         })
     }
   }

+ 25 - 8
src/components/Widgets/Test/TestParticipation/components/SingleQuestion.vue

@@ -83,7 +83,8 @@ export default {
       return this.answerBook.test_info.test_set_info.test_set_questions.length === this.questionNumber
     },
     question () {
-      return this.answerBook.test_info.test_set_info.test_set_questions[this.questionNumber - 1]
+      // return this.answerBook.test_info.test_set_info.test_set_questions[this.questionNumber - 1]
+      return this.answerBook.answer_sheet_info.list[this.questionNumber - 1].test_set_question_info.question_info
     }
   },
   mounted () {
@@ -111,6 +112,10 @@ export default {
         FormBuilderAssist.setAttributeByName(this.inputs, 'btnNext', 'col', 'col-12 flex justify-end')
       }
 
+      const questionIndex = this.questionNumber - 1
+      FormBuilderAssist.setAttributeByName(this.inputs, 'answer_text', 'value', this.answerBook.answer_sheet_info.list[questionIndex].answer_text)
+      FormBuilderAssist.setAttributeByName(this.inputs, 'answer_attachment', 'value', this.answerBook.answer_sheet_info.list[questionIndex].answer_attachment)
+
       FormBuilderAssist.setAttributeByName(this.inputs, 'btnFinal', 'atClick', () => { this.sendAnswer('final') })
       FormBuilderAssist.setAttributeByName(this.inputs, 'btnNext', 'atClick', () => { this.sendAnswer('next') })
       FormBuilderAssist.setAttributeByName(this.inputs, 'btnPrev', 'atClick', () => { this.sendAnswer('prev') })
@@ -128,7 +133,13 @@ export default {
 
       this.$emit('sending')
       this.$refs.entityCreate.createEntity(false)
-        .then(() => {
+        .then((response) => {
+          const answerBook = this.answerBook
+          const questionIndex = this.questionNumber - 1
+          answerBook.answer_sheet_info.list[questionIndex].answer_text = response.data.answer_text
+          answerBook.answer_sheet_info.list[questionIndex].answer_attachment = response.data.answer_attachment
+          this.$store.commit('Test/updateAnswerBook', answerBook)
+
           this.$emit('sentSuccess', actionType)
           if (actionType === 'next') {
             this.goToQuestion(this.questionNumber + 1)
@@ -137,12 +148,18 @@ export default {
             this.goToQuestion(this.questionNumber - 1)
           }
           if (actionType === 'final') {
-            this.$q.notify({
-              message: 'پاسخ شما با موفقیت ارسال شد.',
-              type: 'positive'
-            })
-            // this.$router.push({ name: 'UserPanel.Profile.AllClassrooms' })
-            this.goToQuestion('complete')
+            APIGateway.answerBook.confirmAnswers(this.answerBook.id)
+              .then(() => {
+                this.$q.notify({
+                  message: 'پاسخ شما با موفقیت ارسال شد.',
+                  type: 'positive'
+                })
+                // this.$router.push({ name: 'UserPanel.Profile.AllClassrooms' })
+                this.goToQuestion('complete')
+              })
+              .catch(() => {
+                this.$emit('sentfailed')
+              })
           }
         })
         .catch(() => {

+ 5 - 1
src/models/AnswerSheet.js

@@ -1,4 +1,5 @@
 import { Collection, Model } from 'js-abstract-model'
+import { TestSetQuestion } from 'src/models/TestSetQuestion.js'
 
 class AnswerSheet extends Model {
   constructor (data) {
@@ -8,7 +9,10 @@ class AnswerSheet extends Model {
       { key: 'answer_attachment' },
       { key: 'score' },
       { key: 'test_set_question' },
-      { key: 'test_set_question_info' }
+      {
+        key: 'test_set_question_info',
+        relatedModel: TestSetQuestion
+      }
     ])
   }
 }

+ 25 - 0
src/models/TestSetQuestion.js

@@ -0,0 +1,25 @@
+import { Collection, Model } from 'js-abstract-model'
+import { Question } from 'src/models/Question.js'
+
+class TestSetQuestion extends Model {
+  constructor (data) {
+    super(data, [
+      { key: 'id' },
+      { key: 'is_extra_mark' },
+      { key: 'mark' },
+      { key: 'question' },
+      {
+        key: 'question_info',
+        relatedModel: Question
+      }
+    ])
+  }
+}
+
+class TestSetQuestionList extends Collection {
+  model () {
+    return TestSetQuestion
+  }
+}
+
+export { TestSetQuestion, TestSetQuestionList }