SelectExperimentScene.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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, mapActions } from 'vuex'
  66. import Experiments from '@/router/experiments'
  67. import { API_ROUTES, shuffleArray } from '@/functions'
  68. import { getExperimentSceneList, getCalibrationScene, getCalibrationFrequency } 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. ...mapActions(['loadScenesList']),
  91. numberOfScenes() {
  92. return this.scenes.length
  93. },
  94. numberOfValidatedScenes() {
  95. return this.scenes.filter(x => x.progression === 'done').length
  96. },
  97. completionPercent() {
  98. return Math.round(this.numberOfValidatedScenes / this.numberOfScenes * 100)
  99. }
  100. },
  101. async mounted() {
  102. // get information from calibration scene
  103. let calibrationScene = getCalibrationScene(this.experimentName)
  104. let calibrationSceneFreq = getCalibrationFrequency(this.experimentName)
  105. // reload scene list to update
  106. await this.loadScenesList
  107. const scenesList = getExperimentSceneList(this.experimentName)
  108. // retrieve experiment data of user
  109. this.progression = this.getAllExperimentProgress()
  110. // Find the selected experiment full name
  111. this.experimentFullName = Experiments.find(x => x.name === this.experimentName).meta.fullName
  112. // Order each scene by progression group, random sort in each group
  113. let todo = []
  114. let working = []
  115. let done = []
  116. for (const aScene of scenesList) {
  117. const { data: thumb } = await fetch(`${this.getHostURI}${API_ROUTES.getImage(aScene, 'max')}`)
  118. .then(res => res.json())
  119. .catch(e => console.log(e))
  120. let sceneObj = {
  121. name: thumb.sceneName,
  122. thumbLink: `${this.getHostURI}${thumb.link}`,
  123. experimentLink: `/experiments/${this.experimentName}/${thumb.sceneName}`
  124. }
  125. if (this.progression[this.experimentName] && this.progression[this.experimentName][thumb.sceneName]) {
  126. const obj = this.progression[this.experimentName][thumb.sceneName]
  127. if (obj.done) {
  128. sceneObj.progression = 'done'
  129. done.push(sceneObj)
  130. }
  131. else if (Object.entries(obj.data).length !== 0 && obj.constructor === Object) {
  132. sceneObj.progression = 'working'
  133. working.push(sceneObj)
  134. }
  135. else {
  136. sceneObj.progression = 'todo'
  137. todo.push(sceneObj)
  138. }
  139. }
  140. }
  141. // Randomize each group
  142. todo = shuffleArray(todo)
  143. working = shuffleArray(working)
  144. done = shuffleArray(done)
  145. // here push in session (if not already there) current user advancement
  146. if (window.sessionStorage.getItem('sin3d-nb-scenes') === null) {
  147. window.sessionStorage.setItem('sin3d-nb-scenes', 1)
  148. this.$router.push(`/experiments/${this.experimentName}/${calibrationScene}`)
  149. }
  150. // check if necessary to show calibration before new scenes
  151. if (window.sessionStorage.getItem('sin3d-nb-scenes') !== null) {
  152. let nScenes = Number(window.sessionStorage.getItem('sin3d-nb-scenes'))
  153. if (nScenes % calibrationSceneFreq === 0)
  154. this.$router.push(`/experiments/${this.experimentName}/${calibrationScene}`)
  155. }
  156. // for the experiment user is redirect to current working on
  157. if (working.length > 0) {
  158. this.$router.push(working[0].experimentLink)
  159. }
  160. // for the experiment user is redirect to new random scene (already shuffle, so first element)
  161. else if (todo.length > 0) {
  162. this.$router.push(todo[0].experimentLink)
  163. }
  164. // Render the scenes, in the following order : working, todo, done
  165. this.scenes = this.scenes.concat(working, todo, done)
  166. this.loaded = setTimeout(() => {
  167. return true
  168. }, 2500)
  169. }
  170. }
  171. </script>