wekan/client/lib/utils.js
Maxime Quandalle b3851817ec Enforce a consistent ES6 coding style
Replace the old (and broken) jshint + jscsrc by eslint and configure
it to support some of the ES6 features.

The command `eslint` currently has one error which is a bug that was
discovered by its static analysis and should be fixed (usage of a
dead object).
2015-09-03 23:12:46 +02:00

70 lines
1.9 KiB
JavaScript

Utils = {
// XXX We should remove these two methods
goBoardId(_id) {
const board = Boards.findOne(_id);
return board && FlowRouter.go('board', {
id: board._id,
slug: board.slug,
});
},
goCardId(_id) {
const card = Cards.findOne(_id);
const board = Boards.findOne(card.boardId);
return board && FlowRouter.go('card', {
cardId: card._id,
boardId: board._id,
slug: board.slug,
});
},
capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
},
getLabelIndex(boardId, labelId) {
const board = Boards.findOne(boardId);
const labels = {};
_.each(board.labels, (a, b) => {
labels[a._id] = b;
});
return {
index: labels[labelId],
key(key) {
return `labels.${labels[labelId]}.${key}`;
},
};
},
// Determine the new sort index
calculateIndex(prevCardDomElement, nextCardDomElement, nCards = 1) {
let base, increment;
// If we drop the card to an empty column
if (!prevCardDomElement && !nextCardDomElement) {
base = 0;
increment = 1;
// If we drop the card in the first position
} else if (!prevCardDomElement) {
base = Blaze.getData(nextCardDomElement).sort - 1;
increment = -1;
// If we drop the card in the last position
} else if (!nextCardDomElement) {
base = Blaze.getData(prevCardDomElement).sort + 1;
increment = 1;
}
// In the general case take the average of the previous and next element
// sort indexes.
else {
const prevSortIndex = Blaze.getData(prevCardDomElement).sort;
const nextSortIndex = Blaze.getData(nextCardDomElement).sort;
increment = (nextSortIndex - prevSortIndex) / (nCards + 1);
base = prevSortIndex + increment;
}
// XXX Return a generator that yield values instead of a base with a
// increment number.
return {
base,
increment,
};
},
};