From 2075cbc222e180b8568d2eed8cced27849aa558e Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Mon, 13 Dec 2021 16:22:24 +0000 Subject: [PATCH] :sparkles: Adds refresh button to widget, for reloading data --- src/assets/interface-icons/widget-update.svg | 1 + src/components/LinkItems/Section.vue | 21 +++- src/components/Widgets/Clock.vue | 15 ++- src/components/Widgets/CryptoPriceChart.vue | 4 + src/components/Widgets/CryptoWatchList.vue | 4 + src/components/Widgets/ExchangeRates.vue | 4 + src/components/Widgets/IframeWidget.vue | 13 ++- src/components/Widgets/Jokes.vue | 4 + src/components/Widgets/StockPriceChart.vue | 4 + src/components/Widgets/TflStatus.vue | 4 + src/components/Widgets/Weather.vue | 12 +- src/components/Widgets/WeatherForecast.vue | 4 + src/components/Widgets/WidgetBase.vue | 110 ++++++++++++++++--- src/components/Widgets/WidgetError.vue | 18 +++ src/components/Widgets/XkcdComic.vue | 9 +- src/mixins/WidgetMixin.js | 21 ++++ src/styles/color-themes.scss | 3 + src/views/Home.vue | 52 +++++---- 18 files changed, 254 insertions(+), 49 deletions(-) create mode 100644 src/assets/interface-icons/widget-update.svg create mode 100644 src/components/Widgets/WidgetError.vue diff --git a/src/assets/interface-icons/widget-update.svg b/src/assets/interface-icons/widget-update.svg new file mode 100644 index 00000000..29e37fbe --- /dev/null +++ b/src/assets/interface-icons/widget-update.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/components/LinkItems/Section.vue b/src/components/LinkItems/Section.vue index 9c5a8d6f..5424bc19 100644 --- a/src/components/LinkItems/Section.vue +++ b/src/components/LinkItems/Section.vue @@ -12,11 +12,11 @@ @openContextMenu="openContextMenu" > -
+
{{ $t('home.no-items-section') }}
-
@@ -57,6 +57,14 @@ :itemSize="itemSize" />
+
+ +
import router from '@/router'; import Item from '@/components/LinkItems/Item.vue'; +import WidgetBase from '@/components/Widgets/WidgetBase'; import Collapsable from '@/components/LinkItems/Collapsable.vue'; import IframeModal from '@/components/LinkItems/IframeModal.vue'; import EditSection from '@/components/InteractiveEditor/EditSection.vue'; @@ -107,12 +116,14 @@ export default { icon: String, displayData: Object, items: Array, + widgets: Array, index: Number, }, components: { Collapsable, ContextMenu, Item, + WidgetBase, IframeModal, EditSection, }, @@ -139,6 +150,12 @@ export default { sortOrder() { return this.displayData.sortBy || defaultSortOrder; }, + /* A section can contain either items or widgets */ + sectionType() { + if (this.widgets && this.widgets.length > 0) return 'widget'; + if (this.items && this.items.length > 0) return 'item'; + return 'empty'; + }, /* If the sortBy attribute is specified, then return sorted data */ sortedItems() { let { items } = this; diff --git a/src/components/Widgets/Clock.vue b/src/components/Widgets/Clock.vue index acb89946..1e4a5d66 100644 --- a/src/components/Widgets/Clock.vue +++ b/src/components/Widgets/Clock.vue @@ -39,8 +39,12 @@ export default { }, }, methods: { + update() { + this.setTime(); + this.setDate(); + }, /* Get and format the current time */ - updateTime() { + setTime() { this.time = Intl.DateTimeFormat(this.timeFormat, { timeZone: this.timeZone, hour: 'numeric', @@ -49,7 +53,7 @@ export default { }).format(); }, /* Get and format the date */ - updateDate() { + setDate() { this.date = new Date().toLocaleDateString(this.timeFormat, { weekday: 'long', day: 'numeric', year: 'numeric', month: 'short', }); @@ -57,14 +61,13 @@ export default { }, created() { // Set initial date and time - this.updateTime(); - this.updateDate(); + this.update(); // Update the date every hour, and the time each second this.timeUpdateInterval = setInterval(() => { - this.updateTime(); + this.setTime(); const now = new Date(); if (now.getMinutes() === 0 && now.getSeconds() === 0) { - this.updateDate(); + this.setDate(); } }, 1000); }, diff --git a/src/components/Widgets/CryptoPriceChart.vue b/src/components/Widgets/CryptoPriceChart.vue index ac1e3559..e8a07bdd 100644 --- a/src/components/Widgets/CryptoPriceChart.vue +++ b/src/components/Widgets/CryptoPriceChart.vue @@ -65,6 +65,10 @@ export default { }, }, methods: { + /* Extends mixin, and updates data. Called by parent component */ + update() { + this.fetchData(); + }, /* Create new chart, using the crypto data */ generateChart() { return new Chart(`#${this.chartId}`, { diff --git a/src/components/Widgets/CryptoWatchList.vue b/src/components/Widgets/CryptoWatchList.vue index 56d6fced..47dd8adc 100644 --- a/src/components/Widgets/CryptoWatchList.vue +++ b/src/components/Widgets/CryptoWatchList.vue @@ -75,6 +75,10 @@ export default { }, }, methods: { + /* Extends mixin, and updates data. Called by parent component */ + update() { + this.fetchData(); + }, /* Make GET request to CoinGecko API endpoint */ fetchData() { axios.get(this.endpoint) diff --git a/src/components/Widgets/ExchangeRates.vue b/src/components/Widgets/ExchangeRates.vue index e0303fef..5b523e65 100644 --- a/src/components/Widgets/ExchangeRates.vue +++ b/src/components/Widgets/ExchangeRates.vue @@ -52,6 +52,10 @@ export default { }, }, methods: { + /* Extends mixin, and updates data. Called by parent component */ + update() { + this.fetchData(); + }, /* Make GET request to CoinGecko API endpoint */ fetchData() { axios.get(this.endpoint) diff --git a/src/components/Widgets/IframeWidget.vue b/src/components/Widgets/IframeWidget.vue index 7f31bf66..372f5f15 100644 --- a/src/components/Widgets/IframeWidget.vue +++ b/src/components/Widgets/IframeWidget.vue @@ -1,6 +1,6 @@