SelectExperimentScene.vue 4.1 KB

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