Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 42 additions & 26 deletions client/components/swimlanes/swimlanes.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,36 +250,52 @@ BlazeComponent.extendComponent({
return [
{
submit(evt) {
evt.preventDefault();
const lastList = this.currentBoard.getLastList();
const titleInput = this.find('.list-name-input');
const title = titleInput.value.trim();
let sortIndex = 0
if (lastList) {
const positionInput = this.find('.list-position-input');
evt.preventDefault();
const titleInput = this.find('.list-name-input');
const title = titleInput?.value.trim();
const positionInput = this.find('.list-position-input');

let sortIndex = 0;

if (title) {
const currentBoardId = Utils.getCurrentBoardId();

if (positionInput) {
const position = positionInput.value.trim();
const ret = ReactiveCache.getList({ boardId: Utils.getCurrentBoardId(), _id: position, archived: false })
sortIndex = parseInt(JSON.stringify(ret['sort']))
sortIndex = sortIndex+1
const prevList = Lists.findOne({ _id: position, boardId: currentBoardId, archived: false });
const nextList = Lists.findOne({
boardId: currentBoardId,
archived: false,
sort: { $gt: prevList?.sort },
}, { sort: { sort: 1 } });

if (prevList) {
sortIndex = Utils.calculateIndexData(prevList, nextList).base;
} else {
const lastList = Lists.findOne({ boardId: currentBoardId }, { sort: { sort: -1 } });
sortIndex = lastList ? lastList.sort + 1 : 0;
}
} else {
sortIndex = Utils.calculateIndexData(lastList, null).base;
const lastList = Lists.findOne({ boardId: currentBoardId }, { sort: { sort: -1 } });
sortIndex = lastList ? lastList.sort + 1 : 0;
}

if (title) {
Lists.insert({
title,
boardId: Session.get('currentBoard'),
sort: sortIndex,
type: this.isListTemplatesSwimlane ? 'template-list' : 'list',
swimlaneId: this.currentBoard.isTemplatesBoard()
? this.currentSwimlane._id
: '',
});

titleInput.value = '';
titleInput.focus();
}
},
Lists.insert({
title,
boardId: currentBoardId,
sort: sortIndex,
type: this.isListTemplatesSwimlane ? 'template-list' : 'list',
swimlaneId: this.currentBoard.isTemplatesBoard()
? this.currentSwimlane._id
: '',
});

titleInput.value = '';
titleInput.focus();
}
}

,
'click .js-list-template': Popup.open('searchElement'),
},
];
Expand Down
Loading