ExperimentsList.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div>
  3. List of experiments
  4. <v-card>
  5. <v-card-title>
  6. Choose an experiment
  7. <v-spacer />
  8. <v-text-field
  9. v-model="search"
  10. append-icon="search"
  11. label="Search"
  12. single-line
  13. hide-details
  14. />
  15. </v-card-title>
  16. <v-data-table
  17. v-if="items"
  18. :headers="headers"
  19. :items="items"
  20. :search="search"
  21. :pagination.sync="pagination"
  22. >
  23. <template v-slot:items="props">
  24. <td>{{ props.item.name }}</td>
  25. <td class="text-xs-center">{{ props.item.completion }}</td>
  26. <td class="text-xs-center"><v-btn small dark :to="props.item.link">Start</v-btn></td>
  27. <td class="text-xs-center"><v-btn small dark :to="props.item.linkRandom">Start with random scene</v-btn></td>
  28. </template>
  29. <template v-slot:no-results>
  30. <v-alert :value="true" color="error" icon="warning">
  31. Your search for "{{ search }}" found no results.
  32. </v-alert>
  33. </template>
  34. </v-data-table>
  35. </v-card>
  36. </div>
  37. </template>
  38. <script>
  39. import { mapState } from 'vuex'
  40. import Experiments from '@/router/experiments'
  41. import { getExperimentSceneList } from '@/config.utils'
  42. import { rand } from '@/functions'
  43. export default {
  44. name: 'ExperimentsList',
  45. data() {
  46. return {
  47. search: '',
  48. pagination: { rowsPerPage: 10 },
  49. headers: [
  50. { text: 'Experiment name', value: 'name' },
  51. { text: 'Completion', value: 'completion', align: 'center' },
  52. { text: 'Start', value: 'start', sortable: false, align: 'center' },
  53. { text: 'Start random scene', value: 'startRandom', sortable: false, align: 'center' }
  54. ],
  55. items: null
  56. }
  57. },
  58. computed: {
  59. ...mapState(['progression'])
  60. },
  61. mounted() {
  62. this.items = Experiments.map(expe => {
  63. const scenesList = getExperimentSceneList(expe.name)
  64. const res = {
  65. name: expe.meta.fullName,
  66. link: `/experiments/${expe.name}`
  67. }
  68. // Check cache has an entry for each scenes in this experiment
  69. if (this.progression && this.progression[expe.name]) {
  70. // Set experiment completion percentage
  71. const numberOfDoneScenes = Object.keys(this.progression[expe.name]).filter(y => this.progression[expe.name][y].done).length
  72. const percentage = Math.round(numberOfDoneScenes / scenesList.length * 100)
  73. res.completion = `${numberOfDoneScenes}/${scenesList.length} - ${percentage}%`
  74. // Get scenes that are NOT done
  75. const unDoneScenes = Object.keys(this.progression[expe.name]).filter(y => scenesList.includes(y) && !this.progression[expe.name][y].done)
  76. // Select a random scenes
  77. const randomScene = unDoneScenes[rand(0, unDoneScenes.length - 1)]
  78. res.linkRandom = `/experiments/${expe.name}/${randomScene}`
  79. }
  80. else res.completion = '0%'
  81. return res
  82. })
  83. }
  84. }
  85. </script>