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!

✨ Shiny new workspace view

Alicia Sykese4d5a20b411d
diff --git a/src/App.vue b/src/App.vue
index f14c1cce..37979bdc 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,5 +1,5 @@
<template>
- <div id="dashy" :style="topLevelStyleModifications" :class="subPageClassName">
+ <div id="dashy" :style="topLevelStyleModifications" :class="[subPageClassName, `view-${currentView}`]">
<EditModeTopBanner v-if="isEditMode" />
<LoadingScreen :isLoading="isLoading" v-if="shouldShowSplash" />
<Header :pageInfo="pageInfo" />
@@ -76,9 +76,12 @@ export default {
footerText() {
return this.pageInfo && this.pageInfo.footer ? this.pageInfo.footer : '';
},
+ currentView() {
+ return viewFromPath(this.$route.path);
+ },
/* Footer renders only when there's text AND we're not on workspace */
footerVisible() {
- if (viewFromPath(this.$route.path) === 'workspace') return false;
+ if (this.currentView === 'workspace') return false;
return !!this.footerText;
},
/* Determine if splash screen should be shown */
diff --git a/src/assets/locales/en.json b/src/assets/locales/en.json
index 4c688e54..dbc88111 100644
--- a/src/assets/locales/en.json
+++ b/src/assets/locales/en.json
@@ -124,6 +124,13 @@
"workspace": "Workspace",
"minimal": "Minimal"
},
+ "workspace": {
+ "expand-sidebar": "Expand sidebar",
+ "collapse-sidebar": "Collapse sidebar",
+ "open-apps": "Open apps",
+ "close-app": "Close {app}",
+ "empty-state": "Select an app from the sidebar to open it here"
+ },
"remote-config": {
"title": "Load Remote Config?",
"apply-button": "Apply Preview",
diff --git a/src/components/Settings/SearchBar.vue b/src/components/Settings/SearchBar.vue
index 08fe45ac..a620299b 100644
--- a/src/components/Settings/SearchBar.vue
+++ b/src/components/Settings/SearchBar.vue
@@ -27,7 +27,7 @@
import router from '@/router';
import ArrowKeyNavigation from '@/utils/ArrowKeyNavigation';
import ErrorHandler from '@/utils/logging/ErrorHandler';
-import { getCustomKeyShortcuts } from '@/utils/config/ConfigHelpers';
+import { getCustomKeyShortcuts, makeWorkspaceRoute } from '@/utils/config/ConfigHelpers';
import {
getSearchEngineFromBang, findUrlForSearchEngine, stripBangs, isUrlLike,
} from '@/utils/Search';
@@ -147,7 +147,7 @@ export default {
window.open(url, '_self');
break;
case 'workspace':
- router.push({ name: 'workspace', query: { url } });
+ router.push(makeWorkspaceRoute(url, this.$store));
break;
default:
ErrorHandler(`Unknown opening method: ${method}`);
diff --git a/src/components/Widgets/CustomSearch.vue b/src/components/Widgets/CustomSearch.vue
index 3ad9d192..8c79347a 100644
--- a/src/components/Widgets/CustomSearch.vue
+++ b/src/components/Widgets/CustomSearch.vue
@@ -18,6 +18,7 @@
import router from '@/router';
import WidgetMixin from '@/mixins/WidgetMixin';
import ErrorHandler from '@/utils/logging/ErrorHandler';
+import { makeWorkspaceRoute } from '@/utils/config/ConfigHelpers';
export default {
mixins: [WidgetMixin],
@@ -53,7 +54,7 @@ export default {
window.open(url, '_self');
break;
case 'workspace':
- router.push({ name: 'workspace', query: { url } });
+ router.push(makeWorkspaceRoute(url, this.$store));
break;
default:
ErrorHandler(`Unknown opening method: ${openingMethod}`);
diff --git a/src/components/Workspace/MultiTaskingWebComtent.vue b/src/components/Workspace/MultiTaskingWebComtent.vue
deleted file mode 100644
index 9b5778cc..00000000
--- a/src/components/Workspace/MultiTaskingWebComtent.vue
+++ /dev/null
@@ -1,70 +0,0 @@
-<template>
- <div class="multi-taking-view" ref="container"></div>
-</template>
-
-<script>
-/* eslint-disable vue/one-component-per-file -- intentional: dynamically-mounted inline component */
-import { createApp, h } from 'vue';
-import WebContent from '@/components/Workspace/WebContent';
-
-export default {
- name: 'WebContent',
- props: {
- url: { type: String, default: '' }, // The URL of currently visible app
- },
- data: () => ({
- openApps: [], // List of all currently open apps
- appInstances: [], // Track mounted app instances for cleanup
- }),
- watch: {
- /* Update the currently open app, when URL changes */
- url() { this.launchApp(); },
- },
- beforeUnmount() {
- this.appInstances.forEach(instance => instance.unmount());
- },
- methods: {
- /* Check if app already open or not, and call appropriate opener */
- launchApp() {
- if (this.openApps.includes(this.url)) {
- this.openExistingApp();
- } else {
- this.openApps.push(this.url);
- this.appendNewApp();
- }
- },
- /* Opens a new app */
- appendNewApp() {
- const wrapper = document.createElement('div');
- this.$refs.container.appendChild(wrapper);
- const appUrl = this.url;
- const instance = createApp({
- render() { return h(WebContent, { url: appUrl, id: btoa(appUrl) }); },
- });
- instance.mount(wrapper);
- this.appInstances.push(instance);
- },
- /* Switches visibility to an already open app */
- openExistingApp() {
- Array.from(document.getElementsByClassName('web-content')).forEach((frame) => {
- frame.classList.add('hide');
- });
- const el = document.getElementById(btoa(this.url));
- if (el) el.classList.remove('hide');
- },
- },
-};
-</script>
-
-<style lang="scss" scoped>
-
-iframe {
- position: absolute;
- left: var(--side-bar-width);
- height: calc(100% - var(--header-height));
- width: calc(100% - var(--side-bar-width));
- border: none;
- background: white;
-}
-
-</style>
diff --git a/src/components/Workspace/SideBar.vue b/src/components/Workspace/SideBar.vue
index 6988f59a..bb956cfc 100644
--- a/src/components/Workspace/SideBar.vue
+++ b/src/components/Workspace/SideBar.vue
@@ -1,112 +1,205 @@
<template>
- <nav class="side-bar">
- <div v-for="(section, index) in filteredSections" :key="index" class="side-bar-section">
- <!-- Section button -->
- <div @click="openSection(index)" class="side-bar-item-container">
- <SideBarItem
- class="item"
- :icon="section.icon"
- :title="section.name"
- />
+ <nav class="side-bar" :class="{ expanded }">
+ <div class="side-bar-tools">
+ <input
+ v-if="expanded && searchEnabled"
+ ref="search"
+ v-model="search"
+ type="search"
+ class="side-bar-search"
+ :placeholder="$t('search.search-placeholder')"
+ :aria-label="$t('search.search-label')"
+ @keydown.esc="search = ''"
+ @keydown.enter="launchFirstResult"
+ />
+ <button
+ class="side-bar-toggle"
+ :aria-expanded="expanded"
+ :aria-label="toggleLabel"
+ v-tooltip="toggleLabel"
+ @click="toggleExpanded"
+ >
+ <IconMenu />
+ </button>
+ </div>
+ <div class="side-bar-sections">
+ <div v-for="(section, index) in visibleSections" :key="index" class="side-bar-section">
+ <div class="side-bar-item-container">
+ <SideBarItem
+ :item="{ title: section.name, icon: section.icon }"
+ :aria-expanded="isOpen(section)"
+ @click="toggleSection(section)"
+ />
+ </div>
+ <Transition
+ name="section-slide"
+ @enter="(el, done) => slide(el, done)"
+ @leave="(el, done) => slide(el, done, true)"
+ >
+ <div v-if="isOpen(section) && section.items.length" class="sub-side-bar">
+ <template v-for="(item, itemIndex) in section.items" :key="item.id || itemIndex">
+ <div v-if="item.subItems" class="sub-item-group">
+ <SideBarItem
+ v-for="(subItem, subIndex) in item.subItems"
+ :key="subIndex"
+ :item="subItem"
+ :active="isActive(subItem)"
+ @launch-app="launchApp"
+ />
+ </div>
+ <SideBarItem v-else :item="item" :active="isActive(item)" @launch-app="launchApp" />
+ </template>
+ </div>
+ </Transition>
+ </div>
+ </div>
+ <!-- Apps opened this session, for quick switching -->
+ <div v-if="openApps.length" class="open-apps">
+ <span class="side-bar-label">{{ $t('workspace.open-apps') }}</span>
+ <div v-for="app in openApps" :key="app.url" class="open-app">
+ <SideBarItem :item="app" :active="isActive(app)" @launch-app="launchApp" />
+ <button
+ class="close-app"
+ :aria-label="$t('workspace.close-app', { app: app.title })"
+ v-tooltip="$t('workspace.close-app', { app: app.title })"
+ @click="$emit('close-app', app.url)"
+ >
+ <IconClose />
+ </button>
</div>
- <!-- Section inner -->
- <transition name="slide">
- <SideBarSection
- v-if="isOpen[index]"
- :items="visibleItems(section.items)"
- @launch-app="launchApp"
- />
- </transition>
</div>
- <!-- Show links for switching back to Home / Minimal views, preserving sub-page -->
+ <!-- Links for switching back to Home / Minimal views, preserving sub-page -->
<div class="switch-view-buttons">
- <router-link :to="pathFor('home')">
- <IconHome class="view-icon" v-tooltip="$t('alternate-views.default')" />
+ <router-link
+ :to="pathFor('home')"
+ :aria-label="$t('alternate-views.default')"
+ v-tooltip="$t('alternate-views.default')"
+ >
+ <IconHome />
</router-link>
- <router-link :to="pathFor('minimal')">
- <IconMinimalView class="view-icon" v-tooltip="$t('alternate-views.minimal')" />
+ <router-link
+ :to="pathFor('minimal')"
+ :aria-label="$t('alternate-views.minimal')"
+ v-tooltip="$t('alternate-views.minimal')"
+ >
+ <IconMinimalView />
</router-link>
</div>
</nav>
</template>
<script>
-
import SideBarItem from '@/components/Workspace/SideBarItem.vue';
-import SideBarSection from '@/components/Workspace/SideBarSection.vue';
import IconHome from '@/assets/interface-icons/application-home.svg';
import IconMinimalView from '@/assets/interface-icons/application-minimal.svg';
+import IconMenu from '@/assets/interface-icons/burger-menu.svg';
+import IconClose from '@/assets/interface-icons/config-close.svg';
import { getCurrentUser, isLoggedInAsGuest } from '@/utils/auth/Auth';
import { isVisibleToUser } from '@/utils/IsVisibleToUser';
+import { searchTiles } from '@/utils/Search';
+import { localStorageKeys } from '@/utils/config/defaults';
import { makeRoutePath, resolveRouteIntent } from '@/utils/config/ConfigHelpers';
+import { sameUrl } from '@/utils/MiscHelpers';
export default {
name: 'SideBar',
props: {
sections: { type: Array, default: () => [] },
- initUrl: { type: String, default: '' },
+ activeUrl: { type: String, default: '' },
+ openUrls: { type: Array, default: () => [] },
+ },
+ emits: ['launch-app', 'launch-widget', 'close-app'],
+ components: {
+ SideBarItem,
+ IconHome,
+ IconMinimalView,
+ IconMenu,
+ IconClose,
},
- emits: ['launch-widget', 'launch-app'],
data() {
return {
- isOpen: [],
+ openSection: null,
+ expanded: localStorage.getItem(localStorageKeys.WORKSPACE_SIDEBAR_EXPANDED) === 'true',
+ search: '',
};
},
computed: {
- /* Return a list of sections that should be visible in workspace */
- filteredSections() {
- if (!this.sections) return [];
- return this.sections.filter((section) => !section.displayData?.hideFromWorkspace);
+ /* Sections and items that the current user can see, and aren't hidden from workspace */
+ workspaceSections() {
+ const currentUser = getCurrentUser();
+ const isGuest = isLoggedInAsGuest();
+ const isShown = (item) => !item.displayData?.hideFromWorkspace
+ && isVisibleToUser(item.displayData || {}, currentUser, isGuest);
+ return this.sections.filter((section) => !section.displayData?.hideFromWorkspace)
+ .map((section) => ({ ...section, items: (section.items || []).filter(isShown) }));
},
- },
- watch: {
- /* Update isOpen array when filtered sections change */
- filteredSections(newSections) {
- // Resize isOpen array if needed
- const currentLength = this.isOpen.length;
- const newLength = newSections.length;
- if (newLength !== currentLength) {
- this.isOpen = new Array(newLength).fill(false);
- }
+ /* Sections with only the items matching the search term */
+ visibleSections() {
+ if (!this.search) return this.workspaceSections;
+ return this.workspaceSections
+ .map((section) => ({ ...section, items: searchTiles(section.items, this.search, section.name) }))
+ .filter((section) => section.items.length);
+ },
+ /* Open apps, with title and icon from their item, if there is one */
+ openApps() {
+ const items = this.workspaceSections.flatMap((section) => section.items)
+ .flatMap((item) => item.subItems || [item]);
+ return this.openUrls.map((url) => {
+ const { title, icon } = items.find((item) => sameUrl(item.url, url)) || { title: new URL(url).host };
+ return { title, icon, url };
+ });
+ },
+ searchEnabled() {
+ return this.$store.getters.visibleComponents.searchBar;
+ },
+ toggleLabel() {
+ return this.$t(`workspace.${this.expanded ? 'collapse' : 'expand'}-sidebar`);
},
},
- components: {
- SideBarItem,
- SideBarSection,
- IconMinimalView,
- IconHome,
+ watch: {
+ activeUrl: { handler: 'openActiveSection', immediate: true },
+ sections: 'openActiveSection',
},
methods: {
- /* Toggles the section clicked, and closes all other sections */
- openSection(index) {
- this.isOpen = this.isOpen.map((val, ind) => (ind !== index ? false : !val));
- if (this.filteredSections[index].widgets) this.$emit('launch-widget', this.filteredSections[index].widgets);
+ isActive(item) {
+ return sameUrl(item.url, this.activeUrl);
},
- /* When item clicked, emit a launch event */
- launchApp(options) {
- this.$emit('launch-app', options);
+ sectionHasActive(section) {
+ return !!section && section.items.some((item) => [item, ...(item.subItems || [])].some(this.isActive));
},
- /* If an initial URL is specified, then open relevant section */
- openDefaultSection() {
- if (!this.initUrl) return;
- const process = (url) => (url ? url.replace(/[^\w\s]/gi, '').toLowerCase() : undefined);
- const compare = (item) => (process(item.url) === process(this.initUrl));
- this.filteredSections.forEach((section, secIndx) => {
- if (!section.items) return; // Cancel if no items
- if (section.items.findIndex(compare) !== -1) this.openSection(secIndx);
- section.items.forEach((item) => { // Do the same for sub-items, if set
- if (item.subItems && item.subItems.findIndex(compare) !== -1) this.openSection(secIndx);
- });
- });
+ isOpen(section) {
+ return !!this.search || this.visibleSections.length === 1 || this.openSection === section.name;
},
- /* Return the items in a section that the current user/guest can see
- * and that aren't explicitly hidden from the workspace view */
- visibleItems(allTiles) {
- if (!allTiles) return [];
- const currentUser = getCurrentUser();
- const isGuest = isLoggedInAsGuest();
- return allTiles.filter((tile) => !tile.displayData?.hideFromWorkspace
- && isVisibleToUser(tile.displayData || {}, currentUser, isGuest));
+ /* Toggles the section clicked (closing all others), and shows its widgets */
+ toggleSection(section) {
+ this.openSection = this.openSection === section.name ? null : section.name;
+ if (section.widgets && this.isOpen(section)) this.$emit('launch-widget', section.widgets);
+ },
+ /* Expands the section containing the active app, unless it's already open */
+ openActiveSection() {
+ const sections = this.workspaceSections;
+ if (this.sectionHasActive(sections.find((section) => section.name === this.openSection))) return;
+ const activeSection = sections.find(this.sectionHasActive);
+ if (activeSection) this.openSection = activeSection.name;
+ },
+ toggleExpanded() {
+ this.expanded = !this.expanded;
+ this.search = '';
+ localStorage.setItem(localStorageKeys.WORKSPACE_SIDEBAR_EXPANDED, this.expanded);
+ if (this.expanded) this.$nextTick(() => this.$refs.search?.focus());
+ },
+ /* Slides a section's items open or closed */
+ slide(el, done, closing) {
+ const closed = { height: 0, paddingBlock: 0, marginBlock: 0 };
+ const open = { height: `${el.offsetHeight}px` };
+ const duration = window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 0 : 200;
+ el.animate(closing ? [open, closed] : [closed, open], { duration, easing: 'ease-out' }).onfinish = done;
+ },
+ launchApp(url) {
+ this.$emit('launch-app', url);
+ },
+ launchFirstResult() {
+ this.$el.querySelector('.sub-side-bar .side-bar-item')?.click();
},
/* Build a URL for the given view, preserving the current sub-page and section */
pathFor(view) {
@@ -114,61 +207,181 @@ export default {
return makeRoutePath(view, pageId, sectionSlug);
},
},
- mounted() {
- // Initialize isOpen array based on filteredSections length
- this.isOpen = new Array(this.filteredSections.length).fill(false);
- if (this.filteredSections.length === 1) { // If only 1 section, go ahead and open it
- this.openSection(0);
- } else { // Otherwise, see if user set a default section, and open that
- this.openDefaultSection();
- }
- },
};
</script>
<style lang="scss" scoped>
-
@import '@/styles/media-queries.scss';
@import '@/styles/style-helpers.scss';
+$divider: color-mix(in srgb, var(--side-bar-color) 25%, transparent);
+
nav.side-bar {
- position: fixed;
display: flex;
flex-direction: column;
+ flex: 0 0 var(--side-bar-width);
+ min-width: 0;
+ gap: 0.25rem;
+ padding: 0.25rem;
+ box-sizing: border-box;
background: var(--side-bar-background);
color: var(--side-bar-color);
- height: 100%;
- width: var(--side-bar-width);
- text-align: center;
- overflow: auto;
- @extend .scroll-bar;
- .side-bar-item-container {
- z-index: 5;
+ &.expanded {
+ flex-basis: var(--side-bar-width-expanded);
+ :deep(.side-bar-item) {
+ justify-content: flex-start;
+ padding: 0.25rem 0.5rem;
+ .title { display: block; }
+ }
+ }
+ .side-bar-toggle, .close-app {
+ border: none;
+ background: none;
+ color: inherit;
+ &:focus-visible { outline: 2px solid currentColor; }
+ }
+}
+
+.side-bar-tools {
+ display: flex;
+ gap: 0.25rem;
+ .side-bar-toggle {
+ flex: 1 0 auto;
+ min-height: 2.5rem;
+ border-radius: var(--curve-factor);
+ &:hover { background: var(--side-bar-background-lighter); }
+ }
+ .side-bar-search {
+ flex: 1;
+ min-width: 0;
+ padding: 0.4rem 0.5rem;
+ border: 1px solid var(--outline-color);
+ border-radius: var(--curve-factor);
+ background: var(--side-bar-background-lighter);
+ color: var(--side-bar-color);
+ font: inherit;
+ outline: none;
+ &:focus { border-color: var(--side-bar-color); }
+ }
+ .expanded & .side-bar-toggle { flex-grow: 0; margin-left: auto; padding: 0 0.6rem; }
+}
+
+.open-apps {
+ display: flex;
+ flex-direction: column;
+ gap: 0.1rem;
+ padding-top: 0.25rem;
+ border-top: 1px solid $divider;
+ .side-bar-label {
+ display: none;
+ padding: 0.25rem 0.5rem 0;
+ font-size: 0.7rem;
+ font-weight: bold;
+ text-transform: uppercase;
+ opacity: var(--dimming-factor);
+ .expanded & { display: block; }
+ }
+ .open-app {
+ position: relative;
+ display: flex;
+ align-items: center;
}
- .item:not(:last-child) {
- border-bottom: 1px dashed var(--side-bar-color);
- z-index: 5;
+ .close-app {
+ position: absolute;
+ top: 0;
+ right: 0;
+ padding: 0.1rem;
+ line-height: 0;
+ clip-path: inset(50%); // Hidden until hovered, but still reachable by keyboard
+ svg { width: 0.8rem; height: 0.8rem; }
}
+ .open-app:hover .close-app, .close-app:focus-visible { clip-path: none; }
+ .expanded & .close-app { position: static; clip-path: none; padding: 0.4rem; }
+}
+
+.side-bar-sections {
+ flex: 1;
+ min-height: 0;
+ overflow-y: auto;
+ @extend .scroll-bar;
}
-.slide-leave-active,
-.slide-enter-active {
- transition: all 0.1s ease-in-out;
+.side-bar-section:not(:last-child) {
+ border-bottom: 1px dashed $divider;
}
-.slide-enter-from {
- transform: translate(0, -80%);
+
+/* Chevron on section headers, so they read as expandable */
+.side-bar-item-container > .side-bar-item {
+ position: relative;
+ &::after {
+ content: '';
+ position: absolute;
+ right: 0.25rem;
+ width: 0.25rem;
+ height: 0.25rem;
+ border: solid currentColor;
+ border-width: 0 2px 2px 0;
+ opacity: 0.7;
+ transform: rotate(-45deg);
+ transition: transform 0.2s ease-out;
+ }
+ &[aria-expanded="true"]::after { transform: rotate(45deg); }
+ .expanded &::after { position: static; margin-right: 0.25rem; }
}
-.slide-leave-to {
- transform: translate(0, -80%);
+
+.sub-side-bar {
+ display: flex;
+ flex-direction: column;
+ gap: 0.1rem;
+ margin: 0.2rem 0;
+ padding: 0.2rem;
+ box-sizing: border-box;
+ border-radius: var(--curve-factor);
+ background: var(--side-bar-background-lighter);
+ .sub-item-group {
+ display: flex;
+ flex-direction: column;
+ border-radius: var(--curve-factor);
+ background: var(--side-bar-background);
+ }
+ .expanded & { padding-left: 0.5rem; }
+ &.section-slide-enter-active, &.section-slide-leave-active { overflow: hidden; }
}
.switch-view-buttons {
- margin-top: 0.5rem;
display: flex;
- @extend .svg-button;
- .view-icon {
- border: none;
+ flex-wrap: wrap;
+ justify-content: center;
+ gap: 0.25rem;
+ a {
+ display: flex;
+ padding: 0.25rem;
+ color: var(--side-bar-color);
+ border-radius: var(--curve-factor);
+ &:hover, &:focus-visible { background: var(--side-bar-background-lighter); }
}
}
+/* On small screens, the collapsed sidebar is a scrollable row above the content */
+@include phone {
+ nav.side-bar {
+ flex-basis: auto;
+ max-height: 50%;
+ &.expanded { flex-basis: auto; }
+ &:not(.expanded) {
+ flex-direction: row;
+ align-items: center;
+ overflow: auto hidden;
+ .side-bar-sections, .side-bar-section, .sub-side-bar, .sub-item-group, .open-apps {
+ display: flex;
+ flex-direction: row;
+ }
+ .side-bar-sections { flex: none; overflow: visible; }
+ .side-bar-section:not(:last-child) { border: none; }
+ .open-apps { padding: 0 0 0 0.25rem; border: none; border-left: 1px solid $divider; }
+ .sub-side-bar { margin: 0 0.2rem; }
+ :deep(.side-bar-item) { width: 2.5rem; }
+ }
+ }
+}
</style>
diff --git a/src/components/Workspace/SideBarItem.vue b/src/components/Workspace/SideBarItem.vue
index 3b9fd413..989df78c 100644
--- a/src/components/Workspace/SideBarItem.vue
+++ b/src/components/Workspace/SideBarItem.vue
@@ -1,78 +1,94 @@
<template>
- <div
- @click="itemClicked($event)"
- @auxclick="itemAuxClicked($event)"
- :class="`side-bar-item ${icon ? 'w-icon' : 'text-only'}`"
- v-tooltip="tooltip"
+ <component
+ :is="item.url ? 'a' : 'button'"
+ :href="item.url"
+ :class="{ 'side-bar-item': true, active }"
+ :aria-label="item.title"
+ v-tooltip="{ content: item.title, disabled: !item.title, placement: 'right' }"
+ @click.exact="launch"
>
- <Icon v-if="icon" :icon="icon" size="small" :url="url" />
- <p class="small-title" v-else>{{ title }}</p>
- </div>
+ <Icon v-if="item.icon" :icon="item.icon" :url="item.url" size="small" />
+ <span v-else class="initials">{{ initials }}</span>
+ <span class="title">{{ item.title }}</span>
+ </component>
</template>
<script>
-
import Icon from '@/components/LinkItems/ItemIcon.vue';
+import ItemMixin from '@/mixins/ItemMixin';
export default {
name: 'SideBarItem',
+ mixins: [ItemMixin],
props: {
- icon: { type: String, default: '' },
- title: { type: String, default: '' },
- url: { type: String, default: '' },
- target: { type: String, default: '' },
- click: { type: Function, default: () => {} },
+ active: Boolean,
},
emits: ['launch-app'],
components: {
Icon,
},
- methods: {
- itemClicked(e) {
- if (e && (e.ctrlKey || e.metaKey)) {
- this.openInNewTab(e);
- return;
- }
- if (this.url) this.$emit('launch-app', { url: this.url, target: this.target });
- },
- itemAuxClicked(e) {
- if (e && e.button === 1) {
- this.openInNewTab(e);
- }
- },
- openInNewTab(e) {
- if (e && e.preventDefault) e.preventDefault();
- if (this.url) window.open(this.url, '_blank', 'noopener,noreferrer');
+ computed: {
+ /* Up to two letters, shown in place of a missing icon */
+ initials() {
+ return (this.item.title || '').split(/\s+/).filter(Boolean)
+ .slice(0, 2).map((word) => [...word][0]).join('');
},
},
- data() {
- return {
- tooltip: {
- disabled: !this.title,
- content: this.title,
- placement: 'bottom-end',
- },
- };
+ methods: {
+ /* Opens in the workspace, unless the item targets a new tab, window or clipboard */
+ launch(e) {
+ if (!this.item.url) return;
+ e.preventDefault();
+ const { target } = this.item;
+ if (['newtab', 'newwindow', 'clipboard'].includes(target)) this.launchItem(target);
+ else this.$emit('launch-app', this.effectiveUrl);
+ },
},
};
</script>
<style lang="scss" scoped>
-
-div.side-bar-item {
- color: var(--side-bar-item-color);
+.side-bar-item {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ gap: 0.5rem;
+ width: 100%;
+ min-width: 0;
+ min-height: 2.5rem;
+ padding: 0.25rem;
+ box-sizing: border-box;
+ border: none;
+ border-radius: var(--curve-factor);
background: var(--side-bar-item-background);
- text-align: center;
- &.text-only {
- background: none;
- border: none;
- box-shadow: none;
- p.small-title {
- margin: 0.1rem 0 0 -0.5rem;
- font-size: 0.6rem;
- transform: rotate(-25deg);
- padding: 0.5rem 0;
- }
+ color: var(--side-bar-item-color);
+ font: inherit;
+ text-align: left;
+ text-decoration: none;
+ &:hover, &.active {
+ background: color-mix(in srgb, var(--side-bar-item-color) 15%, transparent);
+ }
+ &.active {
+ box-shadow: inset 3px 0 0 var(--side-bar-item-color);
+ }
+ &:focus-visible {
+ outline: 2px solid var(--side-bar-item-color);
+ outline-offset: -2px;
+ }
+ .item-icon, .initials {
+ flex: 0 0 2rem;
+ text-align: center;
+ }
+ .initials {
+ font-weight: bold;
+ text-transform: uppercase;
+ }
+ .title {
+ display: none;
+ flex: 1;
+ overflow: hidden;
+ white-space: nowrap;
+ text-overflow: ellipsis;
}
}
</style>
diff --git a/src/components/Workspace/SideBarSection.vue b/src/components/Workspace/SideBarSection.vue
deleted file mode 100644
index ffd231fa..00000000
--- a/src/components/Workspace/SideBarSection.vue
+++ /dev/null
@@ -1,70 +0,0 @@
-<template>
- <div class="sub-side-bar">
- <div v-for="(item, index) in items" :key="index">
- <SideBarItem
- v-if="!item.subItems"
- class="item"
- :icon="item.icon"
- :title="item.title"
- :url="item.url"
- :target="item.target"
- @launch-app="launchApp"
- />
- <div v-if="item.subItems" class="sub-item-group">
- <SideBarItem
- v-for="(subItem, subIndex) in item.subItems"
- :key="subIndex"
- class="item sub-item"
- :icon="subItem.icon"
- :title="subItem.title"
- :url="subItem.url"
- :target="subItem.target"
- @launch-app="launchApp"
- />
- </div>
- </div>
- </div>
-</template>
-
-<script>
-
-import SideBarItem from '@/components/Workspace/SideBarItem.vue';
-
-export default {
- name: 'SideBarSection',
- props: {
- items: { type: Array, default: () => [] },
- },
- emits: ['launch-app'],
- components: {
- SideBarItem,
- },
- methods: {
- launchApp(options) {
- this.$emit('launch-app', options);
- },
- },
-};
-</script>
-
-<style lang="scss" scoped>
-@import '@/styles/media-queries.scss';
-@import '@/styles/style-helpers.scss';
-
-div.sub-side-bar {
- display: flex;
- flex-direction: column;
- background: var(--side-bar-background-lighter);
- border-radius: var(--curve-factor);
- margin: 0.2rem;
- color: var(--side-bar-color);
- text-align: center;
- z-index: 3;
- .sub-item-group {
- border: 1px dotted var(--side-bar-color);
- border-radius: 4px;
- background: #00000033;
- }
-}
-
-</style>
diff --git a/src/components/Workspace/WebContent.vue b/src/components/Workspace/WebContent.vue
index 2515dcc7..125c8a33 100644
--- a/src/components/Workspace/WebContent.vue
+++ b/src/components/Workspace/WebContent.vue
@@ -1,36 +1,58 @@
<template>
- <div class="web-content" :id="id">
- <iframe :src="url" allow="fullscreen; clipboard-write" />
+ <div class="web-content">
+ <iframe
+ v-for="url in urls"
+ v-show="url === activeUrl"
+ :key="url"
+ :src="url"
+ :title="url"
+ allow="fullscreen; clipboard-write"
+ />
+ <div v-if="!activeUrl" class="empty-state">
+ <IconWorkspace />
+ <p>{{ $t('workspace.empty-state') }}</p>
+ </div>
</div>
</template>
<script>
+import IconWorkspace from '@/assets/interface-icons/open-workspace.svg';
export default {
name: 'WebContent',
props: {
- url: { type: String, default: '' },
- id: {
- type: String,
- default: 'web-app-view',
- },
+ urls: { type: Array, default: () => [] }, // Apps to keep mounted
+ activeUrl: { type: String, default: '' }, // The app currently visible
+ },
+ components: {
+ IconWorkspace,
},
};
</script>
<style lang="scss" scoped>
-
-iframe {
- position: absolute;
- left: var(--side-bar-width);
- height: calc(100% - var(--header-height));
- width: calc(100% - var(--side-bar-width));
- border: none;
+.web-content {
+ flex: 1;
+ min-width: 0;
background: var(--workspace-web-content-background);
+ iframe {
+ display: block;
+ width: 100%;
+ height: 100%;
+ border: none;
+ }
+ .empty-state {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ height: 100%;
+ padding: 1rem;
+ box-sizing: border-box;
+ color: var(--side-bar-color);
+ opacity: var(--dimming-factor);
+ text-align: center;
+ svg { width: 3rem; height: 3rem; }
+ }
}
-
-.web-content.hide {
- display: none;
-}
-
</style>
diff --git a/src/components/Workspace/WidgetView.vue b/src/components/Workspace/WidgetView.vue
index b6c1d20d..9c20ae32 100644
--- a/src/components/Workspace/WidgetView.vue
+++ b/src/components/Workspace/WidgetView.vue
@@ -1,8 +1,8 @@
<template>
- <div class="workspace-widget-view" v-if="widgets">
+ <div class="workspace-widget-view">
<WidgetBase
v-for="(widget, widgetIndx) in widgets"
- :key="widgetIndx"
+ :key="widget.id || widgetIndx"
:widget="widget"
:index="widgetIndx"
class="workspace-widget"
@@ -14,6 +14,7 @@
import WidgetBase from '@/components/Widgets/WidgetBase';
export default {
+ name: 'WidgetView',
components: {
WidgetBase,
},
@@ -24,13 +25,15 @@ export default {
</script>
<style lang="scss" scoped>
+@import '@/styles/style-helpers.scss';
+
.workspace-widget-view {
- padding: 1rem 0;
+ flex: 1;
+ min-width: 0;
+ padding: 1rem;
+ overflow-y: auto;
background: var(--background);
- position: absolute;
- left: var(--side-bar-width);
- height: calc(100% - var(--header-height) - 1rem);
- width: calc(100% - var(--side-bar-width));
+ @extend .scroll-bar;
.workspace-widget {
max-width: 800px;
margin: 0.5rem auto 1rem auto;
diff --git a/src/directives/Tooltip.js b/src/directives/Tooltip.js
index eeecdd2a..eb80993f 100644
--- a/src/directives/Tooltip.js
+++ b/src/directives/Tooltip.js
@@ -194,6 +194,7 @@ function show(el) {
const opts = state.options;
if (!opts) return;
clearTimeout(state.hideTimer);
+ clearTimeout(state.showTimer);
state.showTimer = setTimeout(() => {
injectStyles();
diff --git a/src/mixins/ItemMixin.js b/src/mixins/ItemMixin.js
index b7186a8d..6179fdbc 100644
--- a/src/mixins/ItemMixin.js
+++ b/src/mixins/ItemMixin.js
@@ -3,6 +3,7 @@ import request from '@/utils/request';
import router from '@/router';
import longPress from '@/directives/LongPress';
import ErrorHandler from '@/utils/logging/ErrorHandler';
+import { makeWorkspaceRoute } from '@/utils/config/ConfigHelpers';
import {
openingMethod as defaultOpeningMethod,
serviceEndpoints,
@@ -298,7 +299,7 @@ export default {
this.$emit('triggerModal', url);
} else if (this.accumulatedTarget === 'workspace') {
e.preventDefault();
- router.push({ name: 'workspace', query: { url } });
+ router.push(makeWorkspaceRoute(url, this.$store));
} else if (this.accumulatedTarget === 'clipboard') {
e.preventDefault();
this.copyToClipboard(url);
@@ -336,7 +337,7 @@ export default {
this.$emit('triggerModal', url);
break;
case 'workspace':
- router.push({ name: 'workspace', query: { url } });
+ router.push(makeWorkspaceRoute(url, this.$store));
break;
case 'clipboard':
this.copyToClipboard(url);
diff --git a/src/styles/dimensions.scss b/src/styles/dimensions.scss
index f380aaa8..90b40a10 100644
--- a/src/styles/dimensions.scss
+++ b/src/styles/dimensions.scss
@@ -27,6 +27,7 @@
/* Workspace View */
--side-bar-width: 3.5rem; // The width of the sidebar
+ --side-bar-width-expanded: 14rem; // Width of the sidebar, when expanded
--tooltip-arrow-size: 6px;
--tooltip-width: 250px;
diff --git a/src/styles/themes/_dashy-docs.scss b/src/styles/themes/_dashy-docs.scss
index 15d6d08f..eb5774cf 100644
--- a/src/styles/themes/_dashy-docs.scss
+++ b/src/styles/themes/_dashy-docs.scss
@@ -69,31 +69,30 @@ html[data-theme="dashy-docs"] {
}
nav.side-bar {
- div div.side-bar-item-container div {
- padding: 0.15rem 0;
+ .side-bar-item-container .side-bar-item {
color: var(--background);
}
- div.side-bar-section:nth-child(1n) {
- div.side-bar-item-container div.side-bar-item {
+ .side-bar-section:nth-child(1n) {
+ .side-bar-item-container .side-bar-item {
@include make-colors(#db78fc, #b83ddd);
}
.sub-side-bar { background: #b83ddd80; }
}
- div.side-bar-section:nth-child(2n) {
- div.side-bar-item-container div.side-bar-item {
+ .side-bar-section:nth-child(2n) {
+ .side-bar-item-container .side-bar-item {
@include make-colors(#5c85f7, #3d48dd);
}
.sub-side-bar { background: #3d48dd80; }
}
- div.side-bar-section:nth-child(3n) {
- div.side-bar-item-container div.side-bar-item {
+ .side-bar-section:nth-child(3n) {
+ .side-bar-item-container .side-bar-item {
@include make-colors(#41ef90, #1e9554);
}
.sub-side-bar { background: #1e955480; }
}
- div.side-bar-section:nth-child(4n) {
- div.side-bar-item-container div.side-bar-item {
+ .side-bar-section:nth-child(4n) {
+ .side-bar-item-container .side-bar-item {
@include make-colors(#dcff5a, #ceb73f);
}
.sub-side-bar { background: #ceb73f80; }
diff --git a/src/utils/MiscHelpers.js b/src/utils/MiscHelpers.js
index be40c7cc..b7248e38 100644
--- a/src/utils/MiscHelpers.js
+++ b/src/utils/MiscHelpers.js
@@ -156,6 +156,13 @@ export const truncateStr = (str, len = 60, ellipse = '...') => {
return str.length > len + ellipse.length ? `${str.slice(0, len)}${ellipse}` : str;
};
+const normalizeUrl = (url) => {
+ try { return new URL(url).href.replace(/\/+$/, ''); } catch { return url; }
+};
+
+/* Compare URLs, ignoring host case and trailing slashes */
+export const sameUrl = (a, b) => !!a && !!b && normalizeUrl(a) === normalizeUrl(b);
+
/* Given two timestamp, return the difference in text format, e.g. '10 minutes' */
export const getTimeDifference = (startTime, endTime) => {
const msDifference = new Date(endTime).getTime() - new Date(startTime).getTime();
diff --git a/src/utils/config/ConfigHelpers.js b/src/utils/config/ConfigHelpers.js
index 0a2b17a5..b2481532 100644
--- a/src/utils/config/ConfigHelpers.js
+++ b/src/utils/config/ConfigHelpers.js
@@ -104,6 +104,12 @@ export const makeRoutePath = (view, pageId, sectionName) => {
/* Convenience wrapper: turn a raw page name into a view URL (e.g. nav links) */
export const makePageSlug = (pageName, view) => makeRoutePath(view, makePageName(pageName));
+/* Route for opening a URL in the workspace, staying on the current sub-page */
+export const makeWorkspaceRoute = (url, store) => ({
+ path: makeRoutePath('workspace', store?.state?.currentConfigInfo?.confId),
+ query: { url },
+});
+
/* Extract the view segment from a path, defaulting to 'home' */
export const viewFromPath = (path) => {
const seg = (path || '').split('/').filter(Boolean)[0];
diff --git a/src/utils/config/defaults.js b/src/utils/config/defaults.js
index cdf2345d..a6bc1935 100644
--- a/src/utils/config/defaults.js
+++ b/src/utils/config/defaults.js
@@ -150,6 +150,7 @@ const defaults = {
ID_TOKEN: 'idToken',
DISABLE_CRITICAL_WARNING: 'disableCriticalWarning',
PI_HOLE_SESSION: 'piHoleSession',
+ WORKSPACE_SIDEBAR_EXPANDED: 'workspaceSidebarExpanded',
},
/* Key names for cookie identifiers */
cookieKeys: {
diff --git a/src/views/Workspace.vue b/src/views/Workspace.vue
index 17aa58e1..8877b1d7 100644
--- a/src/views/Workspace.vue
+++ b/src/views/Workspace.vue
@@ -2,13 +2,14 @@
<div class="work-space">
<SideBar
:sections="sections"
+ :activeUrl="activeUrl"
+ :openUrls="openUrls"
@launch-app="launchApp"
- @launch-widget="launchWidget"
- :initUrl="getInitialUrl()"
+ @launch-widget="launchWidgets"
+ @close-app="closeApp"
/>
- <WebContent :url="url" v-if="!isMultiTaskingEnabled" />
- <MultiTaskingWebComtent :url="url" v-else />
- <WidgetView :widgets="widgets" v-if="widgets" />
+ <WidgetView v-if="widgets" :widgets="widgets" />
+ <WebContent v-show="!widgets" :urls="frameUrls" :activeUrl="activeUrl" />
</div>
</template>
@@ -17,88 +18,99 @@ import HomeMixin from '@/mixins/HomeMixin';
import SideBar from '@/components/Workspace/SideBar';
import WebContent from '@/components/Workspace/WebContent';
import WidgetView from '@/components/Workspace/WidgetView';
-import MultiTaskingWebComtent from '@/components/Workspace/MultiTaskingWebComtent';
-import Defaults from '@/utils/config/defaults';
-import ErrorHandler from '@/utils/logging/ErrorHandler';
import { sanitizeUrl } from '@/utils/Sanitizer';
+import { sameUrl } from '@/utils/MiscHelpers';
export default {
name: 'Workspace',
mixins: [HomeMixin],
+ components: {
+ SideBar,
+ WebContent,
+ WidgetView,
+ },
data: () => ({
- url: '',
+ openUrls: [], // Apps opened this session, most recent last
widgets: null,
}),
computed: {
- sections() {
- return this.$store.getters.sections;
+ /* The visible app is kept in the URL, so it can be linked to or reloaded */
+ activeUrl() {
+ return sanitizeUrl(this.$route.query.url) || '';
},
- appConfig() {
- return this.$store.getters.appConfig;
+ /* Apps to render, or all open apps when multi-tasking, to keep them running */
+ frameUrls() {
+ if (this.appConfig.enableMultiTasking) return this.openUrls;
+ return this.activeUrl ? [this.activeUrl] : [];
},
- isMultiTaskingEnabled() {
- return this.appConfig.enableMultiTasking || false;
+ /* The page's landing app, once its config has loaded */
+ landingUrl() {
+ const loadedPage = this.$store.state.currentConfigInfo?.confId || null;
+ if (loadedPage !== (this.determineConfigFile() || null)) return null;
+ return sanitizeUrl(this.appConfig.workspaceLandingUrl);
},
},
- components: {
- SideBar,
- WebContent,
- WidgetView,
- MultiTaskingWebComtent,
+ watch: {
+ activeUrl: {
+ immediate: true,
+ handler(url) {
+ if (!url) return;
+ this.widgets = null;
+ if (!this.openUrls.includes(url)) this.openUrls.push(url);
+ },
+ },
+ landingUrl: {
+ immediate: true,
+ handler(url) {
+ if (url && !this.$route.query.url) this.launchApp(url);
+ },
+ },
+ /* Widgets belong to the page they were opened on */
+ '$route.path'() {
+ this.widgets = null;
+ },
},
methods: {
- launchApp(options) {
- if (options.target === 'newtab') {
- window.open(options.url, '_blank');
- } else if (options.target === 'newwindow') {
- const { width, height } = window.screen;
- window.open(options.url, '_blank', `width=${width},height=${height},noopener,noreferrer`);
- } else if (options.target === 'clipboard') {
- if (navigator.clipboard) {
- navigator.clipboard.writeText(options.url);
- this.$toast.success(this.$t('context-menus.item.copied-toast'));
- } else {
- ErrorHandler('Clipboard access requires HTTPS. See: https://bit.ly/3N5WuAA');
- this.$toast.error('Unable to copy, see log');
- }
- return;
- } else {
- this.url = options.url;
- }
- this.widgets = null;
+ /* Opens an app, reusing its open copy if a variant of the URL is already open */
+ launchApp(url) {
+ const appUrl = this.openUrls.find((openUrl) => sameUrl(openUrl, url)) || url;
+ this.$router.replace({ query: appUrl ? { url: appUrl } : {} });
},
- launchWidget(widgets) {
- this.url = '';
+ /* Shows a section's widgets in place of the current app */
+ launchWidgets(widgets) {
this.widgets = widgets;
+ this.$router.replace({ query: {} });
},
- initiateFontAwesome() {
- const fontAwesomeScript = document.createElement('script');
- const faKey = this.appConfig.fontAwesomeKey || Defaults.fontAwesomeKey;
- fontAwesomeScript.setAttribute('src', `https://kit.fontawesome.com/${faKey}.js`);
- document.head.appendChild(fontAwesomeScript);
- },
- /* Returns a service URL, if set as a URL param, or if user has specified landing URL */
- getInitialUrl() {
- const route = this.$route;
- if (route.query && route.query.url) {
- return sanitizeUrl(decodeURI(route.query.url)) || undefined;
- } else if (this.appConfig.workspaceLandingUrl) {
- return this.appConfig.workspaceLandingUrl;
- }
- return undefined;
+ /* Closes an app, and switches to the last opened one if the visible app was closed */
+ closeApp(url) {
+ this.openUrls = this.openUrls.filter((openUrl) => openUrl !== url);
+ const { activeUrl, openUrls } = this;
+ if (activeUrl && !openUrls.includes(activeUrl)) this.launchApp(openUrls.at(-1));
},
},
mounted() {
this.initiateFontAwesome();
this.initiateMaterialDesignIcons();
- this.url = this.getInitialUrl();
},
};
-
</script>
<style scoped lang="scss">
+@import '@/styles/media-queries.scss';
+
+:global(#dashy.view-workspace) {
+ position: fixed;
+ inset: 0;
+ display: flex;
+ flex-direction: column;
+}
+
.work-space {
- min-height: fit-content;
+ flex: 1;
+ display: flex;
+ min-height: 0;
+ @include phone {
+ flex-direction: column;
+ }
}
</style>