diff --git a/umap/static/umap/js/modules/caption.js b/umap/static/umap/js/modules/caption.js index 21768dde..1ec7c218 100644 --- a/umap/static/umap/js/modules/caption.js +++ b/umap/static/umap/js/modules/caption.js @@ -74,10 +74,10 @@ export default class Caption extends Utils.WithTemplate { this.addCredits() if (this._umap.properties.created_at) { const created_at = translate('created at {date}', { - date: new Date(this._umap.properties.created_at).toLocaleDateString(), + date: this._umap.createdAt.toLocaleDateString(), }) const modified_at = translate('modified at {date}', { - date: new Date(this._umap.properties.modified_at).toLocaleDateString(), + date: this._umap.modifiedAt.toLocaleDateString(), }) this.elements.dates.innerHTML = `${created_at} - ${modified_at}` } else { diff --git a/umap/static/umap/js/modules/data/layer.js b/umap/static/umap/js/modules/data/layer.js index f05b2ce3..7dc03e8f 100644 --- a/umap/static/umap/js/modules/data/layer.js +++ b/umap/static/umap/js/modules/data/layer.js @@ -220,6 +220,7 @@ export class DataLayer { this._loading = true const [geojson, response, error] = await this._umap.server.get(this._dataUrl()) if (!error) { + this._umap.modifiedAt = response.headers.get('last-modified') this.setReferenceVersion({ response, sync: false }) // FIXME: for now the _umap_options property is set dynamically from backend // And thus it's not in the geojson file in the server @@ -303,7 +304,10 @@ export class DataLayer { async getUrl(url, initialUrl) { const response = await this._umap.request.get(url) return new Promise((resolve) => { - if (response?.ok) return resolve(response.text()) + if (response?.ok) { + this._umap.modifiedAt = response.headers.get('last-modified') + return resolve(response.text()) + } Alert.error( translate('Cannot load remote data for layer "{layer}" with url "{url}"', { layer: this.getName(), diff --git a/umap/static/umap/js/modules/umap.js b/umap/static/umap/js/modules/umap.js index 51c98552..bcff5c50 100644 --- a/umap/static/umap/js/modules/umap.js +++ b/umap/static/umap/js/modules/umap.js @@ -57,6 +57,8 @@ export default class Umap { }, geojson.properties ) + this.createdAt = new Date(this.properties.created_at) + this.modifiedAt = this.properties.modified_at this.searchParams = new URLSearchParams(window.location.search) // Locale name (pt_PT, en_US…) @@ -237,6 +239,21 @@ export default class Umap { this._activeFeature = feature } + get modifiedAt() { + return this._modifiedAt + } + + set modifiedAt(at) { + if (!at) return + if (typeof at === 'string') { + at = new Date(at) + } + if (!this._modifiedAt || at > this._modifiedAt) { + console.log('set modifiedAt to', at) + this._modifiedAt = at + } + } + setPropertiesFromQueryString() { const asBoolean = (key) => { const value = this.searchParams.get(key)