| 1 | import type { RouteLocationRaw } from "vue-router" |
| 2 | import { useRouter } from "vue-router" |
| 3 | |
| 4 | export function useNavigation() { |
| 5 | const router = useRouter() |
| 6 | |
| 7 | function routerConstructor(route: RouteLocationRaw) { |
| 8 | return { |
| 9 | navigate: () => router.push(route), |
| 10 | replace: () => router.replace(route), |
| 11 | valueOf: () => router.resolve(route).href, |
| 12 | toString: () => router.resolve(route).href, |
| 13 | fullUrl: () => { |
| 14 | const resolved = router.resolve(route) |
| 15 | return `${window.location.protocol}//${window.location.host}${resolved.href}` |
| 16 | } |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | function routeCustomer(params?: { code?: string | number; action?: "add-customer" }) { |
| 21 | if (params?.code) { |
| 22 | return routerConstructor({ name: "Customers", query: { code: params.code.toString() } }) |
| 23 | } else if (params?.action) { |
| 24 | return routerConstructor({ name: "Customers", query: { action: params.action.toString() } }) |
| 25 | } else { |
| 26 | return routerConstructor({ name: "Customers" }) |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | function routeAgent(agentId?: string | number) { |
| 31 | if (agentId) { |
| 32 | return routerConstructor({ name: "Agent", params: { id: agentId.toString() } }) |
| 33 | } else { |
| 34 | return routerConstructor({ name: "Agents" }) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | function routeIndex(indexName?: string) { |
| 39 | return routerConstructor({ name: "Indices", query: indexName ? { index_name: indexName } : {} }) |
| 40 | } |
| 41 | |
| 42 | function routeLicense() { |
| 43 | return routerConstructor({ name: "License" }) |
| 44 | } |
| 45 | |
| 46 | function routeHealthcheck() { |
| 47 | return routerConstructor({ name: "Healthcheck" }) |
| 48 | } |
| 49 | |
| 50 | function routeMetrics() { |
| 51 | return routerConstructor({ name: "Metrics" }) |
| 52 | } |
| 53 | |
| 54 | function routeGraylogMetrics() { |
| 55 | return routerConstructor({ name: "Graylog-Metrics" }) |
| 56 | } |
| 57 | |
| 58 | function routeGraylogManagement( |
| 59 | tabName?: "messages" | "alerts" | "events" | "streams" | "provisioning" | "inputs" |
| 60 | ) { |
| 61 | return routerConstructor({ name: "Graylog-Management", hash: tabName ? `#${tabName}` : undefined }) |
| 62 | } |
| 63 | |
| 64 | function routeSocAlerts() { |
| 65 | return routerConstructor({ name: "Soc-Alerts" }) |
| 66 | } |
| 67 | |
| 68 | function routeAlerts() { |
| 69 | return routerConstructor({ name: "Alerts" }) |
| 70 | } |
| 71 | |
| 72 | function routeConnectors() { |
| 73 | return routerConstructor({ name: "Connectors" }) |
| 74 | } |
| 75 | |
| 76 | function routeGraylogPipelines(rule?: string) { |
| 77 | return routerConstructor({ name: "Graylog-Pipelines", query: rule ? { rule } : {} }) |
| 78 | } |
| 79 | |
| 80 | function routeSocUsers(userId?: string | number) { |
| 81 | return routerConstructor({ name: "Soc-Users", query: userId ? { user_id: userId } : {} }) |
| 82 | } |
| 83 | |
| 84 | function routeIncidentManagementAlerts(alertId?: number) { |
| 85 | return routerConstructor({ name: "IncidentManagement-Alerts", query: alertId ? { alert_id: alertId } : {} }) |
| 86 | } |
| 87 | |
| 88 | function routeIncidentManagementCases(caseId?: number) { |
| 89 | return routerConstructor({ name: "IncidentManagement-Cases", query: caseId ? { case_id: caseId } : {} }) |
| 90 | } |
| 91 | |
| 92 | function routeEventSearch(params?: { customer_code?: string; source_name?: string; query?: string }) { |
| 93 | const routeQuery: Record<string, string> = {} |
| 94 | if (params?.customer_code) routeQuery.customer_code = params.customer_code |
| 95 | if (params?.source_name) routeQuery.source_name = params.source_name |
| 96 | if (params?.query) routeQuery.query = params.query |
| 97 | return routerConstructor({ name: "EventSearch", query: routeQuery }) |
| 98 | } |
| 99 | |
| 100 | function routeSSOConfig() { |
| 101 | return routerConstructor({ name: "SSOConfig" }) |
| 102 | } |
| 103 | |
| 104 | return { |
| 105 | routeCustomer, |
| 106 | routeAgent, |
| 107 | routeIndex, |
| 108 | routeLicense, |
| 109 | routeHealthcheck, |
| 110 | routeMetrics, |
| 111 | routeGraylogMetrics, |
| 112 | routeGraylogManagement, |
| 113 | routeSocAlerts, |
| 114 | routeGraylogPipelines, |
| 115 | routeSocUsers, |
| 116 | routeAlerts, |
| 117 | routeConnectors, |
| 118 | routeIncidentManagementAlerts, |
| 119 | routeIncidentManagementCases, |
| 120 | routeEventSearch, |
| 121 | routeSSOConfig |
| 122 | } |
| 123 | } |