ExperimentBase.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <script>
  2. import { mapGetters, mapActions } from 'vuex'
  3. import { API_ROUTES } from '@/functions'
  4. export default {
  5. props: {
  6. sceneName: {
  7. type: String,
  8. required: true
  9. }
  10. },
  11. data() {
  12. return {
  13. experimentName: null, // Must be redefined in parent component
  14. loadingMessage: null,
  15. loadingErrorMessage: null,
  16. qualities: null
  17. }
  18. },
  19. computed: {
  20. ...mapGetters(['getHostURI', 'getExperimentProgress'])
  21. },
  22. methods: {
  23. ...mapActions(['setExperimentProgress', 'sendMessage']),
  24. // Load progress from store into local state
  25. loadProgress() {
  26. if (!this.experimentName || !this.sceneName)
  27. console.warn('Could not load progress : experimentName and sceneName must be defined')
  28. const progress = this.getExperimentProgress({ experimentName: this.experimentName, sceneName: this.sceneName })
  29. Object.assign(this.$data, progress)
  30. // console.log('Loaded data from store to local state.', progress)
  31. },
  32. // Save progress from local state into store
  33. saveProgress() {
  34. if (!this.experimentName || !this.sceneName)
  35. console.warn('Could not load progress : experimentName and sceneName must be defined')
  36. this.setExperimentProgress({ experimentName: this.experimentName, sceneName: this.sceneName, data: this.$data })
  37. // console.log('Saved data from local state to store.', this.$data)
  38. },
  39. // Load qualities list from the API
  40. async getQualitiesList() {
  41. if (this.qualities) return
  42. const URI = `${this.getHostURI}${API_ROUTES.listSceneQualities(this.sceneName)}`
  43. const { data } = await fetch(URI).then(res => res.json())
  44. this.qualities = data
  45. this.saveProgress()
  46. }
  47. }
  48. }
  49. </script>