feat: update routes with color and direction, improve admin routes view, and update firebase config/auth
This commit is contained in:
@ -293,16 +293,21 @@ function handleBack() {
|
||||
async function createRoute() {
|
||||
const name = prompt("Nombre de la nueva ruta:")
|
||||
if (!name) return
|
||||
const route = await routesService.createRoute({
|
||||
name,
|
||||
origin_city: 'David',
|
||||
destination_city: 'Boquete',
|
||||
status: 'active',
|
||||
color: '#FEE715',
|
||||
direction: 'outbound'
|
||||
})
|
||||
routes.value = await routesService.getAllRoutes()
|
||||
selectRoute(route)
|
||||
try {
|
||||
const route = await routesService.createRoute({
|
||||
name,
|
||||
origin_city: 'David',
|
||||
destination_city: 'Boquete',
|
||||
status: 'active',
|
||||
color: '#FEE715',
|
||||
direction: 'outbound'
|
||||
})
|
||||
routes.value = await routesService.getAllRoutes()
|
||||
selectRoute(route)
|
||||
} catch (err: any) {
|
||||
console.error('Error creating route:', err)
|
||||
alert('No se pudo crear la ruta: ' + (err.response?.data?.detail || err.message))
|
||||
}
|
||||
}
|
||||
|
||||
async function selectRoute(route: Route) {
|
||||
@ -312,14 +317,19 @@ async function selectRoute(route: Route) {
|
||||
|
||||
async function updateRouteDetails() {
|
||||
if (!selectedRoute.value) return
|
||||
await routesService.updateRoute(selectedRoute.value.id, {
|
||||
name: selectedRoute.value.name,
|
||||
origin_city: selectedRoute.value.origin_city,
|
||||
destination_city: selectedRoute.value.destination_city,
|
||||
average_speed_kmh: selectedRoute.value.average_speed_kmh,
|
||||
status: selectedRoute.value.status,
|
||||
color: selectedRoute.value.color
|
||||
})
|
||||
try {
|
||||
await routesService.updateRoute(selectedRoute.value.id, {
|
||||
name: selectedRoute.value.name,
|
||||
origin_city: selectedRoute.value.origin_city,
|
||||
destination_city: selectedRoute.value.destination_city,
|
||||
average_speed_kmh: selectedRoute.value.average_speed_kmh,
|
||||
status: selectedRoute.value.status,
|
||||
color: selectedRoute.value.color
|
||||
})
|
||||
} catch (err: any) {
|
||||
console.error('Error updating route:', err)
|
||||
// Opcional: mostrar notificación sutil en lugar de alert recurrente
|
||||
}
|
||||
}
|
||||
|
||||
async function addStop() {
|
||||
@ -331,11 +341,16 @@ async function addStop() {
|
||||
|
||||
async function addExistingStop(stopId: string) {
|
||||
if (!selectedRoute.value) return
|
||||
await routesService.addStopToRoute(selectedRoute.value.id, {
|
||||
stop_id: stopId,
|
||||
stop_order: routeStops.value.length + 1
|
||||
})
|
||||
routeStops.value = await routesService.getRouteStops(selectedRoute.value.id)
|
||||
try {
|
||||
await routesService.addStopToRoute(selectedRoute.value.id, {
|
||||
stop_id: stopId,
|
||||
stop_order: routeStops.value.length + 1
|
||||
})
|
||||
routeStops.value = await routesService.getRouteStops(selectedRoute.value.id)
|
||||
} catch (err: any) {
|
||||
console.error('Error adding stop:', err)
|
||||
alert('Error al añadir parada: ' + (err.response?.data?.detail || err.message))
|
||||
}
|
||||
}
|
||||
|
||||
async function updateStop(stop: BusStop) {
|
||||
@ -364,9 +379,14 @@ async function removeStop(stop: BusStop) {
|
||||
async function deleteRoute() {
|
||||
if (!selectedRoute.value) return
|
||||
if (confirm(`Estás SEGURO de que quieres eliminar la ruta ${selectedRoute.value.name}? Esta acción es permanente.`)) {
|
||||
await routesService.deleteRoute(selectedRoute.value.id)
|
||||
selectedRoute.value = null
|
||||
routes.value = await routesService.getAllRoutes()
|
||||
try {
|
||||
await routesService.deleteRoute(selectedRoute.value.id)
|
||||
selectedRoute.value = null
|
||||
routes.value = await routesService.getAllRoutes()
|
||||
} catch (err: any) {
|
||||
console.error('Error deleting route:', err)
|
||||
alert('No se pudo eliminar la ruta: ' + (err.response?.data?.detail || err.message))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -26,9 +26,8 @@ onMounted(async () => {
|
||||
else if (role === 'PROMOTER') router.push('/promoter')
|
||||
else router.push('/map')
|
||||
}
|
||||
} catch (e) {
|
||||
// No redirect result pending, or error — ignore silently
|
||||
console.warn('Google redirect result:', e)
|
||||
} catch (e: any) {
|
||||
console.error('Google redirect result error:', e)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
@ -42,7 +41,7 @@ onMounted(async () => {
|
||||
<!-- Botón volver al mapa -->
|
||||
<button class="back-to-map" @click="router.push('/map')">
|
||||
<span class="material-icons">arrow_back</span>
|
||||
Volver al mapa
|
||||
Volver
|
||||
</button>
|
||||
|
||||
<!-- Branding -->
|
||||
|
||||
@ -28,10 +28,14 @@ import { ref, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useRouteStore } from '@/stores/route'
|
||||
import { useBusStopStore } from '@/stores/busStop'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { authService } from '@/services/authService'
|
||||
import { getGoogleRedirectResult } from '@/firebaseConfig'
|
||||
|
||||
const router = useRouter()
|
||||
const routeStore = useRouteStore()
|
||||
const busStopStore = useBusStopStore()
|
||||
const authStore = useAuthStore()
|
||||
|
||||
const logoVisible = ref(false)
|
||||
const showLoading = ref(false)
|
||||
@ -79,7 +83,23 @@ function navigate() {
|
||||
}
|
||||
|
||||
async function performInitializationTasks() {
|
||||
// Task 1: Check connection and load routes
|
||||
// Task 1: Check for Google Redirect Result (Mobile Login)
|
||||
statusMessage.value = 'Verificando sesión...'
|
||||
try {
|
||||
const googleResult = await getGoogleRedirectResult()
|
||||
if (googleResult) {
|
||||
statusMessage.value = 'Iniciando sesión con Google...'
|
||||
const response = await authService.googleLogin(googleResult.token)
|
||||
authStore.login(response.access_token, response.role, response.full_name)
|
||||
statusMessage.value = `¡Bienvenido ${response.full_name}!`
|
||||
// Wait a bit to show the welcome message
|
||||
await new Promise(r => setTimeout(r, 800))
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Google Redirect handling failed:', error)
|
||||
}
|
||||
|
||||
// Task 2: Check connection and load routes
|
||||
statusMessage.value = 'Cargando datos de rutas...'
|
||||
try {
|
||||
await routeStore.loadRoutes()
|
||||
@ -87,7 +107,7 @@ async function performInitializationTasks() {
|
||||
console.error('Error loading routes:', error)
|
||||
}
|
||||
|
||||
// Task 2: Load bus stops
|
||||
// Task 3: Load bus stops
|
||||
statusMessage.value = 'Cargando paradas...'
|
||||
try {
|
||||
await busStopStore.loadBusStops()
|
||||
@ -95,7 +115,7 @@ async function performInitializationTasks() {
|
||||
console.error('Error loading bus stops:', error)
|
||||
}
|
||||
|
||||
// Task 3: Prepared
|
||||
// Task 4: Prepared
|
||||
statusMessage.value = 'Listo para usar'
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user