mirror of
https://github.com/wekan/wekan.git
synced 2026-11-08 03:22:32 -05:00
The Table view only listed cards. Now a member who may write gets an add row under the table - a title, a list and a swimlane - and can drag a row onto another: the dragged card goes just before the target card, in the target's list and swimlane, through the same card.move the board uses. Adding goes through tableViewAddCard, which checks that list and swimlane are on that board and not archived and that the member may write in that list, as for any card added. Rows are not draggable without the right. models/lib/tableViewDrop.js places the card; tests/tableViewDrop.test.cjs covers between, first and same-list drops, a drop onto itself, the server's checks and that only writers get the controls. Thanks to guakamole and xet7 ! Fixes #864.
21 lines
1010 B
JavaScript
21 lines
1010 B
JavaScript
'use strict';
|
|
|
|
// #864: dropping a Table view row onto another row puts the dragged card just
|
|
// before the target card, in the target's list and swimlane - between the
|
|
// target and the card before it there, or one before the target when the
|
|
// target is first. Pure: tests/tableViewDrop.test.cjs.
|
|
|
|
function tableViewDropTarget(dragged, target, cardsInTargetCell) {
|
|
if (!dragged || !target || dragged._id === target._id) return null;
|
|
const cell = (Array.isArray(cardsInTargetCell) ? cardsInTargetCell : [])
|
|
.filter(c => c && c._id !== dragged._id && Number.isFinite(c.sort))
|
|
.sort((a, b) => a.sort - b.sort);
|
|
const at = cell.findIndex(c => c._id === target._id);
|
|
const targetSort = Number.isFinite(target.sort) ? target.sort : 0;
|
|
const before = at > 0 ? cell[at - 1] : null;
|
|
const sort = before ? (before.sort + targetSort) / 2 : targetSort - 1;
|
|
return { boardId: target.boardId, swimlaneId: target.swimlaneId, listId: target.listId, sort };
|
|
}
|
|
|
|
module.exports = { tableViewDropTarget };
|