Advertisement
borsha06

l360

May 8th, 2018
146
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.                     { isTrue:''}
  115.                     ]
  116.  
  117.  
  118.             }
  119.         },
  120.         mounted() {
  121.             this.loaded();
  122.         },
  123.         updated (){
  124.             this.timerOff();
  125.         },
  126.         methods: {
  127.  
  128.             congratz() {
  129.                 var that = this;
  130.                 this.$http({
  131.                     method: 'post',
  132.                     url: this.base_url + '/exam/api/' + this.$store.state.user.id + '/',
  133.  
  134.                     auth: {
  135.                         username: 'l360_mobile_app',
  136.                         password: 'itsd321#'
  137.                     },
  138.                     data: {
  139.                         "exam_id": this.$store.state.exam.exam_id,
  140.                         "started_at": this.$store.state.exam.started_at,
  141.                         "ended_at": this.$store.state.exam.ended_at,
  142.                         "question_answered": this.answered,
  143.                         "ans_right": this.c,
  144.                         "ans_wrong": this.$store.state.exam.questions.length - this.c,
  145.                         "mark_received": this.c
  146.                     }
  147.  
  148.                 }).then(res => {
  149.                     console.log(res);
  150.                     console.log("hello "+ data.question_answered);
  151.                     console.log(this.$store.state.exam.exam_id);
  152.                 }).catch(err => {
  153.                     console.log(err.details);
  154.                 })
  155.                // this.pageStack.push(congratz)
  156.             },
  157.  
  158.             next() {
  159.                 this.ques_index++;
  160.  
  161.                 var time = new Date()
  162.                 if (this.$store.state.exam.questions.length === this.ques_index) {
  163.                     var exam = {
  164.                         ended_at: time.getHours() + 'h:' + time.getMinutes() + 'm:' + time.getSeconds() + 's',
  165.                     }
  166.  
  167.                     this.$store.commit('questionInfo', exam)
  168.                 }
  169.  
  170.             },
  171.             prev() {
  172.                 this.ques_index--;
  173.                 this.progress--;
  174.             },
  175.  
  176.  
  177.             loaded() {
  178.                 var that = this;
  179.                 that.interval = setInterval(that.intervalCallback.bind(that), 1000)
  180.             },
  181.             intervalCallback() {
  182.                 if (!this.started) return false
  183.                 if (this.seconds === 0) {
  184.                     if (this.minutes === 0) {
  185.                         return null
  186.                     }
  187.                     this.seconds = 59
  188.                     this.minutes--
  189.                 } else {
  190.                     this.seconds--
  191.                 }
  192.             },
  193.  
  194.  
  195.             correct: function () {
  196.                 var that = this;
  197.                 setTimeout(function(){
  198.                     alert(that.userResponses[that.ques_index]);
  199.                     that.question_response.isTrue = that.userResponses[that.ques_index];
  200.                     if (that.userResponses[that.ques_index]) {
  201.                         that.ques_index++;
  202.  
  203.                         console.log(that.ques_index);
  204.                     }
  205.                     that.answered = that.userResponses.filter(ur => (ur[0] === 't'|| ur[0] === 'f')).length;
  206.                     console.log(that.answered);
  207.                     return this.answered;
  208.                 },1000)
  209.                 //ls
  210.                //that.question_response.ques_id = this.response.data.question_id;
  211.                 console.log(that.question_response);
  212.             },
  213.             timerOff: function (){
  214.                 if ( this.minutes === 0 && this.seconds === 0 )
  215.                 {
  216.  
  217.                     this.ques_index = this.questions.length;
  218.                 }
  219.             },
  220.             complete_test: function () {
  221.                 this.completed=false;
  222.                 alert("clicked");
  223.                 var info =
  224.                     { questions: this.questions,
  225.                         ques_index: this.ques_index,
  226.                         minutes: this.minutes
  227.  
  228.                     }
  229.  
  230.                 localStorage.setItem('ke', JSON.stringify(info));
  231.                 const val= JSON.parse(localStorage.getItem('ke'));
  232.  
  233.                 console.log((val) + "hh");
  234.                 this.page = this.pageStack.length;
  235.                 for (this.i = 1; this.i < this.page; this.i++) {
  236.                     this.pageStack.pop()
  237.                 }
  238.  
  239.  
  240.             }
  241.  
  242.  
  243.         },
  244.         computed: {
  245.             secondsShown: function () {
  246.                 if (this.seconds < 10) {
  247.                     return "0" + parseInt(this.seconds, 10)
  248.                 }
  249.  
  250.                 return this.seconds
  251.             },
  252.             timeStop: function () {
  253.                 if (this.ques_index === this.questions.length) {
  254.                     this.started = false;
  255.                     return this.seconds;
  256.                 }
  257.             },
  258.             score: function () {
  259.  
  260.  
  261.                 this.c = this.userResponses.filter(val => (val[0]==='t')).length;
  262.  
  263.                 return this.c;
  264.             },
  265.  
  266.  
  267.  
  268.         },
  269.         props: ['pageStack']
  270.     }
  271. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement