mirror of
https://github.com/Lissy93/dashy.git
synced 2024-12-24 01:12:06 +03:00
🚧 WIP
This commit is contained in:
parent
8f893c36d7
commit
cdf1bb9529
@ -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' }))
|
||||
|
@ -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,
|
||||
|
@ -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();
|
||||
});
|
||||
|
@ -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: {},
|
||||
|
@ -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
|
||||
|
@ -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]) {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user