HostConfig.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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-text-field
  13. v-model="config.host"
  14. label="Host IP address or hostname"
  15. :rules="[v => !!v || 'Host is required']"
  16. required
  17. />
  18. <v-text-field
  19. v-model="config.port"
  20. label="Port"
  21. type="number"
  22. :rules="[v => !!v || 'Port is required']"
  23. required
  24. />
  25. <v-btn color="error" @click="reset">Reset Form</v-btn>
  26. <v-btn color="success" @click="validate">Submit</v-btn>
  27. <v-slide-y-transition mode="out-in">
  28. <v-alert v-if="configErrorMessage" :value="true" type="error" v-text="configErrorMessage" />
  29. </v-slide-y-transition>
  30. </v-form>
  31. </v-slide-y-transition>
  32. </v-layout>
  33. </v-container>
  34. </v-content>
  35. </v-card>
  36. </v-flex>
  37. </v-layout>
  38. </template>
  39. <script>
  40. import Loader from '@/components/Loader.vue'
  41. import { mapActions } from 'vuex'
  42. export default {
  43. name: 'HostConfig',
  44. components: {
  45. Loader
  46. },
  47. data() {
  48. return {
  49. config: {
  50. protocol: 'HTTP',
  51. host: 'diran.univ-littoral.fr',
  52. port: '80'
  53. },
  54. loadingMessage: null,
  55. configErrorMessage: null
  56. }
  57. },
  58. methods: {
  59. ...mapActions(['setHostConfig']),
  60. reset() {
  61. this.config.protocol = 'HTTP'
  62. this.config.host = ''
  63. this.config.port = null
  64. this.configErrorMessage = null
  65. this.$refs.form.reset()
  66. },
  67. async validate() {
  68. if (!this.$refs.form.validate()) return
  69. this.loadingMessage = 'Checking host configuration...'
  70. this.configErrorMessage = null
  71. try {
  72. await this.setHostConfig(this.config)
  73. }
  74. catch (err) {
  75. this.configErrorMessage = err.message
  76. return
  77. }
  78. finally {
  79. this.loadingMessage = null
  80. }
  81. // Success while configuring the project's host
  82. }
  83. }
  84. }
  85. </script>