Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

✨ Remote config preview

Alicia Sykesc86badeda519
diff --git a/src/App.vue b/src/App.vue
index 148f1188..7ec62a4d 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -6,6 +6,7 @@
<router-view v-if="!isFetching" />
<CriticalError v-if="hasCriticalError" />
<Footer :text="footerText" v-if="footerVisible && !isFetching" />
+ <RemoteConfigLoader v-if="!isFetching" />
</div>
</template>
<script>
@@ -15,6 +16,7 @@ import Footer from '@/components/PageStrcture/Footer.vue';
import EditModeTopBanner from '@/components/InteractiveEditor/EditModeTopBanner.vue';
import CriticalError from '@/components/PageStrcture/CriticalError.vue';
import LoadingScreen from '@/components/PageStrcture/LoadingScreen.vue';
+import RemoteConfigLoader from '@/components/Configuration/RemoteConfigLoader.vue';
import { welcomeMsg } from '@/utils/logging/CoolConsole';
import ErrorHandler from '@/utils/logging/ErrorHandler';
import { syncPageMeta } from '@/utils/PageMeta';
@@ -36,6 +38,7 @@ export default {
LoadingScreen,
EditModeTopBanner,
CriticalError,
+ RemoteConfigLoader,
},
data() {
return {
diff --git a/src/assets/locales/en.json b/src/assets/locales/en.json
index fed15ecf..0d03c46f 100644
--- a/src/assets/locales/en.json
+++ b/src/assets/locales/en.json
@@ -122,6 +122,25 @@
"workspace": "Workspace",
"minimal": "Minimal"
},
+ "remote-config": {
+ "title": "Load Remote Config?",
+ "apply-button": "Apply Preview",
+ "intro": "You are loading a configuration from an external URL. Would you like to continue?",
+ "warning": "You should ensure that you've read the content you are loading before proceeding. Once loaded, your browser will be able to execute any client-side code specified within this config.",
+ "field-title": "Title",
+ "field-source": "Source",
+ "field-sections": "Sections",
+ "field-items": "Items",
+ "preview-note": "Preview only. This won't make any changes on disk, nor affect your Dashy instance in any way.",
+ "applied-toast": "Remote config applied (preview only)",
+ "previewing-banner": "Previewing remote config",
+ "revert-button": "Revert",
+ "error-invalid-url": "Remote config URL is not valid (must be http or https)",
+ "error-fetch": "Could not fetch remote config. Check the URL is reachable and CORS is allowed.",
+ "error-parse": "Remote config is not valid YAML",
+ "error-not-config": "Remote file does not look like a Dashy config",
+ "error-apply": "Failed to apply remote config"
+ },
"settings": {
"theme-label": "Theme",
"layout-label": "Layout",
diff --git a/src/components/Configuration/RemoteConfigLoader.vue b/src/components/Configuration/RemoteConfigLoader.vue
new file mode 100644
index 00000000..51de282a
--- /dev/null
+++ b/src/components/Configuration/RemoteConfigLoader.vue
@@ -0,0 +1,221 @@
+<template>
+ <ConfirmDialog
+ v-model:open="showDialog"
+ :title="$t('remote-config.title')"
+ :confirmText="$t('remote-config.apply-button')"
+ @confirm="apply"
+ @cancel="dismiss"
+ >
+ <template v-if="preview">
+ <p class="intro">{{ $t('remote-config.intro') }}</p>
+ <p class="warning">{{ $t('remote-config.warning') }}</p>
+ <dl class="preview-fields">
+ <dt>{{ $t('remote-config.field-title') }}</dt>
+ <dd>{{ preview.title }}</dd>
+ <dt>{{ $t('remote-config.field-source') }}</dt>
+ <dd class="src" :title="preview.url">{{ preview.url }}</dd>
+ <dt>{{ $t('remote-config.field-sections') }}</dt>
+ <dd>{{ preview.sectionCount }}</dd>
+ <dt>{{ $t('remote-config.field-items') }}</dt>
+ <dd>{{ preview.itemCount }}</dd>
+ </dl>
+ <p class="note">{{ $t('remote-config.preview-note') }}</p>
+ </template>
+ </ConfirmDialog>
+ <div v-if="originalConfig" class="preview-pill" role="status">
+ <span class="label">{{ $t('remote-config.previewing-banner') }}</span>
+ <button type="button" class="revert" @click="revert">
+ {{ $t('remote-config.revert-button') }}
+ </button>
+ </div>
+</template>
+
+<script>
+import { load as yamlLoad } from 'js-yaml';
+import request from '@/utils/request';
+import ErrorHandler from '@/utils/logging/ErrorHandler';
+import StoreKeys from '@/utils/StoreMutations';
+import ConfirmDialog from '@/components/FormElements/ConfirmDialog';
+
+export default {
+ name: 'RemoteConfigLoader',
+ components: { ConfirmDialog },
+ data() {
+ return {
+ showDialog: false,
+ preview: null,
+ pendingConfig: null,
+ originalConfig: null,
+ };
+ },
+ watch: {
+ /* If config gets reloaded via sub-page nav, our snapshot is stale β€” drop it. */
+ '$store.state.currentConfigInfo.confId'() {
+ this.originalConfig = null;
+ },
+ },
+ mounted() {
+ const url = this.parseUrlParam();
+ if (url) this.loadRemoteConfig(url);
+ },
+ methods: {
+ parseUrlParam() {
+ const raw = this.$route?.query?.config;
+ const value = Array.isArray(raw) ? raw[0] : raw;
+ const url = typeof value === 'string' ? value.trim() : '';
+ if (!url) return null;
+ if (!/^https?:\/\//i.test(url)) {
+ this.fail(`Remote config URL must be http(s): '${url}'`, 'error-invalid-url');
+ return null;
+ }
+ return url;
+ },
+ async loadRemoteConfig(url) {
+ let response;
+ try {
+ response = await request.get(url);
+ } catch (err) {
+ this.fail(`Failed to fetch remote config: ${url}`, 'error-fetch', err);
+ return;
+ }
+ let parsed;
+ try {
+ parsed = typeof response.data === 'string' ? yamlLoad(response.data) : response.data;
+ } catch (err) {
+ this.fail(`Remote config YAML parse failed: ${url}`, 'error-parse', err);
+ return;
+ }
+ if (!this.looksLikeConfig(parsed)) {
+ this.fail(`Remote file is not a Dashy config: ${url}`, 'error-not-config');
+ return;
+ }
+ this.pendingConfig = parsed;
+ this.preview = this.summarise(url, parsed);
+ this.showDialog = true;
+ },
+ looksLikeConfig(cfg) {
+ if (!cfg || typeof cfg !== 'object' || Array.isArray(cfg)) return false;
+ return 'pageInfo' in cfg || 'sections' in cfg || 'appConfig' in cfg;
+ },
+ summarise(url, cfg) {
+ const sections = Array.isArray(cfg.sections) ? cfg.sections : [];
+ const itemCount = sections.reduce(
+ (n, s) => n + (Array.isArray(s.items) ? s.items.length : 0), 0,
+ );
+ return {
+ url,
+ title: cfg.pageInfo?.title || 'β€”',
+ sectionCount: sections.length,
+ itemCount,
+ };
+ },
+ apply() {
+ const snapshot = this.$store.state.config;
+ try {
+ this.$store.commit(StoreKeys.SET_CONFIG, this.pendingConfig);
+ this.originalConfig = snapshot;
+ this.$toast(this.$t('remote-config.applied-toast'));
+ } catch (err) {
+ this.fail('Failed to apply remote config', 'error-apply', err);
+ return;
+ }
+ this.cleanup();
+ },
+ revert() {
+ if (!this.originalConfig) return;
+ this.$store.commit(StoreKeys.SET_CONFIG, this.originalConfig);
+ this.originalConfig = null;
+ },
+ dismiss() {
+ this.cleanup();
+ },
+ cleanup() {
+ this.pendingConfig = null;
+ this.preview = null;
+ this.stripParam();
+ },
+ stripParam() {
+ if (!this.$route?.query?.config) return;
+ const query = { ...this.$route.query };
+ delete query.config;
+ this.$router.replace({ path: this.$route.path, query, hash: this.$route.hash });
+ },
+ fail(logMessage, i18nKey, err) {
+ ErrorHandler(logMessage, err);
+ this.$toast.error(this.$t(`remote-config.${i18nKey}`));
+ this.cleanup();
+ },
+ },
+};
+</script>
+
+<style scoped lang="scss">
+.intro {
+ margin: 0 0 0.5rem;
+}
+
+.warning {
+ margin: 0 0 0.75rem;
+ color: var(--danger);
+ opacity: 1;
+}
+
+.preview-fields {
+ display: grid;
+ grid-template-columns: auto 1fr;
+ gap: 0.4rem 0.75rem;
+ margin: 0 0 0.75rem;
+ dt {
+ font-weight: bold;
+ opacity: var(--dimming-factor);
+ }
+ dd {
+ margin: 0;
+ word-break: break-word;
+ &.src {
+ font-family: var(--font-monospace);
+ font-size: 0.85rem;
+ }
+ }
+}
+
+.note {
+ margin: 0;
+ padding: 0.5rem 0.75rem;
+ font-size: 0.9rem;
+ border-left: 2px solid var(--primary);
+ background: color-mix(in srgb, var(--primary), transparent 90%);
+}
+
+.preview-pill {
+ position: fixed;
+ bottom: 1rem;
+ right: 1rem;
+ z-index: 40;
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+ padding: 0.4rem 0.75rem;
+ font-size: 0.9rem;
+ color: var(--background);
+ background: var(--primary);
+ border-radius: var(--curve-factor);
+ box-shadow: 0 4px 12px hsl(0deg 0% 0% / 30%);
+
+ .label { font-weight: bold; }
+
+ .revert {
+ padding: 0.2rem 0.6rem;
+ font-size: 0.85rem;
+ color: var(--primary);
+ background: var(--background);
+ border: none;
+ border-radius: var(--curve-factor);
+ cursor: pointer;
+ &:hover, &:focus-visible {
+ background: var(--background-darker);
+ outline: none;
+ }
+ }
+}
+</style>