SelectExperimentScene.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <div>
  3. <!-- <v-layout justify-start>
  4. <v-btn flat exact :to="`/experiments`">
  5. <v-icon left>arrow_back</v-icon>
  6. Back to experiment selection
  7. </v-btn>
  8. </v-layout>
  9. <h4>Select a scene for the experiment "{{ experimentFullName }}"</h4>
  10. <span>Completion: {{ numberOfValidatedScenes }}/{{ numberOfScenes }} - {{ completionPercent }}%</span> -->
  11. <loader v-if="!loaded" :message="loadingMessage" />
  12. <v-card v-if="loaded">
  13. <v-container
  14. fluid
  15. grid-list-md
  16. >
  17. <v-layout row wrap>
  18. <v-flex
  19. v-for="aScene in scenes"
  20. :key="aScene.name"
  21. >
  22. <v-card>
  23. <v-img
  24. :src="aScene.thumbLink"
  25. height="200px"
  26. />
  27. <v-card-title primary-title>
  28. <div>
  29. <div class="headline">{{ aScene.name }}</div>
  30. </div>
  31. <v-card-actions>
  32. <v-chip v-if="aScene.progression === 'done'" color="green" text-color="white" small>
  33. <v-avatar class="green darken-4">
  34. <v-icon>check</v-icon>
  35. </v-avatar>
  36. <span>Validated</span>
  37. </v-chip>
  38. <v-chip v-else-if="aScene.progression === 'working'" color="orange" text-color="white" small>
  39. <v-avatar class="orange darken-4">
  40. <v-icon>edit</v-icon>
  41. </v-avatar>
  42. <span>Started but not validated</span>
  43. </v-chip>
  44. <v-chip v-else-if="aScene.progression === 'todo'" color="red" text-color="white" small>
  45. <v-avatar class="red darken-4">
  46. <v-icon>close</v-icon>
  47. </v-avatar>
  48. <span>Not started</span>
  49. </v-chip>
  50. </v-card-actions>
  51. <v-spacer />
  52. <v-card-actions>
  53. <v-btn round :disabled="aScene.progression === 'done'" :to="aScene.experimentLink">Start experiment</v-btn>
  54. </v-card-actions>
  55. </v-card-title>
  56. </v-card>
  57. </v-flex>
  58. </v-layout>
  59. </v-container>
  60. </v-card>
  61. </div>
  62. </template>
  63. <script>
  64. import Loader from '@/components/Loader.vue'
  65. import { mapGetters } from 'vuex'
  66. import Experiments from '@/router/experiments'
  67. import { API_ROUTES, shuffleArray } from '@/functions'
  68. import { getExperimentSceneList } from '@/config.utils'
  69. export default {
  70. name: 'SelectExperimentScene',
  71. components: {
  72. Loader
  73. },
  74. props: {
  75. experimentName: {
  76. type: String,
  77. required: true
  78. }
  79. },
  80. data() {
  81. return {
  82. scenes: [],
  83. experimentFullName: null,
  84. loaded: false,
  85. loadingMessage: 'Loading your experiment...'
  86. }
  87. },
  88. computed: {
  89. ...mapGetters(['getHostURI', 'getAllExperimentProgress']),
  90. numberOfScenes() {
  91. return this.scenes.length
  92. },
  93. numberOfValidatedScenes() {
  94. return this.scenes.filter(x => x.progression === 'done').length
  95. },
  96. completionPercent() {
  97. return Math.round(this.numberOfValidatedScenes / this.numberOfScenes * 100)
  98. }
  99. },
  100. async mounted() {
  101. const scenesList = getExperimentSceneList(this.experimentName)
  102. // retrieve experiment data of user
  103. this.progression = this.getAllExperimentProgress()
  104. // Find the selected experiment full name
  105. this.experimentFullName = Experiments.find(x => x.name === this.experimentName).meta.fullName
  106. // Order each scene by progression group, random sort in each group
  107. let todo = []
  108. let working = []
  109. let done = []
  110. for (const aScene of scenesList) {
  111. const { data: thumb } = await fetch(`${this.getHostURI}${API_ROUTES.getImage(aScene, 'max')}`)
  112. .then(res => res.json())
  113. let sceneObj = {
  114. name: thumb.sceneName,
  115. thumbLink: `${this.getHostURI}${thumb.link}`,
  116. experimentLink: `/experiments/${this.experimentName}/${thumb.sceneName}`
  117. }
  118. if (this.progression[this.experimentName] && this.progression[this.experimentName][thumb.sceneName]) {
  119. const obj = this.progression[this.experimentName][thumb.sceneName]
  120. if (obj.done) {
  121. sceneObj.progression = 'done'
  122. done.push(sceneObj)
  123. }
  124. else if (Object.entries(obj.data).length !== 0 && obj.constructor === Object) {
  125. sceneObj.progression = 'working'
  126. working.push(sceneObj)
  127. }
  128. else {
  129. sceneObj.progression = 'todo'
  130. todo.push(sceneObj)
  131. }
  132. }
  133. }
  134. // Randomize each group
  135. todo = shuffleArray(todo)
  136. working = shuffleArray(working)
  137. done = shuffleArray(done)
  138. // for the experiment user is redirect to current working on
  139. if (working.length > 0) {
  140. this.$router.push(working[0].experimentLink)
  141. }
  142. // for the experiment user is redirect to new random scene (already shuffle, so first element)
  143. else if (todo.length > 0) {
  144. this.$router.push(todo[0].experimentLink)
  145. }
  146. // Render the scenes, in the following order : working, todo, done
  147. this.scenes = this.scenes.concat(working, todo, done)
  148. this.loaded = setTimeout(() => {
  149. return true
  150. }, 2500)
  151. }
  152. }
  153. </script>