From 6e2120eb2c32227ac7c868f65cc4fd7db0b9cf66 Mon Sep 17 00:00:00 2001 From: Onilton Maciel Date: Sat, 21 Feb 2015 20:46:45 -0200 Subject: [PATCH] Card points are now updated when points are assigned to checklist items Heavily inspired by the pull request #22: https://github.com/Q42/TrelloScrum/pull/22 But a LOT of changes were necessary to make it work with current trunk. --- trelloscrum.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/trelloscrum.js b/trelloscrum.js index ba0e6f1..50db7be 100644 --- a/trelloscrum.js +++ b/trelloscrum.js @@ -757,6 +757,9 @@ function showPointPickerChecklist(location) { // then click our button so it all gets saved away $(".checklist-item-details .edit .js-save-edit").click(); + // updates points of a card based on all checklists items + updateCardTitle(); + return false })) @@ -778,11 +781,63 @@ function showPointPickerChecklist(location) { // then click our button so it all gets saved away $(".checklist-item-details .edit .js-save-edit").click(); + // updates points of a card based on all checklists items + updateCardTitle(); + return false })) }; +function updateCardTitle() +{ + // timeout to allow enough time for checklist item title to update + setTimeout(function() { + var $currentTitle = $('.window-title .window-title-text'); + var titleText = $currentTitle.text(); + var $title = $('.card-detail-title .edit textarea'); + $(".card-detail-title").addClass("editing"); + + var totals = calculateCheckListPoints(); + var newTitleValue = titleText.match(reg)?titleText.replace(reg, '('+totals.estimateTotal+') '):'('+totals.estimateTotal+') ' + titleText; + newTitleValue = newTitleValue.match(regC)?newTitleValue.replace(regC, ' ['+totals.consumedTotal+']'):newTitleValue + ' ['+totals.consumedTotal+']'; + $title[0].value = newTitleValue; + + // add edit button to card title edit controls + $('
').appendTo('.card-detail-title .edit'); + $('').appendTo('.card-detail-title .edit-controls'); + + // then click our button so it all gets saved away + $(".card-detail-title .edit .js-save-edit").click(); + }, 500); + + return true; +} + +function calculateCheckListPoints() +{ + var $checkListItem = $('.checklist-list .checklist .checklist-items-list .checklist-item .checklist-item-details .checklist-item-details-text'); + var estimateTotal = 0; + var consumedTotal = 0; + for (var i in _pointSeq) + { + console.log("text = " + $checkListItem.eq(i).text()); + var estimateParsed = $checkListItem.eq(i).text().match(reg); + var consumedParsed = $checkListItem.eq(i).text().match(regC); + console.log("parsed = " + estimateParsed); + var estimatePoints = estimateParsed?estimateParsed[2]:0; + var consumedPoints = consumedParsed?consumedParsed[2]:0; + console.log("points = " + estimatePoints); + estimateTotal += Number(estimatePoints); + consumedTotal += Number(consumedPoints); + console.log("total = " + estimateTotal); + } + + return { + estimateTotal: estimateTotal, + consumedTotal: consumedTotal + }; +} //for export var $excel_btn,$excel_dl;