SelectExperimentScene.vue 4.0 KB

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