-
Notifications
You must be signed in to change notification settings - Fork 75
Feature #774: Show message if Central version is too old #1094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
32e3fa3
a2eddf4
c7c3de0
bbfe9ca
94c1042
4713fb8
e6e554e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,17 +15,29 @@ except according to the terms contained in the LICENSE file. | |
| <span>{{ $t('title') }}</span> | ||
| </template> | ||
| <template #body> | ||
| <iframe src="https://getodk.github.io/central/news.html" :title="$t('title')"></iframe> | ||
| <iframe :src="iframeSrc" :title="$t('title')"></iframe> | ||
| </template> | ||
| </page-section> | ||
| </template> | ||
|
|
||
| <script setup> | ||
| import { computed, inject } from 'vue'; | ||
| import { useRequestData } from '../../request-data'; | ||
| import PageSection from '../page/section.vue'; | ||
|
|
||
| defineOptions({ | ||
| name: 'HomeNews' | ||
| }); | ||
|
|
||
| const { centralVersion } = useRequestData(); | ||
|
|
||
|
|
||
| const container = inject('container'); | ||
| const { i18n: globalI18n } = container; | ||
| const languageSubtag = computed(() => new Intl.Locale(globalI18n.locale).language); | ||
|
||
|
|
||
| const iframeSrc = computed(() => `https://getodk.github.io/central/news.html?version=${centralVersion.data?.currentVersion}&lang=${languageSubtag.value}`); | ||
|
||
|
|
||
| </script> | ||
|
|
||
| <style lang="scss"> | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,114 @@ | ||||||
| <!-- | ||||||
| Copyright 2024 ODK Central Developers | ||||||
| See the NOTICE file at the top-level directory of this distribution and at | ||||||
| https://github.com/getodk/central-frontend/blob/master/NOTICE. | ||||||
|
|
||||||
| This file is part of ODK Central. It is subject to the license terms in | ||||||
| the LICENSE file found in the top-level directory of this distribution and at | ||||||
| https://www.apache.org/licenses/LICENSE-2.0. No part of ODK Central, | ||||||
| including this file, may be copied, modified, propagated, or distributed | ||||||
| except according to the terms contained in the LICENSE file. | ||||||
| --> | ||||||
|
|
||||||
| <template> | ||||||
| <div v-if="showBanner" class="outdated-version-banner"> | ||||||
| <iframe :src="iframeSrc" :title="$t('title')"></iframe> | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to add a test of the value of the |
||||||
|
|
||||||
| <a class="btn btn-primary" | ||||||
| href="https://docs.getodk.org/central-upgrade/" | ||||||
| target="_blank" rel="noopener" | ||||||
|
||||||
| v-tooltip.aria-describedby="$t('instructionsToUpgradeTooltip')"> | ||||||
| {{ $t('instructionsToUpgrade') }} | ||||||
| </a> | ||||||
|
|
||||||
| <button class="btn btn-danger" | ||||||
| type="button" | ||||||
| v-tooltip.aria-describedby="$t('dismissTooltip')" | ||||||
| @click="dismiss"> | ||||||
| {{ $t('dismiss') }} | ||||||
| </button> | ||||||
| </div> | ||||||
| </template> | ||||||
|
|
||||||
| <script setup> | ||||||
| import { computed, inject } from 'vue'; | ||||||
| import { useRequestData } from '../request-data'; | ||||||
| import { useSessions } from '../util/session'; | ||||||
|
|
||||||
| const { visiblyLoggedIn } = useSessions(); | ||||||
|
||||||
|
|
||||||
| const { centralVersion, currentUser } = useRequestData(); | ||||||
|
|
||||||
| defineOptions({ | ||||||
| name: 'OutdatedVersionBanner' | ||||||
|
||||||
| }); | ||||||
|
|
||||||
| const container = inject('container'); | ||||||
| const { i18n: globalI18n } = container; | ||||||
| const languageSubtag = computed(() => new Intl.Locale(globalI18n.locale).language); | ||||||
|
||||||
|
|
||||||
| const iframeSrc = computed(() => `https://sadiqkhoja.com/central/outdated-version.html?version=${centralVersion.data?.currentVersion}&lang=${languageSubtag.value}`); | ||||||
|
|
||||||
| const showBanner = computed(() => { | ||||||
| // user is not logged in or doesn't have ability to set config (implying not an admin) | ||||||
| if (!currentUser.dataExists || !visiblyLoggedIn || !currentUser.can('config.set')) return false; | ||||||
| if (!centralVersion.dataExists) return false; | ||||||
|
|
||||||
| // User has seen the warning in the last 30 days, so don't show it again | ||||||
| // 864E5 is the number of milliseconds in a day | ||||||
| const dismissDate = currentUser.preferences?.site?.outdatedVersionWarningDismissDate; | ||||||
| if (dismissDate && centralVersion.currentDate.getTime() < (dismissDate.getTime() + (864E5 * 30))) return false; | ||||||
|
|
||||||
| // Difference between current year and Central version year is less than 2 | ||||||
| const centralVersionYear = Number(centralVersion.currentVersion.match(/^(\d{4})/)[1]); | ||||||
| const currentYear = centralVersion.currentDate.getFullYear(); | ||||||
| if (currentYear - centralVersionYear < 2) return false; | ||||||
|
|
||||||
| return true; | ||||||
| }); | ||||||
|
|
||||||
| const dismiss = () => { | ||||||
| currentUser.preferences.site.outdatedVersionWarningDismissDate = centralVersion.currentDate; | ||||||
| }; | ||||||
| </script> | ||||||
|
|
||||||
| <style lang="scss"> | ||||||
| @import '../assets/scss/variables'; | ||||||
|
|
||||||
| .outdated-version-banner { | ||||||
| background-color: $color-danger-light; | ||||||
| border: 1px solid $color-danger; | ||||||
| border-radius: 8px; | ||||||
| padding: 0 20px 20px 20px; | ||||||
| text-align: center; | ||||||
| width: 700px; | ||||||
| margin: 20px auto; | ||||||
| box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2); | ||||||
|
||||||
| box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2); | |
| box-shadow: $box-shadow-popover; |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "title": "Outdate Version", | |
| "title": "Outdated Version", |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "instructionsToUpgradeTooltip": "Click here to see the instructions to upgrade the Central", | |
| "instructionsToUpgradeTooltip": "Click here to see instructions to upgrade Central", |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,21 @@ export class SitePreferenceNormalizer extends PreferenceNormalizer { | |
| static projectSortMode(val) { | ||
| return ['alphabetical', 'latest', 'newest'].includes(val) ? val : 'latest'; | ||
| } | ||
|
|
||
| static outdatedVersionWarningDismissDate(val) { | ||
| // Frontend to Backend | ||
| if (val instanceof Date) { | ||
| return val.toISOString(); | ||
| } | ||
|
|
||
| // Backend to Frontend | ||
| const isoDateRegex = /^\d{4}-\d{2}-\d{2}([T](\d{2}:\d{2}:\d{2}(\.\d+)?Z)?)?$/; | ||
|
||
| if (typeof (val) === 'string' && isoDateRegex.test(val)) { | ||
| return new Date(val); | ||
|
||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } | ||
|
|
||
| export class ProjectPreferenceNormalizer extends PreferenceNormalizer { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -151,6 +151,10 @@ const loaders = new Map() | |||||
| /* webpackChunkName: "component-not-found" */ | ||||||
| '../components/not-found.vue' | ||||||
| ))) | ||||||
| .set('OutdatedVersion', loader(() => import( | ||||||
| /* webpackChunkName: "component-not-found" */ | ||||||
|
||||||
| /* webpackChunkName: "component-not-found" */ | |
| /* webpackChunkName: "component-outdated-version" */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that
srcis dynamic, how about adding a test of it?