HostConfig.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <v-layout justify-center align-center>
  3. <v-flex xs12 sm5>
  4. <v-card>
  5. <v-content>
  6. <v-container fluid fill-height>
  7. <v-layout style="flex-direction: column; text-align: center">
  8. <h1>Host configuration</h1>
  9. <v-slide-y-transition mode="out-in">
  10. <loader v-if="loadingMessage" :message="loadingMessage" />
  11. <v-form v-else ref="form">
  12. <v-flex xs3>
  13. <v-select
  14. v-model="config.ssl"
  15. :items="[true, false]"
  16. label="SSL"
  17. />
  18. </v-flex>
  19. <v-text-field
  20. v-model="config.host"
  21. label="Host IP address or hostname"
  22. :rules="[v => !!v || 'Host is required']"
  23. required
  24. />
  25. <v-text-field
  26. v-model="config.port"
  27. label="Port"
  28. type="number"
  29. :rules="[v => !!v || 'Port is required']"
  30. required
  31. />
  32. <v-btn color="error" @click="reset">Reset Form</v-btn>
  33. <v-btn color="success" @click="validate">Submit</v-btn>
  34. <v-slide-y-transition mode="out-in">
  35. <v-alert v-if="configErrorMessage" :value="true" type="error" v-text="configErrorMessage" />
  36. </v-slide-y-transition>
  37. </v-form>
  38. </v-slide-y-transition>
  39. </v-layout>
  40. </v-container>
  41. </v-content>
  42. </v-card>
  43. </v-flex>
  44. </v-layout>
  45. </template>
  46. <script>
  47. import Loader from '@/components/Loader.vue'
  48. import { mapActions } from 'vuex'
  49. export default {
  50. name: 'HostConfig',
  51. components: {
  52. Loader
  53. },
  54. data() {
  55. return {
  56. config: {
  57. ssl: true,
  58. host: 'diran.univ-littoral.fr',
  59. port: '80'
  60. },
  61. loadingMessage: null,
  62. configErrorMessage: null
  63. }
  64. },
  65. watch: {
  66. 'config.ssl'(newValue) {
  67. if (newValue === true) this.config.port = 443
  68. }
  69. },
  70. methods: {
  71. ...mapActions(['setHostConfig']),
  72. reset() {
  73. this.config.ssl = true
  74. this.config.host = ''
  75. this.config.port = null
  76. this.configErrorMessage = null
  77. this.$refs.form.reset()
  78. },
  79. async validate() {
  80. if (!this.$refs.form.validate()) return
  81. this.loadingMessage = 'Checking host configuration...'
  82. this.configErrorMessage = null
  83. try {
  84. await this.setHostConfig(this.config)
  85. }
  86. catch (err) {
  87. this.configErrorMessage = err.message
  88. return
  89. }
  90. finally {
  91. this.loadingMessage = null
  92. }
  93. // Success while configuring the project's host
  94. }
  95. }
  96. }
  97. </script>