Fix line feed issues in WidgetBase.vue and removed unused imports in GluetunStatus.vue

This commit is contained in:
Jammo2k5 2022-07-20 22:38:29 +01:00
parent 74fc7419da
commit bbfe9a9def
2 changed files with 279 additions and 281 deletions

View File

@ -37,8 +37,6 @@
<script> <script>
import WidgetMixin from '@/mixins/WidgetMixin'; import WidgetMixin from '@/mixins/WidgetMixin';
import { widgetApiEndpoints } from '@/utils/defaults';
import { getCountryFlag, getMapUrl } from '@/utils/MiscHelpers';
export default { export default {
mixins: [WidgetMixin], mixins: [WidgetMixin],

View File

@ -1,279 +1,279 @@
<template> <template>
<div :class="`widget-base ${ loading ? 'is-loading' : '' }`"> <div :class="`widget-base ${ loading ? 'is-loading' : '' }`">
<!-- Update and Full-Page Action Buttons --> <!-- Update and Full-Page Action Buttons -->
<Button :click="update" class="action-btn update-btn" v-if="!hideControls && !loading"> <Button :click="update" class="action-btn update-btn" v-if="!hideControls && !loading">
<UpdateIcon /> <UpdateIcon />
</Button> </Button>
<Button :click="fullScreenWidget" <Button :click="fullScreenWidget"
class="action-btn open-btn" v-if="!hideControls && !error && !loading"> class="action-btn open-btn" v-if="!hideControls && !error && !loading">
<OpenIcon /> <OpenIcon />
</Button> </Button>
<!-- Loading Spinner --> <!-- Loading Spinner -->
<div v-if="loading" class="loading"> <div v-if="loading" class="loading">
<LoadingAnimation v-if="loading" class="loader" /> <LoadingAnimation v-if="loading" class="loader" />
</div> </div>
<!-- Error Message Display --> <!-- Error Message Display -->
<div v-if="error" class="widget-error"> <div v-if="error" class="widget-error">
<p class="error-msg">An error occurred, see the logs for more info.</p> <p class="error-msg">An error occurred, see the logs for more info.</p>
<p class="error-output">{{ errorMsg }}</p> <p class="error-output">{{ errorMsg }}</p>
<p class="retry-link" @click="update">Retry</p> <p class="retry-link" @click="update">Retry</p>
</div> </div>
<!-- Widget Label --> <!-- Widget Label -->
<div class="widget-label" v-if="widgetOptions.label">{{ widgetOptions.label }}</div> <div class="widget-label" v-if="widgetOptions.label">{{ widgetOptions.label }}</div>
<!-- Widget --> <!-- Widget -->
<div :class="`widget-wrap ${ error ? 'has-error' : '' }`"> <div :class="`widget-wrap ${ error ? 'has-error' : '' }`">
<component <component
v-bind:is="component" v-bind:is="component"
:options="widgetOptions" :options="widgetOptions"
@loading="setLoaderState" @loading="setLoaderState"
@error="handleError" @error="handleError"
:ref="widgetRef" :ref="widgetRef"
/> />
</div> </div>
</div> </div>
</template> </template>
<script> <script>
// Import form elements, icons and utils // Import form elements, icons and utils
import ErrorHandler from '@/utils/ErrorHandler'; import ErrorHandler from '@/utils/ErrorHandler';
import Button from '@/components/FormElements/Button'; import Button from '@/components/FormElements/Button';
import UpdateIcon from '@/assets/interface-icons/widget-update.svg'; import UpdateIcon from '@/assets/interface-icons/widget-update.svg';
import OpenIcon from '@/assets/interface-icons/open-new-tab.svg'; import OpenIcon from '@/assets/interface-icons/open-new-tab.svg';
import LoadingAnimation from '@/assets/interface-icons/loader.svg'; import LoadingAnimation from '@/assets/interface-icons/loader.svg';
const COMPAT = { const COMPAT = {
'adguard-dns-info': 'AdGuardDnsInfo', 'adguard-dns-info': 'AdGuardDnsInfo',
'adguard-filter-status': 'AdGuardFilterStatus', 'adguard-filter-status': 'AdGuardFilterStatus',
'adguard-stats': 'AdGuardStats', 'adguard-stats': 'AdGuardStats',
'adguard-top-domains': 'AdGuardTopDomains', 'adguard-top-domains': 'AdGuardTopDomains',
anonaddy: 'AnonAddy', anonaddy: 'AnonAddy',
apod: 'Apod', apod: 'Apod',
'blacklist-check': 'BlacklistCheck', 'blacklist-check': 'BlacklistCheck',
clock: 'Clock', clock: 'Clock',
'crypto-price-chart': 'CryptoPriceChart', 'crypto-price-chart': 'CryptoPriceChart',
'crypto-watch-list': 'CryptoWatchList', 'crypto-watch-list': 'CryptoWatchList',
'cve-vulnerabilities': 'CveVulnerabilities', 'cve-vulnerabilities': 'CveVulnerabilities',
'domain-monitor': 'DomainMonitor', 'domain-monitor': 'DomainMonitor',
'code-stats': 'CodeStats', 'code-stats': 'CodeStats',
'covid-stats': 'CovidStats', 'covid-stats': 'CovidStats',
embed: 'EmbedWidget', embed: 'EmbedWidget',
'eth-gas-prices': 'EthGasPrices', 'eth-gas-prices': 'EthGasPrices',
'exchange-rates': 'ExchangeRates', 'exchange-rates': 'ExchangeRates',
'flight-data': 'Flights', 'flight-data': 'Flights',
'github-profile-stats': 'GitHubProfile', 'github-profile-stats': 'GitHubProfile',
'github-trending-repos': 'GitHubTrending', 'github-trending-repos': 'GitHubTrending',
'gl-alerts': 'GlAlerts', 'gl-alerts': 'GlAlerts',
'gl-current-cores': 'GlCpuCores', 'gl-current-cores': 'GlCpuCores',
'gl-current-cpu': 'GlCpuGauge', 'gl-current-cpu': 'GlCpuGauge',
'gl-cpu-history': 'GlCpuHistory', 'gl-cpu-history': 'GlCpuHistory',
'gl-disk-io': 'GlDiskIo', 'gl-disk-io': 'GlDiskIo',
'gl-disk-space': 'GlDiskSpace', 'gl-disk-space': 'GlDiskSpace',
'gl-ip-address': 'GlIpAddress', 'gl-ip-address': 'GlIpAddress',
'gl-load-history': 'GlLoadHistory', 'gl-load-history': 'GlLoadHistory',
'gl-current-mem': 'GlMemGauge', 'gl-current-mem': 'GlMemGauge',
'gl-mem-history': 'GlMemHistory', 'gl-mem-history': 'GlMemHistory',
'gl-network-interfaces': 'GlNetworkInterfaces', 'gl-network-interfaces': 'GlNetworkInterfaces',
'gl-network-traffic': 'GlNetworkTraffic', 'gl-network-traffic': 'GlNetworkTraffic',
'gl-system-load': 'GlSystemLoad', 'gl-system-load': 'GlSystemLoad',
'gl-cpu-temp': 'GlCpuTemp', 'gl-cpu-temp': 'GlCpuTemp',
'health-checks': 'HealthChecks', 'health-checks': 'HealthChecks',
'gluetun-status': 'GluetunStatus', 'gluetun-status': 'GluetunStatus',
iframe: 'IframeWidget', iframe: 'IframeWidget',
image: 'ImageWidget', image: 'ImageWidget',
joke: 'Jokes', joke: 'Jokes',
'mullvad-status': 'MullvadStatus', 'mullvad-status': 'MullvadStatus',
'nd-cpu-history': 'NdCpuHistory', 'nd-cpu-history': 'NdCpuHistory',
'nd-load-history': 'NdLoadHistory', 'nd-load-history': 'NdLoadHistory',
'nd-ram-history': 'NdRamHistory', 'nd-ram-history': 'NdRamHistory',
'news-headlines': 'NewsHeadlines', 'news-headlines': 'NewsHeadlines',
'nextcloud-notifications': 'NextcloudNotifications', 'nextcloud-notifications': 'NextcloudNotifications',
'nextcloud-php-opcache': 'NextcloudPhpOpcache', 'nextcloud-php-opcache': 'NextcloudPhpOpcache',
'nextcloud-stats': 'NextcloudStats', 'nextcloud-stats': 'NextcloudStats',
'nextcloud-system': 'NextcloudSystem', 'nextcloud-system': 'NextcloudSystem',
'nextcloud-user': 'NextcloudUser', 'nextcloud-user': 'NextcloudUser',
'nextcloud-user-status': 'NextcloudUserStatus', 'nextcloud-user-status': 'NextcloudUserStatus',
'pi-hole-stats': 'PiHoleStats', 'pi-hole-stats': 'PiHoleStats',
'pi-hole-top-queries': 'PiHoleTopQueries', 'pi-hole-top-queries': 'PiHoleTopQueries',
'pi-hole-traffic': 'PiHoleTraffic', 'pi-hole-traffic': 'PiHoleTraffic',
'public-holidays': 'PublicHolidays', 'public-holidays': 'PublicHolidays',
'public-ip': 'PublicIp', 'public-ip': 'PublicIp',
'rss-feed': 'RssFeed', 'rss-feed': 'RssFeed',
sabnzbd: 'Sabnzbd', sabnzbd: 'Sabnzbd',
'sports-scores': 'SportsScores', 'sports-scores': 'SportsScores',
'stat-ping': 'StatPing', 'stat-ping': 'StatPing',
'stock-price-chart': 'StockPriceChart', 'stock-price-chart': 'StockPriceChart',
'synology-download': 'SynologyDownload', 'synology-download': 'SynologyDownload',
'system-info': 'SystemInfo', 'system-info': 'SystemInfo',
'tfl-status': 'TflStatus', 'tfl-status': 'TflStatus',
'wallet-balance': 'WalletBalance', 'wallet-balance': 'WalletBalance',
weather: 'Weather', weather: 'Weather',
'weather-forecast': 'WeatherForecast', 'weather-forecast': 'WeatherForecast',
'xkcd-comic': 'XkcdComic', 'xkcd-comic': 'XkcdComic',
}; };
export default { export default {
name: 'Widget', name: 'Widget',
components: { components: {
// Register form elements // Register form elements
Button, Button,
UpdateIcon, UpdateIcon,
OpenIcon, OpenIcon,
LoadingAnimation, LoadingAnimation,
}, },
props: { props: {
widget: Object, widget: Object,
index: Number, index: Number,
}, },
data: () => ({ data: () => ({
loading: false, loading: false,
error: false, error: false,
errorMsg: null, errorMsg: null,
}), }),
computed: { computed: {
appConfig() { appConfig() {
return this.$store.getters.appConfig; return this.$store.getters.appConfig;
}, },
/* Returns the widget type, shows error if not specified */ /* Returns the widget type, shows error if not specified */
widgetType() { widgetType() {
if (!this.widget.type) { if (!this.widget.type) {
ErrorHandler('Missing type attribute for widget'); ErrorHandler('Missing type attribute for widget');
return null; return null;
} }
return this.widget.type.toLowerCase(); return this.widget.type.toLowerCase();
}, },
/* Returns users specified widget options, or empty object */ /* Returns users specified widget options, or empty object */
widgetOptions() { widgetOptions() {
const options = this.widget.options || {}; const options = this.widget.options || {};
const timeout = this.widget.timeout || null; const timeout = this.widget.timeout || null;
const ignoreErrors = this.widget.ignoreErrors || false; const ignoreErrors = this.widget.ignoreErrors || false;
const label = this.widget.label || null; const label = this.widget.label || null;
const useProxy = this.appConfig.widgetsAlwaysUseProxy || !!this.widget.useProxy; const useProxy = this.appConfig.widgetsAlwaysUseProxy || !!this.widget.useProxy;
const updateInterval = this.widget.updateInterval !== undefined const updateInterval = this.widget.updateInterval !== undefined
? this.widget.updateInterval : null; ? this.widget.updateInterval : null;
return { return {
timeout, ignoreErrors, label, useProxy, updateInterval, ...options, timeout, ignoreErrors, label, useProxy, updateInterval, ...options,
}; };
}, },
/* A unique string to reference the widget by */ /* A unique string to reference the widget by */
widgetRef() { widgetRef() {
return `widget-${this.widgetType}-${this.index}`; return `widget-${this.widgetType}-${this.index}`;
}, },
hideControls() { hideControls() {
return this.widget.hideControls; return this.widget.hideControls;
}, },
component() { component() {
const type = COMPAT[this.widgetType] || this.widget.type; const type = COMPAT[this.widgetType] || this.widget.type;
if (!type) { if (!type) {
ErrorHandler('Widget type was not found'); ErrorHandler('Widget type was not found');
return null; return null;
} }
// eslint-disable-next-line prefer-template // eslint-disable-next-line prefer-template
return () => import('@/components/Widgets/' + type + '.vue').catch(() => import('@/components/Widgets/Blank.vue')); return () => import('@/components/Widgets/' + type + '.vue').catch(() => import('@/components/Widgets/Blank.vue'));
}, },
}, },
methods: { methods: {
/* Calls update data method on widget */ /* Calls update data method on widget */
update() { update() {
this.error = false; this.error = false;
this.$refs[this.widgetRef].update(); this.$refs[this.widgetRef].update();
}, },
/* Shows message when error occurred */ /* Shows message when error occurred */
handleError(msg) { handleError(msg) {
this.error = true; this.error = true;
this.errorMsg = msg; this.errorMsg = msg;
}, },
/* Opens current widget in full-page */ /* Opens current widget in full-page */
fullScreenWidget() { fullScreenWidget() {
this.$emit('navigateToSection'); this.$emit('navigateToSection');
}, },
/* Toggles loading state */ /* Toggles loading state */
setLoaderState(loading) { setLoaderState(loading) {
this.loading = loading; this.loading = loading;
}, },
}, },
}; };
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
@import '@/styles/media-queries.scss'; @import '@/styles/media-queries.scss';
.widget-base { .widget-base {
position: relative; position: relative;
padding: 0.75rem 0.5rem 0.5rem 0.5rem; padding: 0.75rem 0.5rem 0.5rem 0.5rem;
background: var(--widget-base-background); background: var(--widget-base-background);
box-shadow: var(--widget-base-shadow, none); box-shadow: var(--widget-base-shadow, none);
// Refresh and full-page action buttons // Refresh and full-page action buttons
button.action-btn { button.action-btn {
height: 1rem; height: 1rem;
min-width: auto; min-width: auto;
width: 1.75rem; width: 1.75rem;
margin: 0; margin: 0;
padding: 0.1rem 0; padding: 0.1rem 0;
position: absolute; position: absolute;
top: 0; top: 0;
border: none; border: none;
opacity: var(--dimming-factor); opacity: var(--dimming-factor);
color: var(--widget-text-color); color: var(--widget-text-color);
&:hover { &:hover {
opacity: 1; opacity: 1;
color: var(--widget-background-color); color: var(--widget-background-color);
} }
&.update-btn { &.update-btn {
right: -0.25rem; right: -0.25rem;
} }
&.open-btn { &.open-btn {
right: 1.75rem; right: 1.75rem;
} }
} }
// Optional widget label // Optional widget label
.widget-label { .widget-label {
color: var(--widget-text-color); color: var(--widget-text-color);
} }
// Actual widget container // Actual widget container
.widget-wrap { .widget-wrap {
&.has-error { &.has-error {
cursor: not-allowed; cursor: not-allowed;
opacity: 0.5; opacity: 0.5;
border-radius: var(--curve-factor); border-radius: var(--curve-factor);
background: #ffff0040; background: #ffff0040;
&:hover { background: none; } &:hover { background: none; }
} }
} }
// Error message output // Error message output
.widget-error { .widget-error {
p.error-msg { p.error-msg {
color: var(--warning); color: var(--warning);
font-weight: bold; font-weight: bold;
font-size: 1rem; font-size: 1rem;
margin: 0 auto 0.5rem auto; margin: 0 auto 0.5rem auto;
} }
p.error-output { p.error-output {
font-family: var(--font-monospace); font-family: var(--font-monospace);
color: var(--widget-text-color); color: var(--widget-text-color);
font-size: 0.85rem; font-size: 0.85rem;
margin: 0.5rem auto; margin: 0.5rem auto;
} }
p.retry-link { p.retry-link {
cursor: pointer; cursor: pointer;
text-decoration: underline; text-decoration: underline;
color: var(--widget-text-color); color: var(--widget-text-color);
font-size: 0.85rem; font-size: 0.85rem;
margin: 0; margin: 0;
} }
} }
// Loading spinner // Loading spinner
.loading { .loading {
margin: 0.2rem auto; margin: 0.2rem auto;
text-align: center; text-align: center;
svg.loader { svg.loader {
width: 100px; width: 100px;
} }
} }
// Hide widget contents while loading // Hide widget contents while loading
&.is-loading { &.is-loading {
.widget-wrap { .widget-wrap {
display: none; display: none;
} }
} }
} }
</style> </style>