Last active
October 1, 2015 09:29
-
-
Save munckymagik/d3d28bab2b6c38e1ea1b to your computer and use it in GitHub Desktop.
An ES6 snippet to total up estimates embedded in Trello cards
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Paste this into the Chrome Dev Console when on a Trello board | |
// Estimates are expected to be integers wrapped in square brackets at the start of the card name e.g. | |
// "[2] as a developer I want a way to total estimates on Trello cards so I can keep stats" | |
(() => { | |
'use strict' | |
class Card { | |
static all($scopeElem) { | |
return Array.from($scopeElem.querySelectorAll('.list-card')).map(($elem) => { | |
return new Card($elem) | |
}) | |
} | |
constructor($elem) { | |
this.$elem = $elem | |
} | |
get name() { | |
return this.$elem.querySelector('.list-card-title').childNodes[1].textContent | |
} | |
get estimate() { | |
let estimateRegex = /^\[(\d+)\]/ | |
let match = this.name.match(estimateRegex) | |
return (match instanceof Array) ? Number(match[1]) : null | |
} | |
} | |
class List { | |
static all() { | |
return Array.from(document.querySelectorAll('.list')).map(($elem) => { | |
return new List($elem) | |
}) | |
} | |
constructor($elem) { | |
this.$elem = $elem | |
} | |
get name() { | |
return this.$elem.querySelector('.list-header-name').innerHTML | |
} | |
get cards() { | |
return Card.all(this.$elem) | |
} | |
get totalPoints() { | |
return this.cards.map(card => card.estimate) | |
.filter(estimate => estimate !== null) | |
.reduce((sum, value) => sum + value, 0) | |
} | |
} | |
let lists = List.all() | |
console.log(lists.map(list => `${list.totalPoints}, ${list.name}`).join("\n")) | |
console.log('Paste the following line into the Google Spreadsheet "Daily Data" sheet') | |
console.log(lists.map(list => list.totalPoints).join("\t")) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment