mirror of
https://github.com/Lissy93/dashy.git
synced 2025-07-26 07:05:43 +02:00
✨ Make homepage render users chosen start page
This commit is contained in:
parent
ecde28811e
commit
c92f578bb0
@ -1,11 +1,13 @@
|
|||||||
|
// Import Vue.js and vue router
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
import Router from 'vue-router';
|
import Router from 'vue-router';
|
||||||
|
// Import views
|
||||||
import Home from '@/views/Home.vue';
|
import Home from '@/views/Home.vue';
|
||||||
import Login from '@/views/Login.vue';
|
import Login from '@/views/Login.vue';
|
||||||
import Workspace from '@/views/Workspace.vue';
|
import Workspace from '@/views/Workspace.vue';
|
||||||
import Minimal from '@/views/Minimal.vue';
|
import Minimal from '@/views/Minimal.vue';
|
||||||
import DownloadConfig from '@/views/DownloadConfig.vue';
|
import DownloadConfig from '@/views/DownloadConfig.vue';
|
||||||
|
// Import helper functions, config data and defaults
|
||||||
import { isLoggedIn } from '@/utils/Auth';
|
import { isLoggedIn } from '@/utils/Auth';
|
||||||
import { config } from '@/utils/ConfigHelpers';
|
import { config } from '@/utils/ConfigHelpers';
|
||||||
import { metaTagData } from '@/utils/defaults';
|
import { metaTagData } from '@/utils/defaults';
|
||||||
@ -22,39 +24,61 @@ const isAuthenticated = () => {
|
|||||||
return (!users || users.length === 0 || isLoggedIn(users));
|
return (!users || users.length === 0 || isLoggedIn(users));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Get the users chosen starting view from app config, or return default */
|
||||||
|
const getStartingView = () => config.appConfig.startingView || 'default';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the component that should be rendered at the base path,
|
||||||
|
* Defaults to Home, but the user can change this to Workspace of Minimal
|
||||||
|
*/
|
||||||
|
const getStartingComponent = () => {
|
||||||
|
const usersPreference = getStartingView();
|
||||||
|
switch (usersPreference) {
|
||||||
|
case 'default': return Home;
|
||||||
|
case 'minimal': return Minimal;
|
||||||
|
case 'workspace': return Workspace;
|
||||||
|
default: return Home;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Returns the meta tags for each route */
|
||||||
|
const makeMetaTags = (defaultTitle) => ({
|
||||||
|
title: config.pageInfo.title || defaultTitle,
|
||||||
|
metaTags: metaTagData,
|
||||||
|
});
|
||||||
|
|
||||||
|
/* List of all routes, props, components and metadata */
|
||||||
const router = new Router({
|
const router = new Router({
|
||||||
routes: [
|
routes: [
|
||||||
{
|
{ // The default view can be customized by the user
|
||||||
path: '/',
|
path: '/',
|
||||||
|
name: `landing-page-${getStartingView()}`,
|
||||||
|
component: getStartingComponent(),
|
||||||
|
props: config,
|
||||||
|
meta: makeMetaTags('Home Page'),
|
||||||
|
},
|
||||||
|
{ // Default home page
|
||||||
|
path: '/home',
|
||||||
name: 'home',
|
name: 'home',
|
||||||
component: Home,
|
component: Home,
|
||||||
props: config,
|
props: config,
|
||||||
meta: {
|
meta: makeMetaTags('Home Page'),
|
||||||
title: config.pageInfo.title || 'Home Page',
|
|
||||||
metaTags: metaTagData,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{ // Workspace view page
|
||||||
path: '/workspace',
|
path: '/workspace',
|
||||||
name: 'workspace',
|
name: 'workspace',
|
||||||
component: Workspace,
|
component: Workspace,
|
||||||
props: config,
|
props: config,
|
||||||
meta: {
|
meta: makeMetaTags('Workspace'),
|
||||||
title: config.pageInfo.title || 'Dashy Workspace',
|
|
||||||
metaTags: metaTagData,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{ // Minimal view page
|
||||||
path: '/minimal',
|
path: '/minimal',
|
||||||
name: 'minimal',
|
name: 'minimal',
|
||||||
component: Minimal,
|
component: Minimal,
|
||||||
props: config,
|
props: config,
|
||||||
meta: {
|
meta: makeMetaTags('Start Page'),
|
||||||
title: config.pageInfo.title || 'Dashy Start Page',
|
|
||||||
metaTags: metaTagData,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{ // The login page
|
||||||
path: '/login',
|
path: '/login',
|
||||||
name: 'login',
|
name: 'login',
|
||||||
component: Login,
|
component: Login,
|
||||||
@ -66,34 +90,38 @@ const router = new Router({
|
|||||||
next();
|
next();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{ // The about app page
|
||||||
path: '/about',
|
path: '/about',
|
||||||
name: 'about',
|
name: 'about',
|
||||||
component: () => import(/* webpackChunkName: "about" */ './views/About.vue'),
|
component: () => import(/* webpackChunkName: "about" */ './views/About.vue'),
|
||||||
|
meta: makeMetaTags('About Dashy'),
|
||||||
},
|
},
|
||||||
{
|
{ // The export config page
|
||||||
path: '/download',
|
path: '/download',
|
||||||
name: 'download',
|
name: 'download',
|
||||||
component: DownloadConfig,
|
component: DownloadConfig,
|
||||||
props: config,
|
props: config,
|
||||||
meta: {
|
meta: makeMetaTags('Download Config'),
|
||||||
title: config.pageInfo.title || 'Download Dashy Config',
|
|
||||||
metaTags: metaTagData,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Before loading a route, check if the user has authentication enabled *
|
||||||
|
* if so, then ensure that they are correctly logged in as a valid user *
|
||||||
|
* If not logged in, prevent access and redirect them to the login page *
|
||||||
|
* */
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
if (to.name !== 'login' && !isAuthenticated()) next({ name: 'login' });
|
if (to.name !== 'login' && !isAuthenticated()) next({ name: 'login' });
|
||||||
else next();
|
else next();
|
||||||
});
|
});
|
||||||
|
|
||||||
const defaultTitle = 'Dashy';
|
/* If title is missing, then apply default page title */
|
||||||
router.afterEach((to) => {
|
router.afterEach((to) => {
|
||||||
Vue.nextTick(() => {
|
Vue.nextTick(() => {
|
||||||
document.title = to.meta.title || defaultTitle;
|
document.title = to.meta.title || 'Dashy';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Export the now configured router
|
||||||
export default router;
|
export default router;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user