nidus-sync/ts/router.ts

222 lines
6.2 KiB
TypeScript
Raw Normal View History

import { createRouter, createWebHistory } from "vue-router";
import type { RouteRecordRaw } from "vue-router";
import Home from "./view/Home.vue";
import About from "./view/About.vue";
import Communication from "./view/Communication.vue";
2026-03-22 17:44:59 +00:00
import ConfigurationIntegration from "./view/configuration/Integration.vue";
2026-03-22 17:49:59 +00:00
import ConfigurationIntegrationArcgis from "./view/configuration/IntegrationArcgis.vue";
import ConfigurationOrganization from "./view/configuration/Organization.vue";
2026-03-22 17:25:11 +00:00
import ConfigurationPesticide from "./view/configuration/Pesticide.vue";
import ConfigurationPesticideAdd from "./view/configuration/PesticideAdd.vue";
2026-03-22 17:20:46 +00:00
import ConfigurationRoot from "./view/configuration/Root.vue";
2026-03-24 13:45:37 -07:00
import ConfigurationUpload from "./view/configuration/Upload.vue";
2026-03-25 21:45:13 -07:00
import ConfigurationUploadDetail from "./view/configuration/UploadDetail.vue";
2026-03-24 13:48:13 -07:00
import ConfigurationUploadPool from "./view/configuration/UploadPool.vue";
2026-04-15 18:25:12 +00:00
import ConfigurationUploadPoolCustom from "./view/configuration/UploadPoolCustom.vue";
2026-03-24 13:50:44 -07:00
import ConfigurationUploadPoolFlyover from "./view/configuration/UploadPoolFlyover.vue";
2026-03-22 17:20:46 +00:00
import ConfigurationUser from "./view/configuration/User.vue";
import ConfigurationUserAdd from "./view/configuration/UserAdd.vue";
2026-03-28 16:31:29 -07:00
import ConfigurationUserEdit from "./view/configuration/UserEdit.vue";
2026-03-21 22:41:47 +00:00
import Intelligence from "./view/Intelligence.vue";
2026-03-23 14:24:24 -07:00
import NotFound from "./view/NotFound.vue";
2026-03-22 18:00:30 +00:00
import OAuthRefreshArcgis from "./view/OAuthRefreshArcgis.vue";
import Operations from "./view/Operations.vue";
import Planning from "./view/Planning.vue";
import ReviewPool from "./view/review/Pool.vue";
import ReviewRoot from "./view/review/Root.vue";
2026-03-23 14:24:24 -07:00
import Signin from "./view/Signin.vue";
import Sudo from "./view/Sudo.vue";
2026-03-23 14:39:57 -07:00
import apiClient from "@/client";
const routes: RouteRecordRaw[] = [
{
path: "/",
name: "Home",
component: Home,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
},
{
path: "/_/communication",
name: "Communication",
component: Communication,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
},
{
path: "/_/configuration",
name: "Configuration",
2026-03-22 17:20:46 +00:00
component: ConfigurationRoot,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
2026-03-22 17:20:46 +00:00
},
2026-03-22 17:44:59 +00:00
{
path: "/_/configuration/integration",
2026-03-22 17:44:59 +00:00
name: "Integration Configuration",
component: ConfigurationIntegration,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
2026-03-22 17:44:59 +00:00
},
2026-03-22 17:49:59 +00:00
{
path: "/_/configuration/integration/arcgis",
2026-03-22 17:49:59 +00:00
name: "Arcgis Integration Configuration",
component: ConfigurationIntegrationArcgis,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
2026-03-22 17:49:59 +00:00
},
{
path: "/_/configuration/organization",
name: "Organization Configuration",
component: ConfigurationOrganization,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
},
2026-03-22 17:25:11 +00:00
{
path: "/_/configuration/pesticide",
2026-03-22 17:25:11 +00:00
name: "Pesticide Configuration",
component: ConfigurationPesticide,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
2026-03-22 17:25:11 +00:00
},
{
path: "/_/configuration/pesticide/add",
name: "Pesticide Add",
component: ConfigurationPesticideAdd,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
2026-03-24 13:45:37 -07:00
},
{
path: "/_/configuration/upload",
2026-03-24 13:45:37 -07:00
name: "Upload Configuration",
component: ConfigurationUpload,
meta: { requiresAuth: true, showSidebar: true },
2026-03-24 13:48:13 -07:00
},
2026-03-25 21:45:13 -07:00
{
component: ConfigurationUploadDetail,
meta: { requiresAuth: true, showSidebar: true },
name: "Upload Detail",
path: "/_/configuration/upload/:id",
props: (route) => ({
id: parseInt(route.params.id as string, 10),
}),
2026-03-25 21:45:13 -07:00
},
2026-03-24 13:48:13 -07:00
{
path: "/_/configuration/upload/pool",
2026-03-24 13:48:13 -07:00
name: "Pool Upload",
component: ConfigurationUploadPool,
meta: { requiresAuth: true, showSidebar: true },
2026-03-24 13:50:44 -07:00
},
2026-04-15 18:25:12 +00:00
{
path: "/_/configuration/upload/pool/custom",
name: "Custom Pool Upload",
component: ConfigurationUploadPoolCustom,
meta: { requiresAuth: true, showSidebar: true },
},
2026-03-24 13:50:44 -07:00
{
path: "/_/configuration/upload/pool/flyover",
2026-03-24 13:50:44 -07:00
name: "Flyover Upload",
component: ConfigurationUploadPoolFlyover,
meta: { requiresAuth: true, showSidebar: true },
},
2026-03-22 17:20:46 +00:00
{
path: "/_/configuration/user",
2026-03-22 17:20:46 +00:00
name: "User Configuration",
component: ConfigurationUser,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
2026-03-22 17:20:46 +00:00
},
{
path: "/_/configuration/user/add",
2026-03-22 17:20:46 +00:00
name: "User Add Configuration",
component: ConfigurationUserAdd,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
},
2026-03-28 16:31:29 -07:00
{
component: ConfigurationUserEdit,
meta: { requiresAuth: true, showSidebar: true },
name: "User Edit",
path: "/_/configuration/user/:id",
2026-04-02 15:26:03 +00:00
props: (route) => ({
id: parseInt(route.params.id as string, 10),
}),
2026-03-28 16:31:29 -07:00
},
2026-03-21 22:41:47 +00:00
{
path: "/_/intelligence",
2026-03-21 22:41:47 +00:00
name: "Intelligence",
component: Intelligence,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
2026-03-21 22:41:47 +00:00
},
2026-03-22 18:00:30 +00:00
{
path: "/_/oauth/refresh/arcgis",
2026-03-22 18:00:30 +00:00
name: "Arcgis OAuth Refresh",
component: OAuthRefreshArcgis,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
2026-03-22 18:00:30 +00:00
},
{
path: "/_/operations",
name: "Operations",
component: Operations,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
},
{
path: "/_/planning",
name: "Planning",
component: Planning,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
},
{
path: "/_/review",
name: "Review",
component: ReviewRoot,
meta: { requiresAuth: true, showSidebar: true },
},
{
path: "/_/review/pool",
name: "Pool Review",
component: ReviewPool,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
},
2026-04-16 07:03:45 +00:00
{
path: "/_/review/site",
name: "Site Review",
component: ReviewSite,
meta: { requiresAuth: true, showSidebar: true },
},
2026-03-23 14:24:24 -07:00
{
path: "/_/signin",
2026-03-23 14:24:24 -07:00
name: "Signin",
component: Signin,
meta: { requiresAuth: false, showSidebar: false },
},
{
path: "/_/sudo",
name: "Sudo",
component: Sudo,
2026-03-23 14:24:24 -07:00
meta: { requiresAuth: true, showSidebar: true },
},
// Catch-all route - must be last
{
path: "/:pathMatch(.*)*",
name: "NotFound",
component: NotFound,
},
];
export const router = createRouter({
history: createWebHistory("/"),
routes,
});
2026-03-23 14:39:57 -07:00
2026-03-23 14:24:24 -07:00
// Global navigation guard
2026-03-25 21:45:13 -07:00
router.beforeEach(async (to, from) => {
const requiresAuth = to.matched.some((record) => record.meta.requiresAuth);
2026-03-23 14:24:24 -07:00
if (requiresAuth) {
try {
// Check if user is authenticated (could be an API call)
const isAuthenticated = await apiClient.isAuthenticated();
if (!isAuthenticated) {
return "/signin";
} else {
return;
}
} catch (error) {
console.log("check auth failed");
return "/signin";
}
}
});
export default router;