|
@@ -2,15 +2,20 @@
|
|
<h1>Conectar un HOST</h1>
|
|
<h1>Conectar un HOST</h1>
|
|
<form action="action/conectar_moodle.php" method="post" v-scope="{host: null}">
|
|
<form action="action/conectar_moodle.php" method="post" v-scope="{host: null}">
|
|
<div class="grid">
|
|
<div class="grid">
|
|
- <?php
|
|
|
|
- if ($db->count('moodle_host') > 0) : ?>
|
|
|
|
|
|
+ <div v-if="hosts.length > 0">
|
|
<label for="moodle-host">
|
|
<label for="moodle-host">
|
|
Moodle host
|
|
Moodle host
|
|
<input list="moodle-hosts" name="moodle-host" placeholder="Moodle host" required v-model="host">
|
|
<input list="moodle-hosts" name="moodle-host" placeholder="Moodle host" required v-model="host">
|
|
</label>
|
|
</label>
|
|
- <?php else : ?>
|
|
|
|
|
|
+ <datalist id="moodle-hosts" v-for="host in hosts">
|
|
|
|
+ <option :value="host.host">
|
|
|
|
+ {{ host.etiqueta }}
|
|
|
|
+ </option>
|
|
|
|
+ </datalist>
|
|
|
|
+ </div>
|
|
|
|
+ <div v-else>
|
|
<p>No hay hosts registrados</p>
|
|
<p>No hay hosts registrados</p>
|
|
- <?php endif ?>
|
|
|
|
|
|
+ </div>
|
|
<label for="agregar-host">
|
|
<label for="agregar-host">
|
|
Agregar host
|
|
Agregar host
|
|
<button id="agregar-host" type="button" @click="page = 'new_host'">
|
|
<button id="agregar-host" type="button" @click="page = 'new_host'">
|
|
@@ -18,13 +23,6 @@
|
|
</button>
|
|
</button>
|
|
</label>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
- <?php if ($db->count('moodle_host') > 0) : ?>
|
|
|
|
- <datalist id="moodle-hosts" v-for="host in hosts">
|
|
|
|
- <option :value="host.host">
|
|
|
|
- {{ host.etiqueta }}
|
|
|
|
- </option>
|
|
|
|
- </datalist>
|
|
|
|
- <?php endif ?>
|
|
|
|
<div class="grid">
|
|
<div class="grid">
|
|
<button type="button" :disabled="!host" @click="editHost(host)">Editar <i class="fas fa-edit"></i></button>
|
|
<button type="button" :disabled="!host" @click="editHost(host)">Editar <i class="fas fa-edit"></i></button>
|
|
<button type="submit" :disabled="!host">Conectar <i class="fas fa-database"></i></button>
|
|
<button type="submit" :disabled="!host">Conectar <i class="fas fa-database"></i></button>
|
|
@@ -32,10 +30,6 @@
|
|
</form>
|
|
</form>
|
|
</main>
|
|
</main>
|
|
|
|
|
|
-<div v-else-if="page === 'new_host'">
|
|
|
|
- <?php require 'new_host.php' ?>
|
|
|
|
-</div>
|
|
|
|
-
|
|
|
|
<div v-else>
|
|
<div v-else>
|
|
<?php require 'edit_host.php' ?>
|
|
<?php require 'edit_host.php' ?>
|
|
</div>
|
|
</div>
|
|
@@ -44,23 +38,23 @@
|
|
|
|
|
|
<script>
|
|
<script>
|
|
PetiteVue.createApp({
|
|
PetiteVue.createApp({
|
|
|
|
+ store,
|
|
// state
|
|
// state
|
|
- loading: false,
|
|
|
|
page: 'host',
|
|
page: 'host',
|
|
// data
|
|
// data
|
|
hosts: [],
|
|
hosts: [],
|
|
current_host: null,
|
|
current_host: null,
|
|
|
|
|
|
async editHost(host) {
|
|
async editHost(host) {
|
|
- this.loading = true
|
|
|
|
- const hosts = await fetch(`http://www.localhost:3000/moodle_host?etiqueta=eq.${host}`, {
|
|
|
|
|
|
+ store.loading = true
|
|
|
|
+ const hosts = await store.fetch(`http://www.localhost:3000/moodle_host?etiqueta=eq.${host}`, {
|
|
headers: {
|
|
headers: {
|
|
'Prefer': 'plurality=singular'
|
|
'Prefer': 'plurality=singular'
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
if (!hosts.ok) {
|
|
if (!hosts.ok) {
|
|
- this.loading = false
|
|
|
|
|
|
+ store.loading = false
|
|
alert('Error al obtener el host: ' + hosts.status)
|
|
alert('Error al obtener el host: ' + hosts.status)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -73,10 +67,10 @@
|
|
},
|
|
},
|
|
|
|
|
|
async mounted() {
|
|
async mounted() {
|
|
- this.loading = true
|
|
|
|
- const hosts = await fetch('http://www.localhost:3000/moodle_host')
|
|
|
|
|
|
+ store.loading = true
|
|
|
|
+ const hosts = await store.fetch('http://www.localhost:3000/moodle_host')
|
|
const data = await hosts.json()
|
|
const data = await hosts.json()
|
|
- this.loading = false
|
|
|
|
|
|
+ store.loading = false
|
|
|
|
|
|
this.hosts = data
|
|
this.hosts = data
|
|
}
|
|
}
|