Guest User

Untitled

a guest
Mar 6th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.17 KB | None | 0 0
  1. <template>
  2. <v-ons-page>
  3. <div class="test_body">
  4.  
  5. <v-ons-card class="test_card">
  6.  
  7. <div class="timer" v-if="!timeStop">
  8.  
  9. <div class="minutes" v-text="this.data.minutes"></div>
  10. <div class="seconds" id="seconds" v-text="secondsShown"></div>
  11. </div>
  12. <div class="timer" v-else>
  13. <div class="minutes" v-text="this.data.minutes"></div>
  14. <div class="seconds" v-text="secondsShown"></div>
  15. </div>
  16.  
  17.  
  18. <div v-for="(ques,index) in questions">
  19. <div v-show="index===ques_index">
  20. <p class="test_text">{{ ques.question_text }} </p>
  21.  
  22. <ol align="left">
  23. <li class="test_list" v-for="choice in ques.choices">
  24.  
  25. <input type="radio" v-bind:value="choice.is_right" v-bind:name="index"
  26. v-model=" userResponses[index] "> {{ choice.choice_text }}
  27.  
  28. </li>
  29.  
  30. </ol>
  31.  
  32.  
  33. <p class="test_number" align="right">{{index+1}} /{{questions.length}} </p>
  34. <v-ons-button class="prev_next_button" modifier="cta" style="margin: 6px 0"
  35. v-if="ques_index > 0" @click="prev">
  36. Prev
  37. </v-ons-button>
  38.  
  39. <v-ons-button class="prev_next_button" modifier="cta" style="margin: 6px 0" @click="next">
  40. Next
  41. </v-ons-button>
  42. </div>
  43. </div>
  44.  
  45.  
  46. <div v-show="ques_index === questions.length">
  47.  
  48. <h2>
  49. Quiz finished
  50. </h2>
  51. <p>
  52. Total score: {{ score() }} / {{ questions.length }}
  53. </p>
  54.  
  55. <v-ons-button class="prev_next_button" modifier="cta" style="margin: 6px 0" @click="congratz">
  56. Congratulation
  57. </v-ons-button>
  58. </div>
  59.  
  60.  
  61. </v-ons-card>
  62.  
  63.  
  64. </div>
  65. </v-ons-page>
  66. </template>
  67. <script>
  68. import swal from 'sweetalert';
  69. import congratz from './congratulation';
  70.  
  71. export default {
  72. data() {
  73. return {
  74. minute: 0,
  75. seconds: 0,
  76. interval: null,
  77. started: true,
  78. questions: {},
  79. ques_index: 0,
  80. userResponses: [],
  81.  
  82. }
  83. },
  84. beforeMount() {
  85. this.question();
  86. },
  87. mounted() {
  88.  
  89. this.loaded()
  90.  
  91. },
  92. methods: {
  93. congratz() {
  94. swal({
  95. text: "Congratulation on Your First Exam!",
  96. });
  97. this.pageStack.push(congratz)
  98. },
  99. question() {
  100. this.$http({
  101. method: 'post',
  102. url: this.base_url + '/exam/api/',
  103. auth: {
  104. username: 'l360_mobile_app',
  105. password: 'itsd321#'
  106. },
  107. data: {
  108. "id": this.$store.state.user.id,
  109. "duration": this.data.minutes
  110. }
  111. }).then((response) => {
  112. //alert(response.data.questions[0].question_text);
  113. //var questions = [];
  114. this.questions = response.data.questions;
  115. })
  116. .catch((error) => {
  117. // alert(error);
  118. });
  119. },
  120. next: function () {
  121. this.ques_index++;
  122. },
  123. prev: function () {
  124. this.ques_index--;
  125. },
  126. score() {
  127. var c = 0;
  128. for (var i = 0; i < this.userResponses.length; i++)
  129. if (this.userResponses[i])
  130. c++;
  131. return c;
  132.  
  133. },
  134. loaded: function () {
  135. this.interval = setInterval(this.intervalCallback, 1000)
  136. },
  137. intervalCallback: function () {
  138. if (!this.started) return false
  139. if (this.seconds == 0) {
  140. if (this.data.minutes == 0) {
  141. return null
  142. }
  143. this.seconds = 59
  144. this.data.minutes--
  145. } else {
  146. this.seconds--
  147. }
  148. },
  149. },
  150. computed: {
  151. secondsShown: function () {
  152. if (this.seconds < 10) {
  153. return "0" + parseInt(this.seconds, 10)
  154. }
  155. return this.seconds
  156. },
  157. timeStop: function () {
  158. if (this.ques_index === this.questions.length) {
  159. this.started = false;
  160. return this.seconds;
  161. }
  162. }
  163. },
  164. props: ['pageStack']
  165. }
  166. </script>
  167. <style>
  168. </style>
Add Comment
Please, Sign In to add comment