From a4d8f9d35a1a342e5eead687f1da5c103a506eba Mon Sep 17 00:00:00 2001 From: morgan craft Date: Mon, 17 Feb 2014 22:55:39 -0500 Subject: [PATCH 1/9] inserting point picker into checklist edit-controls --- trelloscrum.js | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/trelloscrum.js b/trelloscrum.js index 86b8c41..a50a3ca 100644 --- a/trelloscrum.js +++ b/trelloscrum.js @@ -138,6 +138,7 @@ var recalcListAndTotal = debounce(function($el){ var recalcTotalsObserver = new CrossBrowser.MutationObserver(function(mutations) { + console.log('recalcOberser called', mutations); // Determine if the mutation event included an ACTUAL change to the list rather than // a modification caused by this extension making an update to points, etc. (prevents // infinite recursion). @@ -168,6 +169,7 @@ var recalcTotalsObserver = new CrossBrowser.MutationObserver(function(mutations) doFullRefresh = true; } } + }); if(doFullRefresh){ @@ -176,11 +178,19 @@ var recalcTotalsObserver = new CrossBrowser.MutationObserver(function(mutations) calcListPoints(); } - $editControls = $(".card-detail-title .edit-controls"); + var $editControls = $(".card-detail-title .edit-controls"); + var $checklistEditControls = $('.checklist-item-details .edit-controls'); + if($editControls.length > 0) { showPointPicker($editControls.get(0)); } + + if($checklistEditControls.length > 0) + { + showPointPickerChecklist($checklistEditControls.get(0)); + + } }); recalcTotalsObserver.observe(document.body, obsConfig); @@ -691,7 +701,7 @@ function showPointPicker(location) { if($(location).find('.picker').length) return; var $picker = $('
', {class: "picker"}).appendTo('.card-detail-title .edit-controls'); $picker.append($('', {class: "picker-title"}).text("Estimated Points")); - + console.log('had picker? ',$picker); var estimateSequence = (S4T_SETTINGS[SETTING_NAME_ESTIMATES].replace(/ /g, '')).split(','); for (var i in estimateSequence) $picker.append($('', {class: "point-value"}).text(estimateSequence[i]).click(function(){ var value = $(this).text(); @@ -727,6 +737,30 @@ function showPointPicker(location) { })) }; +//the story point picker for checklist +function showPointPickerChecklist(location) { + var $parent = $(location).parent(); + if($(location).find('.picker').length) return; + var $picker = $('
', {class: "picker"}).appendTo('.checklist-item-details .edit-controls'); + var estimateSequence = (S4T_SETTINGS[SETTING_NAME_ESTIMATES]).split(','); + for (var i in estimateSequence) $picker.append($('', {class: "point-value"}).text(estimateSequence[i]).click(function(){ + var value = $(this).text(); + // use our parent element to locate the inner textarea + var $text = $parent.find('textarea'); + var text = $text.val(); + + // replace our new + var replaceText = text.match(reg)?text.replace(reg, '('+value+') '):'('+value+') ' + text; + $text.val(replaceText); + + // then click our button so it all gets saved away + $(".checklist-item-details .edit .js-save-edit").click(); + + return false + })) +}; + + //for export var $excel_btn,$excel_dl; From f1d1f19222911cb9745179bff31d6cb6ef08b567 Mon Sep 17 00:00:00 2001 From: Onilton Maciel Date: Sat, 21 Feb 2015 17:33:47 -0200 Subject: [PATCH 2/9] Use tab for all indents in showPointPickerChecklist --- trelloscrum.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/trelloscrum.js b/trelloscrum.js index a50a3ca..863f6e8 100644 --- a/trelloscrum.js +++ b/trelloscrum.js @@ -739,19 +739,19 @@ function showPointPicker(location) { //the story point picker for checklist function showPointPickerChecklist(location) { - var $parent = $(location).parent(); + var $parent = $(location).parent(); if($(location).find('.picker').length) return; var $picker = $('
', {class: "picker"}).appendTo('.checklist-item-details .edit-controls'); var estimateSequence = (S4T_SETTINGS[SETTING_NAME_ESTIMATES]).split(','); for (var i in estimateSequence) $picker.append($('', {class: "point-value"}).text(estimateSequence[i]).click(function(){ var value = $(this).text(); - // use our parent element to locate the inner textarea - var $text = $parent.find('textarea'); + // use our parent element to locate the inner textarea + var $text = $parent.find('textarea'); var text = $text.val(); // replace our new var replaceText = text.match(reg)?text.replace(reg, '('+value+') '):'('+value+') ' + text; - $text.val(replaceText); + $text.val(replaceText); // then click our button so it all gets saved away $(".checklist-item-details .edit .js-save-edit").click(); From 1f1261af2231d25e993b3be064fc94711fce0d8a Mon Sep 17 00:00:00 2001 From: Onilton Maciel Date: Sat, 21 Feb 2015 17:52:50 -0200 Subject: [PATCH 3/9] Show estimated and consumed points for showPointPickerChecklist --- trelloscrum.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/trelloscrum.js b/trelloscrum.js index 863f6e8..c413d29 100644 --- a/trelloscrum.js +++ b/trelloscrum.js @@ -742,6 +742,8 @@ function showPointPickerChecklist(location) { var $parent = $(location).parent(); if($(location).find('.picker').length) return; var $picker = $('
', {class: "picker"}).appendTo('.checklist-item-details .edit-controls'); + $picker.append($('', {class: "picker-title"}).text("Estimated Points")); + var estimateSequence = (S4T_SETTINGS[SETTING_NAME_ESTIMATES]).split(','); for (var i in estimateSequence) $picker.append($('', {class: "point-value"}).text(estimateSequence[i]).click(function(){ var value = $(this).text(); @@ -758,6 +760,27 @@ function showPointPickerChecklist(location) { return false })) + + var $parent = $(location).parent(); + if($(location).find('.picker-consumed').length) return; + var $picker = $('
', {class: "picker-consumed"}).appendTo('.checklist-item-details .edit-controls'); + $picker.append($('', {class: "picker-title"}).text("Consumed Points")); + + var estimateSequence = (S4T_SETTINGS[SETTING_NAME_ESTIMATES]).split(','); + for (var i in estimateSequence) $picker.append($('', {class: "point-value"}).text(estimateSequence[i]).click(function(){ + var value = $(this).text(); + // use our parent element to locate the inner textarea + var $text = $parent.find('textarea'); + var text = $text.val(); + + // replace our new + $text[0].value=text.match(regC)?text.replace(regC, ' ['+value+']'):text + ' ['+value+']'; + + // then click our button so it all gets saved away + $(".checklist-item-details .edit .js-save-edit").click(); + + return false + })) }; From 009495aef40a3912f8431c87112db17dbdea56a3 Mon Sep 17 00:00:00 2001 From: Onilton Maciel Date: Sat, 21 Feb 2015 17:54:38 -0200 Subject: [PATCH 4/9] Improving point replacement code --- trelloscrum.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/trelloscrum.js b/trelloscrum.js index c413d29..51de7f1 100644 --- a/trelloscrum.js +++ b/trelloscrum.js @@ -752,8 +752,7 @@ function showPointPickerChecklist(location) { var text = $text.val(); // replace our new - var replaceText = text.match(reg)?text.replace(reg, '('+value+') '):'('+value+') ' + text; - $text.val(replaceText); + $text[0].value=text.match(reg)?text.replace(reg, '('+value+') '):'('+value+') ' + text; // then click our button so it all gets saved away $(".checklist-item-details .edit .js-save-edit").click(); From d41e0093566d75fb8559bbee9b8c6c5b432819a5 Mon Sep 17 00:00:00 2001 From: Onilton Maciel Date: Sat, 21 Feb 2015 20:46:45 -0200 Subject: [PATCH 5/9] 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 51de7f1..2e62c02 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; From 6f9737a2a5446073fad75f9d4803ecfd6b7c8abd Mon Sep 17 00:00:00 2001 From: Onilton Maciel Date: Sat, 21 Feb 2015 21:02:41 -0200 Subject: [PATCH 6/9] Improving DOM nodes creation in updateCardTitle --- trelloscrum.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trelloscrum.js b/trelloscrum.js index 2e62c02..7c3dacd 100644 --- a/trelloscrum.js +++ b/trelloscrum.js @@ -803,8 +803,8 @@ function updateCardTitle() $title[0].value = newTitleValue; // add edit button to card title edit controls - $('
').appendTo('.card-detail-title .edit'); - $('').appendTo('.card-detail-title .edit-controls'); + $('
', {class: "edit-controls clearfix"}).appendTo('.card-detail-title .edit'); + $('', {class: "primary confirm js-save-edit", value: "Save"}).appendTo('.card-detail-title .edit-controls'); // then click our button so it all gets saved away $(".card-detail-title .edit .js-save-edit").click(); From b89846943e3d96b55d8a03a6bcd42e20c024777c Mon Sep 17 00:00:00 2001 From: Onilton Maciel Date: Sat, 21 Feb 2015 21:04:36 -0200 Subject: [PATCH 7/9] Cleanup: Removing development console.log commands --- trelloscrum.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/trelloscrum.js b/trelloscrum.js index 7c3dacd..ceb513b 100644 --- a/trelloscrum.js +++ b/trelloscrum.js @@ -701,7 +701,7 @@ function showPointPicker(location) { if($(location).find('.picker').length) return; var $picker = $('
', {class: "picker"}).appendTo('.card-detail-title .edit-controls'); $picker.append($('', {class: "picker-title"}).text("Estimated Points")); - console.log('had picker? ',$picker); + var estimateSequence = (S4T_SETTINGS[SETTING_NAME_ESTIMATES].replace(/ /g, '')).split(','); for (var i in estimateSequence) $picker.append($('', {class: "point-value"}).text(estimateSequence[i]).click(function(){ var value = $(this).text(); @@ -821,16 +821,14 @@ function calculateCheckListPoints() 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 { From e5709042b2d608567d3309799952bd5319b94e1b Mon Sep 17 00:00:00 2001 From: Onilton Maciel Date: Sat, 21 Feb 2015 21:23:57 -0200 Subject: [PATCH 8/9] Better name for var: consumedSequence --- trelloscrum.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trelloscrum.js b/trelloscrum.js index ceb513b..5bf78cf 100644 --- a/trelloscrum.js +++ b/trelloscrum.js @@ -768,8 +768,8 @@ function showPointPickerChecklist(location) { var $picker = $('
', {class: "picker-consumed"}).appendTo('.checklist-item-details .edit-controls'); $picker.append($('', {class: "picker-title"}).text("Consumed Points")); - var estimateSequence = (S4T_SETTINGS[SETTING_NAME_ESTIMATES]).split(','); - for (var i in estimateSequence) $picker.append($('', {class: "point-value"}).text(estimateSequence[i]).click(function(){ + var consumedSequence = (S4T_SETTINGS[SETTING_NAME_ESTIMATES]).split(','); + for (var i in consumedSequence) $picker.append($('', {class: "point-value"}).text(consumedSequence[i]).click(function(){ var value = $(this).text(); // use our parent element to locate the inner textarea var $text = $parent.find('textarea'); From b5210cb25294d8cb86596078d305ce2e30d7088d Mon Sep 17 00:00:00 2001 From: Onilton Maciel Date: Sat, 21 Feb 2015 22:43:49 -0200 Subject: [PATCH 9/9] Replacing really (really) broken for with .each This was a mistake of the original code from pull request #22. We were iterating on pointSeq (Fibonacci numbers). Actually we were iterating on the indices of this array, so we were stopping at the 9th item of the list always. Now we are iterating in all checklists items. --- trelloscrum.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/trelloscrum.js b/trelloscrum.js index 5bf78cf..56b956c 100644 --- a/trelloscrum.js +++ b/trelloscrum.js @@ -819,17 +819,17 @@ 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) - { - var estimateParsed = $checkListItem.eq(i).text().match(reg); - var consumedParsed = $checkListItem.eq(i).text().match(regC); + + $checkListItem.each(function(){ + var estimateParsed = $(this).text().match(reg); + var consumedParsed = $(this).text().match(regC); var estimatePoints = estimateParsed?estimateParsed[2]:0; var consumedPoints = consumedParsed?consumedParsed[2]:0; estimateTotal += Number(estimatePoints); consumedTotal += Number(consumedPoints); - } + }); return { estimateTotal: estimateTotal,