wekan/client/lib/utils.js
Maxime Quandalle d5eec54c72 Start the migration from iron-router to flow-router
Motivations:

* Iron-Router foces us to use Tracker.nonreactive black magic in order
  to avoid un-necessary re-renders;
* There is a community consensus (supported by some MDG members) that
  the flow-router API is easier to reason about;
* The useraccounts now supports flow router (that was a blocking
  element when I considered the switch ~3months ago)

On the server we use the Picker router, as encouraged by the Kadira
team (which develop both Flow and Picker routers).

In the current state of things there are some bugs related to the
missing Loading architecure. Previously onRendered callback where
always called when the data the component needed was available, now
we have to handle this ourselves, which we will in a following commit.
2015-08-23 11:11:03 +02:00

62 lines
1.9 KiB
JavaScript

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