Files
wekan/client/components/settings/tablePage.js
T
Lauri Ojansivu ebe985d453 A location in an Admin Panel table opens a map, through the card's own chooser.
Admin Panel / Problems / Offices names the places accounts log in from -
"London", with the country's flag - and a name is only useful if it leads
somewhere. Clicking one now asks which map to open it at, from the same eleven
providers a card's location offers.

THE SAME CHOOSER, not a second one. The provider list was eleven options inside
cardDetails.jade; it is client/components/main/mapProvider.jade now, and both
callers include it. Two lists would be eleven places to add a provider instead
of one, and they would disagree the first time only one was edited. The
isMapProvider helper moves with it, so neither caller needs its own copy, and so
do its styles - they were scoped to .js-card-location-form, which stopped being
true the moment a second template used them.

What the two do NOT share is the rest. A card's popup EDITS a location - name,
address, coordinates, delete - and none of that applies to an office: its
location arrived in a CDN header, WeKan did not ask for it and cannot correct
it. So tablePageMapPopup is the map half alone: where this is, the link, the
chooser, and a save that makes the choice the default for cards too, because
profile.mapProvider is the one setting both read.

A cell is a link only when the row HAS coordinates. A city name is not a
position, and a map URL built from one would either search for the word or
invent a place, so buildRows drops a location without lat/lon and the cell stays
plain text. The link follows the selection BEFORE it is saved: choosing a
provider and finding the link still pointing at the old one reads as broken.

The handler lives on the shared table page, not on the report. That is also
where the "clicking a user opens the Edit user popup" handler goes: three
reports each had their own identical copy, because each was written where its
own page was. A Blaze event bubbles through the template hierarchy, so one
handler on tablePage reaches every report - and a report added later gets both
without being told.

Two things the guards caught, both worth naming. The popup had no title, which
in WeKan means no header and so no close button; it opens with
titleKey: 'location-open-map-at' - the phrase the chooser is already labelled
with in every language - rather than adding a key to 154 files. And a comment
between an `if` and its `else if` breaks jade nesting, which
tests/jadeCompiles.test.cjs has a negative test for; the comments sit above the
chain.

Thanks to xet7 !
2026-08-16 17:33:09 +03:00

104 lines
4.5 KiB
JavaScript

import { ReactiveVar } from 'meteor/reactive-var';
import { selectedMapProvider } from '/client/components/main/mapProvider';
const { mapLinkFor } = require('/models/lib/mapLink');
// The behaviour every table page shares, on the template that draws them all.
//
// WHY IT IS HERE. The markup lives in tablePage.jade, so a click on a cell in
// ANY report - Problems, Offices, People - happens inside this template. Three
// report templates had their own identical copy of the "clicking a user opens
// the Edit user popup" handler, because each was written where its own page
// was; a Blaze event bubbles through the template hierarchy, so one handler
// here reaches all of them and a fourth report gets it for free.
//
// What does NOT belong here is anything a page owns: search, paging and loading
// differ per report (each has its own state and its own method), so they stay
// with their page.
Template.tablePage.events({
// A user cell: the same "Edit user" popup Admin Panel / People opens, from
// whichever table the avatar or initials were clicked in.
'click .js-table-page-edit-user'(event) {
event.preventDefault();
const userId = event.currentTarget.getAttribute('data-user-id');
if (userId) {
Popup.open('editUser').call({ userId }, event);
}
},
// A location cell: which map to open it at. The cell itself stays SHORT -
// "London", with the country's flag - because the table is wide and the
// detail belongs behind the click, not in the row.
'click .js-table-page-map'(event) {
event.preventDefault();
const el = event.currentTarget;
const latitude = parseFloat(el.getAttribute('data-latitude'));
const longitude = parseFloat(el.getAttribute('data-longitude'));
if (!Number.isFinite(latitude) || !Number.isFinite(longitude)) return;
// titleKey, not a new `tablePageMapPopup-title`: a popup with no title
// renders with no header and so no close button
// (tests/popupTitles.test.cjs), and this popup IS "Open map links at" -
// the phrase the card's chooser is already labelled with, in every
// language WeKan has.
Popup.open('tablePageMap', { titleKey: 'location-open-map-at' }).call({
latitude,
longitude,
label: el.getAttribute('data-label') || '',
}, event);
},
});
// The map popup: where this is, and which map to open it at.
//
// It is the map half of the card's location popup and nothing else. A card's
// popup also EDITS the location - name, address, latitude, longitude, delete -
// and none of that applies here: an office's location arrived in a CDN header,
// WeKan did not ask for it and cannot correct it. So the two share the provider
// chooser (+mapProviderSelect) and diverge where they genuinely differ.
Template.tablePageMapPopup.onCreated(function () {
// Re-read on every change of the select, so the link below it follows the
// choice before it is saved. Choosing a provider and finding the link still
// pointing at the old one reads as a broken popup.
this.provider = new ReactiveVar(selectedMapProvider(null));
this.savedMsg = new ReactiveVar('');
});
Template.tablePageMapPopup.helpers({
label() {
return (Template.currentData() || {}).label || '';
},
coordinates() {
const data = Template.currentData() || {};
if (typeof data.latitude !== 'number' || typeof data.longitude !== 'number') return '';
// Six decimals is about 10 cm, which is more than a city-level header can
// possibly justify and still short enough to read.
return `${data.latitude.toFixed(6)}, ${data.longitude.toFixed(6)}`;
},
mapUrl() {
const data = Template.currentData() || {};
const tmpl = Template.instance();
if (typeof data.latitude !== 'number' || typeof data.longitude !== 'number') return '';
return mapLinkFor(tmpl.provider.get(), data.latitude, data.longitude);
},
savedMessage() {
return Template.instance().savedMsg.get();
},
});
Template.tablePageMapPopup.events({
'change .js-map-provider'(event, tmpl) {
tmpl.provider.set(event.currentTarget.value || 'openstreetmap');
tmpl.savedMsg.set('');
},
// Saving is optional: the link above works with the selection whether or not
// it is kept. Saving makes it the default for cards too, because it is the
// one `profile.mapProvider` both read.
'click .js-save-map-provider'(event, tmpl) {
event.preventDefault();
Meteor.call('setMapProvider', selectedMapProvider(tmpl), err => {
tmpl.savedMsg.set(TAPi18n.__(err ? 'server-error' : 'map-provider-saved'));
});
},
});