Files
wekan/client/components/settings/tablePage.js
T
Lauri Ojansivu dce2898382 Attachments: soft delete on the card, restore from the card history, hard delete only with the archived board.
Delete on an attachment used to remove the document and its file at once.
It is now the 'attachments.softDelete' method (History.md section 12): the
document gets deletedAt/deletedBy/deleteBatchId with the same helpers lists
use, the file is kept, and the card's cover is unset if this was it. Every
card-facing read - the opened card's gallery and "Attachments (N)" count,
the minicard paperclip badge, the slideshow, the cover, the board-background
picker, My Attachments, the API list endpoints and the exporters - filters
to live attachments with liveAttachments(); the publications keep sending
the deleted ones so the card history can reach them.

The card history records who deleted it and when, with the filename in the
row. Restore - the table's selection + Restore, or the row's own Restore
button, both through changeHistory.restore and applyAttachmentContent -
clears the mark, so the card, its count and the minicard badge include the
attachment again; the cover is never re-set. An attachment row previews
with the existing attachmentViewer slideshow and downloads with the same
link the gallery draws, and never offers cover or background. Uploads and
renames are recorded through the existing history hooks.

There is no per-attachment hard delete any more: api.attachment.delete,
DELETE /api/attachment/delete/:id and removeBoardBackground soft-delete,
permanentlyDeleteAttachmentFromFilesReport and the Files report's delete
button are gone, Attachments.allow remove and onBeforeRemove refuse every
client remove and log the attempt under Admin Panel / Problems. The one
hard delete is Admin Panel / Problems / Delete enabled, board archived,
board deleted from the archive: boardRemover now removes every attachment
of the board, live and soft-deleted, with its file.

One new i18n key, attachment-soft-delete-pop, replaces the "permanent, no
undo" confirmation text; it is inserted in English into every locale at
the same position for translation.

Thanks to xet7 !
2026-09-11 21:17:33 +03:00

125 lines
5.4 KiB
JavaScript

import { ReactiveVar } from 'meteor/reactive-var';
import { TAPi18n } from '/imports/i18n';
import { selectedMapProvider } from '/client/components/main/mapProvider';
import { openAttachmentSlideshow } from '/client/components/cards/attachments';
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);
}
},
'click .js-table-page-attachment-preview'(event, tmpl) {
event.preventDefault();
event.stopPropagation();
const attachmentId = event.currentTarget.getAttribute('data-attachment-id');
if (!attachmentId) return;
const attachmentIds = tmpl.findAll('.js-table-page-attachment-preview')
.map(element => element.getAttribute('data-attachment-id'))
.filter((id, index, ids) => id && ids.indexOf(id) === index);
openAttachmentSlideshow(attachmentId, attachmentIds);
},
'click .js-table-page-attachment-download'(event) {
event.stopPropagation();
},
// No per-attachment delete here (History.md §12.3): the Files report lists
// attachments, and the only way an attachment is ever removed is deleting an
// archived board with Admin Panel / Problems / Delete enabled.
// 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'));
});
},
});