mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
The default of CARD_LAYOUT and MINICARD_LAYOUT - what a board with no
stored cardFieldOrder / minicardFieldOrder renders, and what
applyLayoutOrder() falls back to for the keys a stored order does not
name - is now pinned literally to the render order of cardDetails.jade
and minicard.jade at 59f7d61df, the commit before #4448 made fields
orderable. Reading those templates gives exactly the sequence the layout
module already holds, so no board changes shape; the module, the tests
and the docs now say where that order comes from and a new suite pins
both sequences so a reshuffle cannot pass by reshuffling the template
with it. The two fields newer than that commit stay beside their
closest older neighbour: Text notes in the card's tail, Swimlane name
last on the minicard.
Thanks to xet7 !
349 lines
14 KiB
JavaScript
349 lines
14 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. A section is a
|
|
// group of fields that render together (the card's Dates group,
|
|
// the minicard's `.badges` strip). The fields of a section are
|
|
// reorderable WITHIN it, and the section as a whole is
|
|
// reorderable among the sections. `pinnedFirst` marks a section
|
|
// whose first field is its fold header (Labels, Members, Sort,
|
|
// Description on the card) - that field stays first;
|
|
// tail - fields drawn at a fixed place at the bottom (the card's
|
|
// checklists ... activities, which live in their own galleries
|
|
// and 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 DEFAULT ORDER of each layout - head, then the sections and their fields
|
|
// as listed, then the tail - is the order the opened card and the minicard
|
|
// rendered BEFORE fields became orderable: cardDetails.jade and minicard.jade
|
|
// as they were at 59f7d61df, the parent of the first field-order commit
|
|
// (#4448, 131514d61), read top to bottom. It is not a tidied-up order and it
|
|
// must not become one, because that default is also what every board without
|
|
// a stored order renders and what applyLayoutOrder() falls back to for the
|
|
// keys a stored order does not name. A field added since then sits beside
|
|
// its closest older neighbour (Text notes in the card's tail, Swimlane name
|
|
// last on the minicard). tests/cardFieldOrderDefaultIsPreFeatureOrder.test.cjs
|
|
// pins both sequences literally.
|
|
|
|
// ── the opened card ──────────────────────────────────────────────────────────
|
|
|
|
const CARD_LAYOUT = {
|
|
head: ['dueComplete', 'cardNumber', 'cover'],
|
|
sections: [
|
|
{ key: 'labels', fields: ['labels', 'stickers', 'location'], pinnedFirst: true },
|
|
{ key: 'dates', fields: ['receivedDate', 'startDate', 'dueDate', 'endDate'] },
|
|
{ key: 'members', fields: ['members', 'assignee', 'creator', 'requestedBy', 'assignedBy'], pinnedFirst: true },
|
|
{ key: 'dependencies', fields: ['dependencies'] },
|
|
{ key: 'sort', fields: ['cardSortingByNumber', 'showLists', 'spentTime', 'flowtime', 'pomodoro'], pinnedFirst: true },
|
|
{ key: 'customFields', fields: ['customFields'] },
|
|
{ key: 'voteAndPoker', fields: ['vote', 'poker'] },
|
|
{ key: 'description', fields: ['descriptionTitle', 'descriptionText'], pinnedFirst: true },
|
|
],
|
|
tail: ['checklists', 'checklistCount', 'subtasks', 'attachments', 'attachmentCount',
|
|
'textNotes', 'comments', 'activities'],
|
|
// The first version of #4448 stored the five SECTION keys below. They stay
|
|
// valid: each expands to the fields the section rendered then - Members
|
|
// carried Dependencies and Sort as a fixed appendage, Custom Fields carried
|
|
// Vote/Poker - so a stored `['description', 'labels', ...]` still puts
|
|
// exactly what it put where it put it.
|
|
legacy: {
|
|
labels: ['labels'],
|
|
dates: ['dates'],
|
|
members: ['members', 'dependencies', 'sort'],
|
|
customFields: ['customFields', 'voteAndPoker'],
|
|
description: ['description'],
|
|
},
|
|
};
|
|
|
|
// ── the minicard ─────────────────────────────────────────────────────────────
|
|
|
|
// Top to bottom as minicard.jade renders it. `dates` and `badges` are the
|
|
// two groups whose fields share a container (`.dates`, `.badges`); every
|
|
// other section is a single element. Labels text, List title, Requested by,
|
|
// Assigned by and Description title have Board Settings rows but no element
|
|
// of their own on the minicard (they modify another element, or are read by
|
|
// nothing there), so they have no position - see cardSettingsRows.js.
|
|
const MINICARD_LAYOUT = {
|
|
head: ['dueComplete', 'cardNumber'],
|
|
sections: [
|
|
{ key: 'dates', fields: ['receivedDate', 'startDate', 'dueDate', 'endDate', 'spentTime'] },
|
|
{ key: 'cover', fields: ['cover'] },
|
|
{ key: 'labels', fields: ['labels'] },
|
|
{ key: 'customFields', fields: ['customFields'] },
|
|
{ key: 'assignee', fields: ['assignee'] },
|
|
{ key: 'members', fields: ['members'] },
|
|
{ key: 'creator', fields: ['creator'] },
|
|
{ key: 'checklists', fields: ['checklists'] },
|
|
{ key: 'badges', fields: ['dependencies', 'stickers', 'commentCount', 'vote', 'poker',
|
|
'attachmentCount', 'subtasks', 'checklistCount', 'cardSortingByNumber'] },
|
|
{ key: 'descriptionText', fields: ['descriptionText'] },
|
|
{ key: 'comments', fields: ['comments'] },
|
|
{ key: 'showLists', fields: ['showLists'] },
|
|
{ key: 'swimlaneName', fields: ['swimlaneName'] },
|
|
],
|
|
tail: [],
|
|
legacy: {},
|
|
};
|
|
|
|
// ── 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) {
|
|
layout.legacy[key].forEach(sectionKey => {
|
|
const s = layout.sections.find(x => x.key === sectionKey);
|
|
if (s) storedFields.push(...s.fields);
|
|
});
|
|
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);
|
|
});
|
|
|
|
// 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(' |