generated from Seekra/repository-template
Merge pull request 'Feat(color-scheme): make color scheme a setting' (#182) from feature/make-color-scheme-a-setting into main
Deploy on dev / Deploy on dev (push) Successful in 35s
Deploy on dev / Deploy on dev (push) Successful in 35s
Reviewed-on: #182 Reviewed-by: Jakob Gregory
This commit was merged in pull request #182.
This commit is contained in:
+12
-10
@@ -19,34 +19,36 @@ import Navbar from './features/nav/components/Navbar.vue';
|
|||||||
import Footer from './features/footer/components/Footer.vue';
|
import Footer from './features/footer/components/Footer.vue';
|
||||||
|
|
||||||
import { updatePageTitle } from './router';
|
import { updatePageTitle } from './router';
|
||||||
import { useColorScheme } from './features/colorScheme/composables/useColorScheme';
|
import { useSettings } from './features/settings/composables/useSettings.js';
|
||||||
import { ref, provide, watch, watchEffect } from 'vue';
|
import { computed, watch, watchEffect } from 'vue';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
const { getColorScheme, updateColorScheme } = useColorScheme();
|
const { getSetting } = useSettings();
|
||||||
const colorScheme = ref(null);
|
const colorScheme = computed(() => getSetting(['appearance', 'colorScheme']));
|
||||||
provide('colorScheme', colorScheme);
|
|
||||||
watch(colorScheme, (newValue) => {
|
const updateColorScheme = function updateColorScheme (newColorScheme) {
|
||||||
updateColorScheme(newValue);
|
|
||||||
document.body.style.setProperty(colorScheme, {
|
document.body.style.setProperty(colorScheme, {
|
||||||
auto: 'normal',
|
auto: 'normal',
|
||||||
dark: 'dark',
|
dark: 'dark',
|
||||||
light: 'light'
|
light: 'light'
|
||||||
});
|
});
|
||||||
if (newValue === 'dark') {
|
if (newColorScheme === 'dark') {
|
||||||
document.body.classList.add('dark');
|
document.body.classList.add('dark');
|
||||||
} else {
|
} else {
|
||||||
document.body.classList.remove('dark');
|
document.body.classList.remove('dark');
|
||||||
}
|
}
|
||||||
if (newValue === 'auto') {
|
if (newColorScheme === 'auto') {
|
||||||
document.body.classList.add('color-scheme-auto');
|
document.body.classList.add('color-scheme-auto');
|
||||||
} else {
|
} else {
|
||||||
document.body.classList.remove('color-scheme-auto');
|
document.body.classList.remove('color-scheme-auto');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
watch(colorScheme, (newColorScheme) => {
|
||||||
|
updateColorScheme(newColorScheme);
|
||||||
});
|
});
|
||||||
colorScheme.value = getColorScheme();
|
updateColorScheme(colorScheme.value);
|
||||||
|
|
||||||
watchEffect(() => updatePageTitle(route));
|
watchEffect(() => updatePageTitle(route));
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -17,12 +17,14 @@ limitations under the License.
|
|||||||
<script setup>
|
<script setup>
|
||||||
import Icon from '@/features/icons/components/Icon.vue';
|
import Icon from '@/features/icons/components/Icon.vue';
|
||||||
|
|
||||||
import { inject } from 'vue';
|
import { useSettings } from '@/features/settings/composables/useSettings';
|
||||||
|
import { computed } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
const { getSetting, setSetting } = useSettings();
|
||||||
|
|
||||||
const colorScheme = inject('colorScheme');
|
const colorScheme = computed(() => getSetting(['appearance', 'colorScheme']));
|
||||||
|
|
||||||
const colorSchemeNextMapper = {
|
const colorSchemeNextMapper = {
|
||||||
'light': 'dark',
|
'light': 'dark',
|
||||||
@@ -39,11 +41,15 @@ const colorSchemeIconMapper = {
|
|||||||
const getTooltipTranslation = function (colorScheme) {
|
const getTooltipTranslation = function (colorScheme) {
|
||||||
return t(`preferences.colorScheme.switch.${colorSchemeNextMapper[colorScheme]}`);
|
return t(`preferences.colorScheme.switch.${colorSchemeNextMapper[colorScheme]}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const setColorScheme = function setColorScheme (newColorScheme) {
|
||||||
|
setSetting(['appearance', 'colorScheme'], newColorScheme);
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<button class="color-scheme-button"
|
<button class="color-scheme-button"
|
||||||
@click="colorScheme = colorSchemeNextMapper[colorScheme]"
|
@click="setColorScheme(colorSchemeNextMapper[colorScheme])"
|
||||||
:aria-label="getTooltipTranslation(colorScheme)"
|
:aria-label="getTooltipTranslation(colorScheme)"
|
||||||
:title="getTooltipTranslation(colorScheme)"
|
:title="getTooltipTranslation(colorScheme)"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2026 Seekra
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import ColorSchemeButton from '../ColorSchemeButton.vue';
|
||||||
|
import { useSettings } from '@/features/settings/composables/useSettings.js';
|
||||||
|
import { mountComponent } from '@/test-utils/mountComponent';
|
||||||
|
import { describe, expect, test } from 'vitest';
|
||||||
|
|
||||||
|
const { getSetting } = useSettings();
|
||||||
|
|
||||||
|
const colorSchemeSettingPath = ['appearance', 'colorScheme']
|
||||||
|
|
||||||
|
const getWrapper = function getWrapper () {
|
||||||
|
return mountComponent(ColorSchemeButton);
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('ColorSchemeButton', () => {
|
||||||
|
test('sets color scheme setting', async () => {
|
||||||
|
const wrapper = getWrapper();
|
||||||
|
|
||||||
|
expect(getSetting(colorSchemeSettingPath)).toBe('auto');
|
||||||
|
|
||||||
|
const colorSchemeButton = wrapper.find('button');
|
||||||
|
|
||||||
|
await colorSchemeButton.trigger('click');
|
||||||
|
expect(getSetting(colorSchemeSettingPath)).toBe('light');
|
||||||
|
|
||||||
|
await colorSchemeButton.trigger('click');
|
||||||
|
expect(getSetting(colorSchemeSettingPath)).toBe('dark');
|
||||||
|
|
||||||
|
await colorSchemeButton.trigger('click');
|
||||||
|
expect(getSetting(colorSchemeSettingPath)).toBe('auto');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2026 Seekra
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export const useColorScheme = function () {
|
|
||||||
const getColorScheme = function () {
|
|
||||||
let colorScheme = localStorage.getItem('colorScheme') || 'auto';
|
|
||||||
if (!(colorScheme === 'dark' || colorScheme === 'light' || colorScheme === 'auto')) {
|
|
||||||
colorScheme = 'auto';
|
|
||||||
};
|
|
||||||
return colorScheme;
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateColorScheme = function (newScheme) {
|
|
||||||
let actualNewScheme = newScheme;
|
|
||||||
if (!(actualNewScheme === 'dark' || actualNewScheme === 'light' || actualNewScheme === 'auto')) {
|
|
||||||
actualNewScheme = 'auto';
|
|
||||||
};
|
|
||||||
|
|
||||||
localStorage.setItem('colorScheme', actualNewScheme);
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
getColorScheme,
|
|
||||||
updateColorScheme
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -14,63 +14,16 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { useSettingsConfigCacheStore } from '../../stores/settingsConfigCacheStore';
|
|
||||||
import { useSettingsStore } from '../../stores/settingsStore';
|
|
||||||
import { useSettings } from '../useSettings';
|
import { useSettings } from '../useSettings';
|
||||||
import { createTestingPinia } from '@pinia/testing';
|
import { createTestingPinia } from '@pinia/testing';
|
||||||
import { setActivePinia } from 'pinia';
|
import { setActivePinia } from 'pinia';
|
||||||
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||||
|
|
||||||
const settingDefaultValue = 42;
|
const settingDefaultValue = vi.hoisted(() => 42);
|
||||||
const settingPath = ['test', 'number'];
|
const settingPath = ['test', 'number'];
|
||||||
|
|
||||||
describe('useSettings', () => {
|
vi.mock('../../settings.json', () => ({
|
||||||
describe('getSetting', () => {
|
default: {
|
||||||
test('returns stored value', () => {
|
|
||||||
const { getSetting } = useSettings();
|
|
||||||
const settings = useSettingsStore();
|
|
||||||
|
|
||||||
const key = 'setting';
|
|
||||||
const value = 42;
|
|
||||||
|
|
||||||
settings.set(key, value);
|
|
||||||
|
|
||||||
expect(getSetting(key)).toBe(value);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('returns default value', () => {
|
|
||||||
const { getSetting } = useSettings();
|
|
||||||
expect(getSetting(settingPath)).toBe(settingDefaultValue);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('returns stored value instead of default value', () => {
|
|
||||||
const { getSetting } = useSettings();
|
|
||||||
const settings = useSettingsStore();
|
|
||||||
|
|
||||||
const value = 43;
|
|
||||||
|
|
||||||
expect(getSetting(settingPath)).toBe(settingDefaultValue);
|
|
||||||
|
|
||||||
settings.set(settingPath, value);
|
|
||||||
expect(getSetting(settingPath)).toBe(value);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('returns undefined if there is no value', () => {
|
|
||||||
const { getSetting } = useSettings();
|
|
||||||
expect(getSetting(['test', 'bool'])).toBeUndefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
setActivePinia(
|
|
||||||
createTestingPinia({
|
|
||||||
createSpy: vi.fn,
|
|
||||||
stubActions: false
|
|
||||||
})
|
|
||||||
);
|
|
||||||
const settingsConfigCache = useSettingsConfigCacheStore();
|
|
||||||
settingsConfigCache.set({
|
|
||||||
contents: [
|
contents: [
|
||||||
{
|
{
|
||||||
name: 'test',
|
name: 'test',
|
||||||
@@ -90,5 +43,49 @@ beforeEach(() => {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('useSettings', () => {
|
||||||
|
describe('getSetting', () => {
|
||||||
|
test('returns stored value', () => {
|
||||||
|
const { getSetting, setSetting } = useSettings();
|
||||||
|
|
||||||
|
const key = ['setting'];
|
||||||
|
const value = 42;
|
||||||
|
|
||||||
|
setSetting(key, value);
|
||||||
|
expect(getSetting(key)).toBe(value);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns default value', () => {
|
||||||
|
const { getSetting, setSetting } = useSettings();
|
||||||
|
expect(getSetting(settingPath)).toBe(settingDefaultValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns stored value instead of default value', () => {
|
||||||
|
const { getSetting, setSetting } = useSettings();
|
||||||
|
|
||||||
|
const value = 43;
|
||||||
|
|
||||||
|
expect(getSetting(settingPath)).toBe(settingDefaultValue);
|
||||||
|
|
||||||
|
setSetting(settingPath, value);
|
||||||
|
expect(getSetting(settingPath)).toBe(value);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns undefined if there is no value', () => {
|
||||||
|
const { getSetting } = useSettings();
|
||||||
|
expect(getSetting(['test', 'bool'])).toBeUndefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
setActivePinia(
|
||||||
|
createTestingPinia({
|
||||||
|
createSpy: vi.fn,
|
||||||
|
stubActions: false
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|||||||
@@ -14,10 +14,9 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { useSettingsConfigCacheStore } from '../stores/settingsConfigCacheStore';
|
import settings from '../settings.json';
|
||||||
import { useSettingsStore } from '../stores/settingsStore';
|
import { useSettingsStore } from '../stores/settingsStore';
|
||||||
import { getSettingRecursively } from '../utils/getSetting';
|
import { getSettingRecursively } from '../utils/getSetting';
|
||||||
import { loadSettingsConfig } from '../utils/settingsParser';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides access to the stored settings.
|
* Provides access to the stored settings.
|
||||||
@@ -31,9 +30,8 @@ export const useSettings = function useSettings () {
|
|||||||
const getSetting = function getSetting (key) {
|
const getSetting = function getSetting (key) {
|
||||||
const settingsStore = useSettingsStore();
|
const settingsStore = useSettingsStore();
|
||||||
|
|
||||||
const settings = useSettingsConfigCacheStore().get();
|
|
||||||
return (
|
return (
|
||||||
settingsStore.get(key) ??
|
settingsStore.get(key.join('.')) ??
|
||||||
getSettingRecursively(
|
getSettingRecursively(
|
||||||
key, settings.contents ?? []
|
key, settings.contents ?? []
|
||||||
)?.default
|
)?.default
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2026 Seekra
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { ref, readonly } from 'vue';
|
|
||||||
import { loadSettingsConfig } from '../utils/settingsParser.js';
|
|
||||||
|
|
||||||
const config = ref(null);
|
|
||||||
const error = ref(null);
|
|
||||||
const loading = ref(false);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides reactive access to the parsed settings configuration.
|
|
||||||
* The config is loaded once and shared across all consumers.
|
|
||||||
*/
|
|
||||||
export function useSettingsConfig() {
|
|
||||||
async function load() {
|
|
||||||
loading.value = true;
|
|
||||||
error.value = null;
|
|
||||||
try {
|
|
||||||
config.value = await loadSettingsConfig();
|
|
||||||
} catch (e) {
|
|
||||||
error.value = e.message;
|
|
||||||
config.value = null;
|
|
||||||
} finally {
|
|
||||||
loading.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
config: readonly(config),
|
|
||||||
error: readonly(error),
|
|
||||||
loading: readonly(loading),
|
|
||||||
load,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,30 @@
|
|||||||
{
|
{
|
||||||
"contents": []
|
"contents": [
|
||||||
|
{
|
||||||
|
"name": "appearance",
|
||||||
|
"i18n": "settings.settings.appearance.title",
|
||||||
|
"content": [
|
||||||
|
{
|
||||||
|
"name": "colorScheme",
|
||||||
|
"type": "selection",
|
||||||
|
"i18n": "settings.settings.appearance.contents.colorScheme.title",
|
||||||
|
"default": "auto",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"name": "auto",
|
||||||
|
"i18n": "settings.settings.appearance.contents.colorScheme.options.auto"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "light",
|
||||||
|
"i18n": "settings.settings.appearance.contents.colorScheme.options.light"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "dark",
|
||||||
|
"i18n": "settings.settings.appearance.contents.colorScheme.options.dark"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2026 Seekra
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { defineStore } from 'pinia';
|
|
||||||
|
|
||||||
export const useSettingsConfigCacheStore = defineStore('settingsConfigCache', () => {
|
|
||||||
let settingsConfig = undefined;
|
|
||||||
|
|
||||||
const set = function set (value) {
|
|
||||||
settingsConfig = value;
|
|
||||||
};
|
|
||||||
|
|
||||||
const get = function get () {
|
|
||||||
return settingsConfig;
|
|
||||||
};
|
|
||||||
|
|
||||||
return { set, get };
|
|
||||||
});
|
|
||||||
@@ -20,18 +20,10 @@ import { validateSettingsConfig, validateEntry, validateSelectionOptions, assert
|
|||||||
describe('settingsValidator', () => {
|
describe('settingsValidator', () => {
|
||||||
describe('validateSettingsConfig', () => {
|
describe('validateSettingsConfig', () => {
|
||||||
test.for([
|
test.for([
|
||||||
{ raw: false, expected: false },
|
{ settings: {
|
||||||
{ raw: true, expected: false },
|
|
||||||
{ raw: 0, expected: false },
|
|
||||||
{ raw: 42, expected: false },
|
|
||||||
{ raw: '', expected: false },
|
|
||||||
{ raw: ' ', expected: false },
|
|
||||||
{ raw: 'a', expected: false },
|
|
||||||
{ raw: {}, expected: false },
|
|
||||||
{ raw: {
|
|
||||||
contents: []
|
contents: []
|
||||||
}, expected: true },
|
} },
|
||||||
{ raw: {
|
{ settings: {
|
||||||
contents: [
|
contents: [
|
||||||
{
|
{
|
||||||
name: 'general',
|
name: 'general',
|
||||||
@@ -45,8 +37,8 @@ describe('settingsValidator', () => {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}, expected: true },
|
} },
|
||||||
{ raw: {
|
{ settings: {
|
||||||
contents: [
|
contents: [
|
||||||
{
|
{
|
||||||
name: 'general',
|
name: 'general',
|
||||||
@@ -71,8 +63,8 @@ describe('settingsValidator', () => {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}, expected: true },
|
} },
|
||||||
{ raw: {
|
{ settings: {
|
||||||
contents: [
|
contents: [
|
||||||
{
|
{
|
||||||
name: 'general',
|
name: 'general',
|
||||||
@@ -128,12 +120,12 @@ describe('settingsValidator', () => {
|
|||||||
default: 'str'
|
default: 'str'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
]
|
]
|
||||||
}, expected: true },
|
} },
|
||||||
{ raw: {
|
{ settings: {
|
||||||
contents: [
|
contents: [
|
||||||
{
|
{
|
||||||
name: 'general',
|
name: 'general',
|
||||||
@@ -190,12 +182,283 @@ describe('settingsValidator', () => {
|
|||||||
default: 'str'
|
default: 'str'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
} }
|
||||||
|
])('does not throw an error and returns input', ({ settings }) => {
|
||||||
|
validateSettingsConfig(settings);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.for([
|
||||||
|
{ settings: false },
|
||||||
|
{ settings: true },
|
||||||
|
{ settings: 0 },
|
||||||
|
{ settings: 42 },
|
||||||
|
{ settings: '' },
|
||||||
|
{ settings: ' ' },
|
||||||
|
{ settings: 'a' },
|
||||||
|
{ settings: {} },
|
||||||
|
{ settings: {
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'sectio',
|
||||||
|
name: 'general',
|
||||||
|
i18n: 'settings.settings.general',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'copyOfGeneral',
|
||||||
|
i18n: 'settings.settings.copyOfGeneral',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
default: false,
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}, expected: true },
|
},
|
||||||
{ raw: {
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'aSection',
|
||||||
|
i18n: 'settings.settings.aSection',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 43',
|
||||||
|
i18n: 'settings.settings.aSection.enableFeature43'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
name: 'language',
|
||||||
|
i18n: 'settings.settings.aSection.language.label',
|
||||||
|
default: 'en',
|
||||||
|
allowMultiple: 'false',
|
||||||
|
options: [
|
||||||
|
{ name: 'en', i18n: 'settings.settings.aSection.language.options.en' },
|
||||||
|
{ name: 'de', i18n: 'settings.settings.aSection.language.options.de' },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'section2',
|
||||||
|
i18n: 'settings.settings.aSection.section2.label',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: 'string',
|
||||||
|
i18n: 'settings.settings.aSection.sections.string',
|
||||||
|
default: 'str'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
} },
|
||||||
|
{ settings: {
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'sectio',
|
||||||
|
name: 'general',
|
||||||
|
i18n: 'settings.settings.general',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'copyOfGeneral',
|
||||||
|
i18n: 'settings.settings.copyOfGeneral',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
default: false,
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'aSection',
|
||||||
|
i18n: 'settings.settings.aSection',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 43',
|
||||||
|
i18n: 'settings.settings.aSection.enableFeature43'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
name: 'language',
|
||||||
|
i18n: 'settings.settings.aSection.language.label',
|
||||||
|
default: 'en',
|
||||||
|
options: [
|
||||||
|
{ name: 'en', i18n: 'settings.settings.aSection.language.options.en' },
|
||||||
|
{ name: 'de', i18n: 'settings.settings.aSection.language.options.de' },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'section2',
|
||||||
|
i18n: 'settings.settings.aSection.section2.label',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: 'string',
|
||||||
|
i18n: 'settings.settings.aSection.sections.string',
|
||||||
|
default: 'str'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
} },
|
||||||
|
{ settings: {
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'general',
|
||||||
|
i18n: 'settings.settings.general',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'copyOfGeneral',
|
||||||
|
i18n: 'settings.settings.copyOfGeneral',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
default: false,
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'aSection',
|
||||||
|
i18n: 'settings.settings.aSection',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 43',
|
||||||
|
i18n: 'settings.settings.aSection.enableFeature43'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
name: 'language',
|
||||||
|
i18n: 'settings.settings.aSection.language.label',
|
||||||
|
default: 'en',
|
||||||
|
options: [
|
||||||
|
{ name: 'en', i18n: 'settings.settings.aSection.language.options.en' },
|
||||||
|
{ name: 'de', i18n: 'settings.settings.aSection.language.options.de' },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'section2',
|
||||||
|
i18n: 'settings.settings.aSection.section2.label',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: 'string',
|
||||||
|
i18n: 'settings.settings.aSection.sections.string',
|
||||||
|
default: 'str'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
} },
|
||||||
|
{ settings: {
|
||||||
|
contents: [
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'general',
|
||||||
|
i18n: 'settings.settings.general',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'copyOfGeneral',
|
||||||
|
i18n: 'settings.settings.copyOfGeneral',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
default: false,
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'aSection',
|
||||||
|
i18n: 'settings.settings.aSection',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 43',
|
||||||
|
i18n: 'settings.settings.aSection.enableFeature43',
|
||||||
|
default: 'true'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
name: 'language',
|
||||||
|
i18n: 'settings.settings.aSection.language.label',
|
||||||
|
default: 'en',
|
||||||
|
options: [
|
||||||
|
{ name: 'en', i18n: 'settings.settings.aSection.language.options.en' },
|
||||||
|
{ name: 'de', i18n: 'settings.settings.aSection.language.options.de' },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'section2',
|
||||||
|
i18n: 'settings.settings.aSection.section2.label',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: 'string',
|
||||||
|
i18n: 'settings.settings.aSection.sections.string',
|
||||||
|
default: 42
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
} },
|
||||||
|
{ settings: {
|
||||||
contents: [
|
contents: [
|
||||||
{
|
{
|
||||||
type: 'bool',
|
type: 'bool',
|
||||||
@@ -258,276 +521,14 @@ describe('settingsValidator', () => {
|
|||||||
default: 'str'
|
default: 'str'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}, expected: false },
|
|
||||||
{ raw: {
|
|
||||||
contents: [
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'general',
|
|
||||||
i18n: 'settings.settings.general',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 42',
|
|
||||||
i18n: 'settings.settings.general.enableFeature42'
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'copyOfGeneral',
|
|
||||||
i18n: 'settings.settings.copyOfGeneral',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 42',
|
|
||||||
default: false,
|
|
||||||
i18n: 'settings.settings.general.enableFeature42'
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
} }
|
||||||
{
|
])('throws error', ({ settings }) => {
|
||||||
type: 'section',
|
expect(() => validateSettingsConfig(settings)).toThrow(Error)
|
||||||
name: 'aSection',
|
})
|
||||||
i18n: 'settings.settings.aSection',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 43',
|
|
||||||
i18n: 'settings.settings.aSection.enableFeature43',
|
|
||||||
default: 'true'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'selection',
|
|
||||||
name: 'language',
|
|
||||||
i18n: 'settings.settings.aSection.language.label',
|
|
||||||
default: 'en',
|
|
||||||
options: [
|
|
||||||
{ name: 'en', i18n: 'settings.settings.aSection.language.options.en' },
|
|
||||||
{ name: 'de', i18n: 'settings.settings.aSection.language.options.de' },
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'section2',
|
|
||||||
i18n: 'settings.settings.aSection.section2.label',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'string',
|
|
||||||
name: 'string',
|
|
||||||
i18n: 'settings.settings.aSection.sections.string',
|
|
||||||
default: 42
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}, expected: false },
|
|
||||||
{ raw: {
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'general',
|
|
||||||
i18n: 'settings.settings.general',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 42',
|
|
||||||
i18n: 'settings.settings.general.enableFeature42'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'copyOfGeneral',
|
|
||||||
i18n: 'settings.settings.copyOfGeneral',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 42',
|
|
||||||
default: false,
|
|
||||||
i18n: 'settings.settings.general.enableFeature42'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'aSection',
|
|
||||||
i18n: 'settings.settings.aSection',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 43',
|
|
||||||
i18n: 'settings.settings.aSection.enableFeature43'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'selection',
|
|
||||||
name: 'language',
|
|
||||||
i18n: 'settings.settings.aSection.language.label',
|
|
||||||
default: 'en',
|
|
||||||
options: [
|
|
||||||
{ name: 'en', i18n: 'settings.settings.aSection.language.options.en' },
|
|
||||||
{ name: 'de', i18n: 'settings.settings.aSection.language.options.de' },
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'section2',
|
|
||||||
i18n: 'settings.settings.aSection.section2.label',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'string',
|
|
||||||
name: 'string',
|
|
||||||
i18n: 'settings.settings.aSection.sections.string',
|
|
||||||
default: 'str'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}, expected: false },
|
|
||||||
{ raw: {
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'sectio',
|
|
||||||
name: 'general',
|
|
||||||
i18n: 'settings.settings.general',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 42',
|
|
||||||
i18n: 'settings.settings.general.enableFeature42'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'copyOfGeneral',
|
|
||||||
i18n: 'settings.settings.copyOfGeneral',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 42',
|
|
||||||
default: false,
|
|
||||||
i18n: 'settings.settings.general.enableFeature42'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'aSection',
|
|
||||||
i18n: 'settings.settings.aSection',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 43',
|
|
||||||
i18n: 'settings.settings.aSection.enableFeature43'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'selection',
|
|
||||||
name: 'language',
|
|
||||||
i18n: 'settings.settings.aSection.language.label',
|
|
||||||
default: 'en',
|
|
||||||
options: [
|
|
||||||
{ name: 'en', i18n: 'settings.settings.aSection.language.options.en' },
|
|
||||||
{ name: 'de', i18n: 'settings.settings.aSection.language.options.de' },
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'section2',
|
|
||||||
i18n: 'settings.settings.aSection.section2.label',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'string',
|
|
||||||
name: 'string',
|
|
||||||
i18n: 'settings.settings.aSection.sections.string',
|
|
||||||
default: 'str'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}, expected: false },
|
|
||||||
{ raw: {
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'sectio',
|
|
||||||
name: 'general',
|
|
||||||
i18n: 'settings.settings.general',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 42',
|
|
||||||
i18n: 'settings.settings.general.enableFeature42'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'copyOfGeneral',
|
|
||||||
i18n: 'settings.settings.copyOfGeneral',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 42',
|
|
||||||
default: false,
|
|
||||||
i18n: 'settings.settings.general.enableFeature42'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'aSection',
|
|
||||||
i18n: 'settings.settings.aSection',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 43',
|
|
||||||
i18n: 'settings.settings.aSection.enableFeature43'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'selection',
|
|
||||||
name: 'language',
|
|
||||||
i18n: 'settings.settings.aSection.language.label',
|
|
||||||
default: 'en',
|
|
||||||
allowMultiple: 'false',
|
|
||||||
options: [
|
|
||||||
{ name: 'en', i18n: 'settings.settings.aSection.language.options.en' },
|
|
||||||
{ name: 'de', i18n: 'settings.settings.aSection.language.options.de' },
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'section2',
|
|
||||||
i18n: 'settings.settings.aSection.section2.label',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'string',
|
|
||||||
name: 'string',
|
|
||||||
i18n: 'settings.settings.aSection.sections.string',
|
|
||||||
default: 'str'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}, expected: false }
|
|
||||||
])('returns valid: $expected', ({ raw, expected }) => {
|
|
||||||
const result = validateSettingsConfig(raw);
|
|
||||||
if (!result.valid) {
|
|
||||||
console.error('Error message:', result.error);
|
|
||||||
};
|
|
||||||
expect(result.valid).toBe(expected);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('validateEntry', () => {
|
describe('validateEntry', () => {
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2026 Seekra
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { useSettingsConfigCacheStore } from '../stores/settingsConfigCacheStore';
|
|
||||||
import { validateSettingsConfig } from './settingsValidator.js';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads and parses the settings configuration via dynamic import.
|
|
||||||
* @returns {Promise<import('../types/settingsConfig').SettingsConfig>}
|
|
||||||
*/
|
|
||||||
export async function loadSettingsConfig() {
|
|
||||||
const settingsConfigCache = useSettingsConfigCacheStore();
|
|
||||||
let raw;
|
|
||||||
|
|
||||||
try {
|
|
||||||
raw = (await import('../settings.json')).default;
|
|
||||||
settingsConfigCache.set(raw);
|
|
||||||
} catch (e) {
|
|
||||||
throw new Error(`[settings] Failed to load settings.json: ${e.message}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = validateSettingsConfig(raw);
|
|
||||||
if (!result.valid) {
|
|
||||||
throw new Error(result.error);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.config;
|
|
||||||
}
|
|
||||||
@@ -117,7 +117,6 @@ export const validateFirstLevelSection = function validateFirstLevelSection (sec
|
|||||||
* @returns {{ valid: true, config: import('../types/settingsConfig').SettingsConfig } | { valid: false, error: string }}
|
* @returns {{ valid: true, config: import('../types/settingsConfig').SettingsConfig } | { valid: false, error: string }}
|
||||||
*/
|
*/
|
||||||
export function validateSettingsConfig(raw) {
|
export function validateSettingsConfig(raw) {
|
||||||
try {
|
|
||||||
if (!raw || typeof raw !== 'object') {
|
if (!raw || typeof raw !== 'object') {
|
||||||
throw new Error('[settings] Config must be an object');
|
throw new Error('[settings] Config must be an object');
|
||||||
}
|
}
|
||||||
@@ -127,8 +126,4 @@ export function validateSettingsConfig(raw) {
|
|||||||
raw.contents.forEach((entry, i) =>
|
raw.contents.forEach((entry, i) =>
|
||||||
validateFirstLevelSection(entry, `contents[${i}]`)
|
validateFirstLevelSection(entry, `contents[${i}]`)
|
||||||
);
|
);
|
||||||
return { valid: true, config: raw };
|
|
||||||
} catch (e) {
|
|
||||||
return { valid: false, error: e.message };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -18,9 +18,9 @@ limitations under the License.
|
|||||||
import LeftSidebarLayout from '@/layouts/LeftSidebarLayout.vue';
|
import LeftSidebarLayout from '@/layouts/LeftSidebarLayout.vue';
|
||||||
import SettingsPage from '../components/SettingsPage.vue';
|
import SettingsPage from '../components/SettingsPage.vue';
|
||||||
|
|
||||||
|
import settingsConfiguration from '../settings.json';
|
||||||
import { getSettingRecursively } from '../utils/getSetting.js';
|
import { getSettingRecursively } from '../utils/getSetting.js';
|
||||||
import { loadSettingsConfig } from '../utils/settingsParser';
|
import { computed, onMounted, ref, watch } from 'vue';
|
||||||
import { onMounted, ref, watchEffect } from 'vue';
|
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
|
|
||||||
@@ -28,39 +28,27 @@ const { t } = useI18n();
|
|||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const settingsLoaded = ref(false)
|
const settings = settingsConfiguration.contents;
|
||||||
const settings = ref([]);
|
|
||||||
const activeSectionContent = ref({});
|
|
||||||
const activeSection = ref(null);
|
|
||||||
|
|
||||||
watchEffect(() => {
|
const activePath = computed(() => {
|
||||||
const segments = route.path
|
const segments = route.path
|
||||||
.split('/')
|
.split('/')
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
|
|
||||||
activeSection.value = segments.slice(1, segments.length).join('.');
|
return segments.slice(1, segments.length);
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateSettings = function updateSettings () {
|
const activeSection = ref(null);
|
||||||
if (activeSection.value) {
|
const updateSettings = async function updateSettings () {
|
||||||
const setting = getSettingRecursively(activeSection.value.split('.'), settings.value);
|
const setting = getSettingRecursively(activePath.value, settings);
|
||||||
if (!setting) {
|
if (setting) {
|
||||||
router.push('/settings');
|
activeSection.value = setting;
|
||||||
} else {
|
} else {
|
||||||
activeSectionContent.value = setting;
|
await router.push('/settings');
|
||||||
};
|
}
|
||||||
} else {
|
|
||||||
activeSectionContent.value = { content: [] };
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
watch(route, (newRoute) => updateSettings(newRoute));
|
||||||
onMounted(async () => {
|
onMounted(updateSettings);
|
||||||
settings.value = (await loadSettingsConfig()).contents;
|
|
||||||
watchEffect(() => {
|
|
||||||
updateSettings();
|
|
||||||
});
|
|
||||||
settingsLoaded.value = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
const toggleSidebarIfSmallScreen = function toggleSidebarIfSmallScreen (toggleSidebarFunction) {
|
const toggleSidebarIfSmallScreen = function toggleSidebarIfSmallScreen (toggleSidebarFunction) {
|
||||||
if (matchMedia('(max-width: 48rem)').matches) toggleSidebarFunction();
|
if (matchMedia('(max-width: 48rem)').matches) toggleSidebarFunction();
|
||||||
@@ -81,7 +69,7 @@ const toggleSidebarIfSmallScreen = function toggleSidebarIfSmallScreen (toggleSi
|
|||||||
<RouterLink
|
<RouterLink
|
||||||
:to="`/settings/${section.name}`"
|
:to="`/settings/${section.name}`"
|
||||||
class="button button-link link sidebar-section"
|
class="button button-link link sidebar-section"
|
||||||
:class="{ active: activeSection === section.name }"
|
:class="{ active: activeSection && activeSection.name === section.name }"
|
||||||
@click="toggleSidebarIfSmallScreen(toggleSidebar)"
|
@click="toggleSidebarIfSmallScreen(toggleSidebar)"
|
||||||
>
|
>
|
||||||
{{ t(section.i18n) }}
|
{{ t(section.i18n) }}
|
||||||
@@ -89,12 +77,9 @@ const toggleSidebarIfSmallScreen = function toggleSidebarIfSmallScreen (toggleSi
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</template>
|
</template>
|
||||||
<div v-if="!settingsLoaded" class="main-content--loading">
|
<div v-if="activeSection">
|
||||||
{{ t('loading') }}
|
|
||||||
</div>
|
|
||||||
<div v-else-if="activeSection" class="main-content--loaded">
|
|
||||||
<div class="settings-main-content">
|
<div class="settings-main-content">
|
||||||
<SettingsPage :setting="activeSectionContent" :path="activeSection" />
|
<SettingsPage :setting="activeSection" :path="activePath" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="main-content--no-section">
|
<div v-else class="main-content--no-section">
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ limitations under the License.
|
|||||||
|
|
||||||
import SettingsView from '../SettingsView.vue';
|
import SettingsView from '../SettingsView.vue';
|
||||||
import { mountComponent } from '@/test-utils/mountComponent.js';
|
import { mountComponent } from '@/test-utils/mountComponent.js';
|
||||||
import { flushPromises } from '@vue/test-utils';
|
|
||||||
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||||
|
import { nextTick } from 'vue';
|
||||||
|
|
||||||
const settingsHoisted = vi.hoisted(() => [
|
const settingsHoisted = vi.hoisted(() => [
|
||||||
{
|
{
|
||||||
@@ -197,10 +197,8 @@ const settings = settingsHoisted.values();
|
|||||||
const originalCurrentSection = 's0';
|
const originalCurrentSection = 's0';
|
||||||
let currentSection = originalCurrentSection;
|
let currentSection = originalCurrentSection;
|
||||||
|
|
||||||
vi.mock('../../utils/settingsParser', () => ({
|
vi.mock('../../settings.json', () => ({
|
||||||
loadSettingsConfig: vi.fn().mockResolvedValue({
|
default: { contents: settingsHoisted }
|
||||||
contents: settingsHoisted
|
|
||||||
})
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock('vue-router', async (importOriginal) => {
|
vi.mock('vue-router', async (importOriginal) => {
|
||||||
@@ -235,9 +233,7 @@ describe('SettingsView', () => {
|
|||||||
describe('sidebar', () => {
|
describe('sidebar', () => {
|
||||||
test('shows all top-level sections', async () => {
|
test('shows all top-level sections', async () => {
|
||||||
const wrapper = getWrapper();
|
const wrapper = getWrapper();
|
||||||
|
await nextTick();
|
||||||
await flushPromises();
|
|
||||||
await wrapper.vm.$nextTick();
|
|
||||||
|
|
||||||
const sidebarItems = wrapper.findAll('.sidebar-sections-list > li');
|
const sidebarItems = wrapper.findAll('.sidebar-sections-list > li');
|
||||||
settings.forEach((setting, index) => {
|
settings.forEach((setting, index) => {
|
||||||
@@ -254,47 +250,27 @@ describe('SettingsView', () => {
|
|||||||
|
|
||||||
describe('main', () => {
|
describe('main', () => {
|
||||||
describe('correct element', () => {
|
describe('correct element', () => {
|
||||||
test('shows that it is loading', () => {
|
|
||||||
const wrapper = getWrapper();
|
|
||||||
|
|
||||||
const mainContentLoading = wrapper.find('.main-content--loading');
|
|
||||||
const mainContentLoaded = wrapper.find('.main-content--loaded');
|
|
||||||
const mainContentNoSection = wrapper.find('.main-content--no-section');
|
|
||||||
|
|
||||||
expect(mainContentLoading.exists()).toBe(true);
|
|
||||||
expect(mainContentLoaded.exists()).toBe(false);
|
|
||||||
expect(mainContentNoSection.exists()).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('shows that no section is selected', async () => {
|
test('shows that no section is selected', async () => {
|
||||||
currentSection = '';
|
currentSection = '';
|
||||||
|
|
||||||
const wrapper = getWrapper();
|
const wrapper = getWrapper();
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
await flushPromises();
|
const mainContent = wrapper.find('.settings-main-content');
|
||||||
await wrapper.vm.$nextTick();
|
|
||||||
|
|
||||||
const mainContentLoading = wrapper.find('.main-content--loading');
|
|
||||||
const mainContentLoaded = wrapper.find('.main-content--loaded');
|
|
||||||
const mainContentNoSection = wrapper.find('.main-content--no-section');
|
const mainContentNoSection = wrapper.find('.main-content--no-section');
|
||||||
|
|
||||||
expect(mainContentLoading.exists()).toBe(false);
|
expect(mainContent.exists()).toBe(false);
|
||||||
expect(mainContentLoaded.exists()).toBe(false);
|
|
||||||
expect(mainContentNoSection.exists()).toBe(true);
|
expect(mainContentNoSection.exists()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('shows main content', async () => {
|
test('shows main content', async () => {
|
||||||
const wrapper = getWrapper();
|
const wrapper = getWrapper();
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
await flushPromises();
|
const mainContent = wrapper.find('.settings-main-content');
|
||||||
await wrapper.vm.$nextTick();
|
|
||||||
|
|
||||||
const mainContentLoading = wrapper.find('.main-content--loading');
|
|
||||||
const mainContentLoaded = wrapper.find('.main-content--loaded');
|
|
||||||
const mainContentNoSection = wrapper.find('.main-content--no-section');
|
const mainContentNoSection = wrapper.find('.main-content--no-section');
|
||||||
|
|
||||||
expect(mainContentLoading.exists()).toBe(false);
|
expect(mainContent.exists()).toBe(true);
|
||||||
expect(mainContentLoaded.exists()).toBe(true);
|
|
||||||
expect(mainContentNoSection.exists()).toBe(false);
|
expect(mainContentNoSection.exists()).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -60,6 +60,21 @@
|
|||||||
"option": {
|
"option": {
|
||||||
"ariaLabel": "Wählt die Option {option} aus"
|
"ariaLabel": "Wählt die Option {option} aus"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"appearance": {
|
||||||
|
"title": "Erscheinungsbild",
|
||||||
|
"contents": {
|
||||||
|
"colorScheme": {
|
||||||
|
"title": "Farbschema",
|
||||||
|
"options": {
|
||||||
|
"auto": "An Systemfarbschema anpassen",
|
||||||
|
"light": "Hell",
|
||||||
|
"dark": "Dunkel"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,6 +60,21 @@
|
|||||||
"option": {
|
"option": {
|
||||||
"ariaLabel": "Selects option {option}"
|
"ariaLabel": "Selects option {option}"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"appearance": {
|
||||||
|
"title": "Appearance",
|
||||||
|
"contents": {
|
||||||
|
"colorScheme": {
|
||||||
|
"title": "Color Scheme",
|
||||||
|
"options": {
|
||||||
|
"auto": "Adapt to system color scheme",
|
||||||
|
"light": "Light",
|
||||||
|
"dark": "Dark"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,6 +30,9 @@ import rawFonts from './styles/fonts.json';
|
|||||||
import './styles/common.css';
|
import './styles/common.css';
|
||||||
import './styles/variables/colors.css';
|
import './styles/variables/colors.css';
|
||||||
|
|
||||||
|
import settings from './features/settings/settings.json';
|
||||||
|
import { validateSettingsConfig } from './features/settings/utils/settingsValidator';
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const fonts = rawFonts.map((font) => new FontFace(
|
const fonts = rawFonts.map((font) => new FontFace(
|
||||||
font.family ?? '',
|
font.family ?? '',
|
||||||
@@ -55,6 +58,8 @@ import './styles/variables/colors.css';
|
|||||||
const pinia = createPinia();
|
const pinia = createPinia();
|
||||||
pinia.use(piniaPluginPersistedstate);
|
pinia.use(piniaPluginPersistedstate);
|
||||||
|
|
||||||
|
validateSettingsConfig(settings);
|
||||||
|
|
||||||
createApp(App)
|
createApp(App)
|
||||||
.use(router)
|
.use(router)
|
||||||
.use(i18n)
|
.use(i18n)
|
||||||
|
|||||||
Reference in New Issue
Block a user