WithReference.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 @setConfig="setConfig($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 extract"
  49. >
  50. <template v-slot:placeholder>
  51. <v-layout
  52. fill-height
  53. align-center
  54. justify-center
  55. ma-0
  56. >
  57. <v-progress-circular indeterminate color="grey lighten-5" />
  58. </v-layout>
  59. </template>
  60. </v-img>
  61. </v-card>
  62. </v-flex>
  63. </v-layout>
  64. </template>
  65. </v-container>
  66. </v-card>
  67. </v-flex>
  68. <v-flex sm6 xs12>
  69. <v-card dark color="primary">
  70. <v-card-text>Reference image</v-card-text>
  71. <v-img v-if="referenceImage" :src="referenceImage" />
  72. </v-card>
  73. </v-flex>
  74. <!-- Experiment validation button -->
  75. <v-layout justify-end align-content-end>
  76. <v-btn @click="finishExperiment" color="primary" large right>Finish experiment</v-btn>
  77. </v-layout>
  78. <!--/ Experiment validation button -->
  79. </template>
  80. <!--/ Experiment -->
  81. </v-layout>
  82. </v-container>
  83. </div>
  84. </template>
  85. <script>
  86. import ExperimentBaseExtracts from '@/mixins/ExperimentBaseExtracts'
  87. import { API_ROUTES } from '@/functions'
  88. import Loader from '@/components/Loader.vue'
  89. import ExtractConfiguration from '@/components/ExperimentsComponents/ExtractConfiguration.vue'
  90. export default {
  91. name: 'ExperimentWithReference',
  92. components: {
  93. Loader,
  94. ExtractConfiguration
  95. },
  96. mixins: [ExperimentBaseExtracts],
  97. data() {
  98. return {
  99. experimentName: 'ExperimentWithReference',
  100. referenceImage: null
  101. }
  102. },
  103. async mounted() {
  104. // Load progress from store into local state
  105. this.loadProgress()
  106. // Load scene data from the API
  107. await Promise.all([
  108. this.getReferenceImage(),
  109. this.getQualitiesList()
  110. ])
  111. // Load the cached configuration in the configurator component
  112. this.$refs.configurator.setDefaultConfig(this.extractConfig)
  113. // Load extracts of none were cached
  114. if (this.extracts.length === 0) await this.setConfig(this.extractConfig, this.$refs.configurator)
  115. this.saveProgress()
  116. },
  117. methods: {
  118. // Load the reference image from the API
  119. async getReferenceImage() {
  120. if (this.referenceImage) return
  121. const URI = `${this.getHostURI}${API_ROUTES.getImage(this.sceneName, 'max')}`
  122. const { data } = await fetch(URI).then(res => res.json())
  123. this.referenceImage = this.getHostURI + data.link
  124. this.saveProgress()
  125. }
  126. }
  127. }
  128. </script>
  129. <style scoped>
  130. /* White border when hovering on extracts
  131. .extract:hover {
  132. outline: 2px #f4f4f4 solid;
  133. } */
  134. </style>