From f47aa07c60cccde1e8606c25a2f71a821094a45c Mon Sep 17 00:00:00 2001 From: Matthew White Date: Fri, 13 Dec 2024 12:20:30 -0500 Subject: [PATCH] Show Central version in modal --- src/components/app.vue | 34 ++++++----- src/components/central-version.vue | 75 +++++++++++++++++++++++++ src/components/navbar.vue | 7 ++- src/components/navbar/help-dropdown.vue | 5 +- src/components/selectable.vue | 13 ++++- src/main.js | 5 +- transifex/strings_en.json | 12 ++++ 7 files changed, 130 insertions(+), 21 deletions(-) create mode 100644 src/components/central-version.vue diff --git a/src/components/app.vue b/src/components/app.vue index d71310e14..b91a6b20b 100644 --- a/src/components/app.vue +++ b/src/components/app.vue @@ -45,9 +45,10 @@ import Navbar from './navbar.vue'; import useCallWait from '../composables/call-wait'; import useDisabled from '../composables/disabled'; import useFeatureFlags from '../composables/feature-flags'; +import { loadAsync } from '../util/load-async'; +import { noop } from '../util/util'; import { useRequestData } from '../request-data'; import { useSessions } from '../util/session'; -import { loadAsync } from '../util/load-async'; export default { name: 'App', @@ -73,9 +74,12 @@ export default { const { features } = useFeatureFlags(); - const { centralVersion } = useRequestData(); + const { centralVersion, createResource } = useRequestData(); + // Used to re-fetch version.txt in order to check for a version change. + const latestVersion = createResource('latestVersion'); + const { callWait } = useCallWait(); - return { visiblyLoggedIn, centralVersion, callWait, features }; + return { visiblyLoggedIn, centralVersion, latestVersion, callWait, features }; }, computed: { routerReady() { @@ -87,23 +91,28 @@ export default { }, }, created() { + setTimeout(this.requestVersion, 15000); this.callWait('checkVersion', this.checkVersion, (tries) => - (tries === 0 ? 15000 : 60000)); + (tries === 0 ? 75000 : 60000)); }, // Reset backgroundColor after each test. beforeUnmount() { document.documentElement.style.backgroundColor = ''; }, methods: { - checkVersion() { - const previousVersion = this.centralVersion.versionText; - return this.centralVersion.request({ + requestVersion() { + this.centralVersion.request({ url: '/version.txt', - clear: false, + resend: false, alert: false - }) + }).catch(noop); + }, + checkVersion() { + if (!this.centralVersion.dataExists) + return !this.centralVersion.awaitingResponse; + return this.latestVersion.request({ url: '/version.txt', alert: false }) .then(() => { - if (previousVersion == null || this.centralVersion.versionText === previousVersion) + if (this.latestVersion.data === this.centralVersion.versionText) return false; // Alert the user about the version change, then keep alerting them. @@ -116,10 +125,7 @@ export default { ); return true; }) - // This error could be the result of logout, which will cancel all - // requests. - .catch(error => - (error.response != null && error.response.status === 404)); + .catch(noop); }, hideAlertAfterClick(event) { if (this.alert.state && event.target.closest('a[target="_blank"]') != null && diff --git a/src/components/central-version.vue b/src/components/central-version.vue new file mode 100644 index 000000000..856300f97 --- /dev/null +++ b/src/components/central-version.vue @@ -0,0 +1,75 @@ + + + + + + + + +{ + "en": { + // This is the title at the top of a pop-up. It refers to the version of ODK + // Central that the user is using. + "title": "Central Version", + "shortVersion": "You are using version {version} of ODK Central.", + "longVersion": "You can find more detailed version information below:" + } +} + diff --git a/src/components/navbar.vue b/src/components/navbar.vue index f4dd8fa85..480953979 100644 --- a/src/components/navbar.vue +++ b/src/components/navbar.vue @@ -32,7 +32,7 @@ except according to the terms contained in the LICENSE file. {{ $t('analyticsNotice') }} @@ -40,6 +40,8 @@ except according to the terms contained in the LICENSE file. + + @@ -48,6 +50,7 @@ except according to the terms contained in the LICENSE file. diff --git a/src/components/selectable.vue b/src/components/selectable.vue index 7aa79de73..4270e196c 100644 --- a/src/components/selectable.vue +++ b/src/components/selectable.vue @@ -10,7 +10,7 @@ including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file. --> @@ -18,6 +18,10 @@ except according to the terms contained in the LICENSE file.