ali 2 سال پیش
والد
کامیت
0ba049b401

+ 33 - 20
src/components/FormBuilderCustumComponents/QuestionChoices/ChoicesItem.vue

@@ -1,24 +1,29 @@
 <template>
   <div class="ChoicesItem">
-    <div class="title">
-      <q-input v-model="choiceText"
-               class="full-width"
-               type="textarea"
-               @update:model-value="onChangeChoiceText" />
-    </div>
-    <div class="actions">
-      <q-btn icon="edit"
-             outline
-             class="viewBtn"
-             color="primary"
-             @click="onEdit" />
-      <q-btn v-if="canDelete"
-             class="deleteBtn"
-             icon="delete"
-             outline
-             color="red"
-             @click="onDelete" />
-    </div>
+    <template v-if="canEdit || canDelete">
+      <div class="title">
+        <q-input v-model="choiceText"
+                 class="full-width"
+                 type="textarea"
+                 @update:model-value="onChangeChoiceText" />
+      </div>
+      <div class="actions">
+        <q-btn v-if="canEdit"
+               icon="edit"
+               outline
+               class="viewBtn"
+               color="primary"
+               @click="onEdit" />
+        <q-btn v-if="canDelete"
+               class="deleteBtn"
+               icon="delete"
+               outline
+               color="red"
+               @click="onDelete" />
+      </div>
+    </template>
+    <div v-else
+         v-html="choiceText" />
   </div>
 </template>
 
@@ -32,6 +37,10 @@ export default {
       type: QuestionChoice,
       default: new QuestionChoice()
     },
+    canEdit: {
+      type: Boolean,
+      default: true
+    },
     canDelete: {
       type: Boolean,
       default: true
@@ -45,7 +54,11 @@ export default {
     }
   },
   mounted() {
-    this.choiceText = this.choice.text.replace(/<br>/g, '\n')
+    if (this.canEdit || this.canDelete) {
+      this.choiceText = this.choice.text.replace(/<br>/g, '\n')
+    } else {
+      this.choiceText = this.choice.text.replace(/\n/g, '<br>')
+    }
   },
   methods: {
     onChangeChoiceText () {

+ 28 - 1
src/components/FormBuilderCustumComponents/QuestionChoices/QuestionChoices.vue

@@ -32,6 +32,7 @@
       </div>
       <div class="choice-item-component">
         <choices-item :choice="choice"
+                      :can-edit="canEdit"
                       :can-delete="canDelete"
                       @onEdit="onEdit(choice)"
                       @onDelete="onDelete(choice)" />
@@ -55,6 +56,10 @@ export default {
       default: () => [],
       type: [Array, String, Number, Boolean]
     },
+    choicesInfo: {
+      default: () => [],
+      type: [Array, String, Number, Boolean]
+    },
     correctChoiceIndex: {
       default: 0,
       type: Number
@@ -63,6 +68,14 @@ export default {
       default: false,
       type: Boolean
     },
+    participateMode: {
+      type: Boolean,
+      default: false
+    },
+    canEdit: {
+      type: Boolean,
+      default: true
+    },
     canDelete: {
       type: Boolean,
       default: true
@@ -106,6 +119,11 @@ export default {
   watch: {
     value: {
       handler () {
+        if (this.participateMode) {
+          this.localCorrectChoiceIndex = this.value
+          return
+        }
+
         this.inputData = this.value
         if (this.value.length > 0 && this.value[0].id) {
           this.choices = new QuestionChoiceList(this.value)
@@ -119,9 +137,14 @@ export default {
     }
   },
   created () {
+    this.choices = new QuestionChoiceList(this.choicesInfo)
     FormBuilderAssist.setAttributeByName(this.inputs, 'source_type', 'value', this.sourceType)
     this.inputData = this.value
-    this.localCorrectChoiceIndex = this.correctChoiceIndex
+    if (this.participateMode) {
+      this.localCorrectChoiceIndex = this.value || 0
+    } else {
+      this.localCorrectChoiceIndex = this.correctChoiceIndex
+    }
   },
   methods: {
     emitValue (value) {
@@ -129,6 +152,9 @@ export default {
     },
     onChangeCorrectChoiceIndex () {
       // this.$emit('update:correctChoiceIndex', this.localCorrectChoiceIndex)
+      if (this.participateMode) {
+        this.emitValue(this.localCorrectChoiceIndex)
+      }
       this.$bus.emit('onChangeCorrectChoiceIndexInQuestionChoicesInput', this.localCorrectChoiceIndex)
     },
     onEdit (choice) {
@@ -181,6 +207,7 @@ export default {
   width: 100%;
   .choice-item {
     display: flex;
+    margin-top: 16px;
     .choice-item-radio {
       width: 60px;
     }

+ 2 - 2
src/components/Widgets/Classroom/AdminClassroomAnswerBookList/AdminClassroomAnswerBookList.vue

@@ -32,8 +32,8 @@
           <div class="action-column-entity-index">
             <q-btn size="md"
                    color="primary"
-                   :label="inputData.props.row.grader ? 'ویرایش تصحیح' : 'تصحیح آزمون'"
-                   :to="{name: 'Admin.Classroom.Test.AnswerBooks.ShowGrade', params: {classroom_id: $route.params.classroom_id, test_id: $route.params.test_id, answer_book_id: inputData.props.row.id}}"
+                   :label="$route.query.classroom_type === 'EVENT' ? 'مشاهده پرسشنامه' : inputData.props.row.grader ? 'ویرایش تصحیح' : 'تصحیح آزمون'"
+                   :to="{name: 'Admin.Classroom.Test.AnswerBooks.ShowGrade', params: {classroom_id: $route.params.classroom_id, test_id: $route.params.test_id, answer_book_id: inputData.props.row.id}, query: { classroom_type: $route.query.classroom_type}}"
                    class="q-mr-md" />
           </div>
         </template>

+ 27 - 3
src/components/Widgets/Other/Shop/ShopCompleteInfo/components/AllQuestions.vue

@@ -70,8 +70,10 @@ import { APIGateway } from 'src/api/APIGateway.js'
 import { AnswerBook } from 'src/models/AnswerBook.js'
 import BtnControl from 'src/components/Control/btn.vue'
 import { FormBuilderAssist } from 'quasar-form-builder'
+import QuestionChoices from 'src/components/FormBuilderCustumComponents/QuestionChoices/QuestionChoices.vue'
 
 const BtnControlComp = shallowRef(BtnControl)
+const QuestionChoicesComp = shallowRef(QuestionChoices)
 
 export default {
   name: 'AllQuestions',
@@ -101,7 +103,8 @@ export default {
     },
     setInputs () {
       this.answerBook.answer_sheet_info.list.forEach((answerSheetItem, answerSheetIndex) => {
-        this.questionInputs.push([
+        const hasChoise = Array.isArray(answerSheetItem.test_question_info.question_info.choices) && answerSheetItem.test_question_info.question_info.choices.length > 0
+        const inputs = [
           { type: 'input', name: 'answer_text', label: 'متن پاسخ', placeholder: ' ', value: answerSheetItem.answer_text, inputType: 'textarea', col: 'col-12' },
           { type: 'file', name: 'answer_attachment', label: 'فایل پیوست', placeholder: ' ', value: answerSheetItem.answer_attachment, col: 'col-12' },
           { type: 'hidden', name: 'answer_book', value: this.answerBook.id },
@@ -114,7 +117,7 @@ export default {
             placeholder: ' ',
             atClick: () => {
               const answerText = FormBuilderAssist.getInputsByName(this.questionInputs[answerSheetIndex], 'answer_text').value
-              if (!answerText) {
+              if (!answerText && !hasChoise) {
                 this.$q.notify({
                   type: 'negative',
                   message: 'لطفا متن پاسخ را کامل کنید.'
@@ -138,7 +141,28 @@ export default {
             },
             col: 'col-12 flex justify-end'
           }
-        ])
+        ]
+
+        if (hasChoise) {
+          inputs[0].type = 'hidden'
+          inputs[0].value = null
+          inputs[1].type = 'hidden'
+          inputs[1].value = null
+          inputs.splice(2, 0,
+            {
+              type: QuestionChoicesComp,
+              name: 'answer_choice_index',
+              participateMode: true,
+              canAddChoice: false,
+              canEdit: false,
+              canDelete: false,
+              choicesInfo: answerSheetItem.test_question_info.question_info.choices_info,
+              value: isNaN(answerSheetItem.answer_choice_index) ? 0 : parseInt(answerSheetItem.answer_choice_index),
+              col: 'col-12 flex justify-end'
+            })
+        }
+
+        this.questionInputs.push(inputs)
       })
     },
     confirmAnswers () {

+ 19 - 3
src/components/Widgets/Test/AdminAnswerBookShow/AdminAnswerBookShow.vue

@@ -49,10 +49,25 @@
                 :key="answerSheetIndex"
                 clickable>
           <div class="row full-width q-col-gutter-md">
-            <div class="col-md-10 col-12">
+            <div class="col-12"
+                 :class="{'col-md-10': $route.query.classroom_type !== 'EVENT'}">
               <div v-html="'<span>' + (answerSheetIndex + 1) + ' - </span>' + answerSheet.test_question_info.question_info.text" />
               <q-card class="q-mt-sm">
-                <q-card-section>
+                <q-card-section v-if="Array.isArray(answerSheet.test_question_info.question_info.choices_info) && answerSheet.test_question_info.question_info.choices_info.length > 0">
+                  <div v-for="(choice, choiceIndex) in answerSheet.test_question_info.question_info.choices_info"
+                       :key="choiceIndex">
+                    <q-banner>
+                      <template v-slot:avatar>
+                        <q-icon :name="answerSheet.answer_choice_index === choiceIndex ? 'check_box' : 'check_box_outline_blank'"
+                                size="sm"
+                                color="primary" />
+                      </template>
+                      <div v-html="choice.text.replace(/\n/g, '<br>')" />
+                    </q-banner>
+                    <q-separator />
+                  </div>
+                </q-card-section>
+                <q-card-section v-else>
                   <div>
                     متن پاسخ:
                   </div>
@@ -71,7 +86,8 @@
                 </q-card-section>
               </q-card>
             </div>
-            <div class="col-md-2 col-12">
+            <div v-if="$route.query.classroom_type !== 'EVENT'"
+                 class="col-md-2 col-12">
               <q-badge v-if="answerSheet.score !== null">
                 {{ answerSheet.score }}
                 از

+ 1 - 0
src/models/AnswerSheet.js

@@ -7,6 +7,7 @@ class AnswerSheet extends Model {
       { key: 'id' },
       { key: 'answer_text' },
       { key: 'answer_attachment' },
+      { key: 'answer_choice_index' },
       { key: 'score' },
       { key: 'test_question' },
       {

+ 8 - 1
src/models/Question.js

@@ -9,7 +9,14 @@ class Question extends Model {
       { key: 'mark' },
       { key: 'level' },
       { key: 'model_type' },
-      { key: 'choices' },
+      {
+        key: 'choices',
+        default: []
+      },
+      {
+        key: 'choices_info',
+        default: []
+      },
       { key: 'correct_choice_index' },
       {
         key: 'type',