trello integration finished
This commit is contained in:
@@ -22,8 +22,6 @@ var RandomItems = React.createClass({
|
||||
ItemStore.removeChangeListener(this._onChange);
|
||||
},
|
||||
|
||||
|
||||
|
||||
getInitialState: function() {
|
||||
return {
|
||||
items: this.getRandomItems()
|
||||
@@ -34,10 +32,26 @@ var RandomItems = React.createClass({
|
||||
var NUMBER_OF_SUGGESTED_ITEMS = 8;
|
||||
var allItems = ItemStore.getItems();
|
||||
var randomIndexStart = Math.floor(Math.random() * ((allItems.models.length - NUMBER_OF_SUGGESTED_ITEMS + 1)));
|
||||
allItems.models = allItems.models.slice(randomIndexStart, randomIndexStart + NUMBER_OF_SUGGESTED_ITEMS);
|
||||
allItems.models = this.shuffle(allItems.models).slice(randomIndexStart, randomIndexStart + NUMBER_OF_SUGGESTED_ITEMS);
|
||||
return allItems;
|
||||
},
|
||||
|
||||
shuffle: function(array) {
|
||||
var currentIndex = array.length, temporaryValue, randomIndex ;
|
||||
|
||||
// While there remain elements to shuffle...
|
||||
while (0 !== currentIndex) {
|
||||
// Pick a remaining element...
|
||||
randomIndex = Math.floor(Math.random() * currentIndex);
|
||||
currentIndex -= 1;
|
||||
// And swap it with the current element.
|
||||
temporaryValue = array[currentIndex];
|
||||
array[currentIndex] = array[randomIndex];
|
||||
array[randomIndex] = temporaryValue;
|
||||
}
|
||||
return array;
|
||||
},
|
||||
|
||||
|
||||
_onChange: function () {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user