diff --git a/src/pages/gtfs_archivo/Admin.svelte b/src/pages/gtfs_archivo/Admin.svelte index 84316c2..3fac766 100644 --- a/src/pages/gtfs_archivo/Admin.svelte +++ b/src/pages/gtfs_archivo/Admin.svelte @@ -10,7 +10,6 @@ let id_red; let escritura = false; - const limit = 15; let page = 1; @@ -18,29 +17,19 @@ let count = 0; let ordering = 'id_archivo' let redes = [] - let red = null let lista_gtfs = [] - let gtfs = null let location = useLocation() let loading = false; - let gtfsArchivo = null; + let showUpload = null; getPermisosPath($location.pathname) .then(data => escritura = data.escritura) .catch(error => console.log({ error })) - $: onPage(page) - - getRedTransporte({ vigente: 1 }) - .then(data => data.sort((a,b) => a.nombre_red < b.nombre_red? -1 : 1)) - //.then(data => redes = data ) - .then(data => { - redes = data; - if (redes.length > 0) { - id_red = redes[0].id_red; // Establece la primera red como seleccionada por defecto - onPage(1); // Carga los archivos GTFS para la red seleccionada por defecto - } - }) + getRedTransporte({ vigente: 1, ordering: 'nombre_red' }) + .then(data => redes = data) + .then(() => id_red = redes[0]?.id_red || null) + .then(() => onPage(1)) .catch(error => globalThis.toast.error(error)) async function onPage(p) { @@ -60,28 +49,32 @@ } } - function onOrderBy(field) { ordering = ordering === field ? '-' + field : field; onPage(page) } function onChangeRed() { - page = 1; // Reinicia la paginación al cambiar de red onPage(page); } function onNuevo() { - gtfsArchivo = {} + showUpload = true } Listado Archivos GTFS - -
-
+
+
+ {#if escritura} + + {/if} +
+
Red de Transporte
@@ -93,17 +86,6 @@
- - -
- -
- - - -
- -
@@ -164,23 +146,9 @@ /> -
-
- {#if escritura} - - {/if} -
-
-{#if gtfsArchivo} - gtfsArchivo = null} -/> +{#if showUpload} + showUpload = false} {id_red} /> {/if} \ No newline at end of file + .disabled { + pointer-events: none !important; + } + diff --git a/src/services/gtfs_archivo.js b/src/services/gtfs_archivo.js index 646d2da..aa877b2 100644 --- a/src/services/gtfs_archivo.js +++ b/src/services/gtfs_archivo.js @@ -18,10 +18,20 @@ export async function getGtfsArchivoId(id) { } export async function createGtfsArchivo(data) { + const form = new FormData() + for (let key in data) { + if (key === 'archivo') { + const file = data[key] + form.append(key, file, file.name) + } else { + form.append(key, data[key]) + } + } + const res = await fetch(`${base}/gtfs-archivo/`, { method: 'POST', - body: JSON.stringify(data), - headers: { "Authorization": `Bearer ${getToken()}`, "Content-Type": "application/json" } + body: form, + headers: { "Authorization": `Bearer ${getToken()}` } }) if (!res.ok) throw await res.json() return res.json()