Initial commit
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import store from 'new-dashboard/store';
|
||||
import { isAllowed } from 'new-dashboard/core/configuration/filters';
|
||||
|
||||
export default function checkNavigation (storeModule, redirectionRoute) {
|
||||
return checkFilters.bind(this, storeModule, redirectionRoute);
|
||||
}
|
||||
|
||||
export function checkFilters (redirectionRoute, storeModule, to, _, next) {
|
||||
const urlOptions = { ...to.params, ...to.query };
|
||||
|
||||
if (urlOptions.filter && !isAllowed(urlOptions.filter)) {
|
||||
return next({ name: redirectionRoute });
|
||||
}
|
||||
|
||||
store.dispatch(`${storeModule}/setURLOptions`, urlOptions);
|
||||
next();
|
||||
}
|
||||
|
||||
export function mapsBeforeEnter (to, from, next) {
|
||||
store.dispatch('maps/resetFilters');
|
||||
checkFilters('maps', 'maps', to, from, next);
|
||||
}
|
||||
|
||||
export function datasetsBeforeEnter (to, from, next) {
|
||||
store.dispatch('datasets/resetFilters');
|
||||
checkFilters('datasets', 'datasets', to, from, next);
|
||||
}
|
||||
|
||||
export function catalogueDetailBeforeEnter (to, from, next) {
|
||||
if (to.query.category && to.query.country) {
|
||||
store.dispatch('catalogue/fetchDatasets', {
|
||||
category: to.query.category,
|
||||
country: to.query.country
|
||||
});
|
||||
next();
|
||||
} else {
|
||||
next({ name: 'catalogue' });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import store from 'new-dashboard/store';
|
||||
|
||||
export default function fetchOAuthApps (to, from, next) {
|
||||
store.dispatch('oAuthApps/fetch', {
|
||||
baseUrl: store.state.user.base_url,
|
||||
userId: store.state.user.id,
|
||||
apiKey: store.state.user.api_key
|
||||
});
|
||||
next();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import store from 'new-dashboard/store';
|
||||
|
||||
export default function fetchNotifications (to, from, next) {
|
||||
store.dispatch('notifications/fetchNotifications', {
|
||||
baseUrl: store.state.user.base_url,
|
||||
userId: store.state.user.id,
|
||||
apiKey: store.state.user.api_key
|
||||
});
|
||||
next();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import store from 'new-dashboard/store';
|
||||
|
||||
export function fetchOAuthApps (_1, _2, next) {
|
||||
store.dispatch('oAuthApps/fetch', {
|
||||
baseUrl: store.state.user.base_url,
|
||||
userId: store.state.user.id,
|
||||
apiKey: store.state.user.api_key
|
||||
});
|
||||
next();
|
||||
}
|
||||
|
||||
export function fetchIfAppNotFound (to, _, next) {
|
||||
const appId = to.params.id;
|
||||
const storeApp = store.state.oAuthApps.list[appId];
|
||||
|
||||
if (storeApp) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
fetchOAuthApps.apply(this, arguments);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import store from 'new-dashboard/store';
|
||||
|
||||
export default function updateSearchParams (to, _, next) {
|
||||
store.dispatch('search/doSearch', { query: to.params.query, tag: to.params.tag });
|
||||
next();
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
import Vue from 'vue';
|
||||
import Router from 'vue-router';
|
||||
|
||||
// Pages
|
||||
import Home from 'new-dashboard/pages/Home/Home';
|
||||
import Solutions from 'new-dashboard/pages/Solutions';
|
||||
import Maps from 'new-dashboard/pages/Maps';
|
||||
import Data from 'new-dashboard/pages/Data/Data';
|
||||
import Datasets from 'new-dashboard/pages/Data/Datasets';
|
||||
import Catalog from 'new-dashboard/pages/Data/Catalog';
|
||||
import CatalogDetail from 'new-dashboard/pages/Data/CatalogDetail';
|
||||
import Search from 'new-dashboard/pages/Search';
|
||||
import Notifications from 'new-dashboard/pages/Notifications';
|
||||
import ConnectedApps from 'new-dashboard/pages/Apps/ConnectedApps';
|
||||
import OAuthApps from 'new-dashboard/pages/Apps/OAuthApps';
|
||||
import EditApp from 'new-dashboard/components/Apps/EditApp';
|
||||
import CreateApp from 'new-dashboard/components/Apps/CreateApp';
|
||||
import AppList from 'new-dashboard/components/Apps/AppList';
|
||||
|
||||
// Hooks
|
||||
import { mapsBeforeEnter, datasetsBeforeEnter, catalogDetailBeforeEnter } from 'new-dashboard/router/hooks/check-navigation';
|
||||
import updateSearchParams from 'new-dashboard/router/hooks/update-search-params';
|
||||
import fetchNotifications from 'new-dashboard/router/hooks/fetch-notifications';
|
||||
import { fetchOAuthApps, fetchIfAppNotFound } from 'new-dashboard/router/hooks/fetch-oauth-apps';
|
||||
import fetchConnectedApps from 'new-dashboard/router/hooks/fetch-connected-apps';
|
||||
|
||||
// Modules
|
||||
import onboarding from './onboarding';
|
||||
|
||||
Vue.use(Router);
|
||||
|
||||
function getURLPrefix (userBaseURL) {
|
||||
return userBaseURL.replace(location.origin, '');
|
||||
}
|
||||
|
||||
const dashboardBaseURL = '/dashboard';
|
||||
const baseRouterPrefix = `${getURLPrefix(window.CartoConfig.data.user_data.base_url)}${dashboardBaseURL}`;
|
||||
|
||||
const router = new Router({
|
||||
base: baseRouterPrefix,
|
||||
mode: 'history',
|
||||
/* Warning: If any of the following paths is changed,
|
||||
remember to update staticRoute props in NavigationBar component */
|
||||
routes: [
|
||||
{
|
||||
path: '/',
|
||||
name: 'home',
|
||||
component: Home,
|
||||
meta: {
|
||||
title: () => 'Home | 快点'
|
||||
},
|
||||
children: onboarding
|
||||
},
|
||||
{
|
||||
path: '/solutions',
|
||||
name: 'solutions',
|
||||
component: Solutions,
|
||||
meta: {
|
||||
title: () => 'Solutions | 快点'
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/maps/:filter?',
|
||||
name: 'maps',
|
||||
component: Maps,
|
||||
meta: {
|
||||
title: () => 'Maps | 快点'
|
||||
},
|
||||
beforeEnter: mapsBeforeEnter
|
||||
},
|
||||
{
|
||||
path: '/datasets/:filter?',
|
||||
component: Data,
|
||||
meta: {
|
||||
title: () => 'Data | 快点'
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'catalog',
|
||||
name: 'catalog',
|
||||
component: Catalog,
|
||||
meta: {
|
||||
title: () => 'Catalog | 快点'
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '',
|
||||
component: Datasets,
|
||||
name: 'datasets',
|
||||
meta: {
|
||||
title: () => 'Data | 快点'
|
||||
},
|
||||
beforeEnter: datasetsBeforeEnter
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/datasets/catalog/:id',
|
||||
name: 'catalog_detail',
|
||||
component: CatalogDetail,
|
||||
meta: {
|
||||
title: () => 'Detail Dataset Catalog | 快点'
|
||||
},
|
||||
beforeEnter: catalogDetailBeforeEnter
|
||||
},
|
||||
{
|
||||
path: '/search/:query',
|
||||
name: 'search',
|
||||
component: Search,
|
||||
meta: {
|
||||
title: route => `${route.params.query} · Search | 快点`
|
||||
},
|
||||
beforeEnter: updateSearchParams
|
||||
},
|
||||
{
|
||||
path: '/search/tag/:tag',
|
||||
name: 'tagSearch',
|
||||
component: Search,
|
||||
meta: {
|
||||
title: route => `${route.params.tag} · Search | 快点`
|
||||
},
|
||||
beforeEnter: updateSearchParams
|
||||
},
|
||||
{
|
||||
path: '/notifications',
|
||||
name: 'notifications',
|
||||
component: Notifications,
|
||||
meta: {
|
||||
title: () => 'Notifications | 快点'
|
||||
},
|
||||
beforeEnter: fetchNotifications
|
||||
},
|
||||
{
|
||||
path: '/oauth_apps',
|
||||
component: OAuthApps,
|
||||
meta: {
|
||||
title: () => 'OAuth Apps | 快点'
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
name: 'oauth_apps_list',
|
||||
component: AppList,
|
||||
meta: {
|
||||
title: () => 'OAuth Apps | 快点'
|
||||
},
|
||||
beforeEnter: fetchOAuthApps
|
||||
},
|
||||
{
|
||||
path: 'new',
|
||||
name: 'oauth_app_new',
|
||||
component: CreateApp,
|
||||
meta: {
|
||||
title: () => 'Create a new OAuth app | 快点'
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'edit/:id',
|
||||
name: 'oauth_app_edit',
|
||||
component: EditApp,
|
||||
meta: {
|
||||
title: () => 'Edit an existing OAuth App | 快点'
|
||||
},
|
||||
beforeEnter: fetchIfAppNotFound
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/connected_apps',
|
||||
name: 'connected_apps',
|
||||
component: ConnectedApps,
|
||||
meta: {
|
||||
title: () => 'Connected Apps | 快点'
|
||||
},
|
||||
beforeEnter: fetchConnectedApps
|
||||
}
|
||||
],
|
||||
scrollBehavior (to, from, savedPosition) {
|
||||
return { x: 0, y: 0 };
|
||||
}
|
||||
});
|
||||
|
||||
router.beforeEach((to, _, next) => {
|
||||
if (!to.matched || !to.matched.length) {
|
||||
next({ name: 'home' });
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
router.afterEach(to => {
|
||||
window.scrollTo({ top: 0, left: 0 });
|
||||
|
||||
Vue.nextTick(() => {
|
||||
document.title = to.meta.title(to);
|
||||
});
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -0,0 +1,29 @@
|
||||
import OnboardingWelcome from 'new-dashboard/components/Onboarding/distributor/Distributor';
|
||||
import Wizard from 'new-dashboard/components/Onboarding/wizard/Wizard';
|
||||
|
||||
const onboarding = [
|
||||
{
|
||||
path: '/get-started',
|
||||
name: 'onboarding',
|
||||
components: {
|
||||
'onboarding-modal': OnboardingWelcome
|
||||
},
|
||||
meta: {
|
||||
title: () => 'Get Started | 快点'
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '/get-started/:onboardingId',
|
||||
name: 'onboarding-open',
|
||||
components: {
|
||||
onboarding: Wizard
|
||||
},
|
||||
meta: {
|
||||
title: () => 'Get Started | 快点'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
export default onboarding;
|
||||
Reference in New Issue
Block a user