Issue #2215049 by sun: Stop duplicating entire test list table into JavaScript.
parent
186981020c
commit
0935e4c9ab
|
|
@ -82,11 +82,16 @@ class SimpletestTestForm extends FormBase {
|
||||||
'#title' => $this->t('Collapse'),
|
'#title' => $this->t('Collapse'),
|
||||||
'#suffix' => '<a href="#" class="simpletest-collapse">(' . $this->t('Collapse') . ')</a>',
|
'#suffix' => '<a href="#" class="simpletest-collapse">(' . $this->t('Collapse') . ')</a>',
|
||||||
);
|
);
|
||||||
$js = array(
|
$form['tests']['#attached']['js'][] = array(
|
||||||
|
'type' => 'setting',
|
||||||
|
'data' => array(
|
||||||
|
'simpleTest' => array(
|
||||||
'images' => array(
|
'images' => array(
|
||||||
drupal_render($image_collapsed),
|
drupal_render($image_collapsed),
|
||||||
drupal_render($image_extended),
|
drupal_render($image_extended),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Generate the list of tests arranged by group.
|
// Generate the list of tests arranged by group.
|
||||||
|
|
@ -108,13 +113,13 @@ class SimpletestTestForm extends FormBase {
|
||||||
$form['tests'][$group]['select'] = array(
|
$form['tests'][$group]['select'] = array(
|
||||||
'#wrapper_attributes' => array(
|
'#wrapper_attributes' => array(
|
||||||
'id' => $group_class,
|
'id' => $group_class,
|
||||||
'class' => array('simpletest-select-all'),
|
'class' => array('simpletest-group-select-all'),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
$form['tests'][$group]['title'] = array(
|
$form['tests'][$group]['title'] = array(
|
||||||
// Expand/collapse image.
|
// Expand/collapse image.
|
||||||
'#prefix' => '<div class="simpletest-image" id="simpletest-test-group-' . $group_class . '"></div>',
|
'#prefix' => '<div class="simpletest-image" id="simpletest-test-group-' . $group_class . '"></div>',
|
||||||
'#markup' => '<label for="' . $group_class . '-select-all" class="simpletest-group-label">' . $group . '</label>',
|
'#markup' => '<label for="' . $group_class . '-group-select-all">' . $group . '</label>',
|
||||||
'#wrapper_attributes' => array(
|
'#wrapper_attributes' => array(
|
||||||
'class' => array('simpletest-group-label'),
|
'class' => array('simpletest-group-label'),
|
||||||
),
|
),
|
||||||
|
|
@ -126,15 +131,6 @@ class SimpletestTestForm extends FormBase {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add individual tests to group.
|
|
||||||
$current_js = array(
|
|
||||||
'testClass' => $group_class . '-test',
|
|
||||||
'testNames' => array(),
|
|
||||||
// imageDirection maps to the 'images' index in the $js array.
|
|
||||||
'imageDirection' => 0,
|
|
||||||
'clickActive' => FALSE,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Sort test classes within group alphabetically by name/label.
|
// Sort test classes within group alphabetically by name/label.
|
||||||
uasort($tests, function ($a, $b) {
|
uasort($tests, function ($a, $b) {
|
||||||
return SortArray::sortByKeyString($a, $b, 'name');
|
return SortArray::sortByKeyString($a, $b, 'name');
|
||||||
|
|
@ -142,10 +138,6 @@ class SimpletestTestForm extends FormBase {
|
||||||
|
|
||||||
// Cycle through each test within the current group.
|
// Cycle through each test within the current group.
|
||||||
foreach ($tests as $class => $info) {
|
foreach ($tests as $class => $info) {
|
||||||
$test_id = drupal_clean_id_identifier($class);
|
|
||||||
$test_checkbox_id = 'edit-tests-' . $test_id;
|
|
||||||
$current_js['testNames'][] = $test_checkbox_id;
|
|
||||||
|
|
||||||
$form['tests'][$class] = array(
|
$form['tests'][$class] = array(
|
||||||
'#attributes' => array('class' => array($group_class . '-test', 'js-hide')),
|
'#attributes' => array('class' => array($group_class . '-test', 'js-hide')),
|
||||||
);
|
);
|
||||||
|
|
@ -168,16 +160,8 @@ class SimpletestTestForm extends FormBase {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$js['simpletest-test-group-' . $group_class] = $current_js;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add JavaScript array of settings.
|
|
||||||
$form['tests']['#attached']['js'][] = array(
|
|
||||||
'type' => 'setting',
|
|
||||||
'data' => array('simpleTest' => $js),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Action buttons.
|
// Action buttons.
|
||||||
$form['actions'] = array('#type' => 'actions');
|
$form['actions'] = array('#type' => 'actions');
|
||||||
$form['actions']['submit'] = array(
|
$form['actions']['submit'] = array(
|
||||||
|
|
|
||||||
|
|
@ -3,98 +3,56 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the cool table collapsing on the testing overview page.
|
* Collapses table rows followed by group rows on the test listing page.
|
||||||
*/
|
*/
|
||||||
Drupal.behaviors.simpleTestMenuCollapse = {
|
Drupal.behaviors.simpleTestGroupCollapse = {
|
||||||
attach: function (context) {
|
attach: function (context) {
|
||||||
var timeout = null;
|
$(context).find('.simpletest-group').once('simpletest-group-collapse', function () {
|
||||||
// Adds expand-collapse functionality.
|
var $group = $(this);
|
||||||
$('div.simpletest-image').once('simpletest-image', function () {
|
var $image = $group.find('.simpletest-image');
|
||||||
var $this = $(this);
|
$image
|
||||||
var direction = drupalSettings.simpleTest[this.id].imageDirection;
|
.html(drupalSettings.simpleTest.images[0])
|
||||||
$this.html(drupalSettings.simpleTest.images[direction]);
|
.on('click', function () {
|
||||||
|
var $tests = $group.nextUntil('.simpletest-group');
|
||||||
// Adds group toggling functionality to arrow images.
|
var expand = !$group.hasClass('expanded');
|
||||||
$this.on('click', function () {
|
$group.toggleClass('expanded', expand);
|
||||||
var trs = $this.closest('tbody').children('.' + drupalSettings.simpleTest[this.id].testClass);
|
$tests.toggleClass('js-hide', !expand);
|
||||||
var direction = drupalSettings.simpleTest[this.id].imageDirection;
|
$image.html(drupalSettings.simpleTest.images[+expand]);
|
||||||
var row = direction ? trs.length - 1 : 0;
|
|
||||||
|
|
||||||
// If clicked in the middle of expanding a group, stop so we can switch directions.
|
|
||||||
if (timeout) {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Function to toggle an individual row according to the current direction.
|
|
||||||
// We set a timeout of 20 ms until the next row will be shown/hidden to
|
|
||||||
// create a sliding effect.
|
|
||||||
function rowToggle() {
|
|
||||||
if (direction) {
|
|
||||||
if (row >= 0) {
|
|
||||||
$(trs[row]).hide();
|
|
||||||
row--;
|
|
||||||
timeout = setTimeout(rowToggle, 20);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (row < trs.length) {
|
|
||||||
$(trs[row]).removeClass('js-hide').show();
|
|
||||||
row++;
|
|
||||||
timeout = setTimeout(rowToggle, 20);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Kick-off the toggling upon a new click.
|
|
||||||
rowToggle();
|
|
||||||
|
|
||||||
// Toggle the arrow image next to the test group title.
|
|
||||||
$this.html(drupalSettings.simpleTest.images[(direction ? 0 : 1)]);
|
|
||||||
drupalSettings.simpleTest[this.id].imageDirection = !direction;
|
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select/deselect all the inner checkboxes when the outer checkboxes are
|
* Toggles test checkboxes to match the group checkbox.
|
||||||
* selected/deselected.
|
|
||||||
*/
|
*/
|
||||||
Drupal.behaviors.simpleTestSelectAll = {
|
Drupal.behaviors.simpleTestSelectAll = {
|
||||||
attach: function (context) {
|
attach: function (context) {
|
||||||
$('td.simpletest-select-all').once('simpletest-select-all', function () {
|
$(context).find('.simpletest-group').once('simpletest-group-select-all', function () {
|
||||||
var testCheckboxes = drupalSettings.simpleTest['simpletest-test-group-' + $(this).attr('id')].testNames;
|
var $group = $(this);
|
||||||
var groupCheckbox = $('<input type="checkbox" class="form-checkbox" id="' + $(this).attr('id') + '-select-all" />');
|
var $cell = $group.find('.simpletest-group-select-all');
|
||||||
|
var $groupCheckbox = $('<input type="checkbox" id="' + $cell.attr('id') + '-group-select-all" class="form-checkbox" />');
|
||||||
|
var $testCheckboxes = $group.nextUntil('.simpletest-group').find('input[type=checkbox]');
|
||||||
|
$cell.append($groupCheckbox);
|
||||||
|
|
||||||
// Each time a single-test checkbox is checked or unchecked, make sure
|
// Toggle the test checkboxes when the group checkbox is toggled.
|
||||||
// that the associated group checkbox gets the right state too.
|
$groupCheckbox.on('change', function () {
|
||||||
function updateGroupCheckbox() {
|
|
||||||
var checkedTests = 0;
|
|
||||||
for (var i = 0; i < testCheckboxes.length; i++) {
|
|
||||||
if ($('#' + testCheckboxes[i]).prop('checked')) {
|
|
||||||
checkedTests++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$(groupCheckbox).prop('checked', (checkedTests === testCheckboxes.length));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Have the single-test checkboxes follow the group checkbox.
|
|
||||||
groupCheckbox.on('change', function () {
|
|
||||||
var checked = $(this).prop('checked');
|
var checked = $(this).prop('checked');
|
||||||
for (var i = 0; i < testCheckboxes.length; i++) {
|
$testCheckboxes.prop('checked', checked);
|
||||||
$('#' + testCheckboxes[i]).prop('checked', checked);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Have the group checkbox follow the single-test checkboxes.
|
// Update the group checkbox when a test checkbox is toggled.
|
||||||
for (var i = 0; i < testCheckboxes.length; i++) {
|
function updateGroupCheckbox() {
|
||||||
$('#' + testCheckboxes[i]).on('change', updateGroupCheckbox);
|
var allChecked = true;
|
||||||
|
$testCheckboxes.each(function () {
|
||||||
|
if (!$(this).prop('checked')) {
|
||||||
|
allChecked = false;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
// Initialize status for the group checkbox correctly.
|
$groupCheckbox.prop('checked', allChecked);
|
||||||
updateGroupCheckbox();
|
}
|
||||||
$(this).append(groupCheckbox);
|
$testCheckboxes.on('change', updateGroupCheckbox);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -102,9 +60,6 @@
|
||||||
/**
|
/**
|
||||||
* Filters the test list table by a text input search string.
|
* Filters the test list table by a text input search string.
|
||||||
*
|
*
|
||||||
* Additionally accounts for multiple tables being wrapped in "package" details
|
|
||||||
* elements.
|
|
||||||
*
|
|
||||||
* Text search input: input.table-filter-text
|
* Text search input: input.table-filter-text
|
||||||
* Target table: input.table-filter-text[data-table]
|
* Target table: input.table-filter-text[data-table]
|
||||||
* Source text: .table-filter-text-source
|
* Source text: .table-filter-text-source
|
||||||
|
|
@ -139,14 +94,8 @@
|
||||||
else if (searched) {
|
else if (searched) {
|
||||||
searched = false;
|
searched = false;
|
||||||
$('#simpletest-form-table thead th.select-all input').show();
|
$('#simpletest-form-table thead th.select-all input').show();
|
||||||
// Hide all rows and then show groups.
|
// Restore all rows to their original display state.
|
||||||
$rows.hide();
|
$rows.css('display', '');
|
||||||
$rows.filter('.simpletest-group').show().each(function () {
|
|
||||||
var id = 'simpletest-test-group-' + $(this).children().first().attr('id');
|
|
||||||
if (drupalSettings.simpleTest[id].imageDirection) {
|
|
||||||
$(this).closest('tbody').children('.' + drupalSettings.simpleTest[id].testClass).show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue