SelectExperimentScene.vue 5.9 KB

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