WithReference.vue 4.7 KB

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