Created
February 6, 2020 13:58
-
-
Save afmicc/4cb166f9609d10caa7295cf973a0a3e8 to your computer and use it in GitHub Desktop.
Trello - Show card count and sum story point and spends hours
This file contains 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
// template: Create User - Facebook login - [1sp] [5hs] | |
const listTitlesSelector = '.list-header-num-cards.js-num-cards'; | |
const cardTitlesSelector = '.list-card-title.js-card-name'; | |
const storyPointRegex = /\d+(?=[sp SP])/; | |
const spentHourRegex = /\d+(?=[hs HS hr HR])/; | |
const listHeaderSummaryClass = 'list-header-summary'; | |
const listHeaderSummarySelector = `.${listHeaderSummaryClass}`; | |
const showCardCount = () => document.querySelectorAll(listTitlesSelector).forEach(title => title.classList.remove('hide')); | |
const showSummary = () => { | |
let columns = Array.from(document.querySelectorAll(cardTitlesSelector)) | |
.reduce((accumulator, titleContainer) => { | |
const title = titleContainer.innerText && titleContainer.innerText.split('-').map(v => v.trim()); | |
if (title.length == 3) { | |
const flow = title[0], | |
card = title[1], | |
values = title[2].split(' '); | |
const storyPoints = values[0].match(storyPointRegex), | |
spentHours = values[1].match(spentHourRegex); | |
const listConteiner = titleContainer.closest('.list.js-list-content'); | |
const headerContainer = listConteiner.querySelector('.list-header-name.mod-list-name.js-list-name-input') | |
const header = headerContainer && headerContainer.value | |
let column = { | |
header: header, | |
headerContainer: headerContainer, | |
storyPoints: (storyPoints && storyPoints[0]) || 0, | |
spentHours: (spentHours && spentHours[0]) || 0 | |
}; | |
accumulator.push(column); | |
} | |
return accumulator; | |
}, []); | |
const summary = columns.reduce((accumulator, currentValue) => { | |
let item = accumulator.find(e => e.header == currentValue.header); | |
if (!item) | |
{ | |
item = { | |
header: currentValue.header, | |
headerContainer: currentValue.headerContainer, | |
storyPoints: 0, | |
spentHours: 0 | |
}; | |
accumulator.push(item); | |
} | |
item.storyPoints += +currentValue.storyPoints; | |
item.spentHours += +currentValue.spentHours; | |
return accumulator; | |
}, []); | |
summary.forEach(item => { | |
let tag = document.createElement('p'); | |
tag.innerText = `${item.storyPoints}sp | ${item.spentHours}hs`; | |
tag.style.cssText = 'float: right;'; | |
tag.classList = `list-header-num-cards js-num-cards ${listHeaderSummaryClass}`, | |
item.headerContainer.parentNode.append(tag) | |
}); | |
}; | |
const cleanSummary = () => document.querySelectorAll(listHeaderSummarySelector).forEach(e => e.parentNode.removeChild(e));; | |
const setupAgile = () => { | |
showCardCount(); cleanSummary(); showSummary(); | |
}; | |
const setEvent = () => document.querySelectorAll(cardTitlesSelector).forEach(e => e.addEventListener('change', setupAgile())); | |
setupAgile(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment