router.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import { createRouter, createWebHistory } from 'vue-router'
  2. import Dashboard from './Dashboard.vue'
  3. import { Wrench01Icon, LeftToRightListDashIcon, CellsIcon, DashboardSquare01Icon } from '@hugeicons/core-free-icons'
  4. const routes = [
  5. {
  6. path: '/',
  7. name: 'Actions',
  8. component: Dashboard,
  9. meta: { title: 'Actions', icon: DashboardSquare01Icon }
  10. },
  11. {
  12. path: '/dashboards/:title/:entityType?/:entityKey?',
  13. name: 'Dashboard',
  14. component: Dashboard,
  15. props: true,
  16. meta: { title: 'Dashboard' }
  17. },
  18. {
  19. path: '/actionBinding/:bindingId/argumentForm',
  20. name: 'ActionBinding',
  21. component: () => import('./views/ArgumentForm.vue'),
  22. props: true,
  23. meta: { title: 'Action Binding' }
  24. },
  25. {
  26. path: '/logs',
  27. name: 'Logs',
  28. component: () => import('./views/LogsListView.vue'),
  29. meta: {
  30. title: 'Logs',
  31. icon: LeftToRightListDashIcon
  32. }
  33. },
  34. {
  35. path: '/logs/calendar',
  36. name: 'LogsCalendar',
  37. component: () => import('./views/LogsCalendarView.vue'),
  38. meta: {
  39. title: 'Logs Calendar',
  40. keepOnQueryChange: true,
  41. breadcrumbs: () => [
  42. { name: 'Logs', to: { name: 'Logs' } },
  43. { name: 'Calendar' }
  44. ]
  45. }
  46. },
  47. {
  48. path: '/logs/queue',
  49. name: 'LogsQueue',
  50. component: () => import('./views/LogsQueueView.vue'),
  51. meta: {
  52. title: 'Execution Queue',
  53. breadcrumbs: () => [
  54. { name: 'Logs', to: { name: 'Logs' } },
  55. { name: 'Queue' }
  56. ]
  57. }
  58. },
  59. {
  60. path: '/entities',
  61. name: 'Entities',
  62. component: () => import('./views/EntitiesView.vue'),
  63. meta: {
  64. title: 'Entities',
  65. icon: CellsIcon
  66. }
  67. },
  68. {
  69. path: '/entity-details/:entityType/:entityKey',
  70. name: 'EntityDetails',
  71. component: () => import('./views/EntityDetailsView.vue'),
  72. props: true,
  73. meta: {
  74. title: 'OliveTin - Entity Details',
  75. breadcrumbs: () => [
  76. { name: 'Entities', to: { name: 'Entities' } },
  77. { name: 'Entity Details' }
  78. ]
  79. }
  80. },
  81. {
  82. path: '/logs/:executionTrackingId',
  83. name: 'Execution',
  84. component: () => import('./views/ExecutionView.vue'),
  85. props: true,
  86. meta: {
  87. title: 'Execution',
  88. breadcrumbs: () => [
  89. { name: 'Logs', to: { name: 'Logs' } },
  90. { name: 'Execution' }
  91. ]
  92. }
  93. },
  94. {
  95. path: '/action/:actionId',
  96. name: 'ActionDetails',
  97. component: () => import('./views/ActionDetailsView.vue'),
  98. props: true,
  99. meta: {
  100. title: 'Action Details',
  101. breadcrumbs: () => [
  102. { name: 'Actions', to: { name: 'Actions' } },
  103. { name: 'Action Details' }
  104. ]
  105. }
  106. },
  107. {
  108. path: '/action/:actionId/actionexecconditions',
  109. name: 'ActionExecConditions',
  110. component: () => import('./views/ActionExecConditionsView.vue'),
  111. props: true,
  112. meta: {
  113. title: 'Execution conditions',
  114. breadcrumbs: () => [
  115. { name: 'Actions', to: { name: 'Actions' } },
  116. { name: 'Execution conditions' }
  117. ]
  118. }
  119. },
  120. {
  121. path: '/diagnostics',
  122. name: 'Diagnostics',
  123. component: () => import('./views/DiagnosticsView.vue'),
  124. meta: {
  125. title: 'Diagnostics',
  126. icon: Wrench01Icon
  127. }
  128. },
  129. {
  130. path: '/login',
  131. name: 'Login',
  132. component: () => import('./views/LoginView.vue'),
  133. meta: { title: 'Login' }
  134. },
  135. {
  136. path: '/user',
  137. name: 'UserInformation',
  138. component: () => import('./views/UserControlPanel.vue'),
  139. meta: { title: 'User Information' }
  140. },
  141. {
  142. path: '/:pathMatch(.*)*',
  143. name: 'NotFound',
  144. component: () => import('./views/NotFoundView.vue'),
  145. meta: { title: 'Page Not Found' }
  146. }
  147. ]
  148. // Create router instance
  149. const router = createRouter({
  150. history: createWebHistory(),
  151. routes,
  152. scrollBehavior (to, from, savedPosition) {
  153. if (savedPosition) {
  154. return savedPosition
  155. } else {
  156. return { top: 0 }
  157. }
  158. }
  159. })
  160. // Navigation guard to update page title
  161. router.beforeEach((to) => {
  162. if (to.meta && to.meta.title) {
  163. const pageTitle = window.initResponse?.pageTitle || 'OliveTin'
  164. document.title = to.meta.title + ' - ' + pageTitle
  165. }
  166. })
  167. // Navigation guard for authentication (if needed)
  168. router.beforeEach((to) => {
  169. if (window.initResponse?.loginRequired && to.name !== 'Login') {
  170. return '/login'
  171. }
  172. const isAuthenticated = window.isAuthenticated ?? false
  173. if (to.meta.requiresAuth && !isAuthenticated) {
  174. return '/login'
  175. }
  176. })
  177. export default router