Merge pull request #1603 from LianaHus/staticAnalysisTab

check/uncheck all in testing tab and Analysis tab
pull/3094/head
yann300 6 years ago committed by GitHub
commit 41228c0f78
  1. 39
      src/app/staticanalysis/staticAnalysisView.js
  2. 7
      src/app/tabs/styles/test-tab-styles.js
  3. 45
      src/app/tabs/test-tab.js

@ -50,7 +50,7 @@ staticAnalysisView.prototype.render = function () {
${this.modulesView} ${this.modulesView}
</div> </div>
<div class="${css.buttons}"> <div class="${css.buttons}">
<button class=${css.buttonRun} onclick=${function () { self.run() }} >Run</button> <button class="${css.buttonRun}" onclick="${function () { self.run() }}" >Run</button>
<label class="${css.label}" for="autorunstaticanalysis"> <label class="${css.label}" for="autorunstaticanalysis">
<input id="autorunstaticanalysis" <input id="autorunstaticanalysis"
type="checkbox" type="checkbox"
@ -59,8 +59,8 @@ staticAnalysisView.prototype.render = function () {
> >
Auto run Auto run
</label> </label>
<label class="${css.label}" for="checkallstaticanalysis"> <label class="${css.label}" for="checkAllEntries">
<input id="checkallstaticanalysis" <input id="checkAllEntries"
type="checkbox" type="checkbox"
onclick="${function (event) { self.checkAll(event) }}" onclick="${function (event) { self.checkAll(event) }}"
style="vertical-align:bottom" style="vertical-align:bottom"
@ -135,29 +135,23 @@ staticAnalysisView.prototype.run = function () {
} }
} }
staticAnalysisView.prototype.checkAll = function (event) { staticAnalysisView.prototype.checkModule = function (event) {
if (!this.view) { let selected = this.view.querySelectorAll('[name="staticanalysismodule"]:checked')
return let checkAll = this.view.querySelector('[id="checkAllEntries"]')
} if (event.target.checked) {
var all = this.view.querySelectorAll('[name="staticanalysismodule"]') checkAll.checked = true
var isAnySelected = false } else if (!selected.length) {
for (var i = 0; i < all.length; i++) { checkAll.checked = false
if (all[i].checked === true) {
isAnySelected = true
break
}
}
for (var j = 0; j < all.length; j++) {
all[j].checked = !isAnySelected
} }
event.target.checked = !isAnySelected
} }
staticAnalysisView.prototype.checkModule = function (event) { staticAnalysisView.prototype.checkAll = function (event) {
var selectAll = this.view.querySelector('[id="checkallstaticanalysis" ]') if (!this.view) {
if (event.target.checked) { return
selectAll.checked = true
} }
// checks/unchecks all
var checkBoxes = this.view.querySelectorAll('[name="staticanalysismodule"]')
checkBoxes.forEach((checkbox) => { checkbox.checked = event.target.checked })
} }
staticAnalysisView.prototype.renderModules = function () { staticAnalysisView.prototype.renderModules = function () {
@ -170,6 +164,7 @@ staticAnalysisView.prototype.renderModules = function () {
<label class="${css.label}"> <label class="${css.label}">
<input id="staticanalysismodule_${categoryId}_${i}" <input id="staticanalysismodule_${categoryId}_${i}"
type="checkbox" type="checkbox"
class="staticAnalysisItem"
name="staticanalysismodule" name="staticanalysismodule"
index=${item._index} index=${item._index}
checked="true" checked="true"

@ -45,6 +45,8 @@ var css = csjs`
.buttons { .buttons {
${styles.rightPanel.testTab.box_listTests}; ${styles.rightPanel.testTab.box_listTests};
margin: 2%; margin: 2%;
display: flex;
align-items: center;
} }
.runButton { .runButton {
${styles.rightPanel.testTab.button_runTests}; ${styles.rightPanel.testTab.button_runTests};
@ -58,6 +60,9 @@ var css = csjs`
font-weight: bold; font-weight: bold;
margin-bottom: 1em; margin-bottom: 1em;
} }
.label {
display: flex;
align-items: center;
}
` `
module.exports = css module.exports = css

@ -100,8 +100,8 @@ module.exports = class TestTab {
} }
self._deps.filePanel.event.register('newTestFileCreated', file => { self._deps.filePanel.event.register('newTestFileCreated', file => {
var testList = document.querySelector("[class^='testList']") var testList = self.view.querySelector("[class^='testList']")
var test = yo`<label><input onchange=${(e) => toggleCheckbox(e, file)} type="checkbox" checked="true">${file}</label>` var test = yo`<label class="singleTestLabel"><input class="singleTest" onchange=${(e) => toggleCheckbox(e.target.checked, file)} type="checkbox" checked="true">${file}</label>`
testList.appendChild(test) testList.appendChild(test)
self.data.allTests.push(file) self.data.allTests.push(file)
self.data.selectedTests.push(file) self.data.selectedTests.push(file)
@ -133,13 +133,32 @@ module.exports = class TestTab {
function listTests () { function listTests () {
var tests = self.data.allTests var tests = self.data.allTests
return tests.map(test => yo`<label><input onchange =${(e) => toggleCheckbox(e, test)} type="checkbox" checked="true">${test} </label>`) return tests.map(test => yo`<label class="singleTestLabel"><input class="singleTest" onchange =${(e) => toggleCheckbox(e.target.checked, test)} type="checkbox" checked="true">${test} </label>`)
} }
function toggleCheckbox (e, test) { function toggleCheckbox (eChecked, test) {
var selectedTests = self.data.selectedTests if (!self.data.selectedTests) {
selectedTests = e.target.checked ? [...selectedTests, test] : selectedTests.filter(el => el !== test) self.data.selectedTests = self._view.el.querySelectorAll('.singleTest:checked')
}
let selectedTests = self.data.selectedTests
selectedTests = eChecked ? [...selectedTests, test] : selectedTests.filter(el => el !== test)
self.data.selectedTests = selectedTests self.data.selectedTests = selectedTests
let checkAll = self._view.el.querySelector('[id="checkAllTests"]')
if (eChecked) {
checkAll.checked = true
} else if (!selectedTests.length) {
checkAll.checked = false
}
}
function checkAll (event) {
let checkBoxes = self._view.el.querySelectorAll('.singleTest')
const checkboxesLabels = self._view.el.querySelectorAll('.singleTestLabel')
// checks/unchecks all
for (let i = 0; i < checkBoxes.length; i++) {
checkBoxes[i].checked = event.target.checked
toggleCheckbox(event.target.checked, checkboxesLabels[i].innerText)
}
} }
var runTests = function () { var runTests = function () {
@ -177,12 +196,20 @@ module.exports = class TestTab {
<br/> <br/>
For more details, see For more details, see
How to test smart contracts guide in our documentation. How to test smart contracts guide in our documentation.
<div class=${css.generateTestFile} onclick=${generateTestFile}>Generate test file</div> <div class="${css.generateTestFile}" onclick="${generateTestFile}">Generate test file</div>
</div> </div>
<div class="${css.tests}"> <div class="${css.tests}">
${self.testList} ${self.testList}
<div class=${css.buttons}> <div class="${css.buttons}">
<div class=${css.runButton} onclick=${runTests}>Run Tests</div> <div class="${css.runButton}" onclick="${runTests}">Run Tests</div>
<label class="${css.label}" for="checkAllTests">
<input id="checkAllTests"
type="checkbox"
onclick="${function (event) { checkAll(event) }}"
checked="true"
>
Check/Uncheck all
</label>
</div> </div>
${testsOutput} ${testsOutput}
${testsSummary} ${testsSummary}

Loading…
Cancel
Save