Files
egorin/src/config/modules.ts
T

59 lines
5.0 KiB
TypeScript

import type { ComponentType } from 'react';
import { Zap, Cpu, Navigation, Network, ShieldCheck, Siren, Smartphone, FolderGit2, Gauge, Wallet, BellRing, MapPinned, History, MapPin, Building2, Archive, Boxes, RadioTower } from 'lucide-react';
import { EnergyModule } from '@/modules/energy/EnergyModule';
import { LoraModule } from '@/modules/energy/LoraModule';
import { SmartModule } from '@/modules/smart/SmartModule';
import { LocationsModule } from '@/modules/smart/LocationsModule';
import { SecurityModule } from '@/modules/security/SecurityModule';
import { ObjectsModule } from '@/modules/security/ObjectsModule';
import { ArchiveModule } from '@/modules/security/ArchiveModule';
import { GpsModule } from '@/modules/gps/GpsModule';
import { MapLabModule } from '@/modules/gps/MapLabModule';
import { GeoModule } from '@/modules/geo/GeoModule';
import { EventsModule } from '@/modules/gps/EventsModule';
import { NetworkModule } from '@/modules/network/NetworkModule';
import { DevicesModule } from '@/modules/devices/DevicesModule';
import { CabinetModule } from '@/modules/cabinet/CabinetModule';
import { AccessModule } from '@/modules/access/AccessModule';
import { AdminModule } from '@/modules/admin/AdminModule';
import { NotifyModule } from '@/modules/notify/NotifyModule';
import { ReposModule } from '@/modules/repos/ReposModule';
import { can, type SectionId, type User } from '@/core/auth';
export interface ModuleDef {
id: string;
path: string;
title: string;
short: string;
icon: ComponentType<{ className?: string }>;
component: ComponentType;
section?: SectionId; // раздел для RBAC (нет — служебный, напр. админский)
adminOnly?: boolean;
hidden?: boolean; // маршрут есть, но в левом сайдбаре НЕ показывать (подпункт/служебный)
}
export const MODULES: ModuleDef[] = [
{ id: 'energy', path: '/energy', title: 'Энергомониторинг', short: 'Энерго', icon: Zap, component: EnergyModule, section: 'energy' },
{ id: 'lora', path: '/lora', title: 'Энерго LoRa/LAN', short: 'LoRa', icon: RadioTower, component: LoraModule, section: 'energy' },
{ id: 'smart', path: '/smart', title: 'Смартпанель', short: 'Смарт', icon: Cpu, component: SmartModule, section: 'smart' },
{ id: 'smart-locations', path: '/smart-locations', title: 'Локации', short: 'Локации', icon: MapPin, component: LocationsModule, section: 'smart', hidden: true },
{ id: 'security', path: '/security', title: 'Охранный пульт (ПЦН)', short: 'Охрана', icon: Siren, component: SecurityModule, section: 'security' },
{ id: 'security-objects', path: '/security-objects', title: 'Охраняемые объекты', short: 'Объекты', icon: Building2, component: ObjectsModule, section: 'security', hidden: true },
{ id: 'security-archive', path: '/security-archive', title: 'Архив сработок', short: 'Архив', icon: Archive, component: ArchiveModule, section: 'security', hidden: true },
{ id: 'gps', path: '/gps', title: 'GPS-мониторинг', short: 'GPS', icon: Navigation, component: GpsModule, section: 'gps' },
{ id: 'map-lab', path: '/map-lab', title: 'Карта-лаборатория (GL)', short: 'GL-карта', icon: Boxes, component: MapLabModule, section: 'gps' },
{ id: 'geo', path: '/geofences', title: 'Геозоны', short: 'Геозоны', icon: MapPinned, component: GeoModule, section: 'gps', hidden: true },
{ id: 'events', path: '/events', title: 'История событий', short: 'События', icon: History, component: EventsModule, section: 'gps', hidden: true },
{ id: 'network', path: '/network', title: 'Сетевая инфраструктура', short: 'Сеть', icon: Network, component: NetworkModule, section: 'netinfra' },
{ id: 'devices', path: '/devices', title: 'Мои устройства', short: 'Устройства', icon: Smartphone, component: DevicesModule },
{ id: 'cabinet', path: '/cabinet', title: 'Личный кабинет', short: 'Кабинет', icon: Wallet, component: CabinetModule, hidden: true },
{ id: 'access', path: '/access', title: 'Доступ и роли', short: 'Доступ', icon: ShieldCheck, component: AccessModule, adminOnly: true },
{ id: 'notify', path: '/notify', title: 'Уведомления', short: 'Уведомл.', icon: BellRing, component: NotifyModule, adminOnly: true },
{ id: 'admin', path: '/admin', title: 'Админ-консоль', short: 'Админ', icon: Gauge, component: AdminModule, adminOnly: true },
{ id: 'repos', path: '/repos', title: 'Карта репозиториев', short: 'Репо', icon: FolderGit2, component: ReposModule, adminOnly: true },
];
// Видимые пользователю модули: служебные — по admin, разделы — по праву view.
export const visibleModules = (user: User): ModuleDef[] =>
MODULES.filter((m) => (m.adminOnly ? !!user.admin : m.section ? can(user, m.section, 'view') : true));