Files
wekan/models/lib/originalPositions.js
T
Lauri Ojansivu b9e28a8fbb Original positions: a right-sidebar view from the board menu, in every language.
Where each swimlane, list and card was put when it was made has been
recorded on creation for a long time, and shown by nothing: the two
templates for it were drawn nowhere, every string was English and they
printed raw ids, and the client helpers beside them were never called.

Board menu → Original positions (after Archive, open to everyone who sees
the board) opens originalPositionsSidebar: Swimlanes, Lists and Cards, each
by the name it has now, Moved when it is no longer where it was put, where
it was put by the names those have now, the title it was made with when that
changed, and when. The server already narrows the history to what the
reader may see, assigned-only roles included.

The text is existing translation keys plus one new one, original-positions,
translated into every language. models/lib/originalPositions.js builds the
groups and is tested without Meteor; the old templates, the per-item
component and the uncalled helpers are removed, and the design page is now
the feature's guide.

Thanks to xet7 !
2026-10-17 01:23:15 +03:00

63 lines
2.6 KiB
JavaScript

'use strict';
// Board menu → Original positions, the pure half: turn the board's position
// history (models/positionHistory.js, one row per swimlane, list and card,
// written when it was made) into the three groups the sidebar shows, each row
// with the name the thing has NOW, where it was put, its first title when that
// differs, and whether it has moved since. Everything that needs Meteor is
// passed in, so tests/originalPositions.test.cjs runs it as it is.
const GROUPS = [
{ type: 'swimlane', labelKey: 'swimlanes', icon: 'fa-bars' },
{ type: 'list', labelKey: 'lists', icon: 'fa-columns' },
{ type: 'card', labelKey: 'cards', icon: 'fa-sticky-note' },
];
function hasMoved(type, entry, now) {
if (!now) return false;
const was = entry.originalPosition || {};
if (Number.isFinite(was.sort) && Number.isFinite(now.sort) && was.sort !== now.sort) return true;
if (type !== 'swimlane' && entry.originalSwimlaneId && now.swimlaneId && entry.originalSwimlaneId !== now.swimlaneId) return true;
if (type === 'card' && entry.originalListId && now.listId && entry.originalListId !== now.listId) return true;
return false;
}
// "List: Doing · Swimlane: Default" - by the names those have now.
function originalPlace(type, entry, { titleOf, label }) {
const parts = [];
if (type === 'card' && entry.originalListId) {
const name = titleOf('list', entry.originalListId);
if (name) parts.push(`${label('list')}: ${name}`);
}
if (type !== 'swimlane' && entry.originalSwimlaneId) {
const name = titleOf('swimlane', entry.originalSwimlaneId);
if (name) parts.push(`${label('swimlane')}: ${name}`);
}
return parts.join(' · ');
}
function originalPositionGroups(history, deps) {
const rows = Array.isArray(history) ? history : [];
return GROUPS.map(group => ({
...group,
items: rows.filter(entry => entry && entry.entityType === group.type).map(entry => {
const now = deps.current(group.type, entry.entityId);
const first = entry.originalTitle || (entry.originalPosition && entry.originalPosition.title) || '';
const title = (now && now.title) || first;
return {
id: entry.entityId,
title,
originalTitle: first && first !== title ? first : '',
originalPlace: originalPlace(group.type, entry, deps),
moved: hasMoved(group.type, entry, now),
// A thing that no longer exists (deleted, or not loaded) is shown by
// its first title, never as "moved".
exists: !!now,
createdAt: entry.createdAt ? deps.formatDate(entry.createdAt) : '',
};
}),
})).filter(group => group.items.length);
}
module.exports = { originalPositionGroups, hasMoved };