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!

✨ Bring all home section features into minimal view

Alicia Sykes43d1824b4f5c
diff --git a/src/components/LinkItems/Section.vue b/src/components/LinkItems/Section.vue
index 2483fa29..61d3ce79 100644
--- a/src/components/LinkItems/Section.vue
+++ b/src/components/LinkItems/Section.vue
@@ -107,13 +107,10 @@ import IframeModal from '@/components/LinkItems/IframeModal.vue';
import EditSection from '@/components/InteractiveEditor/EditSection.vue';
import ContextMenu from '@/components/LinkItems/SectionContextMenu.vue';
import ErrorHandler from '@/utils/logging/ErrorHandler';
+import sortItems from '@/utils/SortItems';
import { makeRoutePath, viewFromPath } from '@/utils/config/ConfigHelpers';
import StoreKeys from '@/utils/StoreMutations';
-import {
- sortOrder as defaultSortOrder,
- localStorageKeys,
- modalNames,
-} from '@/utils/config/defaults';
+import { sortOrder as defaultSortOrder, modalNames } from '@/utils/config/defaults';
export default {
name: 'Section',
@@ -177,22 +174,8 @@ export default {
},
/* If the sortBy attribute is specified, then return sorted data */
sortedItems() {
- const items = [...this.items];
- if (this.appConfig.disableSmartSort) return items;
- if (this.sortOrder === 'alphabetical') {
- return this.sortAlphabetically(items);
- } else if (this.sortOrder === 'reverse-alphabetical') {
- return this.sortAlphabetically(items).reverse();
- } else if (this.sortOrder === 'most-used') {
- return this.sortByMostUsed(items);
- } else if (this.sortOrder === 'last-used') {
- return this.sortByLastUsed(items);
- } else if (this.sortOrder === 'random') {
- return this.sortRandomly(items);
- } else if (this.sortOrder && this.sortOrder !== 'default') {
- ErrorHandler(`Unknown Sort order '${this.sortOrder}' under '${this.title}'`);
- }
- return items;
+ if (this.appConfig.disableSmartSort) return [...this.items];
+ return sortItems(this.items, this.sortOrder, this.title);
},
isGridLayout() {
return this.displayData.sectionLayout === 'grid'
@@ -217,31 +200,6 @@ export default {
triggerModal(url) {
this.$refs[`iframeModal-${this.groupId}`].show(url);
},
- /* Sorts items alphabetically using the title attribute */
- sortAlphabetically(items) {
- return items.sort((a, b) => (a.title.toLowerCase() > b.title.toLowerCase() ? 1 : -1));
- },
- /* Sorts items by most used to least used, based on click-count */
- sortByMostUsed(items) {
- const usageCount = JSON.parse(localStorage.getItem(localStorageKeys.MOST_USED) || '{}');
- const gmu = (item) => usageCount[item.id] || 0;
- items.reverse().sort((a, b) => (gmu(a) < gmu(b) ? 1 : -1));
- return items;
- },
- /* Sorts items by most recently used */
- sortByLastUsed(items) {
- const usageCount = JSON.parse(localStorage.getItem(localStorageKeys.LAST_USED) || '{}');
- const glu = (item) => usageCount[item.id] || 0;
- items.reverse().sort((a, b) => (glu(a) < glu(b) ? 1 : -1));
- return items;
- },
- /* Sorts items randomly */
- sortRandomly(items) {
- return items
- .map((value) => ({ value, sort: Math.random() }))
- .sort((a, b) => a.sort - b.sort)
- .map(({ value }) => value);
- },
/* Navigate to the section's single-section view */
navigateToSection() {
if (!this.title) {
diff --git a/src/components/MinimalView/MinimalHeading.vue b/src/components/MinimalView/MinimalHeading.vue
index 210c5ba7..d9f968e1 100644
--- a/src/components/MinimalView/MinimalHeading.vue
+++ b/src/components/MinimalView/MinimalHeading.vue
@@ -48,7 +48,12 @@ div.minimal-section-heading {
border-bottom: none;
border-radius: var(--curve-factor) var(--curve-factor) 0 0;
h3.section-title {
+ flex: 1 1 auto;
+ min-width: 0;
margin: 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
color: var(--minimal-view-section-heading-color);
}
.section-icon {
diff --git a/src/components/MinimalView/MinimalSection.vue b/src/components/MinimalView/MinimalSection.vue
index a221e114..59e1e287 100644
--- a/src/components/MinimalView/MinimalSection.vue
+++ b/src/components/MinimalView/MinimalSection.vue
@@ -1,7 +1,9 @@
<template>
- <div :class="`minimal-section-inner ${selected ? 'selected' : ''} ${showAll ? 'show-all': ''}`">
- <div class="section-items" v-if="items && (selected || showAll)">
- <template v-for="(item) in items" :key="item.id">
+ <div
+ :class="`minimal-section-inner ${selected ? 'selected' : ''} ${showAll ? 'show-all': ''}`"
+ :style="dynamicStyle">
+ <div class="section-items" :style="gridStyle" v-if="items && (selected || showAll)">
+ <template v-for="(item) in sortedItems" :key="item.id">
<SubItemGroup
v-if="item.subItems"
:itemId="item.id"
@@ -47,6 +49,7 @@ import Item from '@/components/LinkItems/Item.vue';
import WidgetBase from '@/components/Widgets/WidgetBase';
import SubItemGroup from '@/components/LinkItems/SubItemGroup.vue';
import IframeModal from '@/components/LinkItems/IframeModal.vue';
+import sortItems from '@/utils/SortItems';
import { makeRoutePath, viewFromPath } from '@/utils/config/ConfigHelpers';
export default {
@@ -58,7 +61,6 @@ export default {
displayData: Object,
items: Array,
widgets: Array,
- itemSize: String,
modalOpen: Boolean,
index: Number,
selected: Boolean,
@@ -68,6 +70,33 @@ export default {
appConfig() {
return this.$store.getters.appConfig;
},
+ /* Mirror Section.vue: per-section override wins, otherwise the current
+ * icon size (localStorage + appConfig) chosen by the user */
+ itemSize() {
+ return (this.displayData && this.displayData.itemSize) || this.$store.getters.iconSize;
+ },
+ /* Same itemCountX/Y handling as the home view */
+ gridStyle() {
+ const d = this.displayData || {};
+ const parts = [];
+ if (d.itemCountX) parts.push(`grid-template-columns: repeat(${d.itemCountX}, minmax(0, 1fr))`);
+ if (d.itemCountY) parts.push(`grid-template-rows: repeat(${d.itemCountY}, auto)`);
+ return parts.join('; ');
+ },
+ /* Respect sortBy exactly as the home view does; `disableSmartSort` opt-out */
+ sortedItems() {
+ if (this.appConfig.disableSmartSort) return [...(this.items || [])];
+ const order = (this.displayData && this.displayData.sortBy) || undefined;
+ return sortItems(this.items || [], order, this.title);
+ },
+ /* Apply per-section `color` (background tint) and sanitized `customStyles` */
+ dynamicStyle() {
+ const d = this.displayData || {};
+ const parts = [];
+ if (d.color) parts.push(`background: ${d.color}`);
+ if (d.customStyles) parts.push(d.customStyles.replace(/[^a-zA-Z0-9- :;.]/g, ''));
+ return parts.join('; ');
+ },
},
components: {
Item,
@@ -144,7 +173,6 @@ export default {
}
&.selected {
border: 1px solid var(--minimal-view-group-color);
- grid-column-start: span var(--col-count, 3);
&:not(.show-all) { min-height: 300px; }
}
&.show-all {
diff --git a/src/utils/SortItems.js b/src/utils/SortItems.js
new file mode 100644
index 00000000..8f17be26
--- /dev/null
+++ b/src/utils/SortItems.js
@@ -0,0 +1,36 @@
+import { localStorageKeys, sortOrder as defaultSortOrder } from '@/utils/config/defaults';
+import ErrorHandler from '@/utils/logging/ErrorHandler';
+
+/* Reads a `{ itemId: count }` map out of local storage, returning {} on any error. */
+const readUsage = (key) => {
+ try { return JSON.parse(localStorage.getItem(key) || '{}'); } catch (e) { return {}; }
+};
+
+const byTitle = (items) => [...items].sort(
+ (a, b) => ((a.title || '').toLowerCase() > (b.title || '').toLowerCase() ? 1 : -1),
+);
+
+const byUsage = (items, key) => {
+ const counts = readUsage(key);
+ const get = (item) => counts[item.id] || 0;
+ return [...items].reverse().sort((a, b) => (get(a) < get(b) ? 1 : -1));
+};
+
+const shuffled = (items) => items
+ .map((value) => ({ value, sort: Math.random() }))
+ .sort((a, b) => a.sort - b.sort)
+ .map(({ value }) => value);
+
+/* If valid sort order provided, then returns a sorted copy of items */
+export default function sortItems(items, order, sectionTitle = '') {
+ const list = Array.isArray(items) ? items.slice() : [];
+ const ord = order || defaultSortOrder;
+ if (ord === 'default') return list;
+ if (ord === 'alphabetical') return byTitle(list);
+ if (ord === 'reverse-alphabetical') return byTitle(list).reverse();
+ if (ord === 'most-used') return byUsage(list, localStorageKeys.MOST_USED);
+ if (ord === 'last-used') return byUsage(list, localStorageKeys.LAST_USED);
+ if (ord === 'random') return shuffled(list);
+ ErrorHandler(`Unknown Sort order '${ord}'${sectionTitle ? ` under '${sectionTitle}'` : ''}`);
+ return list;
+}
diff --git a/src/views/Home.vue b/src/views/Home.vue
index bf3cd4df..34515ecb 100644
--- a/src/views/Home.vue
+++ b/src/views/Home.vue
@@ -137,7 +137,9 @@ export default {
},
/* Returns optional section display preferences if available */
getDisplayData(section) {
- return !section.displayData ? {} : section.displayData;
+ const displayData = section.displayData ? { ...section.displayData } : {};
+ if (this.singleSectionView) displayData.collapsed = false;
+ return displayData;
},
openAddNewSectionMenu() {
this.addNewSectionOpen = true;
diff --git a/src/views/Minimal.vue b/src/views/Minimal.vue
index 1970152d..d62c72ac 100644
--- a/src/views/Minimal.vue
+++ b/src/views/Minimal.vue
@@ -1,5 +1,5 @@
<template>
- <div class="minimal-home" :style="getBackgroundImage() + setColumnCount()">
+ <div class="minimal-home" :style="getBackgroundImage()">
<!-- Buttons for config and home page -->
<div class="minimal-buttons">
<ConfigLauncher @modalChanged="updateModalVisibility" class="config-launcher" />
@@ -15,18 +15,26 @@
</div>
<div v-if="checkTheresData(sections)"
:class="`item-group-container ${!tabbedView ? 'showing-all' : ''}`">
- <!-- Section heading buttons -->
- <MinimalHeading
- v-for="(section, index) in sections"
- :key="`heading-${index}`"
- :index="index"
- :title="section.name"
- :icon="section.icon"
- :selected="selectedSection === index"
- @sectionSelected="sectionSelected"
- class="headings"
- :hideTitleText="sections.length > 8"
- />
+ <!-- Section heading tabs. Equal-width, scroll horizontally with arrows when they overflow -->
+ <div class="minimal-headings-wrap">
+ <button v-if="canScrollTabs" class="tab-scroll-btn"
+ :disabled="!canScrollLeft" @click="scrollTabs(-1)" aria-label="Previous tabs">‹</button>
+ <div ref="tabsStrip" class="minimal-headings-row" @scroll="updateTabScroll">
+ <MinimalHeading
+ v-for="(section, index) in sections"
+ :key="`heading-${index}`"
+ :index="index"
+ :title="section.name"
+ :icon="section.icon"
+ :selected="selectedSection === index"
+ @sectionSelected="sectionSelected"
+ class="headings"
+ :hideTitleText="sections.length > 8"
+ />
+ </div>
+ <button v-if="canScrollTabs" class="tab-scroll-btn"
+ :disabled="!canScrollRight" @click="scrollTabs(1)" aria-label="Next tabs">›</button>
+ </div>
<!-- Section item groups -->
<MinimalSection
v-for="(section, index) in sections"
@@ -37,9 +45,9 @@
:groupId="makeSectionId(section)"
:items="filterTiles(section.items)"
:widgets="section.widgets"
+ :displayData="section.displayData || {}"
:selected="selectedSection === index"
:showAll="!tabbedView"
- itemSize="small"
@sectionSelected="sectionSelected"
@itemClicked="finishedSearching()"
@change-modal-visibility="updateModalVisibility"
@@ -74,6 +82,10 @@ export default {
layout: '',
selectedSection: 0, // The index of currently selected section
tabbedView: true, // By default use tabs, when searching then show all instead
+ canScrollTabs: false, // Tabs strip is wider than its container
+ canScrollLeft: false,
+ canScrollRight: false,
+ tabResizeObserver: null,
}),
watch: {
searchValue() {
@@ -116,10 +128,6 @@ export default {
return itemsFound;
}
},
- /* Make CSS to set the number of columns based on the number of sections */
- setColumnCount() {
- return `--col-count: ${this.sections.length};`;
- },
/* Make CSS styles to apply the users custom background image */
getBackgroundImage() {
if (this.appConfig && this.appConfig.backgroundImg) {
@@ -127,10 +135,38 @@ export default {
}
return '';
},
+ /* Scroll the tab strip by ~one visible page; leaves a small overlap so
+ * the user can see where they came from */
+ scrollTabs(direction) {
+ const strip = this.$refs.tabsStrip;
+ if (!strip) return;
+ const amount = Math.max(strip.clientWidth - 64, 120);
+ strip.scrollBy({ left: amount * direction, behavior: 'smooth' });
+ },
+ updateTabScroll() {
+ const strip = this.$refs.tabsStrip;
+ if (!strip) return;
+ this.canScrollTabs = strip.scrollWidth > strip.clientWidth + 1;
+ this.canScrollLeft = strip.scrollLeft > 0;
+ this.canScrollRight = strip.scrollLeft + strip.clientWidth < strip.scrollWidth - 1;
+ },
},
mounted() {
this.initiateFontAwesome();
this.initiateMaterialDesignIcons();
+ this.$nextTick(() => {
+ this.updateTabScroll();
+ if (typeof ResizeObserver !== 'undefined' && this.$refs.tabsStrip) {
+ this.tabResizeObserver = new ResizeObserver(this.updateTabScroll);
+ this.tabResizeObserver.observe(this.$refs.tabsStrip);
+ }
+ });
+ },
+ beforeUnmount() {
+ if (this.tabResizeObserver) {
+ this.tabResizeObserver.disconnect();
+ this.tabResizeObserver = null;
+ }
},
};
</script>
@@ -165,27 +201,51 @@ export default {
/* Outside container wrapping the item groups*/
.item-group-container {
- display: grid;
- gap: 0 0.5rem;
+ display: flex;
+ flex-direction: column;
margin: 3rem auto;
width: 90%;
- grid-template-columns: repeat(var(--col-count), 1fr);
@extend .scroll-bar;
- &.showing-all {
- flex-direction: column;
- display: flex;
- .headings {
- display: none;
- }
+ &.showing-all .minimal-headings-wrap {
+ display: none;
}
}
- @include phone {
- .item-group-container {
- display: flex;
- flex-direction: column;
- }
+.minimal-headings-wrap {
+ display: flex;
+ align-items: stretch;
+ gap: 0.25rem;
+}
+.minimal-headings-row {
+ flex: 1 1 auto;
+ display: flex;
+ gap: 0.25rem;
+ overflow-x: auto;
+ scroll-behavior: smooth;
+ scrollbar-width: none;
+ &::-webkit-scrollbar { display: none; }
+ .headings {
+ flex: 1 0 8rem;
+ max-width: 14rem;
+ min-width: 0;
+ &.center {
+ flex: 1 0 3rem;
+ max-width: 4rem;
+ }
+ }
+}
+.tab-scroll-btn {
+ flex: 0 0 auto;
+ padding: 0 0.5rem;
+ font-size: 1.25rem;
+ line-height: 1;
+ cursor: pointer;
+ background: var(--minimal-view-section-heading-background);
+ color: var(--minimal-view-section-heading-color);
+ border: 1px solid var(--minimal-view-section-heading-color);
+ border-radius: var(--curve-factor);
+ &:disabled { opacity: 0.3; cursor: default; }
}
.no-data {