Remove all instances of inject, replace with VueX store

This commit is contained in:
Alicia Sykes 2021-10-09 19:24:51 +01:00
parent 8a8166bb47
commit b55f96c839
16 changed files with 97 additions and 75 deletions

View File

@ -36,7 +36,11 @@ import ErrorHandler from '@/utils/ErrorHandler';
export default { export default {
name: 'AppInfoModal', name: 'AppInfoModal',
inject: ['config'], computed: {
appConfig() {
return this.$store.getters.appConfig;
},
},
data() { data() {
return { return {
appVersion: process.env.VUE_APP_VERSION, // Current version, from package.json appVersion: process.env.VUE_APP_VERSION, // Current version, from package.json
@ -50,8 +54,7 @@ export default {
}; };
}, },
mounted() { mounted() {
const appConfig = this.config.appConfig || {}; if (!this.appVersion || (this.appConfig && this.appConfig.disableUpdateChecks)) {
if (!this.appVersion || (appConfig && appConfig.disableUpdateChecks)) {
// Either current version isn't found, or user disabled checks // Either current version isn't found, or user disabled checks
this.checksEnabled = false; this.checksEnabled = false;
} else { } else {

View File

@ -55,7 +55,11 @@ import { modalNames, serviceEndpoints } from '@/utils/defaults';
export default { export default {
name: 'RebuildApp', name: 'RebuildApp',
inject: ['config'], computed: {
appConfig() {
return this.$store.getters.appConfig;
},
},
components: { components: {
Button, Button,
RebuildIcon, RebuildIcon,
@ -112,12 +116,8 @@ export default {
}, },
}, },
mounted() { mounted() {
if (this.config) { if (this.appConfig.allowConfigEdit === false) {
if (this.config.appConfig) { this.allowRebuild = false;
if (this.config.appConfig.allowConfigEdit === false) {
this.allowRebuild = false;
}
}
} }
}, },
}; };

View File

@ -1,6 +1,6 @@
<template> <template>
<transition name="slide"> <transition name="slide">
<div class="context-menu" v-if="show && menuEnabled" <div class="context-menu" v-if="show && !isMenuDisabled()"
:style="posX && posY ? `top:${posY}px;left:${posX}px;` : ''"> :style="posX && posY ? `top:${posY}px;left:${posX}px;` : ''">
<ul> <ul>
<li @click="launch('sametab')"> <li @click="launch('sametab')">
@ -33,7 +33,6 @@ import WorkspaceOpenIcon from '@/assets/interface-icons/open-workspace.svg';
export default { export default {
name: 'ContextMenu', name: 'ContextMenu',
inject: ['config'],
components: { components: {
SameTabOpenIcon, SameTabOpenIcon,
NewTabOpenIcon, NewTabOpenIcon,
@ -45,10 +44,10 @@ export default {
posY: Number, // The Y coordinate for positioning posY: Number, // The Y coordinate for positioning
show: Boolean, // Should show or hide the menu show: Boolean, // Should show or hide the menu
}, },
data() { computed: {
return { appConfig() {
menuEnabled: !this.isMenuDisabled(), // Specifies if the context menu should be used return this.$store.getters.appConfig;
}; },
}, },
methods: { methods: {
/* Called on item click, emits an event up to Item */ /* Called on item click, emits an event up to Item */
@ -58,10 +57,7 @@ export default {
}, },
/* Checks if the user as disabled context menu in config */ /* Checks if the user as disabled context menu in config */
isMenuDisabled() { isMenuDisabled() {
if (this.config && this.config.appConfig) { return !!this.appConfig.disableContextMenu;
return !!this.config.appConfig.disableContextMenu;
}
return false;
}, },
}, },
}; };

View File

@ -53,7 +53,6 @@ import { localStorageKeys, serviceEndpoints } from '@/utils/defaults';
export default { export default {
name: 'Item', name: 'Item',
inject: ['config'],
props: { props: {
id: String, // The unique ID of a tile (e.g. 001) id: String, // The unique ID of a tile (e.g. 001)
title: String, // The main text of tile, required title: String, // The main text of tile, required
@ -77,6 +76,11 @@ export default {
statusCheckInterval: Number, statusCheckInterval: Number,
statusCheckAllowInsecure: Boolean, statusCheckAllowInsecure: Boolean,
}, },
computed: {
appConfig() {
return this.$store.getters.appConfig;
},
},
data() { data() {
return { return {
contextMenuOpen: false, contextMenuOpen: false,
@ -110,7 +114,7 @@ export default {
this.$emit('itemClicked'); this.$emit('itemClicked');
} }
// Update the most/ last used ledger, for smart-sorting // Update the most/ last used ledger, for smart-sorting
if (!this.config.appConfig.disableSmartSort) { if (!this.appConfig.disableSmartSort) {
this.incrementMostUsedCount(this.id); this.incrementMostUsedCount(this.id);
this.incrementLastUsedCount(this.id); this.incrementLastUsedCount(this.id);
} }

View File

@ -30,7 +30,6 @@ import { asciiHash } from '@/utils/MiscHelpers';
export default { export default {
name: 'Icon', name: 'Icon',
inject: ['config'],
props: { props: {
icon: String, // Path to icon asset icon: String, // Path to icon asset
url: String, // Used for fetching the favicon url: String, // Used for fetching the favicon
@ -40,6 +39,10 @@ export default {
BrokenImage, BrokenImage,
}, },
computed: { computed: {
/* Get appConfig from store */
appConfig() {
return this.$store.getters.appConfig;
},
/* Determines the type of icon */ /* Determines the type of icon */
iconType: function iconType() { iconType: function iconType() {
return this.determineImageType(this.icon); return this.determineImageType(this.icon);
@ -96,7 +99,7 @@ export default {
if (urlParts.length >= 2) return `${urlParts[0]}/${urlParts[1]}/${urlParts[2]}/${iconCdns.faviconName}`; if (urlParts.length >= 2) return `${urlParts[0]}/${urlParts[1]}/${urlParts[2]}/${iconCdns.faviconName}`;
} else if (fullUrl.includes('http')) { // Service is running publicly } else if (fullUrl.includes('http')) { // Service is running publicly
const host = this.getHostName(fullUrl); const host = this.getHostName(fullUrl);
const faviconApi = specificApi || this.config.appConfig.faviconApi || defaultFaviconApi; const faviconApi = specificApi || this.appConfig.faviconApi || defaultFaviconApi;
const endpoint = faviconApiEndpoints[faviconApi]; const endpoint = faviconApiEndpoints[faviconApi];
return endpoint.replace('$URL', host); return endpoint.replace('$URL', host);
} }
@ -120,7 +123,7 @@ export default {
/* or if user prefers local favicon, then return true */ /* or if user prefers local favicon, then return true */
shouldUseDefaultFavicon(fullUrl) { shouldUseDefaultFavicon(fullUrl) {
const isLocalIP = /(127\.)|(192\.168\.)|(10\.)|(172\.1[6-9]\.)|(172\.2[0-9]\.)|(172\.3[0-1]\.)|(::1$)|([fF][cCdD])|(localhost)/; const isLocalIP = /(127\.)|(192\.168\.)|(10\.)|(172\.1[6-9]\.)|(172\.2[0-9]\.)|(172\.3[0-1]\.)|(::1$)|([fF][cCdD])|(localhost)/;
return (isLocalIP.test(fullUrl) || this.config.appConfig.faviconApi === 'local'); return (isLocalIP.test(fullUrl) || this.appConfig.faviconApi === 'local');
}, },
/* Fetches the path of local images, from Docker container */ /* Fetches the path of local images, from Docker container */
getLocalImagePath(img) { getLocalImagePath(img) {

View File

@ -58,7 +58,6 @@ import IframeModal from '@/components/LinkItems/IframeModal.vue';
export default { export default {
name: 'Section', name: 'Section',
inject: ['config'],
props: { props: {
groupId: String, groupId: String,
title: String, title: String,
@ -74,13 +73,16 @@ export default {
IframeModal, IframeModal,
}, },
computed: { computed: {
appConfig() {
return this.$store.getters.appConfig;
},
sortOrder() { sortOrder() {
return this.displayData.sortBy || defaultSortOrder; return this.displayData.sortBy || defaultSortOrder;
}, },
/* If the sortBy attribute is specified, then return sorted data */ /* If the sortBy attribute is specified, then return sorted data */
sortedItems() { sortedItems() {
let { items } = this; let { items } = this;
if (this.config.appConfig.disableSmartSort) return items; if (this.appConfig.disableSmartSort) return items;
if (this.sortOrder === 'alphabetical') { if (this.sortOrder === 'alphabetical') {
this.sortAlphabetically(items); this.sortAlphabetically(items);
} else if (this.sortOrder === 'reverse-alphabetical') { } else if (this.sortOrder === 'reverse-alphabetical') {
@ -128,12 +130,12 @@ export default {
}, },
/* Determines if user has enabled online status checks */ /* Determines if user has enabled online status checks */
shouldEnableStatusCheck(itemPreference) { shouldEnableStatusCheck(itemPreference) {
const globalPreference = this.config.appConfig.statusCheck || false; const globalPreference = this.appConfig.statusCheck || false;
return itemPreference !== undefined ? itemPreference : globalPreference; return itemPreference !== undefined ? itemPreference : globalPreference;
}, },
/* Determine how often to re-fire status checks */ /* Determine how often to re-fire status checks */
getStatusCheckInterval() { getStatusCheckInterval() {
let interval = this.config.appConfig.statusCheckInterval; let interval = this.appConfig.statusCheckInterval;
if (!interval) return 0; if (!interval) return 0;
if (interval > 60) interval = 60; if (interval > 60) interval = 60;
if (interval < 1) interval = 0; if (interval < 1) interval = 0;

View File

@ -35,7 +35,6 @@ import {
export default { export default {
name: 'MinimalSearch', name: 'MinimalSearch',
inject: ['config'],
props: { props: {
active: Boolean, active: Boolean,
}, },
@ -47,10 +46,12 @@ export default {
}; };
}, },
computed: { computed: {
appConfig() {
return this.$store.getters.appConfig;
},
webSearchEnabled() { webSearchEnabled() {
const { appConfig } = this.config; if (this.appConfig && this.appConfig.webSearch) {
if (appConfig && appConfig.webSearch) { return !this.appConfig.webSearch.disableWebSearch;
return !appConfig.webSearch.disableWebSearch;
} }
return true; return true;
}, },
@ -117,8 +118,7 @@ export default {
/* If web search enabled, then launch search results when enter is pressed */ /* If web search enabled, then launch search results when enter is pressed */
searchSubmitted() { searchSubmitted() {
// Get search preferences from appConfig // Get search preferences from appConfig
const { appConfig } = this.config; const searchPrefs = this.appConfig.webSearch || {};
const searchPrefs = appConfig.webSearch || {};
if (this.webSearchEnabled) { // Only proceed if user hasn't disabled web search if (this.webSearchEnabled) { // Only proceed if user hasn't disabled web search
const openingMethod = searchPrefs.openingMethod || defaultSearchOpeningMethod; const openingMethod = searchPrefs.openingMethod || defaultSearchOpeningMethod;
// Get search engine, and make URL // Get search engine, and make URL

View File

@ -37,7 +37,6 @@ import IframeModal from '@/components/LinkItems/IframeModal.vue';
export default { export default {
name: 'ItemGroup', name: 'ItemGroup',
inject: ['config'],
props: { props: {
groupId: String, groupId: String,
title: String, title: String,
@ -50,6 +49,11 @@ export default {
selected: Boolean, selected: Boolean,
showAll: Boolean, showAll: Boolean,
}, },
computed: {
appConfig() {
return this.$store.getters.appConfig;
},
},
components: { components: {
Item, Item,
IframeModal, IframeModal,
@ -70,11 +74,11 @@ export default {
this.$emit('change-modal-visibility', changedTo); this.$emit('change-modal-visibility', changedTo);
}, },
shouldEnableStatusCheck(itemPreference) { shouldEnableStatusCheck(itemPreference) {
const globalPreference = this.config.appConfig.statusCheck || false; const globalPreference = this.appConfig.statusCheck || false;
return itemPreference !== undefined ? itemPreference : globalPreference; return itemPreference !== undefined ? itemPreference : globalPreference;
}, },
getStatusCheckInterval() { getStatusCheckInterval() {
let interval = this.config.appConfig.statusCheckInterval; let interval = this.appConfig.statusCheckInterval;
if (!interval) return 0; if (!interval) return 0;
if (interval > 60) interval = 60; if (interval > 60) interval = 60;
if (interval < 1) interval = 0; if (interval < 1) interval = 0;

View File

@ -1,5 +1,5 @@
<template> <template>
<header v-if="visible"> <header v-if="componentVisible">
<PageTitle <PageTitle
v-if="titleVisible" v-if="titleVisible"
:title="pageInfo.title" :title="pageInfo.title"
@ -13,12 +13,10 @@
<script> <script>
import PageTitle from '@/components/PageStrcture/PageTitle.vue'; import PageTitle from '@/components/PageStrcture/PageTitle.vue';
import Nav from '@/components/PageStrcture/Nav.vue'; import Nav from '@/components/PageStrcture/Nav.vue';
import { visibleComponents as defaultVisibleComponents } from '@/utils/defaults';
import { shouldBeVisible } from '@/utils/MiscHelpers'; import { shouldBeVisible } from '@/utils/MiscHelpers';
export default { export default {
name: 'Header', name: 'Header',
inject: ['visibleComponents'],
components: { components: {
PageTitle, PageTitle,
Nav, Nav,
@ -26,16 +24,19 @@ export default {
props: { props: {
pageInfo: Object, pageInfo: Object,
}, },
data() {
return {
titleVisible: (this.visibleComponents || defaultVisibleComponents).pageTitle,
navVisible: (this.visibleComponents || defaultVisibleComponents).navigation,
};
},
computed: { computed: {
visible() { componentVisible() {
return shouldBeVisible(this.$route.name); return shouldBeVisible(this.$route.name);
}, },
visibleComponents() {
return this.$store.getters.visibleComponents;
},
titleVisible() {
return this.visibleComponents.pageTitle;
},
navVisible() {
return this.visibleComponents.navigation;
},
}, },
}; };
</script> </script>

View File

@ -33,7 +33,6 @@ import { localStorageKeys, modalNames } from '@/utils/defaults';
export default { export default {
name: 'LanguageSwitcher', name: 'LanguageSwitcher',
inject: ['config'],
components: { components: {
Button, Button,
SaveConfigIcon, SaveConfigIcon,
@ -45,6 +44,10 @@ export default {
}; };
}, },
computed: { computed: {
/* Get appConfig from store */
appConfig() {
return this.$store.getters.appConfig;
},
/* Return the array of language objects, plus a friends name */ /* Return the array of language objects, plus a friends name */
languageList: () => languages.map((lang) => { languageList: () => languages.map((lang) => {
const newLang = lang; const newLang = lang;
@ -85,7 +88,7 @@ export default {
/* Gets the users current language from local storage */ /* Gets the users current language from local storage */
getCurrentLanguage() { getCurrentLanguage() {
const getLanguageFromIso = (iso) => languages.find((lang) => lang.code === iso); const getLanguageFromIso = (iso) => languages.find((lang) => lang.code === iso);
const current = localStorage[localStorageKeys.LANGUAGE] || this.config.appConfig.language; const current = localStorage[localStorageKeys.LANGUAGE] || this.appConfig.language;
return getLanguageFromIso(current); return getLanguageFromIso(current);
}, },
}, },

View File

@ -35,7 +35,6 @@ import {
export default { export default {
name: 'FilterTile', name: 'FilterTile',
inject: ['config'],
props: { props: {
active: Boolean, active: Boolean,
}, },
@ -48,7 +47,7 @@ export default {
}, },
computed: { computed: {
searchPrefs() { searchPrefs() {
return this.config.appConfig.webSearch || {}; return this.$store.getters.webSearch || {};
}, },
}, },
mounted() { mounted() {

View File

@ -69,7 +69,29 @@ export default {
IconOpen, IconOpen,
IconClose, IconClose,
}, },
inject: ['visibleComponents'], computed: {
/**
* Determines which button should display, based on the user type
* 0 = Auth not configured, don't show anything
* 1 = Auth condifured, and user logged in, show logout button
* 2 = Auth configured, guest access enabled, and not logged in, show login
* Note that if auth is enabled, but not guest access, and user not logged in,
* then they will never be able to view the homepage, so no button needed
*/
userState() {
return getUserState();
},
/* Object indicating which components should be hidden, based on user preferences */
visibleComponents() {
return this.$store.getters.visibleComponents;
},
},
data() {
return {
settingsVisible: this.getSettingsVisibility(),
searchVisible: (this.visibleComponents || defaultVisibleComponents).searchBar,
};
},
methods: { methods: {
userIsTypingSomething(something) { userIsTypingSomething(something) {
this.$emit('user-is-searchin', something); this.$emit('user-is-searchin', something);
@ -104,25 +126,6 @@ export default {
|| (this.visibleComponents || defaultVisibleComponents).settings); || (this.visibleComponents || defaultVisibleComponents).settings);
}, },
}, },
computed: {
/**
* Determines which button should display, based on the user type
* 0 = Auth not configured, don't show anything
* 1 = Auth condifured, and user logged in, show logout button
* 2 = Auth configured, guest access enabled, and not logged in, show login
* Note that if auth is enabled, but not guest access, and user not logged in,
* then they will never be able to view the homepage, so no button needed
*/
userState() {
return getUserState();
},
},
data() {
return {
settingsVisible: this.getSettingsVisibility(),
searchVisible: (this.visibleComponents || defaultVisibleComponents).searchBar,
};
},
}; };
</script> </script>

View File

@ -36,7 +36,6 @@ import IconMinimalView from '@/assets/interface-icons/application-minimal.svg';
export default { export default {
name: 'SideBar', name: 'SideBar',
inject: ['config'],
props: { props: {
sections: Array, sections: Array,
initUrl: String, initUrl: String,

View File

@ -12,7 +12,6 @@ import Icon from '@/components/LinkItems/ItemIcon.vue';
export default { export default {
name: 'SideBarItem', name: 'SideBarItem',
inject: ['config'],
props: { props: {
icon: String, icon: String,
title: String, title: String,

View File

@ -19,7 +19,6 @@ import SideBarItem from '@/components/Workspace/SideBarItem.vue';
export default { export default {
name: 'SideBarSection', name: 'SideBarSection',
inject: ['config'],
props: { props: {
items: Array, items: Array,
}, },

View File

@ -3,6 +3,7 @@ import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import Keys from '@/utils/StoreMutations'; import Keys from '@/utils/StoreMutations';
import ConfigAccumulator from '@/utils/ConfigAccumalator'; import ConfigAccumulator from '@/utils/ConfigAccumalator';
import { componentVisibility } from '@/utils/ConfigHelpers';
Vue.use(Vuex); Vue.use(Vuex);
@ -25,6 +26,12 @@ const store = new Vuex.Store({
sections(state) { sections(state) {
return state.config.sections || []; return state.config.sections || [];
}, },
webSearch(state, getters) {
return getters.appConfig.webSearch || {};
},
visibleComponents(state, getters) {
return componentVisibility(getters.appConfig);
},
}, },
mutations: { mutations: {
[UPDATE_CONFIG](state, config) { [UPDATE_CONFIG](state, config) {