2019-07-19 16:07:26 +02:00
|
|
|
<template>
|
2021-06-11 18:18:07 +02:00
|
|
|
<div id="dashy">
|
2021-10-17 20:14:12 +02:00
|
|
|
<EditModeTopBanner v-if="isEditMode" />
|
2021-09-11 02:14:23 +02:00
|
|
|
<LoadingScreen :isLoading="isLoading" v-if="shouldShowSplash" />
|
2021-07-05 22:09:17 +02:00
|
|
|
<Header :pageInfo="pageInfo" />
|
2021-04-05 15:06:39 +02:00
|
|
|
<router-view />
|
2021-09-11 02:14:23 +02:00
|
|
|
<Footer :text="footerText" v-if="visibleComponents.footer" />
|
2019-07-19 16:07:26 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
2019-07-20 22:50:29 +02:00
|
|
|
<script>
|
|
|
|
|
2021-04-13 13:36:31 +02:00
|
|
|
import Header from '@/components/PageStrcture/Header.vue';
|
|
|
|
import Footer from '@/components/PageStrcture/Footer.vue';
|
2021-10-17 20:14:12 +02:00
|
|
|
import EditModeTopBanner from '@/components/InteractiveEditor/EditModeTopBanner.vue';
|
2021-06-11 18:18:07 +02:00
|
|
|
import LoadingScreen from '@/components/PageStrcture/LoadingScreen.vue';
|
2021-07-31 19:53:12 +02:00
|
|
|
import { welcomeMsg } from '@/utils/CoolConsole';
|
2021-09-11 02:14:23 +02:00
|
|
|
import ErrorHandler from '@/utils/ErrorHandler';
|
2021-10-10 16:52:39 +02:00
|
|
|
import Keys from '@/utils/StoreMutations';
|
2021-07-04 10:04:53 +02:00
|
|
|
import {
|
|
|
|
localStorageKeys,
|
|
|
|
splashScreenTime,
|
|
|
|
visibleComponents as defaultVisibleComponents,
|
2021-07-25 13:30:43 +02:00
|
|
|
language as defaultLanguage,
|
2021-07-04 10:04:53 +02:00
|
|
|
} from '@/utils/defaults';
|
|
|
|
|
2019-07-20 22:50:29 +02:00
|
|
|
export default {
|
|
|
|
name: 'app',
|
|
|
|
components: {
|
2021-04-05 15:06:39 +02:00
|
|
|
Header,
|
2019-09-01 14:38:13 +02:00
|
|
|
Footer,
|
2021-06-11 18:18:07 +02:00
|
|
|
LoadingScreen,
|
2021-10-17 20:14:12 +02:00
|
|
|
EditModeTopBanner,
|
2021-06-11 18:18:07 +02:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2021-07-05 22:09:17 +02:00
|
|
|
isLoading: true, // Set to false after mount complete
|
2021-06-11 18:18:07 +02:00
|
|
|
};
|
2019-09-01 14:38:13 +02:00
|
|
|
},
|
2021-09-11 02:14:23 +02:00
|
|
|
computed: {
|
2021-07-05 22:09:17 +02:00
|
|
|
/* If the user has specified custom text for footer - get it */
|
2021-09-11 02:14:23 +02:00
|
|
|
footerText() {
|
|
|
|
return this.pageInfo && this.pageInfo.footerText ? this.pageInfo.footerText : '';
|
|
|
|
},
|
|
|
|
/* Determine if splash screen should be shown */
|
|
|
|
shouldShowSplash() {
|
2021-09-19 23:23:26 +02:00
|
|
|
return (this.visibleComponents || defaultVisibleComponents).splashScreen;
|
2021-05-04 20:43:42 +02:00
|
|
|
},
|
2021-10-09 19:31:10 +02:00
|
|
|
config() {
|
|
|
|
return this.$store.state.config;
|
|
|
|
},
|
|
|
|
appConfig() {
|
|
|
|
return this.$store.getters.appConfig;
|
|
|
|
},
|
|
|
|
pageInfo() {
|
|
|
|
return this.$store.getters.pageInfo;
|
|
|
|
},
|
|
|
|
sections() {
|
|
|
|
return this.$store.getters.pageInfo;
|
|
|
|
},
|
2021-10-09 20:28:36 +02:00
|
|
|
visibleComponents() {
|
|
|
|
return this.$store.getters.visibleComponents;
|
|
|
|
},
|
2021-10-17 20:14:12 +02:00
|
|
|
isEditMode() {
|
|
|
|
return this.$store.state.editMode;
|
|
|
|
},
|
2021-10-09 19:31:10 +02:00
|
|
|
},
|
|
|
|
created() {
|
2021-10-17 21:08:38 +02:00
|
|
|
this.$store.dispatch(Keys.INITIALIZE_CONFIG);
|
2021-09-11 02:14:23 +02:00
|
|
|
},
|
|
|
|
methods: {
|
2021-07-05 22:09:17 +02:00
|
|
|
/* Injects the users custom CSS as a style tag */
|
2021-05-31 16:17:54 +02:00
|
|
|
injectCustomStyles(usersCss) {
|
|
|
|
const style = document.createElement('style');
|
|
|
|
style.textContent = usersCss;
|
|
|
|
document.head.append(style);
|
|
|
|
},
|
2021-07-05 22:09:17 +02:00
|
|
|
/* Hide splash screen, either after 2 seconds, or immediately based on user preference */
|
2021-06-11 18:18:07 +02:00
|
|
|
hideSplash() {
|
2021-09-11 02:14:23 +02:00
|
|
|
if (this.shouldShowSplash) {
|
2021-07-07 21:27:45 +02:00
|
|
|
setTimeout(() => { this.isLoading = false; }, splashScreenTime || 1500);
|
2021-06-11 18:18:07 +02:00
|
|
|
} else {
|
|
|
|
this.isLoading = false;
|
|
|
|
}
|
|
|
|
},
|
2021-07-25 13:30:43 +02:00
|
|
|
|
2021-09-11 02:14:23 +02:00
|
|
|
/* Auto-detects users language from browser/ os, when not specified */
|
|
|
|
autoDetectLanguage(availibleLocales) {
|
|
|
|
const isLangSupported = (languageList, userLang) => languageList
|
|
|
|
.map(lang => lang.toLowerCase()).find((lang) => lang === userLang.toLowerCase());
|
|
|
|
|
|
|
|
const usersBorwserLang1 = window.navigator.language || ''; // e.g. en-GB or or ''
|
|
|
|
const usersBorwserLang2 = usersBorwserLang1.split('-')[0]; // e.g. en or undefined
|
|
|
|
const usersSpairLangs = window.navigator.languages; // e.g [en, en-GB, en-US]
|
|
|
|
return isLangSupported(availibleLocales, usersBorwserLang1)
|
|
|
|
|| isLangSupported(availibleLocales, usersBorwserLang2)
|
|
|
|
|| usersSpairLangs.find((spair) => isLangSupported(availibleLocales, spair))
|
|
|
|
|| defaultLanguage;
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Get users language, if not available then call auto-detect */
|
|
|
|
getLanguage() {
|
|
|
|
const availibleLocales = this.$i18n.availableLocales; // All available locales
|
2021-07-25 13:30:43 +02:00
|
|
|
const usersLang = localStorage[localStorageKeys.LANGUAGE] || this.appConfig.language;
|
2021-09-11 02:14:23 +02:00
|
|
|
if (usersLang) {
|
|
|
|
if (availibleLocales.includes(usersLang)) {
|
|
|
|
return usersLang;
|
|
|
|
} else {
|
|
|
|
ErrorHandler(`Unsupported Language: '${usersLang}'`);
|
2021-07-24 22:41:16 +02:00
|
|
|
}
|
|
|
|
}
|
2021-09-11 02:14:23 +02:00
|
|
|
return this.autoDetectLanguage(availibleLocales);
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Fetch or detect users language, then apply it */
|
|
|
|
applyLanguage() {
|
|
|
|
const language = this.getLanguage();
|
2021-10-10 16:52:39 +02:00
|
|
|
this.$store.commit(Keys.SET_LANGUAGE, language);
|
2021-07-25 13:30:43 +02:00
|
|
|
this.$i18n.locale = language;
|
|
|
|
document.getElementsByTagName('html')[0].setAttribute('lang', language);
|
2021-07-24 22:41:16 +02:00
|
|
|
},
|
2021-09-19 23:23:26 +02:00
|
|
|
hideLoader() {
|
|
|
|
const loader = document.getElementById('loader');
|
|
|
|
if (loader) loader.style.display = 'none';
|
|
|
|
},
|
2021-05-31 16:17:54 +02:00
|
|
|
},
|
2021-07-05 22:09:17 +02:00
|
|
|
/* When component mounted, hide splash and initiate the injection of custom styles */
|
2021-05-31 16:17:54 +02:00
|
|
|
mounted() {
|
2021-07-24 22:41:16 +02:00
|
|
|
this.applyLanguage();
|
2021-06-11 18:18:07 +02:00
|
|
|
this.hideSplash();
|
2021-05-31 16:17:54 +02:00
|
|
|
if (this.appConfig.customCss) {
|
|
|
|
const cleanedCss = this.appConfig.customCss.replace(/<\/?[^>]+(>|$)/g, '');
|
|
|
|
this.injectCustomStyles(cleanedCss);
|
2021-09-19 23:23:26 +02:00
|
|
|
this.hideLoader();
|
2021-05-31 16:17:54 +02:00
|
|
|
}
|
2021-07-31 19:53:12 +02:00
|
|
|
welcomeMsg();
|
2021-04-05 15:06:39 +02:00
|
|
|
},
|
2019-09-01 14:38:13 +02:00
|
|
|
};
|
2019-07-20 22:50:29 +02:00
|
|
|
</script>
|
2019-07-19 16:07:26 +02:00
|
|
|
|
|
|
|
<style lang="scss">
|
2021-07-05 22:09:17 +02:00
|
|
|
/* Import styles used globally throughout the app */
|
2021-04-15 20:30:30 +02:00
|
|
|
@import '@/styles/global-styles.scss';
|
|
|
|
@import '@/styles/color-palette.scss';
|
2021-06-17 23:59:56 +02:00
|
|
|
@import '@/styles/dimensions.scss';
|
2021-04-15 20:30:30 +02:00
|
|
|
@import '@/styles/color-themes.scss';
|
2021-06-01 23:44:59 +02:00
|
|
|
@import '@/styles/typography.scss';
|
2021-07-16 23:06:10 +02:00
|
|
|
@import '@/styles/user-defined-themes.scss';
|
2019-07-20 22:50:29 +02:00
|
|
|
|
2019-07-19 16:07:26 +02:00
|
|
|
</style>
|