diff --git a/src/components/TheSettingsMenu.vue b/src/components/TheSettingsMenu.vue index dc10c268..e574303f 100644 --- a/src/components/TheSettingsMenu.vue +++ b/src/components/TheSettingsMenu.vue @@ -80,6 +80,7 @@ import SettingsDashboardTab from '@/components/settings/SettingsDashboardTab.vue import SettingsGCodeViewerTab from '@/components/settings/SettingsGCodeViewerTab.vue' import SettingsEditorTab from '@/components/settings/SettingsEditorTab.vue' import SettingsTimelapseTab from '@/components/settings/SettingsTimelapseTab.vue' +import SettingsNavigationTab from '@/components/settings/SettingsNavigationTab.vue' import Panel from '@/components/ui/Panel.vue' import { @@ -98,6 +99,7 @@ import { mdiVideo3d, mdiWebcam, mdiDipSwitch, + mdiMenu, } from '@mdi/js' import SettingsMiscellaneousTab from '@/components/settings/SettingsMiscellaneousTab.vue' @Component({ @@ -116,6 +118,7 @@ import SettingsMiscellaneousTab from '@/components/settings/SettingsMiscellaneou SettingsEditorTab, SettingsTimelapseTab, SettingsMiscellaneousTab, + SettingsNavigationTab, }, }) export default class TheSettingsMenu extends Mixins(BaseMixin) { @@ -194,6 +197,11 @@ export default class TheSettingsMenu extends Mixins(BaseMixin) { name: 'miscellaneous', title: this.$t('Settings.MiscellaneousTab.Miscellaneous'), }, + { + icon: mdiMenu, + name: 'navigation', + title: this.$t('Settings.NavigationTab.Navigation'), + }, ] if (this.moonrakerComponents.includes('timelapse')) { diff --git a/src/components/TheSidebar.vue b/src/components/TheSidebar.vue index ffbec317..8050321b 100644 --- a/src/components/TheSidebar.vue +++ b/src/components/TheSidebar.vue @@ -1,46 +1,3 @@ - - + + + + diff --git a/src/locales/en.json b/src/locales/en.json index 4f290012..759b51f8 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -911,6 +911,9 @@ "UnableToLoadLight": "Unable to load light", "UnableToLoadPreset": "Unable to load preset" }, + "NavigationTab": { + "Navigation": "Navigation" + }, "PresetsTab": { "AddPreset": "add preset", "Cooldown": "Cooldown", @@ -1036,7 +1039,6 @@ "PowerDeviceName": "Printer power device", "PowerDeviceNameDescription": "Select which Moonraker power device should be used to power on the printer.", "Primary": "Primary", - "ShowWebcamInNavigation": "Show Webcam in navigation", "UiSettings": "UI-Settings" }, "Update": "update", diff --git a/src/routes/index.ts b/src/routes/index.ts index bf79ec28..6964df89 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -28,6 +28,7 @@ const routes: AppRoute[] = [ component: Dashboard, alwaysShow: true, showInNavi: true, + position: 10, }, { title: 'Printers', @@ -43,6 +44,7 @@ const routes: AppRoute[] = [ component: Webcam, alwaysShow: true, showInNavi: true, + position: 20, }, { title: 'Console', @@ -52,6 +54,7 @@ const routes: AppRoute[] = [ alwaysShow: true, showInNavi: true, klipperIsConnected: true, + position: 30, }, { title: 'Heightmap', @@ -61,6 +64,7 @@ const routes: AppRoute[] = [ alwaysShow: false, showInNavi: true, klipperComponent: 'bed_mesh', + position: 40, }, { title: 'G-Code Files', @@ -70,6 +74,7 @@ const routes: AppRoute[] = [ alwaysShow: true, showInNavi: true, registeredDirectory: 'gcodes', + position: 50, }, { title: 'G-Code Viewer', @@ -78,6 +83,7 @@ const routes: AppRoute[] = [ component: () => import('../pages/Viewer.vue'), alwaysShow: true, showInNavi: true, + position: 60, }, { title: 'History', @@ -87,6 +93,7 @@ const routes: AppRoute[] = [ alwaysShow: true, showInNavi: true, moonrakerComponent: 'history', + position: 70, }, { title: 'Timelapse', @@ -96,6 +103,7 @@ const routes: AppRoute[] = [ alwaysShow: true, showInNavi: true, moonrakerComponent: 'timelapse', + position: 80, }, { title: 'Machine', @@ -104,6 +112,7 @@ const routes: AppRoute[] = [ component: Machine, alwaysShow: true, showInNavi: true, + position: 90, }, { title: null, @@ -130,4 +139,5 @@ export interface AppRoute { klipperComponent?: string klipperIsConnected?: boolean children?: AppRoute[] + position?: number } diff --git a/src/store/files/getters.ts b/src/store/files/getters.ts index 71ca66a6..829d01db 100644 --- a/src/store/files/getters.ts +++ b/src/store/files/getters.ts @@ -199,11 +199,14 @@ export const getters: GetterTree = { const file = directory?.childrens?.find( (element: FileStateFile) => - element.filename !== undefined && - element.filename.substr(0, element.filename.lastIndexOf('.')) === acceptName && - acceptExtensions.includes(element.filename.substr(element.filename.lastIndexOf('.') + 1)) + element.filename?.slice(0, element.filename?.lastIndexOf('.')) === acceptName && + acceptExtensions.includes(element.filename?.slice(element.filename?.lastIndexOf('.') + 1)) ) - return file ? rootGetters['socket/getUrl'] + '/server/files/config/' + themeDir + '/' + file.filename : null + if (!file) return null + + return `${rootGetters['socket/getUrl']}/server/files/config/${themeDir}/${ + file.filename + }?timestamp=${file.modified.getTime()}` }, getSidebarLogo: (state, getters) => { @@ -234,6 +237,13 @@ export const getters: GetterTree = { return getters['getThemeFileUrl'](acceptName, acceptExtensions) ?? null }, + getCustomNaviPoints: (state, getters) => { + const acceptName = 'navi' + const acceptExtensions = ['json'] + + return getters['getThemeFileUrl'](acceptName, acceptExtensions) ?? null + }, + getCustomFavicons: (state, getters) => { const acceptName16 = 'favicon-32x32' const acceptName32 = 'favicon-32x32' diff --git a/src/store/gui/index.ts b/src/store/gui/index.ts index 77183051..be57d58d 100644 --- a/src/store/gui/index.ts +++ b/src/store/gui/index.ts @@ -10,10 +10,11 @@ import { console } from '@/store/gui/console' import { gcodehistory } from '@/store/gui/gcodehistory' import { macros } from '@/store/gui/macros' import { miscellaneous } from '@/store/gui/miscellaneous' +import { navigation } from '@/store/gui/navigation' +import { notifications } from '@/store/gui/notifications' import { presets } from '@/store/gui/presets' import { remoteprinters } from '@/store/gui/remoteprinters' import { webcams } from '@/store/gui/webcams' -import { notifications } from '@/store/gui/notifications' export const getDefaultState = (): GuiState => { return { @@ -141,6 +142,9 @@ export const getDefaultState = (): GuiState => { showGCodePanel: false, cncMode: false, }, + navigation: { + entries: [], + }, uiSettings: { logo: defaultLogoColor, primary: defaultPrimaryColor, @@ -152,7 +156,6 @@ export const getDefaultState = (): GuiState => { boolBigThumbnail: true, boolWideNavDrawer: false, boolHideUploadAndPrintButton: false, - boolWebcamNavi: false, navigationStyle: 'iconsAndText', powerDeviceName: null, hideSaveConfigForBedMash: false, @@ -263,6 +266,7 @@ export const gui: Module = { gcodehistory, macros, miscellaneous, + navigation, notifications, presets, remoteprinters, diff --git a/src/store/gui/navigation/actions.ts b/src/store/gui/navigation/actions.ts new file mode 100644 index 00000000..da60b201 --- /dev/null +++ b/src/store/gui/navigation/actions.ts @@ -0,0 +1,27 @@ +import { ActionTree } from 'vuex' +import { RootState } from '@/store/types' +import Vue from 'vue' +import { GuiNavigationState, GuiNavigationStateEntry } from '@/store/gui/navigation/types' + +export const actions: ActionTree = { + reset({ commit }) { + commit('reset') + }, + + upload({ state }) { + Vue.$socket.emit('server.database.post_item', { + namespace: 'mainsail', + key: 'navigation.entries', + value: state.entries, + }) + }, + + updatePos({ commit }, payload: GuiNavigationStateEntry) { + commit('updatePos', payload) + }, + + changeVisibility({ commit, dispatch }, payload: GuiNavigationStateEntry) { + commit('changeVisibility', payload) + dispatch('upload') + }, +} diff --git a/src/store/gui/navigation/getters.ts b/src/store/gui/navigation/getters.ts new file mode 100644 index 00000000..6ef67331 --- /dev/null +++ b/src/store/gui/navigation/getters.ts @@ -0,0 +1,5 @@ +import { GetterTree } from 'vuex' +import { GuiNavigationState } from './types' + +// eslint-disable-next-line +export const getters: GetterTree = {} diff --git a/src/store/gui/navigation/index.ts b/src/store/gui/navigation/index.ts new file mode 100644 index 00000000..c0ca7857 --- /dev/null +++ b/src/store/gui/navigation/index.ts @@ -0,0 +1,23 @@ +import { Module } from 'vuex' +import { actions } from '@/store/gui/navigation/actions' +import { mutations } from '@/store/gui/navigation/mutations' +import { getters } from '@/store/gui/navigation/getters' +import { GuiNavigationState } from '@/store/gui/navigation/types' + +export const getDefaultState = (): GuiNavigationState => { + return { + entries: [], + } +} + +// initial state +const state = getDefaultState() + +// eslint-disable-next-line +export const navigation: Module = { + namespaced: true, + state, + getters, + actions, + mutations, +} diff --git a/src/store/gui/navigation/mutations.ts b/src/store/gui/navigation/mutations.ts new file mode 100644 index 00000000..57afc98e --- /dev/null +++ b/src/store/gui/navigation/mutations.ts @@ -0,0 +1,62 @@ +import { getDefaultState } from './index' +import { MutationTree } from 'vuex' +import { GuiNavigationState, GuiNavigationStateEntry } from './types' +import Vue from 'vue' + +export const mutations: MutationTree = { + reset(state) { + Object.assign(state, getDefaultState()) + }, + + updatePos(state, payload: GuiNavigationStateEntry) { + const index = state.entries.findIndex((entry) => { + return entry.type === payload.type && entry.title === payload.title + }) + + // update existing entry + if (index !== -1) { + state.entries[index].position = payload.position + return + } + + // create new entry + const newEntry: GuiNavigationStateEntry = { + type: payload.type, + title: payload.title, + visible: payload.visible, + position: payload.position, + } + // copy old array + const entries = [...state.entries] + // add new entry + entries.push(newEntry) + // set new array + Vue.set(state, 'entries', entries) + }, + + changeVisibility(state, payload: GuiNavigationStateEntry) { + const index = state.entries.findIndex((entry) => { + return entry.type === payload.type && entry.title === payload.title + }) + + // update existing entry + if (index !== -1) { + state.entries[index].visible = !payload.visible + return + } + + // create new entry + const newEntry: GuiNavigationStateEntry = { + type: payload.type, + title: payload.title, + visible: !payload.visible, + position: payload.position, + } + // copy old array + const entries = [...state.entries] + // add new entry + entries.push(newEntry) + // set new array + Vue.set(state, 'entries', entries) + }, +} diff --git a/src/store/gui/navigation/types.ts b/src/store/gui/navigation/types.ts new file mode 100644 index 00000000..705fb7e0 --- /dev/null +++ b/src/store/gui/navigation/types.ts @@ -0,0 +1,10 @@ +export interface GuiNavigationState { + entries: GuiNavigationStateEntry[] +} + +export interface GuiNavigationStateEntry { + type: 'route' | 'link' + title: string + visible: boolean + position: number +} diff --git a/src/store/gui/types.ts b/src/store/gui/types.ts index c598b3da..bb5f4f32 100644 --- a/src/store/gui/types.ts +++ b/src/store/gui/types.ts @@ -5,6 +5,7 @@ import { GuiRemoteprintersState } from '@/store/gui/remoteprinters/types' import { ServerHistoryStateJob } from '@/store/server/history/types' import { GuiNotificationState } from '@/store/gui/notifications/types' import { FileStateFile, FileStateGcodefile } from '@/store/files/types' +import { GuiNavigationState } from '@/store/gui/navigation/types' export interface GuiState { general: { @@ -90,6 +91,7 @@ export interface GuiState { cncMode: boolean } macros?: GuiMacrosState + navigation: GuiNavigationState notifications?: GuiNotificationState presets?: GuiPresetsState remoteprinters?: GuiRemoteprintersState @@ -104,7 +106,6 @@ export interface GuiState { boolBigThumbnail: boolean boolWideNavDrawer: boolean boolHideUploadAndPrintButton: boolean - boolWebcamNavi: boolean navigationStyle: 'iconsAndText' | 'iconsOnly' powerDeviceName: string | null hideSaveConfigForBedMash: boolean