2024-01-30 17:24:22 -03:00
|
|
|
<script>
|
|
|
|
import Modal from "../../components/Modal.svelte";
|
2024-01-27 22:32:11 -03:00
|
|
|
import {
|
|
|
|
getGtfsArchivo,
|
|
|
|
createGtfsArchivo,
|
|
|
|
updateGtfsArchivo,
|
|
|
|
deleteGtfsArchivo,
|
|
|
|
} from "$/services/gtfs_archivo";
|
2024-01-30 17:24:22 -03:00
|
|
|
import { getRedTransporte } from "$/services/red_transporte";
|
2024-01-27 22:32:11 -03:00
|
|
|
import { createEventDispatcher } from "svelte";
|
|
|
|
import { storeSession } from "$/stores/global";
|
|
|
|
const dispatch = createEventDispatcher();
|
2024-01-30 17:24:22 -03:00
|
|
|
|
|
|
|
export let id_red = null;
|
2024-01-27 22:32:11 -03:00
|
|
|
|
|
|
|
// fecha actual en formato yyyy-mm-dd
|
|
|
|
let fecha_hoy = (new Date()).toISOString().substring(0,10);
|
|
|
|
let form = { valid_from: fecha_hoy, id_red };
|
2024-01-30 17:24:22 -03:00
|
|
|
let loading = false;
|
2024-01-27 22:32:11 -03:00
|
|
|
let inputFile = null;
|
2024-01-30 17:24:22 -03:00
|
|
|
|
2024-01-27 22:32:11 -03:00
|
|
|
let redes = [];
|
2024-01-30 17:24:22 -03:00
|
|
|
|
2024-01-27 22:32:11 -03:00
|
|
|
getRedTransporte({ vigente: 1, ordering: 'nombre_red' })
|
|
|
|
.then((data) => redes = data)
|
|
|
|
.catch((error) => globalThis.toast.error(error));
|
2024-01-30 17:24:22 -03:00
|
|
|
|
|
|
|
async function onSave() {
|
|
|
|
try {
|
|
|
|
loading = true;
|
2024-01-27 22:32:11 -03:00
|
|
|
const archivo = inputFile.files[0]
|
|
|
|
const vigente = form.valid_from >= fecha_hoy;
|
|
|
|
await createGtfsArchivo({ ...form, vigente, archivo });
|
|
|
|
|
|
|
|
globalThis.toast.success("Se ha cargado el Archivo");
|
|
|
|
dispatch("refresh");
|
|
|
|
dispatch("close");
|
2024-01-30 17:24:22 -03:00
|
|
|
} catch (error) {
|
|
|
|
if (error.detail) {
|
2024-01-27 22:32:11 -03:00
|
|
|
globalThis.toast.success(error.detail);
|
2024-01-30 17:24:22 -03:00
|
|
|
} else {
|
2024-01-27 22:32:11 -03:00
|
|
|
globalThis.toast.success(JSON.stringify(error));
|
2024-01-30 17:24:22 -03:00
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
loading = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2024-01-27 22:32:11 -03:00
|
|
|
<form on:submit|preventDefault={onSave}>
|
|
|
|
<Modal
|
|
|
|
title={"Cargar Archivo GTFS"}
|
|
|
|
size="lg"
|
|
|
|
classBody="bg-white"
|
|
|
|
on:close={() => dispatch("close")}
|
|
|
|
>
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md">
|
|
|
|
<div class="input-group mb-3">
|
|
|
|
<div class="input-group-text">Red de Transporte</div>
|
|
|
|
<select bind:value={form.id_red} class="form-select">
|
|
|
|
{#each redes as rt}
|
|
|
|
<option value={rt.id_red}>{rt.nombre_red}</option>
|
|
|
|
{/each}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-01-30 17:24:22 -03:00
|
|
|
|
2024-01-27 22:32:11 -03:00
|
|
|
<div class="row mb-3">
|
|
|
|
<div class="col-md-3">Fecha Carga</div>
|
|
|
|
<div class="col-md">
|
|
|
|
<input type="date" class="form-control" disabled value={fecha_hoy}>
|
|
|
|
</div>
|
2024-01-30 17:24:22 -03:00
|
|
|
</div>
|
2024-01-27 22:32:11 -03:00
|
|
|
<div class="row mb-4">
|
|
|
|
<div class="col-md-3">Valido desde</div>
|
|
|
|
<div class="col-md">
|
|
|
|
<input type="date" class="form-control" required bind:value={form.valid_from}>
|
|
|
|
</div>
|
2024-01-30 17:24:22 -03:00
|
|
|
</div>
|
|
|
|
|
2024-01-27 22:32:11 -03:00
|
|
|
<div class="row mb-5">
|
|
|
|
<div class="col-md-3">Cargado por</div>
|
|
|
|
<div class="col-md">
|
|
|
|
<div class="form-control bg-light">
|
|
|
|
{$storeSession.persona.nombres} {$storeSession.persona.apellido_a || ''} {$storeSession.persona.apellido_b || ''}
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-01-30 17:24:22 -03:00
|
|
|
</div>
|
|
|
|
|
2024-01-27 22:32:11 -03:00
|
|
|
<div class="mb-3">
|
|
|
|
<label for="formFile" class="form-label">Archivo ZIP</label>
|
|
|
|
<input class="form-control" type="file" id="formFile" accept=".zip" required bind:this={inputFile}>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<svelte:fragment slot="buttons">
|
|
|
|
<button type="submit" class="btn btn-primary" disabled={loading}>
|
|
|
|
<i class="bi bi-save"></i> Subir Archivo ZIP
|
|
|
|
</button>
|
|
|
|
</svelte:fragment>
|
|
|
|
</Modal>
|
2024-01-30 17:24:22 -03:00
|
|
|
</form>
|
|
|
|
|
|
|
|
<style>
|
2024-01-27 22:32:11 -03:00
|
|
|
.disabled {
|
|
|
|
pointer-events: none !important;
|
|
|
|
}
|
|
|
|
</style>
|