Skip to content

Commit

Permalink
⚡ New state options for sub-config
Browse files Browse the repository at this point in the history
  • Loading branch information
Lissy93 committed Apr 8, 2024
1 parent 31b40e6 commit a1bf7a6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 40 deletions.
3 changes: 2 additions & 1 deletion src/components/PageStrcture/Footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
Get the <a :href="defaultInfo.repoUrl">Source Code</a>.
</span>
<span>
Using: {{ $store.state.currentConfigId || 'Default Config' }}
Using:
{{ $store.state.currentConfigInfo? $store.state.currentConfigInfo.confId : 'Default Config' }}
</span>
</footer>
</template>
Expand Down
2 changes: 1 addition & 1 deletion src/mixins/ConfigSaving.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default {
return;
}
// 1. Get the config, and strip appConfig if is sub-page
const isSubPag = !!this.$store.state.currentConfigInfo;
const isSubPag = !!this.$store.state.currentConfigInfo.confId;
const jsonConfig = config;
if (isSubPag) delete jsonConfig.appConfig;
jsonConfig.sections = jsonConfig.sections.map(({ filteredItems, ...section }) => section);
Expand Down
47 changes: 11 additions & 36 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,8 @@ import Home from '@/views/Home.vue';

// Import helper functions, config data and defaults
import { isAuthEnabled, isLoggedIn, isGuestAccessEnabled } from '@/utils/Auth';
import { metaTagData, startingView, routePaths } from '@/utils/defaults';
import { metaTagData, startingView as defaultStartingView, 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';

// 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 pageInfo = {};
const appConfig = {};

Vue.use(Router);
const progress = new Progress({ color: 'var(--progress-bar)' });
Expand All @@ -47,32 +28,30 @@ 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;
// Get the default starting view from environmental variable
const startingView = process.env.VUE_APP_STARTING_VIEW || defaultStartingView;

/**
* 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) {
switch (startingView) {
case 'minimal': return () => import('./views/Minimal.vue');
case 'workspace': return () => import('./views/Workspace.vue');
default: return Home;
}
};

/* Returns the meta tags for each route */
const makeMetaTags = (defaultTitle) => ({
title: pageInfo.title || defaultTitle,
metaTags: metaTagData,
});
const makeMetaTags = (defaultTitle) => {
const userTitle = process.env.VUE_APP_TITLE || '';
const title = userTitle ? `${userTitle} | ${defaultTitle}` : defaultTitle;
return { title, metaTags: metaTagData };
};

/* Routing mode, can be either 'hash', 'history' or 'abstract' */
const mode = appConfig.routingMode || 'history';
const mode = process.env.VUE_APP_ROUTING_MODE || 'history';

/* List of all routes, props, components and metadata */
const router = new Router({
Expand All @@ -81,7 +60,7 @@ const router = new Router({
// ...makeMultiPageRoutes(pages),
{ // The default view can be customized by the user
path: '/',
name: `landing-page-${getStartingView()}`,
name: `landing-page-${startingView}`,
component: getStartingComponent(),
meta: makeMetaTags('Home Page'),
},
Expand Down Expand Up @@ -157,10 +136,6 @@ const router = new Router({
* */
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();
});
Expand Down
2 changes: 0 additions & 2 deletions src/utils/ConfigAccumalator.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import ErrorHandler from '@/utils/ErrorHandler';
import { applyItemId } from '@/utils/SectionHelpers';
import $store from '@/store';

// import buildConf from '../../public/conf.yml';

export default class ConfigAccumulator {
constructor() {
this.conf = $store.state.config;
Expand Down

0 comments on commit a1bf7a6

Please sign in to comment.