index.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <main class="container" v-if="page === 'host'" v-scope @vue:mounted="mounted">
  2. <h1>Conectar un HOST</h1>
  3. <form action="action/conectar_moodle.php" method="post" v-scope="{host: null}">
  4. <div class="grid">
  5. <div v-if="hosts.length > 0">
  6. <label for="moodle-host">
  7. Moodle host
  8. <input list="moodle-hosts" name="moodle-host" placeholder="Moodle host" required v-model="host">
  9. </label>
  10. <datalist id="moodle-hosts" v-for="host in hosts">
  11. <option :value="host.host">
  12. {{ host.etiqueta }}
  13. </option>
  14. </datalist>
  15. </div>
  16. <div v-else>
  17. <p>No hay hosts registrados</p>
  18. </div>
  19. <label for="agregar-host">
  20. Agregar host
  21. <button id="agregar-host" type="button" @click="page = 'new_host'">
  22. <i class="fas fa-plus"></i>
  23. </button>
  24. </label>
  25. </div>
  26. <div class="grid">
  27. <button type="button" :disabled="!host" @click="editHost(host)">Editar <i class="fas fa-edit"></i></button>
  28. <button type="submit" :disabled="!host">Conectar <i class="fas fa-database"></i></button>
  29. </div>
  30. </form>
  31. </main>
  32. <div v-else>
  33. <?php require 'edit_host.php' ?>
  34. </div>
  35. <script>
  36. PetiteVue.createApp({
  37. store,
  38. // state
  39. page: 'host',
  40. // data
  41. hosts: [],
  42. current_host: null,
  43. async editHost(host) {
  44. store.loading = true
  45. const hosts = await store.fetch(`http://www.localhost:3000/moodle_host?etiqueta=eq.${host}`, {
  46. headers: {
  47. 'Prefer': 'plurality=singular'
  48. }
  49. })
  50. if (!hosts.ok) {
  51. store.loading = false
  52. alert('Error al obtener el host: ' + hosts.status)
  53. return
  54. }
  55. const data = await hosts.json()
  56. this.current_host = data[0]
  57. this.loading = false
  58. this.page = 'edit_host'
  59. },
  60. async mounted() {
  61. store.loading = true
  62. const hosts = await store.fetch('http://www.localhost:3000/moodle_host')
  63. const data = await hosts.json()
  64. store.loading = false
  65. this.hosts = data
  66. }
  67. }).mount()
  68. </script>