SelectExperimentScene.vue 3.6 KB

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