Skip to content

Commit

Permalink
Merge pull request #32 from DealerDirect/feature/developer-pain-summary
Browse files Browse the repository at this point in the history
Adds developer pain summary
  • Loading branch information
Potherca committed May 18, 2017
2 parents 374163e + 08dde4b commit e28fbd5
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 30 deletions.
12 changes: 12 additions & 0 deletions assets/css/protocols-estimating-developer-pain-criteria.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,16 @@ input.criteria__score {
top: 0;
}

.criteria__summary {
display: block;
font-size: 1em;
height: 4em;
max-width: 100%;
position: -webkit-sticky;
position: sticky;
text-align: center;
top: 15em;
width: 100%;
}

/*EOF*/
97 changes: 67 additions & 30 deletions assets/js/protocols-estimating-developer-pain-criteria.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,25 @@

'use strict';

var g_aCriteria = [], g_oPoints, g_$Score;
var g_aCriteria = [], g_oPoints, g_$Score, g_$Summary;

function addEventHandler(p_sSubject, p_oPoints, p_oCriteria, p_iCriteriaIndex) {

function getOpposite(p_sSubject) {
var sOpposite;

switch (p_sSubject) {
switch (p_sSubject) {
case 'upper':
sOpposite = 'lower';
break;
case 'lower':
sOpposite = 'upper';
break;
default:
throw new Error('Could not get opposite. Key "' + p_sSubject + '" not recognized');
break;
}

p_oCriteria[p_sSubject].addClass('criteria__selector criteria__selector--' + p_sSubject);

p_oCriteria[p_sSubject].on('click', function (/*p_oEvent*/) {
var iScoreIndex, iTotalScore, oScores, sScoreJson;

p_oCriteria[p_sSubject].addClass('criteria__selector--selected');
p_oCriteria[sOpposite].removeClass('criteria__selector--selected');

sScoreJson = g_$Score.attr('data-score');
oScores = JSON.parse(sScoreJson);

oScores[p_iCriteriaIndex] = p_oPoints[p_sSubject];

g_$Score.attr('data-score', JSON.stringify(oScores));

iTotalScore = 0;

for (iScoreIndex in oScores) {
if( oScores.hasOwnProperty(iScoreIndex)) {
iTotalScore += oScores[iScoreIndex];
}
}

g_$Score.val(Math.floor(iTotalScore) + '%');
});
return sOpposite;
}

function retrieveRows(p_iRowIndex, p_oRowElement) {
Expand Down Expand Up @@ -69,6 +49,60 @@
g_aCriteria.push(oCriteria);
}

function updateClasses(p_sSubject, p_oCriteria) {
var sOpposite;

sOpposite = getOpposite(p_sSubject);

p_oCriteria[sOpposite].removeClass('criteria__selector--selected');
p_oCriteria[p_sSubject].addClass('criteria__selector--selected');
}

function updateScore(p_oPoints, p_sSubject, p_iCriteriaIndex) {
var iScoreIndex, iTotalScore, oScores, sScoreJson;

iTotalScore = 0;

sScoreJson = g_$Score.attr('data-score');
oScores = JSON.parse(sScoreJson);
oScores[p_iCriteriaIndex] = p_oPoints[p_sSubject];
g_$Score.attr('data-score', JSON.stringify(oScores));

for (iScoreIndex in oScores) {
if (oScores.hasOwnProperty(iScoreIndex)) {
iTotalScore += oScores[iScoreIndex];
}
}

g_$Score.val(Math.floor(iTotalScore) + '%');
}

function updateSummary(p_oPoints, p_sSubject, p_oCriteria) {
var oSummary, sOpposite, sSummaryJson;

sOpposite = getOpposite(p_sSubject);

sSummaryJson = g_$Summary.attr('data-summary');
oSummary = JSON.parse(sSummaryJson);
delete oSummary[p_oCriteria[sOpposite].text()];
oSummary[p_oCriteria[p_sSubject].text()] = p_oPoints[p_sSubject];

g_$Summary.attr('data-summary', JSON.stringify(oSummary));
g_$Summary.val(JSON.stringify(oSummary));
}

function addEventHandler(p_sSubject, p_oPoints, p_oCriteria, p_iCriteriaIndex) {

p_oCriteria[p_sSubject].addClass('criteria__selector criteria__selector--' + p_sSubject);

p_oCriteria[p_sSubject].on('click', function (/*p_oEvent*/) {

updateClasses(p_sSubject, p_oCriteria);
updateSummary(p_oPoints, p_sSubject, p_oCriteria);
updateScore(p_oPoints, p_sSubject, p_iCriteriaIndex);
});
}

function main (p_sTableSelector) {
var $Help, $Table;

Expand All @@ -77,9 +111,11 @@
$Table.find('tbody tr').each(retrieveRows);

g_$Score = $('<input type="text" class="criteria__score" data-score="{}" readonly />');

g_$Score.Stickyfill();

g_$Summary= $('<textarea class="criteria__summary" data-summary="{}" readonly />');
g_$Summary.Stickyfill();

$Help = $('<p class="criteria__help">' +
'<span class="octicon octicon-info criteria__help-icon"></span>' +
'To calculate the developer pain for a given issue, ' +
Expand All @@ -88,7 +124,8 @@
);

g_$Score.insertBefore($Table.parent());
$Help.insertAfter(g_$Score);
g_$Summary.insertAfter(g_$Score);
$Help.insertAfter(g_$Summary);

g_oPoints = {'lower': 10 / g_aCriteria.length, 'upper': 100 / g_aCriteria.length};

Expand Down

0 comments on commit e28fbd5

Please sign in to comment.