Browse Source

Merge branch 'release/v0.5.6'

Jérôme BUISINE 2 months ago
parent
commit
b30860d954

+ 3 - 0
src/main.js

@@ -30,6 +30,9 @@ router.beforeEach((to, from, next) => {
     // Set the userId and experimentId (to explicitly identify the user)
     store.commit('setUserExperimentId', { userId: request.userId, experimentId: request.experimentId })
 
+    // update experiment progress due to perhaps new ids
+    store.commit('updateExperimentProgress')
+
     // Redirect to the experiment scene selector (or directly to a scene if specified)
     if (request.experimentName) {
       if (request.sceneName)

+ 0 - 1
src/mixins/ExperimentBase.vue

@@ -30,7 +30,6 @@ export default {
   computed: {
     ...mapGetters(['getHostURI', 'getExperimentProgress', 'isExperimentDone'])
   },
-
   mounted() {
     if (!this.getExperimentProgress({ experimentName: this.experimentName, sceneName: this.sceneName }).experimentName)
       this.sendMessage({

+ 3 - 0
src/store/actions.js

@@ -89,6 +89,9 @@ export default {
     commit('setListScenes', scenes.data)
   },
 
+  updateExperimentProgress({ commit }) {
+    commit('updateExperimentProgress')
+  },
   setExperimentProgress({ commit }, { experimentName, sceneName, data }) {
     commit('setExperimentProgress', { experimentName, sceneName, data })
   },

+ 19 - 6
src/store/getters.js

@@ -12,7 +12,12 @@ export default {
     if (getters.isHostConfigured)
       return state.hostConfig
   },
-
+  getUserId(state) {
+    return state.userId
+  },
+  getExperimentId(state) {
+    return state.experimentId
+  },
   areScenesLoaded(state) {
     if (!state) return
     return state.scenesList !== null
@@ -22,16 +27,24 @@ export default {
   // areScenesThumbsLoaded(state) {
   //   return state.scenesList !== null
   // }
-
+  getAllExperimentProgress: state => () => {
+    if (!state) return
+    // use of experiment and user id to store progression
+    if (state.progression && state.progression[state.experimentId] && state.progression[state.experimentId][state.userId] && state.progression[state.experimentId][state.userId])
+      return state.progression[state.experimentId][state.userId]
+  },
   getExperimentProgress: state => ({ experimentName, sceneName }) => {
     if (!state) return
-    if (state.progression && state.progression[experimentName])
-      return state.progression[experimentName][sceneName].data
+    // use of experiment and user id to store progression
+    if (state.progression && state.progression[state.experimentId] && state.progression[state.experimentId][state.userId] && state.progression[state.experimentId][state.userId][experimentName])
+      return state.progression[state.experimentId][state.userId][experimentName][sceneName].data
   },
 
   isExperimentDone: state => ({ experimentName, sceneName }) => {
     if (!state) return
-    if (state.progression && state.progression[experimentName])
-      return state.progression[experimentName][sceneName].done
+
+    // use of experiment and user id to store progression
+    if (state.progression && state.progression[state.experimentId] && state.progression[state.experimentId][state.userId] && state.progression[state.experimentId][state.userId][experimentName])
+      return state.progression[state.experimentId][state.userId][experimentName][sceneName].done
   }
 }

+ 26 - 9
src/store/mutations.js

@@ -2,24 +2,35 @@ import defaultState from '@/store/state'
 import Experiments from '@/router/experiments'
 
 const checkProgression = (state, experimentName, sceneName) => {
-  if (!state.progression[experimentName])
-    state.progression[experimentName] = {}
-  if (!state.progression[experimentName][sceneName])
-    state.progression[experimentName][sceneName] = { done: false, data: {} }
+  if (!state.progression[state.experimentId])
+    state.progression[state.experimentId] = {}
+
+  if (!state.progression[state.experimentId][state.userId])
+    state.progression[state.experimentId][state.userId] = {}
+
+  if (!state.progression[state.experimentId][state.userId][experimentName])
+    state.progression[state.experimentId][state.userId][experimentName] = {}
+
+  if (!state.progression[state.experimentId][state.userId][experimentName][sceneName])
+    state.progression[state.experimentId][state.userId][experimentName][sceneName] = { done: false, data: {} }
 }
 const createProgressionObj = (state, scenes) => {
   const progressionObj = Experiments.reduce((accExpe, expe) => {
     const scenesProgressObj = scenes.reduce((accScene, scene) => {
+
+      // check progression
+      checkProgression(state, expe, scene)
+
       // Do not overwrite current progression
-      if (state.progression[expe.name] && state.progression[expe.name][scene])
-        accScene[scene] = state.progression[expe.name][scene]
+      if (state.progression[state.experimentId][state.userId][expe.name] && state.progression[state.experimentId][state.userId][expe.name][scene])
+        accScene[scene] = state.progression[state.experimentId][state.userId][expe.name][scene]
       else accScene[scene] = { done: false, data: {} }
       return accScene
     }, {})
     accExpe[expe.name] = scenesProgressObj
     return accExpe
   }, {})
-  state.progression = progressionObj
+  state.progression[state.experimentId][state.userId] = progressionObj
 }
 
 export default {
@@ -72,12 +83,18 @@ export default {
     createProgressionObj(state, scenes)
   },
 
+  updateExperimentProgress(state) {
+    if (!state.scenesList)
+      return
+    createProgressionObj(state, state.scenesList)
+  },
+
   setExperimentProgress(state, { experimentName, sceneName, data }) {
     checkProgression(state, experimentName, sceneName)
-    state.progression[experimentName][sceneName].data = data
+    state.progression[state.experimentId][state.userId][experimentName][sceneName].data = data
   },
   setExperimentDone(state, { experimentName, sceneName, done }) {
     checkProgression(state, experimentName, sceneName)
-    state.progression[experimentName][sceneName].done = done
+    state.progression[state.experimentId][state.userId][experimentName][sceneName].done = done
   }
 }

+ 2 - 2
src/store/state.js

@@ -1,8 +1,8 @@
 // Deep copy to not mutate it with the store (default state is needed when reloading after a refresh)
 export default () => JSON.parse(JSON.stringify({
   uuid: null,
-  userId: null,
-  experimentId: null,
+  userId: 'default', // default param
+  experimentId: 'default', // default param
   gdprConsent: false,
   hostConfig: null,
   scenesList: null,

+ 6 - 2
src/views/ExperimentValidated.vue

@@ -31,7 +31,8 @@
 </template>
 
 <script>
-import { mapState } from 'vuex'
+import { mapState, mapGetters } from 'vuex'
+import getters from '@/store/getters'
 import Experiments from '@/router/experiments'
 import { getExperimentSceneList } from '@/config.utils'
 import { rand } from '@/functions'
@@ -55,7 +56,7 @@ export default {
     }
   },
   computed: {
-    ...mapState(['progression']),
+    ...mapGetters(['getAllExperimentProgress']),
 
     hasScenesLeft() {
       return this.availableScenes.length > 0
@@ -67,6 +68,9 @@ export default {
   mounted() {
     const scenesList = getExperimentSceneList(this.experimentName)
 
+    // load current user progression
+    this.progression = this.getAllExperimentProgress()
+
     // Find the selected experiment full name
     this.experimentFullName = Experiments.find(x => x.name === this.experimentName).meta.fullName
 

+ 6 - 2
src/views/ExperimentsList.vue

@@ -38,7 +38,7 @@
 </template>
 
 <script>
-import { mapState } from 'vuex'
+import { mapGetters } from 'vuex'
 import Experiments from '@/router/experiments'
 import { getExperimentSceneList } from '@/config.utils'
 import { rand } from '@/functions'
@@ -59,7 +59,7 @@ export default {
     }
   },
   computed: {
-    ...mapState(['progression'])
+    ...mapGetters(['getAllExperimentProgress'])
   },
   mounted() {
     this.items = Experiments.map(expe => {
@@ -68,6 +68,10 @@ export default {
         name: expe.meta.fullName,
         link: `/experiments/${expe.name}`
       }
+
+      // load current user progression
+      this.progression = this.getAllExperimentProgress()
+
       // Check cache has an entry for each scenes in this experiment
       if (this.progression && this.progression[expe.name]) {
         // Set experiment completion percentage