Parcourir la source

Changed hostConfig to simple link

rigwild il y a 4 ans
Parent
commit
48d6864657

+ 0 - 2
src/functions.js

@@ -23,8 +23,6 @@ export const API_ROUTES = {
 
 export const delay = ms => new Promise(res => setTimeout(res, ms))
 
-export const buildURI = (ssl, host, port, route = '') => `${ssl ? 'https' : 'http'}://${host}:${port}${route}`
-
 export const sortIntArray = intArray => intArray ? intArray.sort((a, b) => a - b) : null
 
 export const findNearestUpper = (value, arrInt) => {

+ 4 - 4
src/store/actions.js

@@ -1,5 +1,5 @@
 import router from '../router'
-import { API_ROUTES, buildURI, serialize } from '../functions'
+import { API_ROUTES, serialize } from '../functions'
 
 export default {
   setGdprValidated({ state, commit }) {
@@ -21,13 +21,13 @@ export default {
     commit('resetApp', { gdprConsent, hostConfig, progression })
   },
 
-  async setHostConfig({ commit, dispatch }, { ssl, host, port }) {
+  async setHostConfig({ commit, dispatch }, hostConfig) {
     // Timeout after 1s
     const controller = new AbortController()
     const signal = controller.signal
     setTimeout(() => controller.abort(), 1500)
 
-    const URI = buildURI(ssl, host, port, API_ROUTES.ping)
+    const URI = `${hostConfig}${API_ROUTES.ping}`
     return fetch(URI, { signal })
       .then(async res => {
         if (res.status !== 200) throw new Error(`Received wrong HTTP status code : ${res.status} (Need 200).`)
@@ -36,7 +36,7 @@ export default {
         if (content !== 'pong') throw new Error('Received wrong web content (Need to receive "pong").')
 
         // Configuration is valid
-        commit('setHostConfig', { ssl, host, port })
+        commit('setHostConfig', hostConfig)
         router.push('/experiments')
         dispatch('collectUserData')
       })

+ 2 - 4
src/store/getters.js

@@ -1,5 +1,3 @@
-import { buildURI } from '../functions'
-
 export default {
   isGdprValidated(state) {
     if (!state) return
@@ -7,12 +5,12 @@ export default {
   },
   isHostConfigured(state) {
     if (!state) return
-    return !!(state.hostConfig.ssl !== null && state.hostConfig.host && state.hostConfig.port)
+    return state.hostConfig !== null
   },
   getHostURI(state, getters) {
     if (!state) return
     if (getters.isHostConfigured)
-      return buildURI(state.hostConfig.ssl, state.hostConfig.host, state.hostConfig.port)
+      return state.hostConfig
   },
 
   areScenesLoaded(state) {

+ 1 - 5
src/store/mutations.js

@@ -50,11 +50,7 @@ export default {
       return
     }
 
-    if (hostConfig) {
-      state.hostConfig = defaultStateObj.hostConfig
-      state.userId = defaultStateObj.userId
-      state.experimentId = defaultStateObj.experimentId
-    }
+    if (hostConfig) state.hostConfig = defaultStateObj.hostConfig
     if (progression) {
       // Reset progression and recreate the progression object
       state.progression = defaultStateObj.progression

+ 1 - 5
src/store/state.js

@@ -4,11 +4,7 @@ export default () => JSON.parse(JSON.stringify({
   userId: null,
   experimentId: null,
   gdprConsent: false,
-  hostConfig: {
-    ssl: null,
-    host: null,
-    port: null
-  },
+  hostConfig: null,
   scenesList: null,
   progression: {},
   customLinkData: null

+ 9 - 38
src/views/HostConfig.vue

@@ -10,29 +10,13 @@
               <v-slide-y-transition mode="out-in">
                 <loader v-if="loadingMessage" :message="loadingMessage" />
                 <v-form v-else ref="form">
-                  <v-flex xs3>
-                    <v-select
-                      v-model="config.ssl"
-                      :items="[false, true]"
-                      label="SSL"
-                    />
-                  </v-flex>
-
                   <v-text-field
-                    v-model="config.host"
-                    label="Host IP address or hostname"
+                    v-model="hostConfig"
+                    label="Host link"
                     :rules="[v => !!v || 'Host is required']"
                     required
                   />
 
-                  <v-text-field
-                    v-model="config.port"
-                    label="Port"
-                    type="number"
-                    :rules="[v => !!v || 'Port is required']"
-                    required
-                  />
-
                   <v-layout row wrap>
                     <v-flex xs5>
                       <v-checkbox
@@ -98,11 +82,7 @@ export default {
   },
   data() {
     return {
-      config: {
-        ssl: true,
-        host: 'diran.univ-littoral.fr',
-        port: '443'
-      },
+      hostConfig: null,
 
       id: {
         user: null,
@@ -116,27 +96,17 @@ export default {
     }
   },
 
-  watch: {
-    'config.ssl'(newValue) {
-      if (newValue === true) this.config.port = 443
-    }
-  },
-
   mounted() {
     // if (process.env.NODE_ENV === 'development')
-    //   this.config = {
-    //     ssl: false,
-    //     host: 'localhost',
-    //     port: '5000'
-    //   }
+    //   this.hostConfig = 'http://localhost:5000'
+
+    this.reset()
   },
 
   methods: {
     ...mapActions(['setHostConfig', 'setUserExperimentId']),
     reset() {
-      this.config.ssl = true
-      this.config.host = 'diran.univ-littoral.fr'
-      this.config.port = 443
+      this.hostConfig = 'https://diran.univ-littoral.fr'
       this.id.user = null
       this.id.hasUserId = false
       this.id.experiment = null
@@ -144,13 +114,14 @@ export default {
       this.configErrorMessage = null
       this.$refs.form.reset()
     },
+
     async validate() {
       if (!this.$refs.form.validate()) return
 
       this.loadingMessage = 'Checking host configuration...'
       this.configErrorMessage = null
       try {
-        await this.setHostConfig(this.config)
+        await this.setHostConfig(this.hostConfig)
         this.setUserExperimentId({ userId: this.id.user, experimentId: this.id.experiment })
       }
       catch (err) {

+ 5 - 31
src/views/LinkGenerator.vue

@@ -9,33 +9,15 @@
             <v-card-text>
               <v-form>
                 <h2>*Host configuration</h2>
-                <h4>Web application configuration</h4>
                 <v-text-field
                   v-model="form.webAppUrl"
                   label="*Web application link"
                 />
-
-                <h4>Server configuration</h4>
-                <v-flex xs3>
-                  <v-select
-                    v-model="form.server.ssl"
-                    :items="[false, true]"
-                    label="*SSL"
-                  />
-                </v-flex>
-
                 <v-text-field
-                  v-model="form.server.host"
-                  label="*Host IP address or hostname"
+                  v-model="form.hostConfig"
+                  label="*Server link"
                 />
 
-                <v-text-field
-                  v-model="form.server.port"
-                  label="*Port"
-                  type="number"
-                />
-
-
                 <h2>User ID and experiment ID</h2>
                 <v-layout row wrap>
                   <v-flex xs4>
@@ -159,11 +141,7 @@ export default {
     return {
       form: {
         webAppUrl: 'https://diran.univ-littoral.fr',
-        server: {
-          ssl: true,
-          host: 'diran.univ-littoral.fr',
-          port: '80'
-        },
+        hostConfig: 'https://diran.univ-littoral.fr',
 
         userId: {
           activated: false,
@@ -223,7 +201,7 @@ export default {
       this.alertMessage = null
 
       // Check host configuration is set
-      if (this.form.webAppUrl === '' || this.form.server.host === '' || this.form.server.port === '') {
+      if (this.form.webAppUrl === '' || this.form.hostConfig === '') {
         this.alertMessage = 'The host configuration is required.'
         this.linkOutput = null
         this.dataOutput = null
@@ -232,11 +210,7 @@ export default {
 
       // Generate the link
       const obj = {
-        hostConfig: {
-          ssl: this.form.server.ssl,
-          host: this.form.server.host,
-          port: this.form.server.port
-        }
+        hostConfig: this.form.hostConfig
       }
       if (this.form.userId.activated && this.form.userId.value !== '') obj.userId = this.form.userId.value
       if (this.form.experimentId.activated && this.form.experimentId.value !== '') obj.experimentId = this.form.experimentId.value