mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
The opened card and the minicard now draw Card Settings' sections, in
Card Settings' order, each section's fields in the order of its rows:
- Section order is per side: cardSettingsSectionOrder for the card,
the new minicardSettingsSectionOrder for the minicard. A board that
stores none: the card starts with Labels, Date, Members, Card, ...
(the card's historical order as far as the grouping allows), the
minicard with what it drew first before.
- CARD_LAYOUT's and MINICARD_LAYOUT's reorderable sections are Card
Settings' sections, so dragging a section or a row in Card Settings
moves it on the card or the minicard. Stored field orders map: a
field keeps its place relative to the others of its new section.
- On the card every section has the shared heading (its icon, title,
caret and hamburger) - Voting and Planning Poker too, which had a
heading of their own. The minicard stays compact: no headings.
Card Settings shows both sides at once: the minicard's pane first (on
the left), the card's second, each with a caret that folds it, each
scrolling on its own, stacked when the popup is too narrow for two.
The Show radio is gone. A splitter between the panes changes their
widths by dragging, like spreadsheet columns (clamped, kept per user
as a fraction, reset by a double-click, moved by the arrow keys). The
popup is wider again for two panes and its corner grip resizes it,
the panes following.
A hamburger's content opens under its line inside the pane, not in a
popup: the hamburger shows it is open (aria-expanded, highlighted, the
panel attached to it); its button, the panel's X or Escape closes it.
A custom field's edit form and the + create form open inline the same
way and close only their panel when saved. The popup layer added in
9c9742e09d is removed, as nothing uses it now.
Docs: Card-Settings.md, Card-Fields.md and Board Settings / Card.md.
New tests cardSectionsOnCard, minicardSections, cardSettingsSplit,
cardSettingsInlinePanels and card-settings-sections-order.e2e.js; the
guards of the old layouts and orders say why they changed.
Thanks to xet7 !
440 lines
19 KiB
JavaScript
440 lines
19 KiB
JavaScript
'use strict';
|
|
|
|
// Pure helpers for the card and minicard "field order" settings (#4448, and
|
|
// the per-field / per-minicard extension of it): a board may reorder what the
|
|
// opened card and the minicard show. Extracted so the ordering decision is
|
|
// unit-testable in plain Node without Meteor (mirrors
|
|
// models/lib/boardSortReorder.js).
|
|
//
|
|
// THE MODEL. Each surface (card, minicard) has a LAYOUT:
|
|
//
|
|
// head - fields drawn at a fixed place at the top (the card's title bar:
|
|
// Mark complete, number, cover) that the order cannot move;
|
|
// sections - the reorderable middle, in default order: Card Settings'
|
|
// sections (see below). The fields of a section are
|
|
// reorderable WITHIN it. `pinnedFirst` marks a section whose
|
|
// first field is its heading (Description: Title on the card) -
|
|
// that field stays first;
|
|
// tail - fields drawn at a fixed place outside the sections (the
|
|
// card's attachment count on its heading, the activities in the
|
|
// right column).
|
|
//
|
|
// What is STORED is one flat array of field keys (`board.cardFieldOrder`,
|
|
// `board.minicardFieldOrder`). `applyLayoutOrder()` turns whatever is stored -
|
|
// missing, partial, stale, unknown-containing, or one of the five LEGACY
|
|
// section keys the first version of #4448 stored - into the canonical flat
|
|
// order: head, then the sections in the order their first stored field
|
|
// appears, each section's fields in stored order with the missing ones
|
|
// appended in default order, then the tail. So the popup's list, the card
|
|
// and the minicard all read one canonical sequence and cannot disagree, and a
|
|
// board that never touched the setting renders byte-for-byte what it always
|
|
// has.
|
|
//
|
|
// THE SECTIONS ARE CARD SETTINGS' SECTIONS (2026-10-28). The reorderable
|
|
// sections of both layouts are the sections of Board Settings / Card
|
|
// (models/lib/cardSettingsSections.js), with the same ids, and each holds the
|
|
// rows of that section that have a place of their own on that surface - so a
|
|
// field is dragged in Card Settings inside its section and is drawn on the
|
|
// card and the minicard inside the same section. Where the SECTIONS go is no
|
|
// longer this file's: the opened card and the minicard draw them in the
|
|
// board's section order of that side (cardSettingsSectionOrder,
|
|
// minicardSettingsSectionOrder). The section order inside the flat array
|
|
// below is still kept canonical, but nothing draws by it any more.
|
|
//
|
|
// THE DEFAULT ORDER inside each section is the order the opened card and the
|
|
// minicard drew those fields in before (cardDetails.jade and minicard.jade as
|
|
// they were at 59f7d61df, the parent of the first field-order commit, #4448,
|
|
// 131514d61, read top to bottom), so a board that never set an order still
|
|
// draws each section's fields in the order it always drew them. Until
|
|
// 2026-10-28 the layouts' sections were the templates' own groups (the card's
|
|
// "Sort" group, the minicard's `.badges` strip ...) and the default flat order
|
|
// was those templates read top to bottom; it changed on purpose when the
|
|
// surfaces started drawing Card Settings' sections.
|
|
// tests/cardFieldOrderDefaultIsPreFeatureOrder.test.cjs pins both sequences.
|
|
//
|
|
// A stored order from before keeps meaning what it can: its field keys keep
|
|
// their relative order inside their new section, the first version's five
|
|
// LEGACY section keys and the template groups' keys the REST API spoke in
|
|
// (`dates`, `sort`, `voteAndPoker`, the minicard's `badges` ...) expand to
|
|
// their fields (`aliases`).
|
|
|
|
// ── the Scrum fields ─────────────────────────────────────────────────────────
|
|
|
|
// The rows of Board Settings / Card that show the Scrum fields ("Scrum
|
|
// settings: Sprint" ...; models/lib/cardSettingsRows.js), all in the Scrum
|
|
// section.
|
|
const SCRUM_FIELD_KEYS = ['scrumSprint', 'scrumPastSprints', 'scrumRelease', 'scrumIssueType',
|
|
'scrumAcceptanceCriteria', 'scrumBacklogRank'];
|
|
|
|
// ── the opened card ──────────────────────────────────────────────────────────
|
|
|
|
// The head is the card's title bar (Mark complete, the number, the cover
|
|
// above it): fixed, never dragged. The tail holds what has a fixed place
|
|
// outside the sections - the attachment count is on the Attachments heading,
|
|
// and the activities are the right column of every opened card.
|
|
const CARD_LAYOUT = {
|
|
head: ['dueComplete', 'cardNumber', 'cover'],
|
|
sections: [
|
|
{ key: 'labels', fields: ['labels', 'stickers', 'location'] },
|
|
{ key: 'date', fields: ['receivedDate', 'startDate', 'dueDate', 'endDate'] },
|
|
{ key: 'members', fields: ['members', 'assignee', 'creator', 'requestedBy', 'assignedBy'] },
|
|
// The old Dependencies section and the first half of "Sort", then the
|
|
// card buttons (drawn after the labels before) and the similar cards
|
|
// (drawn after the text notes before).
|
|
{ key: 'card', fields: ['dependencies', 'cardSortingByNumber', 'showLists', 'cardButtons', 'similarCards'] },
|
|
// The second half of the old "Sort" group.
|
|
{ key: 'time', fields: ['spentTime', 'flowtime', 'pomodoro'] },
|
|
{ key: 'customFields', fields: ['customFields'] },
|
|
{ key: 'vote', fields: ['vote'] },
|
|
{ key: 'poker', fields: ['poker'] },
|
|
// "Description: Title" is the section's heading, so it stays first.
|
|
{ key: 'description', fields: ['descriptionTitle', 'descriptionText'], pinnedFirst: true },
|
|
{ key: 'scrum', fields: SCRUM_FIELD_KEYS.slice() },
|
|
// The old fixed tail, now sections: the checklist count was drawn above
|
|
// the checklists.
|
|
{ key: 'checklists', fields: ['checklistCount', 'checklists'] },
|
|
{ key: 'subtasks', fields: ['subtasks'] },
|
|
{ key: 'attachments', fields: ['attachments', 'textNotes'] },
|
|
{ key: 'comments', fields: ['comments'] },
|
|
],
|
|
tail: ['attachmentCount', 'activities'],
|
|
// The first version of #4448 stored the five SECTION keys below; each
|
|
// expands to the fields that section rendered then - Members carried
|
|
// Dependencies and Sort as a fixed appendage, Custom Fields carried
|
|
// Vote/Poker - so the fields keep their relative order.
|
|
legacy: {
|
|
labels: ['labels', 'stickers', 'location'],
|
|
dates: ['receivedDate', 'startDate', 'dueDate', 'endDate'],
|
|
members: ['members', 'assignee', 'creator', 'requestedBy', 'assignedBy', 'dependencies',
|
|
'cardSortingByNumber', 'showLists', 'spentTime', 'flowtime', 'pomodoro'],
|
|
customFields: ['customFields', 'vote', 'poker'],
|
|
description: ['descriptionTitle', 'descriptionText'],
|
|
},
|
|
// The section keys of the layout before 2026-10-28 that are not keys now
|
|
// (the REST cardFieldOrder API spoke in them), each standing for its fields.
|
|
aliases: {
|
|
dates: ['receivedDate', 'startDate', 'dueDate', 'endDate'],
|
|
sort: ['cardSortingByNumber', 'showLists', 'spentTime', 'flowtime', 'pomodoro'],
|
|
voteAndPoker: ['vote', 'poker'],
|
|
},
|
|
};
|
|
|
|
// ── the minicard ─────────────────────────────────────────────────────────────
|
|
|
|
// The head is the title row and the cover drawn under it: fixed. Labels
|
|
// text, List title, Requested by's ... rows that only modify another element
|
|
// have no position (cardSettingsRows.js `after`). Inside a section the
|
|
// minicard groups what shares a container - the dates line, the badge strip
|
|
// - so the minicard stays as compact as it was (client/components/cards
|
|
// /minicard.js minicardGroups).
|
|
const MINICARD_LAYOUT = {
|
|
head: ['dueComplete', 'cardNumber', 'cover'],
|
|
sections: [
|
|
// The Scrum blocks were first; the work item type was the first badge.
|
|
{ key: 'scrum', fields: ['scrumSprint', 'scrumPastSprints', 'scrumRelease', 'scrumAcceptanceCriteria',
|
|
'scrumBacklogRank', 'scrumIssueType'] },
|
|
{ key: 'date', fields: ['receivedDate', 'startDate', 'dueDate', 'endDate'] },
|
|
// Spent time was the last of the dates line; the timers came last of all.
|
|
{ key: 'time', fields: ['spentTime', 'flowtime', 'pomodoro'] },
|
|
{ key: 'labels', fields: ['labels', 'stickers', 'location'] },
|
|
{ key: 'customFields', fields: ['customFields'] },
|
|
{ key: 'members', fields: ['assignee', 'members', 'creator', 'requestedBy', 'assignedBy'] },
|
|
{ key: 'checklists', fields: ['checklists', 'checklistCount'] },
|
|
{ key: 'card', fields: ['dependencies', 'cardSortingByNumber', 'showLists', 'swimlaneName'] },
|
|
{ key: 'comments', fields: ['commentCount', 'comments', 'activities'] },
|
|
{ key: 'vote', fields: ['vote'] },
|
|
{ key: 'poker', fields: ['poker'] },
|
|
{ key: 'attachments', fields: ['attachmentCount', 'attachments', 'textNotes'] },
|
|
{ key: 'subtasks', fields: ['subtasks'] },
|
|
{ key: 'description', fields: ['descriptionText'] },
|
|
],
|
|
tail: [],
|
|
legacy: {},
|
|
// The template groups the minicard order was made of before 2026-10-28.
|
|
aliases: {
|
|
dates: ['receivedDate', 'startDate', 'dueDate', 'endDate', 'spentTime'],
|
|
badges: ['scrumIssueType', 'dependencies', 'stickers', 'commentCount', 'vote', 'poker',
|
|
'attachmentCount', 'subtasks', 'checklistCount', 'cardSortingByNumber'],
|
|
},
|
|
};
|
|
|
|
// ── generic layout arithmetic ────────────────────────────────────────────────
|
|
|
|
function sectionOfField(layout, field) {
|
|
return layout.sections.find(s => s.fields.includes(field)) || null;
|
|
}
|
|
|
|
function defaultOrder(layout) {
|
|
return [
|
|
...layout.head,
|
|
...layout.sections.flatMap(s => s.fields),
|
|
...layout.tail,
|
|
];
|
|
}
|
|
|
|
// The canonical flat order for `stored` under `layout` (see the top of the
|
|
// file). Never throws; never drops or duplicates a known field.
|
|
function applyLayoutOrder(stored, layout) {
|
|
const allFields = new Set(defaultOrder(layout));
|
|
const entries = Array.isArray(stored) ? stored.filter(k => typeof k === 'string') : [];
|
|
// A LEGACY value is made of legacy section keys only and has one that is
|
|
// not also a field key (`dates`, `description`): `members` and
|
|
// `customFields` are both, and in a list of field keys they are fields.
|
|
const isLegacy = entries.length > 0
|
|
&& entries.every(k => layout.legacy[k])
|
|
&& entries.some(k => !allFields.has(k));
|
|
const storedFields = [];
|
|
entries.forEach(key => {
|
|
if (isLegacy) {
|
|
storedFields.push(...layout.legacy[key].filter(field => allFields.has(field)));
|
|
return;
|
|
}
|
|
if (allFields.has(key)) {
|
|
storedFields.push(key);
|
|
return;
|
|
}
|
|
// A section key (the REST cardFieldOrder API still speaks in sections)
|
|
// stands for its fields; anything else is unknown and dropped.
|
|
const section = layout.sections.find(s => s.key === key);
|
|
if (section) {
|
|
storedFields.push(...section.fields);
|
|
return;
|
|
}
|
|
// A key of the layout before 2026-10-28 (see the top of the file).
|
|
const alias = layout.aliases && layout.aliases[key];
|
|
if (alias) storedFields.push(...alias.filter(field => allFields.has(field)));
|
|
});
|
|
|
|
// Sections in the order their first stored field appears, then the rest in
|
|
// default order.
|
|
const sectionKeys = [];
|
|
storedFields.forEach(field => {
|
|
const s = sectionOfField(layout, field);
|
|
if (s && !sectionKeys.includes(s.key)) sectionKeys.push(s.key);
|
|
});
|
|
layout.sections.forEach(s => {
|
|
if (!sectionKeys.includes(s.key)) sectionKeys.push(s.key);
|
|
});
|
|
|
|
const middle = sectionKeys.flatMap(sectionKey => {
|
|
const s = layout.sections.find(x => x.key === sectionKey);
|
|
const fields = [];
|
|
storedFields.forEach(field => {
|
|
if (s.fields.includes(field) && !fields.includes(field)) fields.push(field);
|
|
});
|
|
s.fields.forEach(field => {
|
|
if (!fields.includes(field)) fields.push(field);
|
|
});
|
|
if (s.pinnedFirst) {
|
|
const first = s.fields[0];
|
|
fields.splice(fields.indexOf(first), 1);
|
|
fields.unshift(first);
|
|
}
|
|
return fields;
|
|
});
|
|
|
|
return [...layout.head, ...middle, ...layout.tail];
|
|
}
|
|
|
|
function sectionOrder(stored, layout) {
|
|
const flat = applyLayoutOrder(stored, layout);
|
|
const keys = [];
|
|
flat.forEach(field => {
|
|
const s = sectionOfField(layout, field);
|
|
if (s && !keys.includes(s.key)) keys.push(s.key);
|
|
});
|
|
return keys;
|
|
}
|
|
|
|
function fieldsOfSection(stored, layout, sectionKey) {
|
|
const s = layout.sections.find(x => x.key === sectionKey);
|
|
if (!s) return [];
|
|
return applyLayoutOrder(stored, layout).filter(field => s.fields.includes(field));
|
|
}
|
|
|
|
// Whether the up/down button of `field` does anything, for the popup to
|
|
// disable the arrows that would be no-ops. A field in the head or tail is
|
|
// fixed; the pinned header of a section moves only with its section.
|
|
function canMove(stored, layout, field, direction) {
|
|
return moveKey(stored, field, direction, layout).join(' |