SelectExperimentScene.vue 4.5 KB

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