Skip to content
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

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

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions umap/static/umap/js/modules/caption.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import * as Utils from './utils.js'

const TEMPLATE = `
<div class="umap-caption">
<hgroup>
<h3>
<i class="icon icon-16 icon-caption icon-block"></i>
<span class="map-name" data-ref="name"></span>
</h3>
<h4 data-ref="author"></h4>
</hgroup>
<div class="header">
<i class="icon icon-16 icon-caption icon-block"></i>
<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">
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 8 additions & 2 deletions umap/static/umap/map.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions umap/tests/integration/test_caption.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 7 additions & 0 deletions umap/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,13 @@ def get_map_properties(self):
"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
Expand Down
Loading