From 73ad8c7363179f8f9062e8e65578169d07f58687 Mon Sep 17 00:00:00 2001 From: Jason Thomas Date: Wed, 8 Jan 2025 13:14:08 -0700 Subject: [PATCH] Make news feed a setting --- .../src/services/openc3Api.js | 4 + .../src/tools/admin/tabs/SettingsTab.vue | 4 + .../admin/tabs/settings/NewsFeedSettings.vue | 80 +++++++++++++ .../tabs/settings/SuppressedSettings.vue | 2 +- .../src/tools/admin/tabs/settings/settings.js | 2 +- .../src/tools/base/UserMenu.vue | 108 +++++++++--------- openc3/lib/openc3/api/settings_api.rb | 30 ++++- .../microservices/periodic_microservice.rb | 38 +++--- .../migrations/20250108060000_news_feed.rb | 18 +++ openc3/lib/openc3/models/news_model.rb | 4 +- openc3/lib/openc3/models/scope_model.rb | 2 + 11 files changed, 217 insertions(+), 75 deletions(-) create mode 100644 openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/admin/tabs/settings/NewsFeedSettings.vue create mode 100644 openc3/lib/openc3/migrations/20250108060000_news_feed.rb diff --git a/openc3-cosmos-init/plugins/packages/openc3-js-common/src/services/openc3Api.js b/openc3-cosmos-init/plugins/packages/openc3-js-common/src/services/openc3Api.js index f2512a95d2..ad53d7c2a5 100644 --- a/openc3-cosmos-init/plugins/packages/openc3-js-common/src/services/openc3Api.js +++ b/openc3-cosmos-init/plugins/packages/openc3-js-common/src/services/openc3Api.js @@ -683,6 +683,10 @@ export default class OpenC3Api { return this.exec('set_setting', [name, data]) } + update_news() { + return this.exec('update_news', []) + } + // DEPRECATED for set_setting save_setting(name, data) { return this.exec('set_setting', [name, data]) diff --git a/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/admin/tabs/SettingsTab.vue b/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/admin/tabs/SettingsTab.vue index af93340257..95dc6eb0e0 100644 --- a/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/admin/tabs/SettingsTab.vue +++ b/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/admin/tabs/SettingsTab.vue @@ -26,6 +26,8 @@ + + @@ -44,6 +46,7 @@ import DefaultConfigSettings from './settings/DefaultConfigSettings.vue' import AstroSettings from './settings/AstroSettings.vue' import ClassificationBannerSettings from './settings/ClassificationBannerSettings.vue' import TimeZoneSettings from './settings/TimeZoneSettings.vue' +import NewsFeedSettings from './settings/NewsFeedSettings.vue' import SubtitleSettings from './settings/SubtitleSettings.vue' import SourceCodeSettings from './settings/SourceCodeSettings.vue' import RubyGemsSettings from './settings/RubyGemsSettings.vue' @@ -56,6 +59,7 @@ export default { AstroSettings, ClassificationBannerSettings, TimeZoneSettings, + NewsFeedSettings, SubtitleSettings, SourceCodeSettings, RubyGemsSettings, diff --git a/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/admin/tabs/settings/NewsFeedSettings.vue b/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/admin/tabs/settings/NewsFeedSettings.vue new file mode 100644 index 0000000000..b10df89698 --- /dev/null +++ b/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/admin/tabs/settings/NewsFeedSettings.vue @@ -0,0 +1,80 @@ + + + + + diff --git a/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/admin/tabs/settings/SuppressedSettings.vue b/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/admin/tabs/settings/SuppressedSettings.vue index 3ce45a704a..6074477eb1 100644 --- a/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/admin/tabs/settings/SuppressedSettings.vue +++ b/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/admin/tabs/settings/SuppressedSettings.vue @@ -27,7 +27,7 @@ { diff --git a/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/base/UserMenu.vue b/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/base/UserMenu.vue index 82ba9ac416..501cf618b8 100644 --- a/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/base/UserMenu.vue +++ b/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/base/UserMenu.vue @@ -75,35 +75,39 @@ COSMOS Enterprise Edition -
- COSMOS News - +
+ + COSMOS News + + + Refresh + + + + + +
- - - import { Api } from '@openc3/js-common/services' +import { OpenC3Api } from '@openc3/js-common/services' import { UpgradeToEnterpriseDialog } from '@/components' export default { @@ -130,6 +135,7 @@ export default { data: function () { let user = OpenC3Auth.user() return { + api: new OpenC3Api(), showUserMenu: false, authenticated: !!localStorage.openc3Token, name: user['name'], @@ -137,7 +143,7 @@ export default { username: user['preferred_username'], showUpgradeToEnterpriseDialog: false, activeUsers: ['None'], - displayNews: true, + newsFeed: false, news: [], } }, @@ -147,9 +153,6 @@ export default { }, }, watch: { - displayNews: function (newValue, oldValue) { - localStorage.displayNews = newValue - }, // Whenever we show the user menu, read the news and refresh the list of active users showUserMenu: function (newValue, oldValue) { if (newValue === true) { @@ -172,15 +175,30 @@ export default { }, }, created: function () { - if (localStorage.displayNews) { - this.displayNews = localStorage.displayNews === 'true' - } - this.fetchNews() - // Every hour fetch news from the backend - // Note: the backend updates from news.openc3.org every 12 hours - setInterval(this.fetchNews, 60 * 60 * 1000) + this.api + .get_setting('news_feed') + .then((response) => { + if (response) { + this.newsFeed = response + if (this.newsFeed) { + this.fetchNews() + // Every hour fetch news from the backend + // Note: the backend updates from news.openc3.org every 12 hours + setInterval(this.fetchNews, 60 * 60 * 1000) + } + } + }) + .catch((error) => { + // Do nothing + }) }, methods: { + refreshNews() { + // Force the backend to update the news feed + this.api.update_news().then(() => { + this.fetchNews() + }) + }, formatDate(date) { // Just show the YYYY-MM-DD part of the date return date.split('T')[0] @@ -227,14 +245,6 @@ export default { } -