From 2e81605c95fb948613e5f8fc5c64cd1e2097a88a Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 28 Feb 2020 15:43:01 +0100 Subject: [PATCH] New kanban structure with drag&drop support --- www/kanban/inner.js | 72 ++++++++------- www/kanban/jkanban.js | 201 +++++++++++++++++++----------------------- 2 files changed, 131 insertions(+), 142 deletions(-) diff --git a/www/kanban/inner.js b/www/kanban/inner.js index 621d56cae..c764927bc 100644 --- a/www/kanban/inner.js +++ b/www/kanban/inner.js @@ -39,9 +39,8 @@ define([ $container.find('.kanban-remove-item').remove(); $container.find('.kanban-board .kanban-item').each(function (i, el) { var pos = kanban.findElementPosition(el); - var board = kanban.options.boards.find(function (b) { - return b.id === $(el.parentNode.parentNode).attr('data-id'); - }); + var boards = kanban.options.boards; + var board = boards.data[$(el.parentNode.parentNode).attr('data-id')]; $('' - headerBoard.appendChild(btn); - __onButtonClickHandler(btn, board.id); - } + //__onColorClickHandler(headerBoard, "board"); // XXX color + + // add button to the board + /* // XXX delete board button ==> removed + var btn = document.createElement("BUTTON"); + btn.setAttribute("class", "kanban-title-button btn btn-default btn-xs fa fa-times"); + headerBoard.appendChild(btn); + __onButtonClickHandler(btn, board.id); + */ + //content board var contentBoard = document.createElement('main'); contentBoard.classList.add('kanban-drag'); //add drag to array for dragula self.boardContainer.push(contentBoard); - for (var itemkey in board.item) { + (board.item || []).forEach(function (itemkey) { //create item - var itemKanban = board.item[itemkey]; + var itemKanban = boards.items[itemkey]; + if (!itemKanban) { return; } // XXX clean invalid data var nodeItem = document.createElement('div'); nodeItem.classList.add('kanban-item'); nodeItem.dataset.eid = itemKanban.id; @@ -387,24 +362,32 @@ nodeItemText.dropfn = itemKanban.drop; //add click handler of item __onclickHandler(nodeItemText); + /* + // XXX color handle color differently if (itemKanban.color !== '' && itemKanban.color !== undefined) { - jscolorL = new jscolor(nodeItem,{showOnClick: false, valueElement:undefined}); - jscolorL.fromString(itemKanban.color); - } - __onColorClickHandler(nodeItem, "item"); + jscolorL = new jscolor(nodeItem,{ + showOnClick: false, valueElement:undefined + }); + jscolorL.fromString(itemKanban.color); + }*/ + //__onColorClickHandler(nodeItem, "item"); // XXX color contentBoard.appendChild(nodeItem); - } + }); + //footer board + var footerBoard = document.createElement('footer'); + footerBoard.classList.add('kanban-board-footer'); //add button var addBoardItem = document.createElement('button'); $(addBoardItem).addClass("kanban-title-button btn btn-default fa fa-plus"); - headerBoard.appendChild(addBoardItem); + footerBoard.appendChild(addBoardItem); __onAddItemClickHandler(addBoardItem); //board assembly boardNode.appendChild(headerBoard); boardNode.appendChild(contentBoard); + boardNode.appendChild(footerBoard); //board add self.container.appendChild(boardNode); } @@ -416,12 +399,16 @@ } this.setBoards = function (boards) { - self.element - for (var boardkey in this.options.boards) { - var board = this.options.boards[boardkey]; - this.removeBoard(board.id); + //self.element + for (var boardkey in this.options.boards.list) { + //var board = this.options.boards[boardkey]; + this.removeBoard(boardKey); } - this.options.boards = []; + this.options.boards = { + list: [], + data: boards.data || {}, + items: boards.items || {} + }; this.addBoards(boards); } @@ -508,13 +495,13 @@ var addBoard = document.createElement('div'); addBoard.id = 'kanban-addboard'; addBoard.setAttribute('class', 'fa fa-plus'); + boardContainer.appendChild(addBoard); self.container = boardContainer; //add boards self.addBoards(self.options.boards); //appends to container self.element.appendChild(boardContainerOuter); - self.element.appendChild(addBoard); // send event that board has changed self.onChange(); @@ -571,13 +558,7 @@ } function __findBoardJSON(id) { - var el = [] - self.options.boards.map(function (board) { - if (board.id === id) { - return el.push(board) - } - }) - return el[0] + return (self.options.boards.data || {})[id]; }