SelectExperimentScene.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 "{{ experimentName }}"
  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 { API_ROUTES, shuffleArray } from '@/functions'
  64. export default {
  65. name: 'SelectExperimentScene',
  66. props: {
  67. experimentName: {
  68. type: String,
  69. required: true
  70. }
  71. },
  72. data() {
  73. return {
  74. scenes: []
  75. }
  76. },
  77. computed: {
  78. ...mapState(['scenesList', 'progression']),
  79. ...mapGetters(['getHostURI'])
  80. },
  81. async mounted() {
  82. let todo = []
  83. let working = []
  84. let done = []
  85. for (const aScene of this.scenesList) {
  86. const { data: thumb } = await fetch(`${this.getHostURI}${API_ROUTES.getImage(aScene, 'max')}`)
  87. .then(res => res.json())
  88. let sceneObj = {
  89. name: thumb.sceneName,
  90. thumbLink: `${this.getHostURI}${thumb.link}`,
  91. experimentLink: `/experiments/${this.experimentName}/${thumb.sceneName}`
  92. }
  93. if (this.progression[this.experimentName] && this.progression[this.experimentName][thumb.sceneName]) {
  94. const obj = this.progression[this.experimentName][thumb.sceneName]
  95. if (obj.done) {
  96. sceneObj.progression = 'done'
  97. done.push(sceneObj)
  98. }
  99. else if (Object.entries(obj.data).length !== 0 && obj.constructor === Object) {
  100. sceneObj.progression = 'working'
  101. working.push(sceneObj)
  102. }
  103. else {
  104. sceneObj.progression = 'todo'
  105. todo.push(sceneObj)
  106. }
  107. }
  108. }
  109. // Randomize each group
  110. todo = shuffleArray(todo)
  111. working = shuffleArray(working)
  112. done = shuffleArray(done)
  113. // Render the scenes, in the following order : working, todo, done
  114. this.scenes = this.scenes.concat(working, todo, done)
  115. }
  116. }
  117. </script>