HostConfig.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <v-layout justify-center align-center>
  3. <v-flex xs12 sm5>
  4. <v-btn @click="backToGDPR">
  5. <v-icon left>arrow_back</v-icon>
  6. Go back to GDPR notice
  7. </v-btn>
  8. <v-card>
  9. <v-container fluid fill-height>
  10. <v-layout column align-center>
  11. <v-card-title class="headline d-block text-md-center font-weight-bold">Host configuration</v-card-title>
  12. <v-card-text>
  13. <v-slide-y-transition mode="out-in">
  14. <loader v-if="loadingMessage" :message="loadingMessage" />
  15. <v-form v-else ref="form">
  16. <v-text-field
  17. v-model="hostConfig"
  18. label="Host link"
  19. :rules="[v => !!v || 'Host is required']"
  20. required
  21. />
  22. <v-layout row wrap>
  23. <v-flex xs5>
  24. <v-checkbox
  25. v-model="id.hasUserId"
  26. color="primary"
  27. :label="`I have an user ID`"
  28. />
  29. </v-flex>
  30. <v-spacer />
  31. <v-flex xs6>
  32. <v-text-field
  33. v-model="id.user"
  34. label="User ID"
  35. type="text"
  36. :disabled="!id.hasUserId"
  37. />
  38. </v-flex>
  39. </v-layout>
  40. <v-layout row wrap>
  41. <v-flex xs5>
  42. <v-checkbox
  43. v-model="id.hasExperimentId"
  44. color="primary"
  45. :label="`I have an experiment ID`"
  46. />
  47. </v-flex>
  48. <v-spacer />
  49. <v-flex xs6>
  50. <v-text-field
  51. v-model="id.experiment"
  52. label="Experiment ID"
  53. type="text"
  54. :disabled="!id.hasExperimentId"
  55. />
  56. </v-flex>
  57. </v-layout>
  58. <v-btn color="error" @click="reset">Reset Form</v-btn>
  59. <v-btn color="success" @click="validate">Submit</v-btn>
  60. <v-slide-y-transition mode="out-in">
  61. <v-alert v-if="configErrorMessage" :value="true" type="error" v-text="configErrorMessage" />
  62. </v-slide-y-transition>
  63. </v-form>
  64. </v-slide-y-transition>
  65. </v-card-text>
  66. </v-layout>
  67. </v-container>
  68. </v-card>
  69. </v-flex>
  70. </v-layout>
  71. </template>
  72. <script>
  73. import Loader from '@/components/Loader.vue'
  74. import { mapActions } from 'vuex'
  75. export default {
  76. name: 'HostConfig',
  77. components: {
  78. Loader
  79. },
  80. data() {
  81. return {
  82. hostConfig: null,
  83. id: {
  84. user: null,
  85. hasUserId: false,
  86. experiment: null,
  87. hasExperimentId: false
  88. },
  89. loadingMessage: null,
  90. configErrorMessage: null
  91. }
  92. },
  93. mounted() {
  94. // if (process.env.NODE_ENV === 'development')
  95. // this.hostConfig = 'http://localhost:5000'
  96. this.reset()
  97. },
  98. methods: {
  99. ...mapActions(['setHostConfig', 'setUserExperimentId', 'resetApp']),
  100. backToGDPR() {
  101. this.resetApp({ gdprConsent: true })
  102. this.$router.push('/')
  103. },
  104. reset() {
  105. this.hostConfig = 'https://diran.univ-littoral.fr'
  106. this.id.user = null
  107. this.id.hasUserId = false
  108. this.id.experiment = null
  109. this.id.hasExperimentId = false
  110. this.configErrorMessage = null
  111. },
  112. async validate() {
  113. if (!this.$refs.form.validate()) return
  114. this.loadingMessage = 'Checking host configuration...'
  115. this.configErrorMessage = null
  116. try {
  117. this.setUserExperimentId({ userId: this.id.user, experimentId: this.id.experiment })
  118. await this.setHostConfig(this.hostConfig)
  119. }
  120. catch (err) {
  121. console.error(err)
  122. this.configErrorMessage = err.message
  123. }
  124. finally {
  125. this.loadingMessage = null
  126. }
  127. // Success while configuring the project's host
  128. }
  129. }
  130. }
  131. </script>