Skip to content

Instantly share code, notes, and snippets.

@grekko
Created August 26, 2016 13:50
Show Gist options
  • Save grekko/4972ed71368928e8e3bdceed27e2c67a to your computer and use it in GitHub Desktop.
Save grekko/4972ed71368928e8e3bdceed27e2c67a to your computer and use it in GitHub Desktop.
Trello Session Planner in Trello
// SoCraTes Saturday Board
const boardId = '57c0027c35c4653ca5d1c29a';
const error = (errorMsg) => { asyncOutput(errorMsg); };
// Lists per Board
const listNames = [
"Hamburg",
"Hannover",
"Bremen",
"Berlin",
"Potsdam",
"Dortmund",
"Erfurt",
"Wiesbaden",
"Köln",
"Stuttgart",
"Düsseldorf",
"Dresden",
"Schwerin",
"München"
];
// Cards per Day
const cardsPerDay = [
{ name: "10:30 ?"},
{ name: "11:30 ?"},
{ name: "12:30 Lunch"},
{ name: "14:00 ?"},
{ name: "15:00 ?"},
{ name: "16:00 ?"},
{ name: "17:00 ?"},
];
const archiveAllLists = (boardId) => {
return new Promise((resolve, reject) => {
Trello.get('/boards/' + boardId + '/lists', (lists) => {
if(lists.length == 0) {
resolve();
}
let results = [];
lists.forEach((list) => {
Trello.put('lists/' + list.id + '/closed', { value: true }, (result) => {
results.push(result);
if(results.length == lists.length) {
resolve(results);
}
}, () => { reject(false); });
});
}, () => { reject(false); });
});
};
const createLists = (boardId, listNames) => {
return new Promise((resolve, reject) => {
let results = [];
listNames.forEach((listName) => {
Trello.post('lists', { name: listName, idBoard: boardId }, (result) => {
results.push(result);
if(results.length == listNames.length) {
resolve(results);
}
}, () => { reject("error"); });
});
});
};
const sleep = (time) => {
return new Promise((resolve) => { setTimeout(resolve, time); });
}
const createCardsForLists = (lists) => {
return Promise.all(lists.map((list) => {
return new Promise((resolve, reject) => {
cardsPerDay.reduce((promise, card) => {
return promise.then(() => {
const newCard = {
name: card.name,
due: null,
idList: list.id,
};
return new Promise((resolve, reject) => {
Trello.post('/cards/', newCard, (result) => { resolve(result); }, () => { reject(); });
});
});
}, Promise.resolve()); // Taken from: http://stackoverflow.com/a/30445733/738609
});
}));
};
archiveAllLists(boardId)
.then(() => { return createLists(boardId, listNames) })
.then((lists) => { return createCardsForLists(lists) })
.then(() => { console.log("DONE"); })
//////////////////////////////////////////////
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment