index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <div>
  3. <v-container grid-list-md text-xs-center fluid>
  4. <v-layout row wrap>
  5. <v-flex xs12>
  6. <v-layout justify-start>
  7. <v-btn flat exact :to="`/experiments/${experimentName}`">
  8. <v-icon left>arrow_back</v-icon>
  9. Back to scene selection
  10. </v-btn>
  11. </v-layout>
  12. <h1>Experiment with reference - {{ sceneName }}</h1>
  13. <!-- Extract configuration -->
  14. <extract-configuration v-if="lockConfig === false" @setExtractConfig="setExtractConfig($event, $refs.configurator)" :loading-error-message="loadingErrorMessage" ref="configurator" />
  15. <!--/ Extract configuration -->
  16. </v-flex>
  17. <!-- Loading screen -->
  18. <loader v-if="loadingMessage" :message="loadingMessage" />
  19. <!--/ Loading screen -->
  20. <!-- Experiment -->
  21. <template v-else-if="!loadingErrorMessage">
  22. <v-flex xs12 sm6>
  23. <v-card dark color="primary">
  24. <v-card-text class="px-0">Experiment image</v-card-text>
  25. <v-container class="pa-1">
  26. <template v-for="i in extractConfig.y">
  27. <v-layout row wrap :key="`row-${i}`">
  28. <v-flex
  29. v-for="(anExtract, index) in extracts.slice(extractConfig.x * (i - 1), (extractConfig.x * i))"
  30. :key="`extract-${i}-${extractConfig.x}-${extractConfig.y}-${index}-${anExtract.quality}`"
  31. class="pa-0"
  32. >
  33. <v-card flat tile class="d-flex height100">
  34. <div
  35. v-if="anExtract.loading"
  36. class="img-extract-loader"
  37. @click.right.prevent
  38. >
  39. <v-progress-circular
  40. :indeterminate="true"
  41. />
  42. </div>
  43. <v-img
  44. v-else
  45. :src="anExtract.link"
  46. @click.left.prevent="extractAction($event, anExtract)"
  47. @click.right.prevent="extractAction($event, anExtract)"
  48. class="cursor"
  49. :class="{ 'extract-hover-border': showHoverBorder === true }"
  50. >
  51. <template v-slot:placeholder>
  52. <v-layout
  53. fill-height
  54. align-center
  55. justify-center
  56. ma-0
  57. >
  58. <v-progress-circular indeterminate color="grey lighten-5" />
  59. </v-layout>
  60. </template>
  61. </v-img>
  62. </v-card>
  63. </v-flex>
  64. </v-layout>
  65. </template>
  66. </v-container>
  67. </v-card>
  68. </v-flex>
  69. <v-flex sm6 xs12>
  70. <v-card dark color="primary">
  71. <v-card-text>Reference image</v-card-text>
  72. <v-img v-if="referenceImage" :src="referenceImage" />
  73. </v-card>
  74. </v-flex>
  75. <!-- Experiment validation button -->
  76. <v-layout justify-end align-content-end>
  77. <v-btn @click="finishExperiment" color="primary" large right>Finish experiment</v-btn>
  78. </v-layout>
  79. <!--/ Experiment validation button -->
  80. </template>
  81. <!--/ Experiment -->
  82. </v-layout>
  83. </v-container>
  84. </div>
  85. </template>
  86. <script>
  87. import ExperimentBaseExtracts from '@/mixins/ExperimentBaseExtracts'
  88. import { API_ROUTES } from '@/functions'
  89. import Loader from '@/components/Loader.vue'
  90. import ExtractConfiguration from '@/components/ExperimentsComponents/ExtractConfiguration.vue'
  91. import experimentConfig from './config'
  92. export default {
  93. name: 'ExperimentWithReference',
  94. components: {
  95. Loader,
  96. ExtractConfiguration
  97. },
  98. mixins: [ExperimentBaseExtracts],
  99. data() {
  100. return {
  101. experimentName: 'ExperimentWithReference',
  102. referenceImage: null
  103. }
  104. },
  105. async mounted() {
  106. // Load config for this scene to local state
  107. await this.loadConfig(experimentConfig)
  108. // Load progress from store into local state
  109. this.loadProgress()
  110. // Load scene data from the API
  111. await Promise.all([
  112. this.getReferenceImage(),
  113. this.getQualitiesList()
  114. ])
  115. // Load the cached configuration in the configurator component
  116. if (this.lockConfig === false) this.$refs.configurator.setDefaultConfig(this.extractConfig)
  117. // Load extracts of none were cached
  118. if (this.extracts.length === 0) await this.setExtractConfig(this.extractConfig, this.$refs.configurator)
  119. this.saveProgress()
  120. },
  121. methods: {
  122. // Load the reference image from the API
  123. async getReferenceImage() {
  124. if (this.referenceImage) return
  125. const URI = `${this.getHostURI}${API_ROUTES.getImage(this.sceneName, 'max')}`
  126. const { data } = await fetch(URI).then(res => res.json())
  127. this.referenceImage = this.getHostURI + data.link
  128. this.saveProgress()
  129. }
  130. }
  131. }
  132. </script>