2026-10-13 20:17:52 -05:00
|
|
|
import { isDevMode } from '@angular/core';
|
2026-10-13 20:01:34 -05:00
|
|
|
import type { Route, Routes } from '@angular/router';
|
2026-10-13 19:18:05 -05:00
|
|
|
import { MENU } from '@basic-erp/sap-types';
|
|
|
|
|
import { authGuard, guestGuard, menuLoadedGuard, permissionGuard } from './core/auth/guards';
|
2026-10-13 20:01:34 -05:00
|
|
|
import { DOCUMENT_SCREENS, menuLabel } from './features/documents/document-screens';
|
2026-10-13 19:11:05 -05:00
|
|
|
|
2026-10-13 20:01:34 -05:00
|
|
|
/**
|
|
|
|
|
* Pantallas de documento: la ruta del menú muestra la lista de los últimos documentos;
|
|
|
|
|
* `nuevo` abre el formulario vacío y `:docEntry` el documento para ver o editar.
|
|
|
|
|
* El permiso de menú gobierna las tres (el guard del padre; `data` se hereda en los hijos).
|
|
|
|
|
*/
|
|
|
|
|
const documentRoutes: Routes = DOCUMENT_SCREENS.map(
|
|
|
|
|
(screen): Route => ({
|
|
|
|
|
path: screen.path.slice(1),
|
|
|
|
|
canActivate: [permissionGuard],
|
|
|
|
|
data: { path: screen.path, title: menuLabel(screen.path), screen },
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
path: '',
|
|
|
|
|
loadComponent: () => import('./features/documents/document-list.page').then((m) => m.DocumentListPage),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: 'nuevo',
|
|
|
|
|
loadComponent: () => import('./features/documents/document-form.page').then((m) => m.DocumentFormPage),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: ':docEntry',
|
|
|
|
|
loadComponent: () => import('./features/documents/document-form.page').then((m) => m.DocumentFormPage),
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
2026-10-13 20:17:52 -05:00
|
|
|
/**
|
|
|
|
|
* Página de componentes: solo coincide al ejecutar `npm run dev:web` (isDevMode se evalúa al navegar);
|
|
|
|
|
* en producción cae en la ruta comodín. No aparece en el menú.
|
|
|
|
|
*/
|
|
|
|
|
const devRoutes: Routes = [
|
|
|
|
|
{
|
|
|
|
|
path: 'dev/componentes',
|
|
|
|
|
canMatch: [() => isDevMode()],
|
|
|
|
|
loadComponent: () => import('./features/dev/showcase.page').then((m) => m.ShowcasePage),
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
2026-10-13 22:17:50 -05:00
|
|
|
/** Administración: el permiso de menú `/admin/permisos` solo lo da el acceso total (`*`). */
|
|
|
|
|
const adminRoutes: Routes = [
|
|
|
|
|
{
|
|
|
|
|
path: 'admin/permisos',
|
|
|
|
|
canActivate: [permissionGuard],
|
|
|
|
|
data: { path: '/admin/permisos', title: 'Permisos de menú' },
|
|
|
|
|
loadComponent: () => import('./features/admin/permissions.page').then((m) => m.PermissionsPage),
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
2026-10-13 20:01:34 -05:00
|
|
|
/** Resto de pantallas del menú (maestros, etc.): aún sin construir. */
|
2026-10-13 22:17:50 -05:00
|
|
|
const builtPaths = new Set([...DOCUMENT_SCREENS.map((s) => s.path), '/admin/permisos']);
|
2026-10-13 20:01:34 -05:00
|
|
|
const pendingRoutes: Routes = MENU.flatMap((m) => m.items)
|
2026-10-13 22:17:50 -05:00
|
|
|
.filter((item) => !builtPaths.has(item.path))
|
2026-10-13 20:01:34 -05:00
|
|
|
.map(
|
|
|
|
|
(item): Route => ({
|
|
|
|
|
path: item.path.slice(1),
|
|
|
|
|
canActivate: [permissionGuard],
|
|
|
|
|
data: { path: item.path, title: item.label },
|
|
|
|
|
loadComponent: () => import('./features/shared/coming-soon.page').then((m) => m.ComingSoonPage),
|
|
|
|
|
}),
|
|
|
|
|
);
|
2026-10-13 19:18:05 -05:00
|
|
|
|
|
|
|
|
export const routes: Routes = [
|
|
|
|
|
{
|
|
|
|
|
path: 'login',
|
|
|
|
|
canActivate: [guestGuard],
|
|
|
|
|
loadComponent: () => import('./features/login/login.page').then((m) => m.LoginPage),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '',
|
|
|
|
|
canActivate: [authGuard, menuLoadedGuard],
|
|
|
|
|
loadComponent: () => import('./layout/main-layout').then((m) => m.MainLayout),
|
|
|
|
|
children: [
|
|
|
|
|
{ path: '', pathMatch: 'full', loadComponent: () => import('./features/home/home.page').then((m) => m.HomePage) },
|
|
|
|
|
{
|
|
|
|
|
path: 'sin-acceso',
|
|
|
|
|
loadComponent: () => import('./features/shared/no-access.page').then((m) => m.NoAccessPage),
|
|
|
|
|
},
|
2026-10-13 20:17:52 -05:00
|
|
|
...devRoutes,
|
2026-10-13 20:01:34 -05:00
|
|
|
...documentRoutes,
|
2026-10-13 22:17:50 -05:00
|
|
|
...adminRoutes,
|
2026-10-13 20:01:34 -05:00
|
|
|
...pendingRoutes,
|
2026-10-13 19:18:05 -05:00
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{ path: '**', redirectTo: '' },
|
|
|
|
|
];
|