Advertisement
borsha06

l

May 8th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.     <v-ons-page>
  3.         <div class="test_body">
  4.             <v-ons-toolbar>
  5.                 <div class="center">{{this.$store.state.time.duration}} Minutes Exam</div>
  6.                 <div class="left">
  7.                     <v-ons-toolbar-button>
  8.                         <v-ons-icon icon="ion-navicon, material: md-menu"></v-ons-icon>
  9.                     </v-ons-toolbar-button>
  10.                 </div>
  11.             </v-ons-toolbar>
  12.             <div v-if="ques_index < questions.length">
  13.                 <v-ons-card class="test_card">
  14.  
  15.                     <div class="test_div"  v-for="(ques,index) in  questions">
  16.                         <div v-show="index === ques_index">
  17.                             <div class="title" align="center">
  18.  
  19.                                 <p  align="center" class="test_text"> {{ ques.question_text}}  </p>
  20.                             </div>
  21.                             <div class="content" >
  22.                                 <div align="center" id="donate" >
  23.  
  24.                                     <ul align="center" >
  25.                                         <li v-for="(choice) in ques.choices">
  26.                                             <label :for="choice.choice_id" class="yellow">
  27.                                                 <input class="button_none" type="radio"  @change="correct" :value="choice.is_right + '_' + choice.choice_id" :name="index" v-model=" userResponses[index] " :id="choice.choice_id" />
  28.                                                 <span>
  29.                                                 <strong>{{ choice.choice_text }} </strong>
  30.                                      </span>
  31.                                             </label>
  32.                                         </li>
  33.                                     </ul>
  34.  
  35.                                 </div>
  36.  
  37.                             </div>
  38.                             <!--<v-ons-button class="prev_next_button" align ="center" modifier="cta" style="margin: 6px 0; " @click="next()">-->
  39.                             <!--Skip-->
  40.                             <!--</v-ons-button>-->
  41.                         </div>
  42.                     </div>
  43.                 </v-ons-card>
  44.             </div>
  45.  
  46.             <div v-if="ques_index === questions.length" >
  47.                 <v-ons-card class="score">
  48.                     <div class="score_div">
  49.                         <i  class="fa fa-trophy"></i>
  50.                         <h2 class="score_head">
  51.                             Congratulations!
  52.                         </h2>
  53.                         <h3 class="score_text">You just Completed a Test</h3>
  54.                         SCORE: <p class="score_test" style="display:inline">  {{ score }} </p>  <p class="score_test2" style="display:inline"> /    {{ questions.length }}
  55.                     </p>
  56.                         <!---
  57.                                             <v-ons-button v-if="this.c >= parseInt((Math.ceil(questions.length * .4)))"  class="prev_next_button_score" modifier="cta" style="margin: 6px 0" @click="congratz">
  58.                                                 Next
  59.                                             </v-ons-button>
  60.                                             <v-ons-button v-else class="prev_next_button_score" style="margin: 6px 0" @click="pageStack.pop()">
  61.                                                 Test Again
  62.                                             </v-ons-button>
  63.                                             -->
  64.                     </div>
  65.                 </v-ons-card>
  66.             </div>
  67.             <footer>
  68.                 <div class="footer_test" >
  69.                     <div  align="center" class="timer" v-if="!timeStop">
  70.                         <i class="ion-ios-clock"></i>
  71.                         <div class="minutes" v-html="minutes"></div>
  72.                         <div class="seconds" id="seconds" v-html="secondsShown"></div>
  73.                     </div>
  74.                     <div align="center" class="timer" v-else>
  75.                         <i class="ion-ios-clock"></i>
  76.                         <div class="minutes" v-html="minutes"></div>
  77.                         <div class="seconds" v-html="secondsShown"></div>
  78.                     </div>
  79.                     <div  v-if="questions.length > ques_index" class="timer_button">
  80.                         <div  class="next_button" @click="next()">
  81.                             Next
  82.                         </div>
  83.                     </div>
  84.                     <div v-else class="timer_button">
  85.                         <div class="next_button" >
  86.                             Finished
  87.                         </div>
  88.                     </div>
  89.                 </div>
  90.  
  91.             </footer>
  92.         </div>
  93.     </v-ons-page>
  94. </template>
  95. <script>
  96.  
  97.  
  98.     //import 'babel-polyfill';
  99.  
  100.     export default {
  101.         data() {
  102.             return {
  103.                 minutes: this.$store.state.time.duration,
  104.                 seconds: 0,
  105.                 interval: null,
  106.                 started: true,
  107.                 ques_index: 0,
  108.                 questions: this.$store.state.exam.questions,
  109.                 userResponses: Array(this.$store.state.exam.questions.length),
  110.                 c: 0,
  111.                 count: 0,
  112.                 answered: 0,
  113.                 question_response:[]
  114.             }
  115.         },
  116.         mounted() {
  117.             this.loaded();
  118.         },
  119.         updated (){
  120.             this.timerOff();
  121.         },
  122.         methods: {
  123.  
  124.             congratz() {
  125.                 var that = this;
  126.                 this.$http({
  127.                     method: 'post',
  128.                     url: this.base_url + '/exam/api/' + this.$store.state.user.id + '/',
  129.  
  130.                     auth: {
  131.                         username: 'l360_mobile_app',
  132.                         password: 'itsd321#'
  133.                     },
  134.                     data: {
  135.                         "exam_id": this.$store.state.exam.exam_id,
  136.                         "started_at": this.$store.state.exam.started_at,
  137.                         "ended_at": this.$store.state.exam.ended_at,
  138.                         "question_answered": this.answered,
  139.                         "ans_right": this.c,
  140.                         "ans_wrong": this.$store.state.exam.questions.length - this.c,
  141.                         "mark_received": this.c,
  142.                         //"question_response":this.object,
  143.                     }
  144.  
  145.                 }).then(res => {
  146.                     console.log(res);
  147.                     console.log("hello "+ data.question_answered);
  148.                     console.log(this.$store.state.exam.exam_id);
  149.                 }).catch(err => {
  150.                     console.log(err.details);
  151.                 })
  152.                 // this.pageStack.push(congratz)
  153.             },
  154.  
  155.             next() {
  156.                 this.ques_index++;
  157.  
  158.                 var time = new Date()
  159.                 if (this.$store.state.exam.questions.length === this.ques_index) {
  160.                     var exam = {
  161.                         ended_at: time.getHours() + 'h:' + time.getMinutes() + 'm:' + time.getSeconds() + 's',
  162.                     }
  163.  
  164.                     this.$store.commit('questionInfo', exam)
  165.                 }
  166.  
  167.             },
  168.             prev() {
  169.                 this.ques_index--;
  170.                 this.progress--;
  171.             },
  172.  
  173.  
  174.             loaded() {
  175.                 var that = this;
  176.                 that.interval = setInterval(that.intervalCallback.bind(that), 1000)
  177.             },
  178.             intervalCallback() {
  179.                 if (!this.started) return false
  180.                 if (this.seconds === 0) {
  181.                     if (this.minutes === 0) {
  182.                         return null
  183.                     }
  184.                     this.seconds = 59
  185.                     this.minutes--
  186.                 } else {
  187.                     this.seconds--
  188.                 }
  189.             },
  190.  
  191.  
  192.             correct: function () {
  193.                 var that = this;
  194.                 setTimeout(function(){
  195.                     alert(that.userResponses[that.ques_index]);
  196.  
  197.                     // Rofi's code start
  198.                     var object = {"question_id": "", "correct_ans": ""};
  199.                     object.question_id = that.questions[that.ques_index].question_id;
  200.                     if(that.userResponses[that.ques_index][0] === 't') {
  201.                         object.correct_ans = true;
  202.                     }
  203.                     else {
  204.                         object.correct_ans = false;
  205.                     }
  206.                     that.question_response.push(object);
  207.  
  208.                     // Rofi's code end
  209.  
  210.                     if (that.userResponses[that.ques_index]) {
  211.                         that.ques_index++;
  212.                         console.log(that.ques_index);
  213.                     }
  214.                     that.answered = that.userResponses.filter(ur => (ur[0] === 't'|| ur[0] === 'f')).length;
  215.                     console.log(that.answered);
  216.                     return this.answered;
  217.                 },1000)
  218.                 //ls
  219.                 //that.question_response.ques_id = this.response.data.question_id;
  220.                // console.log(that.question_response);
  221.                 alert(this.question_response);
  222.             },
  223.             timerOff: function (){
  224.                 if ( this.minutes === 0 && this.seconds === 0 )
  225.                 {
  226.  
  227.                     this.ques_index = this.questions.length;
  228.                 }
  229.             },
  230.             complete_test: function () {
  231.                 this.completed=false;
  232.                 alert("clicked");
  233.                 var info =
  234.                     { questions: this.questions,
  235.                         ques_index: this.ques_index,
  236.                         minutes: this.minutes
  237.  
  238.                     }
  239.  
  240.                 localStorage.setItem('ke', JSON.stringify(info));
  241.                 const val= JSON.parse(localStorage.getItem('ke'));
  242.  
  243.                 console.log((val) + "hh");
  244.                 this.page = this.pageStack.length;
  245.                 for (this.i = 1; this.i < this.page; this.i++) {
  246.                     this.pageStack.pop()
  247.                 }
  248.  
  249.  
  250.             }
  251.  
  252.  
  253.         },
  254.         computed: {
  255.             secondsShown: function () {
  256.                 if (this.seconds < 10) {
  257.                     return "0" + parseInt(this.seconds, 10)
  258.                 }
  259.  
  260.                 return this.seconds
  261.             },
  262.             timeStop: function () {
  263.                 if (this.ques_index === this.questions.length) {
  264.                     this.started = false;
  265.                     return this.seconds;
  266.                 }
  267.             },
  268.             score: function () {
  269.  
  270.  
  271.                 this.c = this.userResponses.filter(val => (val[0]==='t')).length;
  272.  
  273.                 return this.c;
  274.             },
  275.  
  276.  
  277.  
  278.         },
  279.         props: ['pageStack']
  280.     }
  281. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement