mirror of https://github.com/Lissy93/dashy.git
😶 what am i doing with my life...
This commit is contained in:
parent
e6a607572e
commit
fb13f84c0e
|
@ -5,8 +5,10 @@
|
||||||
<v-select
|
<v-select
|
||||||
:options="themeNames"
|
:options="themeNames"
|
||||||
v-model="selectedTheme"
|
v-model="selectedTheme"
|
||||||
|
:value="$store.getters.theme"
|
||||||
class="theme-dropdown"
|
class="theme-dropdown"
|
||||||
:tabindex="-2"
|
:tabindex="-2"
|
||||||
|
@input="themeChanged"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<IconPalette
|
<IconPalette
|
||||||
|
@ -36,62 +38,99 @@ import IconPalette from '@/assets/interface-icons/config-color-palette.svg';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ThemeSelector',
|
name: 'ThemeSelector',
|
||||||
props: {
|
|
||||||
externalThemes: Object,
|
|
||||||
confTheme: String,
|
|
||||||
userThemes: Array,
|
|
||||||
},
|
|
||||||
components: {
|
components: {
|
||||||
CustomThemeMaker,
|
CustomThemeMaker,
|
||||||
IconPalette,
|
IconPalette,
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
/* When the theme changes, then call the update method */
|
/* When theme in VueX store changes, then update theme */
|
||||||
selectedTheme(newTheme) {
|
themeFromStore(newTheme) {
|
||||||
|
this.selectedTheme = newTheme;
|
||||||
this.updateTheme(newTheme);
|
this.updateTheme(newTheme);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
selectedTheme: this.getInitialTheme(),
|
selectedTheme: '',
|
||||||
builtInThemes: [...Defaults.builtInThemes, ...this.userThemes],
|
|
||||||
themeHelper: new LoadExternalTheme(),
|
|
||||||
themeConfiguratorOpen: false, // Control the opening of theme config popup
|
themeConfiguratorOpen: false, // Control the opening of theme config popup
|
||||||
|
themeHelper: new LoadExternalTheme(),
|
||||||
ApplyLocalTheme,
|
ApplyLocalTheme,
|
||||||
ApplyCustomVariables,
|
ApplyCustomVariables,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
/* Get appConfig from store */
|
||||||
|
appConfig() {
|
||||||
|
return this.$store.getters.appConfig;
|
||||||
|
},
|
||||||
|
/* Get users theme from store */
|
||||||
|
themeFromStore() {
|
||||||
|
return this.$store.getters.theme;
|
||||||
|
},
|
||||||
/* Combines all theme names (builtin and user defined) together */
|
/* Combines all theme names (builtin and user defined) together */
|
||||||
themeNames: function themeNames() {
|
themeNames: function themeNames() {
|
||||||
const externalThemeNames = Object.keys(this.externalThemes);
|
const externalThemeNames = Object.keys(this.externalThemes);
|
||||||
const specialThemes = ['custom'];
|
const specialThemes = ['custom'];
|
||||||
return [...externalThemeNames, ...this.builtInThemes, ...specialThemes];
|
return [...externalThemeNames, ...Defaults.builtInThemes, ...specialThemes];
|
||||||
|
},
|
||||||
|
extraThemeNames() {
|
||||||
|
const userThemes = this.appConfig.cssThemes || [];
|
||||||
|
if (typeof userThemes === 'string') return [userThemes];
|
||||||
|
return userThemes;
|
||||||
|
},
|
||||||
|
/* Returns an array of links to external CSS from the Config */
|
||||||
|
externalThemes() {
|
||||||
|
const availibleThemes = {};
|
||||||
|
if (this.appConfig) {
|
||||||
|
if (this.appConfig.externalStyleSheet) {
|
||||||
|
const externals = this.appConfig.externalStyleSheet;
|
||||||
|
if (Array.isArray(externals)) {
|
||||||
|
externals.forEach((ext, i) => {
|
||||||
|
availibleThemes[`External Stylesheet ${i + 1}`] = ext;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
availibleThemes['External Stylesheet'] = this.appConfig.externalStyleSheet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
availibleThemes.Default = '#';
|
||||||
|
return availibleThemes;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
created() {
|
mounted() {
|
||||||
|
const initialTheme = this.getInitialTheme();
|
||||||
|
this.selectedTheme = initialTheme;
|
||||||
// Pass all user custom stylesheets to the themehelper
|
// Pass all user custom stylesheets to the themehelper
|
||||||
const added = Object.keys(this.externalThemes).map(
|
const added = Object.keys(this.externalThemes).map(
|
||||||
name => this.themeHelper.add(name, this.externalThemes[name]),
|
name => this.themeHelper.add(name, this.externalThemes[name]),
|
||||||
);
|
);
|
||||||
// Quicker loading, if the theme is local we can apply it immidiatley
|
// Quicker loading, if the theme is local we can apply it immidiatley
|
||||||
if (this.isThemeLocal(this.selectedTheme)) {
|
if (this.isThemeLocal(initialTheme)) {
|
||||||
this.updateTheme(this.selectedTheme);
|
this.updateTheme(initialTheme);
|
||||||
// If it's an external stylesheet, then wait for promise to resolve
|
// If it's an external stylesheet, then wait for promise to resolve
|
||||||
} else if (this.selectedTheme !== Defaults.theme) {
|
} else if (initialTheme !== Defaults.theme) {
|
||||||
Promise.all(added).then(() => {
|
Promise.all(added).then(() => {
|
||||||
this.updateTheme(this.selectedTheme);
|
this.updateTheme(initialTheme);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
/* Get default theme */
|
/* Called when dropdown changed
|
||||||
|
* Updates store, which will in turn update theme through watcher
|
||||||
|
*/
|
||||||
|
themeChanged() {
|
||||||
|
this.$store.commit(Keys.SET_THEME, this.selectedTheme);
|
||||||
|
},
|
||||||
|
/* Returns the initial theme */
|
||||||
getInitialTheme() {
|
getInitialTheme() {
|
||||||
return localStorage[localStorageKeys.THEME] || this.confTheme || Defaults.theme;
|
const localTheme = localStorage[localStorageKeys.THEME];
|
||||||
|
if (localTheme && localTheme !== 'undefined') return localTheme;
|
||||||
|
return this.confTheme || Defaults.theme;
|
||||||
},
|
},
|
||||||
/* Determines if a given theme is local / not a custom user stylesheet */
|
/* Determines if a given theme is local / not a custom user stylesheet */
|
||||||
isThemeLocal(themeToCheck) {
|
isThemeLocal(themeToCheck) {
|
||||||
return this.builtInThemes.includes(themeToCheck);
|
const localThemes = [...Defaults.builtInThemes, ...this.extraThemeNames];
|
||||||
|
return localThemes.includes(themeToCheck);
|
||||||
},
|
},
|
||||||
/* Opens the theme color configurator popup */
|
/* Opens the theme color configurator popup */
|
||||||
openThemeConfigurator() {
|
openThemeConfigurator() {
|
||||||
|
|
Loading…
Reference in New Issue