feat: display map's "created at" and "modified at" in the caption

This commit is contained in:
Yohan Boniface 2025-01-10 15:49:05 +01:00
parent ebae9a8cd0
commit e7fe92c070
4 changed files with 35 additions and 9 deletions

View file

@ -3,13 +3,14 @@ import * as Utils from './utils.js'
const TEMPLATE = `
<div class="umap-caption">
<hgroup>
<h3>
<div class="header">
<i class="icon icon-16 icon-caption icon-block"></i>
<span class="map-name" data-ref="name"></span>
</h3>
<hgroup>
<h3><span class="map-name" data-ref="name"></span></h3>
<h4 data-ref="author"></h4>
<h5 class="dates" data-ref="dates"></h5>
</hgroup>
</div>
<div class="umap-map-description text" data-ref="description"></div>
<div class="datalayer-container" data-ref="datalayersContainer"></div>
<div class="credits-container">
@ -65,6 +66,17 @@ export default class Caption extends Utils.WithTemplate {
// Create the legend when the panel is actually on the DOM
this._umap.eachDataLayerReverse((datalayer) => datalayer.renderLegend())
})
if (this._umap.properties.created_at) {
const created_at = translate('Created at {date}', {
date: new Date(this._umap.properties.created_at).toLocaleDateString(),
})
const modified_at = translate('Modified at {date}', {
date: new Date(this._umap.properties.modified_at).toLocaleDateString(),
})
this.elements.dates.innerHTML = `${created_at} - ${modified_at}`
} else {
this.elements.dates.hidden = true
}
}
addDataLayer(datalayer, parent) {

View file

@ -694,8 +694,14 @@ a.umap-control-caption,
.datalayer-name {
cursor: pointer;
}
.umap-caption .umap-map-author {
padding-inline-start: 31px;
.umap-caption .dates {
color: var(--color-mediumGray);
}
.umap-caption .header {
display: flex;
}
.umap-caption .header i.icon {
flex-shrink: 0;
}
.umap-browser .main-toolbox {
padding-left: 4px; /* Align with toolbox below */

View file

@ -25,6 +25,7 @@ def test_caption(live_server, page, map):
panel.locator(".caption-item .off").get_by_text(non_loaded.name)
).to_be_visible()
expect(panel.locator(".caption-item").get_by_text(hidden.name)).to_be_hidden()
expect(panel.get_by_text("Created at")).to_be_visible()
def test_caption_should_display_owner_as_author(live_server, page, map):

View file

@ -614,6 +614,13 @@ class MapDetailMixin(SessionMixin):
"defaultLabelKeys": settings.UMAP_LABEL_KEYS,
}
created = bool(getattr(self, "object", None))
if created:
properties.update(
{
"created_at": self.object.created_at,
"modified_at": self.object.modified_at,
}
)
if (created and self.object.owner) or (not created and not user.is_anonymous):
edit_statuses = Map.EDIT_STATUS
datalayer_statuses = DataLayer.EDIT_STATUS