2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-27 10:51:33 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2018-11-05 15:26:18 +00:00
|
|
|
import Vue from 'vue';
|
2019-09-09 11:33:39 +01:00
|
|
|
import Router, { RouteRecord } from 'vue-router';
|
|
|
|
|
2019-01-09 15:40:21 +00:00
|
|
|
import AccountArea from '@/components/account/AccountArea.vue';
|
2019-09-09 11:33:39 +01:00
|
|
|
import AccountBilling from '@/components/account/billing/BillingArea.vue';
|
2019-09-11 11:21:45 +01:00
|
|
|
import BillingHistory from '@/components/account/billing/BillingHistory.vue';
|
2019-09-26 14:36:12 +01:00
|
|
|
import ProfileArea from '@/components/account/ProfileArea.vue';
|
2019-01-02 13:46:55 +00:00
|
|
|
import ApiKeysArea from '@/components/apiKeys/ApiKeysArea.vue';
|
2019-08-19 12:20:38 +01:00
|
|
|
import BucketArea from '@/components/buckets/BucketArea.vue';
|
|
|
|
import Page404 from '@/components/errors/Page404.vue';
|
|
|
|
import ProjectDetails from '@/components/project/ProjectDetails.vue';
|
|
|
|
import ProjectOverviewArea from '@/components/project/ProjectOverviewArea.vue';
|
|
|
|
import UsageReport from '@/components/project/UsageReport.vue';
|
2019-09-09 11:33:39 +01:00
|
|
|
import ProjectMembersArea from '@/components/team/ProjectMembersArea.vue';
|
|
|
|
|
2019-08-22 11:44:08 +01:00
|
|
|
import { NavigationLink } from '@/types/navigation';
|
2019-09-09 11:33:39 +01:00
|
|
|
import { AuthToken } from '@/utils/authToken';
|
2019-09-26 14:36:12 +01:00
|
|
|
import DashboardArea from '@/views/DashboardArea.vue';
|
2019-09-09 11:33:39 +01:00
|
|
|
import ForgotPassword from '@/views/forgotPassword/ForgotPassword.vue';
|
2019-09-26 14:36:12 +01:00
|
|
|
import LoginArea from '@/views/login/LoginArea.vue';
|
|
|
|
import RegisterArea from '@/views/register/RegisterArea.vue';
|
2018-11-05 15:26:18 +00:00
|
|
|
|
|
|
|
Vue.use(Router);
|
|
|
|
|
2019-09-27 15:41:04 +01:00
|
|
|
/**
|
|
|
|
* RouteConfig contains information about all routes and subroutes
|
|
|
|
*/
|
2019-08-22 11:44:08 +01:00
|
|
|
export abstract class RouteConfig {
|
|
|
|
// root paths
|
|
|
|
public static Root = new NavigationLink('/', 'Root');
|
|
|
|
public static Login = new NavigationLink('/login', 'Login');
|
|
|
|
public static Register = new NavigationLink('/register', 'Register');
|
|
|
|
public static ForgotPassword = new NavigationLink('/forgot-password', 'Forgot Password');
|
|
|
|
public static Account = new NavigationLink('/account', 'Account');
|
|
|
|
public static ProjectOverview = new NavigationLink('/project-overview', 'Overview');
|
|
|
|
public static Team = new NavigationLink('/project-members', 'Team');
|
|
|
|
public static ApiKeys = new NavigationLink('/api-keys', 'API Keys');
|
|
|
|
public static Buckets = new NavigationLink('/buckets', 'Buckets');
|
|
|
|
|
|
|
|
// child paths
|
|
|
|
public static ProjectDetails = new NavigationLink('details', 'Project Details');
|
|
|
|
public static UsageReport = new NavigationLink('usage-report', 'Usage Report');
|
|
|
|
public static Profile = new NavigationLink('profile', 'Profile');
|
2019-09-04 15:33:26 +01:00
|
|
|
public static Billing = new NavigationLink('billing', 'Billing');
|
2019-09-11 11:21:45 +01:00
|
|
|
public static BillingHistory = new NavigationLink('billing-history', 'Billing History');
|
2019-08-22 11:44:08 +01:00
|
|
|
|
|
|
|
// not in project yet
|
|
|
|
// public static Referral = new NavigationLink('//ref/:ids', 'Referral');
|
|
|
|
}
|
|
|
|
|
|
|
|
const router = new Router({
|
2019-02-20 13:33:56 +00:00
|
|
|
mode: 'history',
|
|
|
|
routes: [
|
|
|
|
{
|
2019-08-22 11:44:08 +01:00
|
|
|
path: RouteConfig.Login.path,
|
|
|
|
name: RouteConfig.Login.name,
|
2019-09-26 14:36:12 +01:00
|
|
|
component: LoginArea,
|
2019-02-20 13:33:56 +00:00
|
|
|
},
|
|
|
|
{
|
2019-08-22 11:44:08 +01:00
|
|
|
path: RouteConfig.Register.path,
|
|
|
|
name: RouteConfig.Register.name,
|
2019-09-26 14:36:12 +01:00
|
|
|
component: RegisterArea,
|
2019-07-19 19:22:10 +01:00
|
|
|
},
|
2019-04-02 14:38:57 +01:00
|
|
|
{
|
2019-08-22 11:44:08 +01:00
|
|
|
path: RouteConfig.ForgotPassword.path,
|
|
|
|
name: RouteConfig.ForgotPassword.name,
|
2019-09-13 15:58:18 +01:00
|
|
|
component: ForgotPassword,
|
2019-04-02 14:38:57 +01:00
|
|
|
},
|
2019-02-20 13:33:56 +00:00
|
|
|
{
|
2019-08-22 11:44:08 +01:00
|
|
|
path: RouteConfig.Root.path,
|
2019-02-20 13:33:56 +00:00
|
|
|
meta: {
|
2019-09-13 15:58:18 +01:00
|
|
|
requiresAuth: true,
|
2019-02-20 13:33:56 +00:00
|
|
|
},
|
2019-09-26 14:36:12 +01:00
|
|
|
component: DashboardArea,
|
2019-02-20 13:33:56 +00:00
|
|
|
children: [
|
|
|
|
{
|
2019-08-22 11:44:08 +01:00
|
|
|
path: RouteConfig.Account.path,
|
|
|
|
name: RouteConfig.Account.name,
|
2019-06-03 13:19:48 +01:00
|
|
|
component: AccountArea,
|
|
|
|
children: [
|
|
|
|
{
|
2019-08-22 11:44:08 +01:00
|
|
|
path: RouteConfig.Profile.path,
|
|
|
|
name: RouteConfig.Profile.name,
|
2019-09-26 14:36:12 +01:00
|
|
|
component: ProfileArea,
|
2019-06-03 13:19:48 +01:00
|
|
|
},
|
2019-09-04 15:33:26 +01:00
|
|
|
{
|
|
|
|
path: RouteConfig.Billing.path,
|
|
|
|
name: RouteConfig.Billing.name,
|
|
|
|
component: AccountBilling,
|
|
|
|
},
|
2019-09-11 11:21:45 +01:00
|
|
|
{
|
|
|
|
path: RouteConfig.BillingHistory.path,
|
|
|
|
name: RouteConfig.BillingHistory.name,
|
|
|
|
component: BillingHistory,
|
|
|
|
},
|
2019-09-13 15:58:18 +01:00
|
|
|
],
|
2019-02-20 13:33:56 +00:00
|
|
|
},
|
|
|
|
{
|
2019-08-22 11:44:08 +01:00
|
|
|
path: RouteConfig.ProjectOverview.path,
|
|
|
|
name: RouteConfig.ProjectOverview.name,
|
2019-05-15 16:01:41 +01:00
|
|
|
component: ProjectOverviewArea,
|
|
|
|
children: [
|
|
|
|
{
|
2019-08-22 11:44:08 +01:00
|
|
|
path: RouteConfig.UsageReport.path,
|
|
|
|
name: RouteConfig.UsageReport.name,
|
2019-05-15 16:01:41 +01:00
|
|
|
component: UsageReport,
|
|
|
|
},
|
|
|
|
{
|
2019-08-22 11:44:08 +01:00
|
|
|
path: RouteConfig.ProjectDetails.path,
|
|
|
|
name: RouteConfig.ProjectDetails.name,
|
2019-09-13 15:58:18 +01:00
|
|
|
component: ProjectDetails,
|
2019-05-15 16:01:41 +01:00
|
|
|
},
|
2019-09-13 15:58:18 +01:00
|
|
|
],
|
2019-04-05 16:08:14 +01:00
|
|
|
},
|
|
|
|
{
|
2019-08-22 11:44:08 +01:00
|
|
|
path: RouteConfig.Root.path,
|
2019-04-05 16:08:14 +01:00
|
|
|
name: 'default',
|
2019-09-13 15:58:18 +01:00
|
|
|
component: ProjectOverviewArea,
|
2019-02-20 13:33:56 +00:00
|
|
|
},
|
|
|
|
{
|
2019-08-22 11:44:08 +01:00
|
|
|
path: RouteConfig.Team.path,
|
|
|
|
name: RouteConfig.Team.name,
|
2019-09-13 15:58:18 +01:00
|
|
|
component: ProjectMembersArea,
|
2019-02-20 13:33:56 +00:00
|
|
|
},
|
|
|
|
{
|
2019-08-22 11:44:08 +01:00
|
|
|
path: RouteConfig.ApiKeys.path,
|
|
|
|
name: RouteConfig.ApiKeys.name,
|
2019-09-13 15:58:18 +01:00
|
|
|
component: ApiKeysArea,
|
2019-02-20 13:33:56 +00:00
|
|
|
},
|
2019-05-16 11:43:46 +01:00
|
|
|
{
|
2019-08-22 11:44:08 +01:00
|
|
|
path: RouteConfig.Buckets.path,
|
|
|
|
name: RouteConfig.Buckets.name,
|
2019-09-13 15:58:18 +01:00
|
|
|
component: BucketArea,
|
2019-05-16 11:43:46 +01:00
|
|
|
},
|
2019-09-13 15:58:18 +01:00
|
|
|
],
|
2019-02-20 13:33:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '*',
|
|
|
|
name: '404',
|
2019-09-13 15:58:18 +01:00
|
|
|
component: Page404,
|
2019-03-14 12:48:43 +00:00
|
|
|
},
|
2019-09-13 15:58:18 +01:00
|
|
|
],
|
2018-11-05 15:26:18 +00:00
|
|
|
});
|
2018-11-28 09:16:35 +00:00
|
|
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
2019-02-20 13:33:56 +00:00
|
|
|
if (to.matched.some(route => route.meta.requiresAuth)) {
|
2019-07-22 10:46:26 +01:00
|
|
|
if (!AuthToken.get()) {
|
2019-08-22 11:44:08 +01:00
|
|
|
next(RouteConfig.Login.path);
|
2018-12-18 14:43:23 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-11-28 09:16:35 +00:00
|
|
|
|
2019-09-27 15:41:04 +01:00
|
|
|
if (navigateToDefaultSubTab(to.matched, RouteConfig.Account)) {
|
2019-08-22 11:44:08 +01:00
|
|
|
next(RouteConfig.Account.with(RouteConfig.Profile).path);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-27 15:41:04 +01:00
|
|
|
if (navigateToDefaultSubTab(to.matched, RouteConfig.ProjectOverview)) {
|
2019-08-22 11:44:08 +01:00
|
|
|
next(RouteConfig.ProjectOverview.with(RouteConfig.ProjectDetails).path);
|
2018-11-28 09:16:35 +00:00
|
|
|
|
2019-08-22 11:44:08 +01:00
|
|
|
return;
|
|
|
|
}
|
2019-04-05 16:08:14 +01:00
|
|
|
|
2019-08-28 14:08:19 +01:00
|
|
|
if (to.name === 'default') {
|
|
|
|
next(RouteConfig.ProjectOverview.with(RouteConfig.ProjectDetails).path);
|
2019-09-27 15:41:04 +01:00
|
|
|
|
|
|
|
return;
|
2019-08-28 14:08:19 +01:00
|
|
|
}
|
|
|
|
|
2019-08-22 11:44:08 +01:00
|
|
|
next();
|
|
|
|
});
|
2019-04-05 16:08:14 +01:00
|
|
|
|
2019-08-22 11:44:08 +01:00
|
|
|
/**
|
|
|
|
* if our route is a tab and has no sub tab route - we will navigate to default subtab.
|
|
|
|
* F.E. /account/ -> /account/profile/; /project-overview/ -> /project-overview/details/
|
|
|
|
* @param routes - array of RouteRecord from vue-router
|
|
|
|
* @param next - callback to process next route
|
|
|
|
* @param tabRoute - tabNavigator route
|
|
|
|
*/
|
2019-09-27 15:41:04 +01:00
|
|
|
function navigateToDefaultSubTab(routes: RouteRecord[], tabRoute: NavigationLink): boolean {
|
2019-09-09 11:33:39 +01:00
|
|
|
return routes.length === 2 && (routes[1].name as string) === tabRoute.name;
|
2019-04-05 16:08:14 +01:00
|
|
|
}
|
|
|
|
|
2018-11-28 09:16:35 +00:00
|
|
|
export default router;
|