ExperimentValidated.vue 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <div>
  3. <h2>"{{ experimentFullName }}"</h2>
  4. <v-card>
  5. <v-card-title primary-title>
  6. <v-spacer />
  7. <div class="headline">Experiment validated for the scene "{{ sceneName }}"</div>
  8. <v-spacer />
  9. </v-card-title>
  10. <v-card-actions>
  11. <v-spacer />
  12. <!-- <v-btn flat exact to="/experiments/">
  13. <v-icon left>home</v-icon>
  14. Select another experiment
  15. </v-btn>
  16. <v-btn flat exact :to="`/experiments/${experimentName}`">
  17. <v-icon left>arrow_back</v-icon>
  18. Go back to scene selection
  19. </v-btn> -->
  20. <v-btn v-if="hasScenesLeft" flat exact :to="`/experiments/${experimentName}/${getRandomScene}`">
  21. <v-icon left>shuffle</v-icon>
  22. Continue with a random scene
  23. </v-btn>
  24. <div v-if="!hasScenesLeft" class="headline">You finished all the scenes, thanks for your contribution!</div>
  25. <v-spacer />
  26. </v-card-actions>
  27. </v-card>
  28. </div>
  29. </template>
  30. <script>
  31. import { mapActions, mapGetters } from 'vuex'
  32. import Experiments from '@/router/experiments'
  33. import { getExperimentSceneList } from '@/config.utils'
  34. import { rand } from '@/functions'
  35. export default {
  36. name: 'ExperimentValidated',
  37. props: {
  38. experimentName: {
  39. type: String,
  40. required: true
  41. },
  42. sceneName: {
  43. type: String,
  44. required: true
  45. }
  46. },
  47. data() {
  48. return {
  49. experimentFullName: null,
  50. availableScenes: []
  51. }
  52. },
  53. computed: {
  54. ...mapGetters(['getAllExperimentProgress']),
  55. ...mapActions(['loadScenesList']),
  56. hasScenesLeft() {
  57. return this.availableScenes.length > 0
  58. },
  59. getRandomScene() {
  60. return this.availableScenes[rand(0, this.availableScenes.length - 1)]
  61. }
  62. },
  63. async mounted() {
  64. // reload scene list to update
  65. await this.loadScenesList
  66. const scenesList = getExperimentSceneList(this.experimentName)
  67. // load current user progression
  68. this.progression = this.getAllExperimentProgress()
  69. // Find the selected experiment full name
  70. this.experimentFullName = Experiments.find(x => x.name === this.experimentName).meta.fullName
  71. // Get a list of available and not already validated scenes for this experiment
  72. this.availableScenes = Object.keys(this.progression[this.experimentName])
  73. .filter(aScene =>
  74. scenesList.includes(aScene) &&
  75. this.progression[this.experimentName] &&
  76. !this.progression[this.experimentName][aScene].done)
  77. if (this.hasScenesLeft) {
  78. this.$router.push(`/experiments/${this.experimentName}/${this.getRandomScene}`)
  79. }
  80. }
  81. }
  82. </script>