From cdf1bb9529dbf1d48b6123cddba4c8a7f89fe8f6 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Fri, 19 Aug 2022 10:04:38 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.js | 1 + src/main.js | 5 ++- src/router.js | 80 +++++++++------------------------- src/store.js | 8 +++- src/utils/Auth.js | 2 + src/utils/ConfigAccumalator.js | 7 +-- src/utils/ErrorReporting.js | 4 +- 7 files changed, 41 insertions(+), 66 deletions(-) diff --git a/server.js b/server.js index 5c83f81e..28692a58 100644 --- a/server.js +++ b/server.js @@ -73,6 +73,7 @@ const app = express() .use(sslServer.middleware) // Serves up static files .use(express.static(path.join(__dirname, 'dist'))) + .use(express.static(path.join(__dirname, 'user-data'))) .use(express.static(path.join(__dirname, 'public'), { index: 'initialization.html' })) // Load middlewares for parsing JSON, and supporting HTML5 history routing .use(express.json({ limit: '1mb' })) diff --git a/src/main.js b/src/main.js index 5b79d619..c3f626d8 100644 --- a/src/main.js +++ b/src/main.js @@ -13,14 +13,15 @@ import TreeView from 'vue-json-tree-view'; // Import base Dashy components and utils import Dashy from '@/App.vue'; // Main Dashy Vue app -import router from '@/router'; // Router, for navigation import store from '@/store'; // Store, for local state management +import router from '@/router'; // Router, for navigation import serviceWorker from '@/utils/InitServiceWorker'; // Service worker initialization import { messages } from '@/utils/languages'; // Language texts import ErrorReporting from '@/utils/ErrorReporting'; // Error reporting initializer (off) import clickOutside from '@/directives/ClickOutside'; // Directive for closing popups, modals, etc import { toastedOptions, tooltipOptions, language as defaultLanguage } from '@/utils/defaults'; import { initKeycloakAuth, isKeycloakEnabled } from '@/utils/KeycloakAuth'; +import Keys from '@/utils/StoreMutations'; // Initialize global Vue components Vue.use(VueI18n); @@ -53,6 +54,8 @@ ErrorReporting(Vue, router); // Render function const render = (awesome) => awesome(Dashy); +store.dispatch(Keys.INITIALIZE_CONFIG).then((thing) => console.log('main', thing)); + // Mount the app, with router, store i18n and render func const mount = () => new Vue({ store, router, render, i18n, diff --git a/src/router.js b/src/router.js index 5fbb12ea..c9b7f5ad 100644 --- a/src/router.js +++ b/src/router.js @@ -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(); }); diff --git a/src/store.js b/src/store.js index 2f379599..32501767 100644 --- a/src/store.js +++ b/src/store.js @@ -337,13 +337,17 @@ const store = new Vuex.Store({ if (!subConfigId) { // Use root config as config commit(SET_CONFIG, rootConfig); commit(SET_CONFIG_ID, null); + return rootConfig; } else { // Find and format path to fetch sub-config from const subConfigPath = formatConfigPath(rootConfig?.pages?.find( (page) => makePageName(page.name) === subConfigId, )?.path); - if (!subConfigPath) ErrorHandler(`Unable to find config for '${subConfigId}'`); + if (!subConfigPath) { + ErrorHandler(`Unable to find config for '${subConfigId}'`); + return null; + } axios.get(subConfigPath).then((response) => { const configContent = yaml.load(response.data); @@ -354,10 +358,12 @@ const store = new Vuex.Store({ configContent.appConfig.theme = theme; commit(SET_CONFIG, configContent); commit(SET_CONFIG_ID, subConfigId); + return configContent; }).catch((err) => { ErrorHandler(`Unable to load config from '${subConfigPath}'`, err); }); } + return null; }, }, modules: {}, diff --git a/src/utils/Auth.js b/src/utils/Auth.js index df9f3478..6b32355f 100644 --- a/src/utils/Auth.js +++ b/src/utils/Auth.js @@ -11,6 +11,8 @@ const getAppConfig = () => { return config.appConfig || {}; }; +// const appConfig = $store.getters.appConfig || {}; + /** * Called when the user is still using array for users, prints warning * This was a breaking change, implemented in V 1.6.5 diff --git a/src/utils/ConfigAccumalator.js b/src/utils/ConfigAccumalator.js index 7f83e28b..25c1c45a 100644 --- a/src/utils/ConfigAccumalator.js +++ b/src/utils/ConfigAccumalator.js @@ -16,7 +16,7 @@ import ErrorHandler from '@/utils/ErrorHandler'; import { applyItemId } from '@/utils/SectionHelpers'; import $store from '@/store'; -import buildConf from '../../public/conf.yml'; +// import buildConf from '../../public/conf.yml'; export default class ConfigAccumulator { constructor() { @@ -33,9 +33,10 @@ export default class ConfigAccumulator { // Set app config from file if (this.conf && this.conf.appConfig) { appConfigFile = this.conf.appConfig; - } else if (buildConf && buildConf.appConfig) { - appConfigFile = buildConf.appConfig; } + // else if (buildConf && buildConf.appConfig) { + // appConfigFile = buildConf.appConfig; + // } // Fill in defaults if anything missing let usersAppConfig = defaultAppConfig; if (localStorage[localStorageKeys.APP_CONFIG]) { diff --git a/src/utils/ErrorReporting.js b/src/utils/ErrorReporting.js index 77cea661..536150d3 100644 --- a/src/utils/ErrorReporting.js +++ b/src/utils/ErrorReporting.js @@ -9,12 +9,12 @@ /* eslint-disable global-require */ -import ConfigAccumulator from '@/utils/ConfigAccumalator'; +import $store from '@/store'; import { sentryDsn } from '@/utils/defaults'; const ErrorReporting = (Vue, router) => { // Fetch users config - const appConfig = new ConfigAccumulator().appConfig() || {}; + const appConfig = $store.getters.appConfig || {}; // Check if error reporting is enabled. Only proceed if user has turned it on. if (appConfig.enableErrorReporting) { // Get current app version