From dbba45e67e7e25d4e63b830fff15cdc71b2e4be1 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 4 Feb 2021 16:23:26 +0100 Subject: [PATCH] Don't remove both kanban items when a duplicate is deleted --- www/kanban/inner.js | 13 +++++++++++-- www/kanban/jkanban_cp.js | 22 +++++++++++++++++----- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/www/kanban/inner.js b/www/kanban/inner.js index 8344a4b26..e9c4e30b8 100644 --- a/www/kanban/inner.js +++ b/www/kanban/inner.js @@ -145,7 +145,7 @@ define([ }; var _updateBoardsThrottle = Util.throttle(_updateBoards, 1000); var updateBoards = function (framework, kanban, boards) { - if ((now() - _lastUpdate) > 5000) { + if ((now() - _lastUpdate) > 5000 || framework.isLocked()) { _updateBoards(framework, kanban, boards); return; } @@ -1207,8 +1207,17 @@ define([ var items = boards.items || {}; var data = boards.data || {}; var list = boards.list || []; + + // Remove duplicate boards + list = boards.list = Util.deduplicateString(list); + Object.keys(data).forEach(function (id) { - if (list.indexOf(Number(id)) === -1) { delete data[id]; } + if (list.indexOf(Number(id)) === -1) { + list.push(Number(id)); + } + // Remove duplicate items + var b = data[id]; + b.item = Util.deduplicateString(b.item || []); }); Object.keys(items).forEach(function (eid) { var exists = Object.keys(data).some(function (id) { diff --git a/www/kanban/jkanban_cp.js b/www/kanban/jkanban_cp.js index 56dcfaa60..742fbc379 100644 --- a/www/kanban/jkanban_cp.js +++ b/www/kanban/jkanban_cp.js @@ -299,7 +299,9 @@ define([ // Move to trash? if (target.classList.contains('kanban-trash')) { list.splice(index1, 1); - delete self.options.boards.data[id]; + if (list.indexOf(id) === -1) { + delete self.options.boards.data[id]; + } self.onChange(); return; } @@ -444,6 +446,14 @@ define([ }); return res; }; + this.checkItem = function (eid) { + var boards = self.options.boards; + var data = boards.data || {}; + var exists = Object.keys(data).some(function (id) { + return (data[id].item || []).indexOf(Number(eid)) !== -1; + }); + return exists; + }; this.moveItem = function (eid, board, pos) { var boards = self.options.boards; var same = -1; @@ -453,11 +463,13 @@ define([ obj.board.item.splice(obj.pos, 1); if (obj.board === board) { same = obj.pos; } }); - // If it's a deletion, remove the item data + // If it's a deletion and not a duplicate, remove the item data if (!board) { - delete boards.items[eid]; - delete self.cache[eid]; - removeUnusedTags(boards); + if (!self.checkItem(eid)) { + delete boards.items[eid]; + delete self.cache[eid]; + removeUnusedTags(boards); + } self.options.refresh(); return; }