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!

✨ Add/edit/remove widget through UI

Alicia Sykesd6aeae067379
diff --git a/src/assets/locales/en.json b/src/assets/locales/en.json
index 0d03c46f..adce569f 100644
--- a/src/assets/locales/en.json
+++ b/src/assets/locales/en.json
@@ -396,6 +396,24 @@
"edit-tooltip": "Click to Edit, or right-click for more options",
"remove-confirm": "Are you sure you want to remove this section? This action can be undone later."
},
+ "edit-widget": {
+ "edit-widget-title": "Edit Widget",
+ "add-widget-title": "Add New Widget",
+ "add-widget-btn": "Add Widget",
+ "type-label": "Widget Type",
+ "label-label": "Label",
+ "update-interval-label": "Update Interval (seconds)",
+ "timeout-label": "Timeout (ms)",
+ "use-proxy-label": "Use Proxy",
+ "ignore-errors-label": "Ignore Errors",
+ "options-heading": "Widget Options",
+ "add-option-btn": "Add Option",
+ "key-placeholder": "Key",
+ "value-placeholder": "Value",
+ "missing-type-err": "A widget type is required",
+ "remove-widget": "Remove Widget",
+ "remove-confirm": "Are you sure you want to remove this widget? This action can be undone later."
+ },
"edit-app-config": {
"warning-msg-title": "Proceed with Caution",
"warning-msg-l1": "The following options are for advanced app configuration.",
diff --git a/src/components/InteractiveEditor/EditWidget.vue b/src/components/InteractiveEditor/EditWidget.vue
new file mode 100644
index 00000000..e75f7962
--- /dev/null
+++ b/src/components/InteractiveEditor/EditWidget.vue
@@ -0,0 +1,260 @@
+<template>
+ <modal
+ :name="modalName"
+ :resizable="true"
+ width="50%"
+ height="80%"
+ classes="dashy-modal edit-widget"
+ @closed="modalClosed"
+ >
+ <div class="interactive-editor-inner edit-widget-inner" v-if="allowViewConfig">
+ <h3 class="title">
+ {{ $t(`interactive-editor.edit-widget.${isAddNew ? 'add' : 'edit'}-widget-title`) }}
+ </h3>
+ <Input
+ v-model="form.type"
+ :label="$t('interactive-editor.edit-widget.type-label')"
+ layout="horizontal"
+ />
+ <Input
+ v-model="form.label"
+ :label="$t('interactive-editor.edit-widget.label-label')"
+ layout="horizontal"
+ />
+ <Input
+ v-model="form.updateInterval"
+ :label="$t('interactive-editor.edit-widget.update-interval-label')"
+ type="number"
+ layout="horizontal"
+ />
+ <Input
+ v-model="form.timeout"
+ :label="$t('interactive-editor.edit-widget.timeout-label')"
+ type="number"
+ layout="horizontal"
+ />
+ <Radio
+ v-model="form.useProxy"
+ :label="$t('interactive-editor.edit-widget.use-proxy-label')"
+ :options="boolRadioOptions"
+ :initialOption="form.useProxy"
+ />
+ <Radio
+ v-model="form.ignoreErrors"
+ :label="$t('interactive-editor.edit-widget.ignore-errors-label')"
+ :options="boolRadioOptions"
+ :initialOption="form.ignoreErrors"
+ />
+ <h4 class="options-heading">
+ {{ $t('interactive-editor.edit-widget.options-heading') }}
+ </h4>
+ <div class="row option-row" v-for="(opt, i) in optionRows" :key="i">
+ <Input
+ v-model="opt.key"
+ :placeholder="$t('interactive-editor.edit-widget.key-placeholder')"
+ layout="horizontal"
+ />
+ <Input
+ v-model="opt.value"
+ :placeholder="$t('interactive-editor.edit-widget.value-placeholder')"
+ layout="horizontal"
+ />
+ <BinIcon @click="removeOption(i)" />
+ </div>
+ <span class="add-field-tag" @click="addOption">
+ <AddIcon /> {{ $t('interactive-editor.edit-widget.add-option-btn') }}
+ </span>
+ <SaveCancelButtons :saveClick="saveWidget" :cancelClick="closeModal" />
+ </div>
+ <AccessError v-else />
+ </modal>
+</template>
+
+<script>
+import AddIcon from '@/assets/interface-icons/interactive-editor-add.svg';
+import BinIcon from '@/assets/interface-icons/interactive-editor-remove.svg';
+import SaveCancelButtons from '@/components/InteractiveEditor/SaveCancelButtons';
+import AccessError from '@/components/Configuration/AccessError';
+import Input from '@/components/FormElements/Input';
+import Radio from '@/components/FormElements/Radio';
+import StoreKeys from '@/utils/StoreMutations';
+import safeClone from '@/utils/safeClone';
+import { modalNames } from '@/utils/config/defaults';
+import ErrorHandler, { InfoHandler, InfoKeys } from '@/utils/logging/ErrorHandler';
+
+const emptyForm = () => ({
+ type: '',
+ label: '',
+ updateInterval: '',
+ timeout: '',
+ useProxy: '',
+ ignoreErrors: '',
+});
+
+/* Coerce a string from a free-form options input back to its likely native type. */
+const coerceValue = (raw) => {
+ if (typeof raw !== 'string') return raw;
+ const trimmed = raw.trim();
+ if (trimmed === '') return '';
+ if (trimmed === 'true') return true;
+ if (trimmed === 'false') return false;
+ if (/^-?\d+$/.test(trimmed)) return parseInt(trimmed, 10);
+ if (/^-?\d*\.\d+$/.test(trimmed)) return parseFloat(trimmed);
+ return raw;
+};
+
+export default {
+ name: 'EditWidget',
+ components: {
+ Input, Radio, AddIcon, BinIcon, AccessError, SaveCancelButtons,
+ },
+ props: {
+ sectionIndex: { type: Number, required: true },
+ widgetIndex: { type: Number, default: -1 },
+ isAddNew: Boolean,
+ },
+ emits: ['closeEditWidget'],
+ data() {
+ return {
+ modalName: modalNames.EDIT_WIDGET,
+ form: emptyForm(),
+ optionRows: [],
+ boolRadioOptions: [
+ { label: 'true', value: 'true' },
+ { label: 'false', value: 'false' },
+ ],
+ };
+ },
+ computed: {
+ allowViewConfig() { return this.$store.getters.permissions.allowViewConfig; },
+ },
+ /* Populate form before children render so Radio's `initialOption` is set on its first creation. */
+ created() {
+ if (this.isAddNew) return;
+ const live = this.$store.getters.getSectionByIndex(this.sectionIndex);
+ const widget = safeClone(live?.widgets?.[this.widgetIndex], {});
+ this.form = {
+ type: widget.type || '',
+ label: widget.label || '',
+ updateInterval: widget.updateInterval ?? '',
+ timeout: widget.timeout ?? '',
+ useProxy: widget.useProxy === undefined ? '' : String(widget.useProxy),
+ ignoreErrors: widget.ignoreErrors === undefined ? '' : String(widget.ignoreErrors),
+ };
+ this.optionRows = Object.entries(widget.options || {}).map(([key, value]) => ({
+ key,
+ value: typeof value === 'object' ? JSON.stringify(value) : String(value),
+ }));
+ },
+ mounted() {
+ this.$modal.show(this.modalName);
+ },
+ methods: {
+ addOption() {
+ this.optionRows.push({ key: '', value: '' });
+ },
+ removeOption(index) {
+ this.optionRows.splice(index, 1);
+ },
+ /* Build a clean widget object, omitting empty/default fields so they don't bloat the YAML. */
+ buildWidget() {
+ const widget = { type: this.form.type.trim() };
+ if (this.form.label) widget.label = this.form.label;
+ if (this.form.updateInterval !== '' && this.form.updateInterval !== null) {
+ widget.updateInterval = Number(this.form.updateInterval);
+ }
+ if (this.form.timeout !== '' && this.form.timeout !== null) {
+ widget.timeout = Number(this.form.timeout);
+ }
+ if (this.form.useProxy === 'true') widget.useProxy = true;
+ else if (this.form.useProxy === 'false') widget.useProxy = false;
+ if (this.form.ignoreErrors === 'true') widget.ignoreErrors = true;
+ else if (this.form.ignoreErrors === 'false') widget.ignoreErrors = false;
+ const options = {};
+ this.optionRows.forEach(({ key, value }) => {
+ const k = (key || '').trim();
+ if (k) options[k] = coerceValue(value);
+ });
+ if (Object.keys(options).length) widget.options = options;
+ return widget;
+ },
+ saveWidget() {
+ if (!this.form.type || !this.form.type.trim()) {
+ this.$toast.error(this.$t('interactive-editor.edit-widget.missing-type-err'));
+ return;
+ }
+ try {
+ const widget = this.buildWidget();
+ if (this.isAddNew) {
+ this.$store.commit(StoreKeys.INSERT_WIDGET, { sectionIndex: this.sectionIndex, widget });
+ } else {
+ this.$store.commit(StoreKeys.UPDATE_WIDGET, {
+ sectionIndex: this.sectionIndex,
+ widgetIndex: this.widgetIndex,
+ widget,
+ });
+ }
+ this.$store.commit(StoreKeys.SET_EDIT_MODE, true);
+ InfoHandler(`Widget ${this.isAddNew ? 'added' : 'updated'}: ${widget.type}`, InfoKeys.EDITOR);
+ this.closeModal();
+ } catch (e) {
+ ErrorHandler('Failed to save widget', e);
+ this.$toast.error('Error saving widget. See Logs.');
+ }
+ },
+ closeModal() {
+ this.$modal.hide(this.modalName);
+ },
+ modalClosed() {
+ this.$store.commit(StoreKeys.SET_MODAL_OPEN, false);
+ this.$emit('closeEditWidget');
+ },
+ },
+};
+</script>
+
+<style lang="scss">
+@import '@/styles/style-helpers.scss';
+
+.edit-widget-inner {
+ @extend .svg-button;
+ h3.title { font-size: 1.5rem; margin: 0.25rem 0; }
+ h4.options-heading { margin: 1rem 0 0.5rem; }
+ .row.option-row {
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+ padding: 0.25rem 0;
+ .input-container { flex: 1; }
+ }
+ .add-field-tag {
+ display: inline-flex;
+ align-items: center;
+ margin: 0.5rem 0.2rem;
+ padding: 0.2rem 0.5rem;
+ cursor: pointer;
+ border: 1px solid var(--interactive-editor-color);
+ border-radius: var(--curve-factor);
+ &:hover {
+ background: var(--interactive-editor-color);
+ color: var(--interactive-editor-background);
+ }
+ svg { margin-right: 0.25rem; border: none; }
+ }
+ /* Match EditItem's local form-element overrides for theme consistency */
+ div.input-container input.input-field,
+ .radio-container div.radio-wrapper {
+ color: var(--interactive-editor-color);
+ border-color: var(--interactive-editor-color);
+ background: var(--interactive-editor-background);
+ }
+ svg {
+ path { fill: var(--interactive-editor-color); }
+ background: var(--interactive-editor-background);
+ &:hover, &.selected {
+ path { fill: var(--interactive-editor-background); }
+ background: var(--interactive-editor-color);
+ }
+ }
+}
+</style>
diff --git a/src/components/LinkItems/Section.vue b/src/components/LinkItems/Section.vue
index 819751d1..51252524 100644
--- a/src/components/LinkItems/Section.vue
+++ b/src/components/LinkItems/Section.vue
@@ -60,14 +60,19 @@
/>
</div>
<div
- v-if="hasWidgets"
+ v-if="hasWidgets || isEditMode"
:class="`widget-list ${isWide? 'wide' : ''}`">
<WidgetBase
v-for="(widget, widgetIndx) in widgets"
:key="widgetIndx"
:widget="widget"
:index="index"
+ @editWidget="openEditWidget(widgetIndx)"
+ @removeWidget="confirmRemoveWidget(widgetIndx)"
/>
+ <span v-if="isEditMode" class="add-widget-launcher" @click="openAddWidget">
+ <AddIcon /> {{ $t('interactive-editor.edit-widget.add-widget-btn') }}
+ </span>
</div>
<!-- Modal for opening in modal view -->
<IframeModal
@@ -101,6 +106,20 @@
:message="$t('interactive-editor.edit-section.remove-confirm')"
@confirm="confirmRemoveSection"
/>
+ <!-- Edit widget menu -->
+ <EditWidget v-if="editWidgetMenuOpen"
+ :sectionIndex="index"
+ :widgetIndex="editingWidgetIndex"
+ :isAddNew="addingWidget"
+ @closeEditWidget="closeEditWidget"
+ />
+ <ConfirmDialog
+ v-model:open="showRemoveWidgetConfirm"
+ danger
+ :title="$t('interactive-editor.edit-widget.remove-widget')"
+ :message="$t('interactive-editor.edit-widget.remove-confirm')"
+ @confirm="doRemoveWidget"
+ />
</Collapsable>
</template>
@@ -114,8 +133,10 @@ import Collapsable from '@/components/LinkItems/Collapsable.vue';
import IframeModal from '@/components/LinkItems/IframeModal.vue';
import ContextMenu from '@/components/LinkItems/SectionContextMenu.vue';
import ConfirmDialog from '@/components/FormElements/ConfirmDialog.vue';
+import AddIcon from '@/assets/interface-icons/interactive-editor-add.svg';
const EditSection = defineAsyncComponent(() => import('@/components/InteractiveEditor/EditSection.vue'));
+const EditWidget = defineAsyncComponent(() => import('@/components/InteractiveEditor/EditWidget.vue'));
import ErrorHandler from '@/utils/logging/ErrorHandler';
import sortItems from '@/utils/SortItems';
import { makeRoutePath, viewFromPath } from '@/utils/config/ConfigHelpers';
@@ -144,7 +165,9 @@ export default {
WidgetBase,
IframeModal,
EditSection,
+ EditWidget,
ConfirmDialog,
+ AddIcon,
},
data() {
return {
@@ -157,6 +180,11 @@ export default {
sectionWidth: 0,
resizeObserver: null,
showRemoveConfirm: false,
+ editWidgetMenuOpen: false,
+ editingWidgetIndex: -1,
+ addingWidget: false,
+ showRemoveWidgetConfirm: false,
+ pendingRemoveWidgetIndex: -1,
};
},
computed: {
@@ -265,6 +293,36 @@ export default {
closeContextMenu() {
this.contextMenuOpen = false;
},
+ /* Open edit modal for an existing widget */
+ openEditWidget(widgetIndx) {
+ this.editingWidgetIndex = widgetIndx;
+ this.addingWidget = false;
+ this.editWidgetMenuOpen = true;
+ this.$store.commit(StoreKeys.SET_MODAL_OPEN, true);
+ },
+ /* Open edit modal for a new widget */
+ openAddWidget() {
+ this.editingWidgetIndex = -1;
+ this.addingWidget = true;
+ this.editWidgetMenuOpen = true;
+ this.$store.commit(StoreKeys.SET_MODAL_OPEN, true);
+ },
+ closeEditWidget() {
+ this.editWidgetMenuOpen = false;
+ this.editingWidgetIndex = -1;
+ this.addingWidget = false;
+ },
+ confirmRemoveWidget(widgetIndx) {
+ this.pendingRemoveWidgetIndex = widgetIndx;
+ this.showRemoveWidgetConfirm = true;
+ },
+ doRemoveWidget() {
+ this.$store.commit(StoreKeys.REMOVE_WIDGET, {
+ sectionIndex: this.index,
+ widgetIndex: this.pendingRemoveWidgetIndex,
+ });
+ this.pendingRemoveWidgetIndex = -1;
+ },
/* Calculate width of section, used to dynamically set number of columns */
calculateSectionWidth() {
const secElem = this.$refs[this.sectionRef];
@@ -369,6 +427,27 @@ export default {
width: -moz-available;
}
}
+ .add-widget-launcher {
+ display: inline-flex;
+ align-items: center;
+ margin: 0.5rem 0;
+ padding: 0.3rem 0.75rem;
+ cursor: pointer;
+ color: var(--primary);
+ border: 1px dashed var(--primary);
+ border-radius: var(--curve-factor);
+ &:hover {
+ background: var(--primary);
+ color: var(--background);
+ svg path { fill: var(--background); }
+ }
+ svg {
+ width: 1rem;
+ height: 1rem;
+ margin-right: 0.35rem;
+ path { fill: var(--primary); }
+ }
+ }
}
</style>
diff --git a/src/components/Widgets/WidgetBase.vue b/src/components/Widgets/WidgetBase.vue
index bc64eaa3..a3457732 100644
--- a/src/components/Widgets/WidgetBase.vue
+++ b/src/components/Widgets/WidgetBase.vue
@@ -4,6 +4,14 @@
<Button :click="update" class="action-btn update-btn" v-if="!hideControls && !loading">
<UpdateIcon />
</Button>
+ <!-- Edit Action Button (visible in edit mode) -->
+ <Button :click="emitEdit" class="action-btn edit-btn" v-if="isEditMode && !loading">
+ <EditIcon />
+ </Button>
+ <!-- Remove Action Button (visible in edit mode) -->
+ <Button :click="emitRemove" class="action-btn remove-btn" v-if="isEditMode && !loading">
+ <BinIcon />
+ </Button>
<!-- Loading Spinner -->
<div v-if="loading" class="loading">
<LoadingAnimation v-if="loading" class="loader" />
@@ -35,6 +43,8 @@ import { defineAsyncComponent } from 'vue';
import ErrorHandler from '@/utils/logging/ErrorHandler';
import Button from '@/components/FormElements/Button';
import UpdateIcon from '@/assets/interface-icons/widget-update.svg';
+import EditIcon from '@/assets/interface-icons/config-edit-json.svg';
+import BinIcon from '@/assets/interface-icons/interactive-editor-remove.svg';
import LoadingAnimation from '@/assets/interface-icons/loader.svg';
const widgetModules = import.meta.glob('./*.vue');
@@ -137,12 +147,15 @@ export default {
// Register form elements
Button,
UpdateIcon,
+ EditIcon,
+ BinIcon,
LoadingAnimation,
},
props: {
widget: { type: Object, required: true },
index: { type: Number, required: true },
},
+ emits: ['editWidget', 'removeWidget'],
data: () => ({
loading: false,
error: false,
@@ -152,6 +165,9 @@ export default {
appConfig() {
return this.$store.getters.appConfig;
},
+ isEditMode() {
+ return this.$store.state.editMode;
+ },
/* Returns the widget type, shows error if not specified */
widgetType() {
if (!this.widget.type) {
@@ -210,6 +226,8 @@ export default {
setLoaderState(loading) {
this.loading = loading;
},
+ emitEdit() { this.$emit('editWidget'); },
+ emitRemove() { this.$emit('removeWidget'); },
},
};
</script>
@@ -243,6 +261,8 @@ export default {
}
&.update-btn { right: -0.25rem; }
+ &.edit-btn { right: 1rem; }
+ &.remove-btn { right: 2.25rem; }
}
// Optional widget label
diff --git a/src/store.js b/src/store.js
index 545625b0..6dae3410 100644
--- a/src/store.js
+++ b/src/store.js
@@ -43,6 +43,9 @@ const {
COPY_ITEM,
REMOVE_ITEM,
INSERT_ITEM,
+ INSERT_WIDGET,
+ UPDATE_WIDGET,
+ REMOVE_WIDGET,
UPDATE_CUSTOM_CSS,
CONF_MENU_INDEX,
CRITICAL_ERROR_MSG,
@@ -401,6 +404,29 @@ const store = createStore({
commitConfigField(state, 'sections', patched);
InfoHandler('Item removed', InfoKeys.EDITOR);
},
+ [INSERT_WIDGET](state, { sectionIndex, widget }) {
+ commitConfigField(state, 'sections', state.config.sections.map((s, i) => (
+ i === sectionIndex ? { ...s, widgets: [...(s.widgets || []), widget] } : s
+ )));
+ InfoHandler('New widget added', InfoKeys.EDITOR);
+ },
+ [UPDATE_WIDGET](state, { sectionIndex, widgetIndex, widget }) {
+ commitConfigField(state, 'sections', state.config.sections.map((s, i) => {
+ if (i !== sectionIndex) return s;
+ return {
+ ...s,
+ widgets: (s.widgets || []).map((w, wi) => (wi === widgetIndex ? widget : w)),
+ };
+ }));
+ InfoHandler('Widget updated', InfoKeys.EDITOR);
+ },
+ [REMOVE_WIDGET](state, { sectionIndex, widgetIndex }) {
+ commitConfigField(state, 'sections', state.config.sections.map((s, i) => {
+ if (i !== sectionIndex) return s;
+ return { ...s, widgets: (s.widgets || []).filter((_, wi) => wi !== widgetIndex) };
+ }));
+ InfoHandler('Widget removed', InfoKeys.EDITOR);
+ },
[SET_THEME](state, theme) {
patchAppConfigField(state, 'theme', theme, configScope(state.currentConfigInfo.confId).THEME);
InfoHandler('Theme updated', InfoKeys.VISUAL);
diff --git a/src/utils/StoreMutations.js b/src/utils/StoreMutations.js
index f9f4201d..dc5beea3 100644
--- a/src/utils/StoreMutations.js
+++ b/src/utils/StoreMutations.js
@@ -28,6 +28,9 @@ const KEY_NAMES = [
'COPY_ITEM',
'REMOVE_ITEM',
'INSERT_ITEM',
+ 'INSERT_WIDGET',
+ 'UPDATE_WIDGET',
+ 'REMOVE_WIDGET',
'UPDATE_CUSTOM_CSS',
'CONF_MENU_INDEX',
'CRITICAL_ERROR_MSG',
diff --git a/src/utils/config/defaults.js b/src/utils/config/defaults.js
index 748851cd..9917bb79 100644
--- a/src/utils/config/defaults.js
+++ b/src/utils/config/defaults.js
@@ -162,6 +162,7 @@ const defaults = {
LANG_SWITCHER: 'LANG_SWITCHER',
EDIT_ITEM: 'EDIT_ITEM',
EDIT_SECTION: 'EDIT_SECTION',
+ EDIT_WIDGET: 'EDIT_WIDGET',
EDIT_PAGE_INFO: 'EDIT_PAGE_INFO',
EDIT_APP_CONFIG: 'EDIT_APP_CONFIG',
EDIT_MULTI_PAGES: 'EDIT_MULTI_PAGES',