11( function ( d , w ) {
22'use strict' ;
33
4- var pointsRegEx = / ^ \( ( [ \d \. ] + ) \) ( .+ ) / i ;
4+ var pointsRegEx = / ^ ( \( ( [ \d \. ] + ) \) \s * ) ? ( .+ ? ) ( \s * \[ ( [ \d \. ] + ) \] ) ? $ / im ; // new RegExp("^(\(([\d\.]+)\))?(.+)(\[([\d\.]+)\])?$", "i"); // Was: /^\(([\d\.]+)\)(.+)/i;
55
66var debounce = function ( func , wait , immediate ) {
77 var timeout ;
@@ -18,6 +18,10 @@ var debounce = function (func, wait, immediate) {
1818 } ;
1919} ;
2020
21+ var pluralize = ( value ) => (
22+ value === 1 ? '' : 's'
23+ ) ;
24+
2125var resetStoryPointsForColumn = ( column ) => {
2226 const customElements = Array . from ( column . getElementsByClassName ( 'github-project-story-points' ) ) ;
2327 for ( let e of customElements ) {
@@ -31,15 +35,14 @@ var resetStoryPointsForColumn = (column) => {
3135 }
3236} ;
3337
34- var titleWithPoints = ( title , points ) => ( `
35- <span class="github-project-story-points counter">
36- <span style="display:none">(</span>${ points } <span style="display:none">)</span>
37- </span>
38- ${ title }
39- ` ) ;
38+ var titleWithPoints = ( title , points , spent ) => (
39+ `<span style="font-weight:bold">${ title } </span><br \>
40+ <span class="github-project-story-points counter"
41+ style="font-size:xx-small">${ spent } spent of ${ points } </span>`
42+ ) ;
4043
41- var titleWithTotalPoints = ( title , points ) => ( ` ${ title }
42- <small class="github-project-story-points">( ${ points } ${ points === 1 ? 'point' : ' points' } )</small >`
44+ var titleWithTotalPoints = ( title , points , spent ) => (
45+ ` ${ title } <span class="github-project-story-points" style="font-size:xx-small"> item ${ pluralize ( title ) } ( ${ spent } spent of ${ points } )</span >`
4346) ;
4447
4548var addStoryPointsForColumn = ( column ) => {
@@ -65,30 +68,34 @@ var addStoryPointsForColumn = (column) => {
6568 pointsRegEx . exec ( titleElement . innerText ) ||
6669 [ null , '0' , titleElement . innerText ]
6770 ) ;
68- const storyPoints = parseFloat ( story [ 1 ] ) ;
69- const storyTitle = story [ 2 ] ;
71+ const storyPoints = parseFloat ( story [ 2 ] ) || 0 ;
72+ const storyTitle = story [ 3 ] ;
73+ const spentPoints = parseFloat ( story [ 5 ] ) || 0 ;
7074 return {
7175 element : card ,
7276 titleElement,
7377 title,
7478 titleNoPoints : storyTitle ,
7579 storyPoints,
80+ spentPoints,
7681 } ;
7782 } ) ;
7883 const columnCountElement = column . getElementsByClassName ( 'js-column-card-count' ) [ 0 ] ;
79- const columnStoryPoints = columnCards . reduce ( ( acc , card ) => acc + card . storyPoints , 0 ) ;
80-
81- // Apply DOM changes
82- if ( columnStoryPoints ) {
83- columnCountElement . innerHTML = titleWithTotalPoints ( columnCards . length , columnStoryPoints ) ;
84- }
8584
85+ let columnStoryPoints = 0 ;
86+ let columnSpentPoints = 0 ;
8687 for ( let card of columnCards ) {
87- if ( card . storyPoints ) {
88+ columnStoryPoints += card . storyPoints ;
89+ columnSpentPoints += card . spentPoints ;
90+ if ( card . storyPoints || card . spentPoints ) {
8891 card . titleElement . dataset . gpspOriginalContent = card . title ;
89- card . titleElement . innerHTML = titleWithPoints ( card . titleNoPoints , card . storyPoints ) ;
92+ card . titleElement . innerHTML = titleWithPoints ( card . titleNoPoints , card . storyPoints , card . spentPoints ) ;
9093 }
9194 }
95+ // Apply DOM changes:
96+ if ( columnStoryPoints || columnSpentPoints ) {
97+ columnCountElement . innerHTML = titleWithTotalPoints ( columnCards . length , columnStoryPoints , columnSpentPoints ) ;
98+ }
9299} ;
93100
94101var resets = [ ] ;
@@ -103,7 +110,7 @@ var start = debounce(() => {
103110 const projects = d . getElementsByClassName ( 'project-columns-container' ) ;
104111 if ( projects . length > 0 ) {
105112 const project = projects [ 0 ] ;
106- const columns = Array . from ( project . getElementsByClassName ( 'col -project-custom ' ) ) ;
113+ const columns = Array . from ( project . getElementsByClassName ( 'js -project-column ' ) ) ; // Was 'col-project-custom', but that's gitenterprise; github.com is 'project-column', fortunately, both have 'js-project-column'
107114 for ( let column of columns ) {
108115 const addStoryPoints = ( ( c ) => debounce ( ( ) => {
109116 resetStoryPointsForColumn ( c ) ;
@@ -127,10 +134,11 @@ var start = debounce(() => {
127134 pointsRegEx . exec ( titleElement . innerText ) ||
128135 [ null , '0' , titleElement . innerText ]
129136 ) ;
130- const storyPoints = parseFloat ( story [ 1 ] ) ;
131- const storyTitle = story [ 2 ] ;
132- if ( storyPoints ) {
133- titleElement . innerHTML = titleWithPoints ( storyTitle , storyPoints ) ;
137+ const storyPoints = parseFloat ( story [ 2 ] ) || 0 ;
138+ const storyTitle = story [ 3 ] ;
139+ const spentPoints = parseFloat ( story [ 5 ] ) || 0 ;
140+ if ( storyPoints || spentPoints ) {
141+ titleElement . innerHTML = titleWithPoints ( storyTitle , storyPoints , spentPoints ) ;
134142 }
135143 }
136144} , 50 ) ;
0 commit comments