This commit is contained in:
Alicia Sykes
2022-08-19 10:04:38 +01:00
parent 8f893c36d7
commit cdf1bb9529
7 changed files with 41 additions and 66 deletions

View File

@@ -14,22 +14,27 @@ import Home from '@/views/Home.vue';
// Import helper functions, config data and defaults
import { isAuthEnabled, isLoggedIn, isGuestAccessEnabled } from '@/utils/Auth';
// import { makePageSlug, makePageName } from '@/utils/ConfigHelpers';
import { metaTagData, startingView, routePaths } from '@/utils/defaults';
import ErrorHandler from '@/utils/ErrorHandler';
import Keys from '@/utils/StoreMutations';
// import $store from '@/store';
// Import data from users conf file. Note that rebuild is required for this to update.
import conf from '../public/conf.yml';
// import conf from '../public/conf.yml';
if (!conf) {
ErrorHandler('You\'ve not got any data in your config file yet.');
}
// this.$store.dispatch(Keys.INITIALIZE_CONFIG, undefined);
// const conf = $store.getters.config;
// if (!conf) {
// ErrorHandler('You\'ve not got any data in your config file yet.');
// }
// console.log($store.state.config);
// Assign top-level config fields, check not null
const config = conf || {};
// const pages = config.pages || [];
const pageInfo = config.pageInfo || {};
const appConfig = config.appConfig || {};
// const config = conf || {};
const pageInfo = {};
const appConfig = {};
Vue.use(Router);
const progress = new Progress({ color: 'var(--progress-bar)' });
@@ -42,6 +47,8 @@ const isAuthenticated = () => {
return (!authEnabled || userLoggedIn || guestEnabled);
};
// appConfig.auth, appConfig.startingView, appConfig.routingMode, pageInfo.title
/* Get the users chosen starting view from app config, or return default */
const getStartingView = () => appConfig.startingView || startingView;
@@ -64,55 +71,6 @@ const makeMetaTags = (defaultTitle) => ({
metaTags: metaTagData,
});
// const makeSubConfigPath = (rawPath) => {
// if (!rawPath) return '';
// if (rawPath.startsWith('/') || rawPath.startsWith('http')) return rawPath;
// else return `/${rawPath}`;
// };
/* For each additional config file, create routes for home, minimal and workspace views */
// const makeMultiPageRoutes = (userPages) => {
// // If no multi pages specified, or is not array, then return nothing
// if (!userPages || !Array.isArray(userPages)) return [];
// const multiPageRoutes = [];
// // For each user page, create an additional route
// userPages.forEach((page) => {
// if (!page.name || !page.path) { // Sumin not right, show warning
// ErrorHandler('Additional pages must have both a `name` and `path`');
// }
// // Props to be passed to home mixin
// const subPageInfo = {
// subPageInfo: {
// confPath: makeSubConfigPath(page.path),
// pageId: makePageName(page.name),
// pageTitle: page.name,
// },
// };
// // Create route for default homepage
// multiPageRoutes.push({
// path: makePageSlug(page.name, 'home'),
// name: `${subPageInfo.subPageInfo.pageId}-home`,
// component: Home,
// props: subPageInfo,
// });
// // Create route for the workspace view
// multiPageRoutes.push({
// path: makePageSlug(page.name, 'workspace'),
// name: `${subPageInfo.subPageInfo.pageId}-workspace`,
// component: () => import('./views/Workspace.vue'),
// props: subPageInfo,
// });
// // Create route for the minimal view
// multiPageRoutes.push({
// path: makePageSlug(page.name, 'minimal'),
// name: `${subPageInfo.subPageInfo.pageId}-minimal`,
// component: () => import('./views/Minimal.vue'),
// props: subPageInfo,
// });
// });
// return multiPageRoutes;
// };
/* Routing mode, can be either 'hash', 'history' or 'abstract' */
const mode = appConfig.routingMode || 'history';
@@ -197,8 +155,12 @@ const router = new Router({
* if so, then ensure that they are correctly logged in as a valid user
* If not logged in, prevent all access and redirect them to login page
* */
router.beforeEach((to, from, next) => {
router.beforeEach(async (to, from, next) => {
progress.start();
router.app.$store.dispatch(Keys.INITIALIZE_CONFIG, null).then((finished) => {
console.log('Done!', finished);
});
await console.log('router.app.$store', router.app.$store.getters.config);
if (to.name !== 'login' && !isAuthenticated()) next({ name: 'login' });
else next();
});