Skip to content

Commit fef2b88

Browse files
author
Maciej Kamela
committed
Adding toggle functionality to step list
1 parent c039519 commit fef2b88

File tree

3 files changed

+59
-31
lines changed

3 files changed

+59
-31
lines changed

templates/assets/js/chart.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,20 @@ app.chart = (function () {
3535
c = this.getContext('2d'),
3636
p = c.getImageData(x, y, 1, 1).data,
3737
hex = "#" + ("000000" + self.rgbToHex(p[0], p[1], p[2])).slice(-6);
38-
/** Displaying text inside donout chart*/
38+
39+
/** Displaying text inside donut chart*/
3940
var a = 200;
4041
var b = 200;
4142
chartCtx.font = '30pt Arial';
4243
chartCtx.textAlign = 'center';
4344
chartCtx.fillStyle = hex;
44-
var statistics = self.getStatistics();
45-
var passed = statistics.passed;
46-
var passedRound = Math.round(passed) + "%";
47-
var failed = statistics.failed;
48-
var failedRound = Math.round(failed) + "%";
45+
var statistics = self.getStatistics(),
46+
passed = statistics.passed,
47+
passedRound = Math.round(passed) + "%",
48+
failed = statistics.failed,
49+
failedRound = Math.round(failed) + "%";
4950
chartCtx.clearRect(120, 150, 150, 90);
5051

51-
52-
5352
if (hex.toLowerCase() === data.colors.cs[0].toLowerCase()) {
5453
chartCtx.fillText(passedRound, a, b);
5554
} else if (hex.toLowerCase() === data.colors.cs[1].toLowerCase()) {
@@ -63,13 +62,13 @@ app.chart = (function () {
6362
document.querySelector('.close_chart').onclick = this.toggleChart.bind(this);
6463
document.querySelector('.document_container').onclick = this.toggleChart.bind(this);
6564
},
66-
65+
/** Transforming rgb colors into Hex */
6766
rgbToHex: function (r, g, b) {
6867
if (r > 255 || g > 255 || b > 255)
6968
throw "Invalid color component";
7069
return ((r << 16) | (g << 8) | b).toString(16);
7170
},
72-
71+
/** Finding mouse position on chart */
7372
findPos: function(obj) {
7473
var curleft = 0, curtop = 0;
7574
if (obj.offsetParent) {
@@ -80,7 +79,7 @@ app.chart = (function () {
8079
return {x: curleft, y: curtop};
8180
}
8281
},
83-
82+
/** Animated displaying and hiding chart */
8483
onAnimationEnd: function () {
8584

8685
var documentContainer = document.querySelector('.document_container');
@@ -107,6 +106,7 @@ app.chart = (function () {
107106
this.to = to;
108107
this.lineWidth = lineWidth;
109108
};
109+
/** Drawing report chart */
110110

111111
this.draw = function (data) {
112112

@@ -128,7 +128,7 @@ app.chart = (function () {
128128
}
129129
};
130130
},
131-
131+
/** Passed and failed percentage */
132132
getStatistics:function () {
133133
var scenarioPassed = document.querySelectorAll('.scenario.passed').length,
134134
scenarioFailed = document.querySelectorAll('.scenario.failed').length,
@@ -150,7 +150,7 @@ app.chart = (function () {
150150
var documentContainer = document.querySelector('.document_container');
151151
documentContainer.style.display = (documentContainer.style.display != 'block' ? 'block' : documentContainer.classList.add('backdrop-hidden'));
152152
},
153-
153+
/** Displaying and hiding chart */
154154
toggleChart: function () {
155155
var chart = document.querySelector('.scenario-chart');
156156

templates/assets/js/navigation.js

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ app.navigation = (function () {
1313
this.bindEvents(errors, scenarios, filteringButtons, displayChartButton);
1414
this.bindFilterButtonsEvent(filteringButtons, scenarios, steps);
1515
},
16-
16+
/** Showing error log for step that failed */
1717
showErrorDetails: function (e) {
1818
e.stopPropagation();
1919
var display = this.querySelector('.error-details').style.display;
@@ -24,7 +24,7 @@ app.navigation = (function () {
2424
this.querySelector('.error-details').style.display = 'block';
2525
}
2626
},
27-
27+
/** Hiding and displaying steps after clicking on scenario header*/
2828
toggleStep: function () {
2929
var steps = this.querySelectorAll('.step');
3030
for (var k = 0; k < steps.length; k++) {
@@ -48,14 +48,15 @@ app.navigation = (function () {
4848
scenarios[i].addEventListener('click', this.toggleStep, false);
4949
}
5050
},
51-
52-
53-
/** Filtering scenarios */
51+
/**
52+
* Filtering passed and failed scenarios by clicking the passed or failed button respectively
53+
*
54+
* @param buttonState indicates the clicked button
55+
*/
5456
filterScenarios: function (buttonState) {
5557
var scenarios = document.querySelectorAll('.scenario'),
5658
hasClass;
5759
for (var i = 0; i < scenarios.length; i++) {
58-
5960
hasClass = scenarios[i].classList.contains(buttonState);
6061
if (hasClass === true) {
6162
if (scenarios[i].parentNode.style.display === 'none') {
@@ -66,16 +67,20 @@ app.navigation = (function () {
6667
}
6768
}
6869
},
69-
70-
/** Displaying all scenarios */
70+
/**
71+
* Displaying all scenarios within the report
72+
*
73+
* @param scenarios indicate the all scenarios in report
74+
*
75+
*/
7176
displayAllScenarios: function (scenarios) {
7277
for (var i = 0; i < scenarios.length; i++) {
7378
if (scenarios[i].style.display != 'block') {
7479
scenarios[i].style.display = 'block';
7580
}
7681
}
7782
},
78-
/*
83+
/**
7984
* @param string buttonsList indicate the group of buttons that have the "active" class name
8085
*
8186
* Removing "active" class from all buttons except for the active one
@@ -85,7 +90,15 @@ app.navigation = (function () {
8590
buttonsList[j].classList.remove('active');
8691
}
8792
},
88-
93+
/**
94+
* Run appropriate action depending on button state
95+
*
96+
* @param filteringButtons indicate the navigation buttons
97+
*
98+
* @param scenarios indicate all scenarios in report
99+
*
100+
* @param steps indicate all steps in report
101+
*/
89102
bindFilterButtonsEvent: function (filteringButtons, scenarios, steps) {
90103
var self = this,
91104
btnState;
@@ -94,7 +107,7 @@ app.navigation = (function () {
94107

95108
btnState = this.dataset.state;
96109

97-
if (btnState !== 'chart') {
110+
if (btnState !== 'steps') {
98111
self.removeActiveClass(filteringButtons);
99112
this.classList.add('active');
100113
self.hideSteps(steps);
@@ -110,7 +123,7 @@ app.navigation = (function () {
110123
break;
111124
case 'steps':
112125
self.displayAllScenarios(scenarios);
113-
self.showSteps(steps);
126+
self.toggleSteps(steps);
114127
break;
115128
default:
116129
self.filterScenarios(btnState);
@@ -120,13 +133,28 @@ app.navigation = (function () {
120133
}, false);
121134
}
122135
},
123-
124-
showSteps: function (steps) {
136+
/**
137+
* Displaying and hiding steps by clicking "chart report" button
138+
*
139+
* @param steps indicate all steps in report
140+
*/
141+
toggleSteps: function (steps) {
125142
for (var i = 0; i < steps.length; i++) {
126-
steps[i].style.display = 'block';
143+
var display = steps[i].style.display;
144+
if (display === 'none' || display === '') {
145+
steps[i].style.display = 'block';
146+
all_btn.classList.add('active');
147+
} else {
148+
all_btn.classList.add('active');
149+
steps[i].style.display = 'none';
150+
}
127151
}
128152
},
129-
153+
/**
154+
* Hiding currently displayed steps
155+
*
156+
* @param steps indicate all steps in report
157+
*/
130158
hideSteps: function (steps) {
131159
for (var i = 0; i < steps.length; i++) {
132160
steps[i].style.display = 'none';

templates/header_template.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ <h1>Cucumber features</h1>
1616
</div>
1717
<div class="col-md-3 col-sm-4 additional_btns">
1818
<div class="btn_support">
19-
<button data-state="steps" class="btn fa fa-list btn_list" id="display_btn"></button>
20-
<button data-state="chart" class=" btn fa fa-pie-chart btn_chart"></button>
19+
<button data-state="steps" title="Display all steps within scenario" class="btn fa fa-list btn_list" id="display_btn"></button>
20+
<button data-state="chart" title="Display chart" class="btn fa fa-pie-chart btn_chart"></button>
2121
</div>
2222
</div>
2323
</div>

0 commit comments

Comments
 (0)