/usr/share/ola/rdm-server/rdm_tests.js is in ola-rdm-tests 0.10.3.nojsmin-2+deb9u1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 | /**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2012 Ravindra Nath Kakarla & Simon Newton
*/
// Global variable that holds the RDMTests object
rdmtests = undefined;
/**
* RDMTests class
*/
RDMTests = function() {
// An array to hold the test results
this.test_results = new Array();
this.tests_running = false;
// init tabs
$('#tabs').tabs({});
// setup dialog windows, one for general notifications and one for the
// download options.
this.notification = $('#rdm-tests-notification');
this.notification.dialog({
autoOpen: false,
closeOnEscape: false,
dialogClass: 'no-close',
draggable: false,
height: 160,
modal: true,
resizable: false,
});
this.save_options = $('#rdm-tests-save-options');
var save_buttons = [
{
text: 'Cancel',
click: function() { $(this).dialog('close'); }
},
{
text: 'Download',
click: function() { rdmtests.save_results() }
},
];
this.save_options.dialog({
autoOpen: false,
draggable: false,
height: 200,
modal: true,
resizable: false,
title: 'Download Options',
buttons: save_buttons,
});
this.error_notification = $('#rdm-error-notification');
var error_buttons = [
{
text: 'Dismiss',
click: function() { $(this).dialog('close'); }
},
{
text: 'Report Bug',
click: function() { rdmtests.report_bug() }
},
];
this.error_notification.dialog({
autoOpen: false,
buttons: error_buttons,
draggable: true,
height: 300,
modal: true,
resizable: true,
width: 550,
});
//Populate the filter with test categories
$('#rdm-tests-results-summary-filter-by_catg')
.append($('<option />').val('All').html('All'));
// and the other list in the download options dialog
$('#rdm-tests-save-catg')
.append($('<option />').val('All').html('All'));
};
/**
* AJAX loader image
* @this {RDMTests}
*/
RDMTests.ajax_loader = '<img src="/static/images/loader.gif" />';
/**
* How long to wait between polls of the test status. In milliseconds
* @this {RDMTests}
*/
RDMTests.poll_delay = 500;
/**
* The path to post the publisher data to
* @this {RDMTests}
*/
RDMTests.publisher_url = 'http://rdm.openlighting.org/incoming/model_data';
/**
* Prepares the notification div and displays it on the page.
* @this {RDMTests}
* @param {Objec} options An object containing title and message to be
* displayed.
*
* {
* 'title': 'Title to display on notification',
* 'message': 'Notification Message',
* 'is_dismissable': true,
* 'buttons: [{'label': , 'on_click': {}],
* }
*/
RDMTests.prototype.set_notification = function(options) {
var title = '';
if (options.title != undefined || options.title != null) {
title = options.title;
}
this.notification.dialog('option', 'title', title);
var message = '';
if (options.message != undefined || options.message != null) {
message = options.message;
}
this.notification.html(message);
var button_list = options.buttons || [];
var buttons = []
if (options.is_dismissable != undefined || options.is_dismissable != null) {
buttons.push({
text: 'Ok',
click: function() { $(this).dialog('close'); }
});
} else {
for (var i = 0; i < button_list.length; ++i) {
var button = button_list[i];
buttons.push({
text: button['label'],
click: function() { button['on_click'](); },
});
}
}
this.notification.dialog('option', 'buttons', buttons);
this.notification.dialog('open');
};
/**
* A simplified version of the method above to display a dismissable dialog
* box.
*/
RDMTests.prototype.display_dialog_message = function(title, message) {
rdmtests.set_notification({
'title': title,
'message': message,
'is_dismissable': true
});
}
/**
* Clears the notification text and hides it from page.
* @this {RDMTests}
*/
RDMTests.prototype.clear_notification = function() {
this.notification.html();
this.notification.dialog('close');
};
/**
* Binds click, keypress and other events to DOMs and
* triggers the their respective handlers.
* @this {RDMTests}
*/
RDMTests.prototype.bind_events_to_doms = function() {
// key event handler
$(document).keydown(function(e) {
var key = e.keyCode || e.which;
var results_div = $('#rdm-tests-results');
var test_frame = $('#tests_control_frame');
// escape
if (results_div.css('display') == 'block' && key == 27) {
results_div.hide();
$('#tests_control_frame').show();
}
// enter
if (key == 13 && test_frame.css('display') == 'block' &&
!rdmtests.tests_running) {
rdmtests.validate_form();
}
});
// Elements on the responder test page
$('#universe_options').change(function() { rdmtests.update_device_list(); });
$('#devices_list').change(function() { rdmtests.device_list_changed(); });
$('#rdm-discovery-button').button().click(
function() { rdmtests.run_discovery(); }
);
$('#rdm-tests-selection-run_tests').button({
icons: {secondary: 'ui-icon-transferthick-e-w'}
}).click(function() { rdmtests.validate_form(); });
$('#rdm-tests-send_dmx_in_bg').change(function() {
$('#rdm-tests-dmx_options').toggle('fast');
});
// Elements on the responder test results page
$('#rdm-tests-results-button-dismiss').button({
icons: {secondary: 'ui-icon-arrowreturnthick-1-w'}
}).click(function() {
$('#rdm-tests-results').hide();
$('#tests_control_frame').show();
});
$('#rdm-tests-results-button-run_again').button({
icons: {secondary: 'ui-icon-transferthick-e-w'}
}).click(function() { rdmtests.run_tests(rdmtests.selected_tests); });
$('#rdm-tests-results-button-save-options').button({
icons: {secondary: 'ui-icon-disk'}
}).click(function() { rdmtests.save_options.dialog('open'); });
$.each($('.ola-expander'), function(i, fieldset) {
var legend = $(fieldset).find('legend');
legend.click(function() {
$(legend).find('span').first()
.toggleClass('ola-expander-collapsed ola-expander-expanded');
$(fieldset).find('div').toggle();
});
});
$.each([
$('#rdm-tests-results-summary-filter-by_catg'),
$('#rdm-tests-results-summary-filter-by_state')
], function(i, div) {
$(div).change(function() {
rdmtests.filter_results($('#rdm-tests-results-list'), {
'category': $('#rdm-tests-results-summary-filter-by_catg').val(),
'state': $('#rdm-tests-results-summary-filter-by_state').val()
});
});
});
// Elements on the publisher page
$('#publisher-collect-button').button({
icons: {secondary: 'ui-icon-search'}
}).click(function() { rdmtests.collect_data(); });
$('#publisher-upload-form').attr('action', RDMTests.publisher_url);
$('#publisher-clear-button').button({
icons: {secondary: 'ui-icon-cancel'}
}).click(function() {
$('#publisher-output').html('');
$('#publisher-upload-button').button('disable');
$('#publisher-download-button').button('disable');
});
$('#publisher-upload-button').button({
disabled: true,
icons: {secondary: 'ui-icon-extlink'}
}).click(function() { rdmtests.upload_responder_info(); });
$('#publisher-download-button').button({
disabled: true,
icons: {secondary: 'ui-icon-disk'}
}).click(function() { rdmtests.download_responder_info(); });
};
/**
* Download the saved results.
* @this {RDMTests}
*/
RDMTests.prototype.save_results = function() {
this.save_options.dialog('close');
var uid = $('#devices_list').val();
var url = ('/DownloadResults?uid=' + uid + '×tamp=' + this.timestamp +
'&state=' + $('#rdm-tests-save-state').val() + '&category=' +
$('#rdm-tests-save-catg').val());
if ($('#rdm-tests-include-debug').attr('checked')) {
url += '&debug=1';
}
if ($('#rdm-tests-include-description').attr('checked')) {
url += '&description=1';
}
$('#rdm-tests-download').attr('src', url);
};
/**
* Prepares a list item with appropriate color, definition and value.
* This will be appended to the results list.
* @this {RDMTests}
* @param {String} definition Key (or test definition) in TEST_RESULTS object.
* @return {Object} A jQuery object representation for a prepared list item.
*/
RDMTests.prototype.make_results_list_item = function(definition) {
var test_option = $('<option />').val(definition).text(definition);
rdmtests.add_state_class(
this.test_results[definition]['state'],
test_option);
return test_option;
};
/**
* Filters definitions in results list by category and state of test result.
* @this {RDMTests}
* @param {Object} results_dom A jQuery object representation of HTML <ul>
* which holds test result definitions.
* @param {Object} filter_options An Object containing selected filter options.
*/
RDMTests.prototype.filter_results = function(results_dom, filter_options) {
$(results_dom).html('');
var filter_category = filter_options['category'];
var filter_state = filter_options['state'];
if (filter_category == 'All') {
if (filter_state == 'All') {
for (var definition in this.test_results) {
$(results_dom).append(rdmtests.make_results_list_item(definition));
}
} else {
for (definition in this.test_results) {
if (this.test_results[definition]['state'] == filter_state) {
$(results_dom).append(rdmtests.make_results_list_item(definition));
}
}
}
} else {
if (filter_state == 'All') {
for (definition in this.test_results) {
if (this.test_results[definition]['category'] == filter_category) {
$(results_dom).append(rdmtests.make_results_list_item(definition));
}
}
} else {
for (definition in this.test_results) {
if (this.test_results[definition]['category'] == filter_category &&
this.test_results[definition]['state'] == filter_state) {
$(results_dom).append(rdmtests.make_results_list_item(definition));
}
}
}
}
};
/**
* Sends an AJAX request to the RDM Tests Server and
* triggers callback with the response.
* Automatically displays ERROR notifications when a request fails.
* @this {RDMTests}
* @param {String} request Request string.
* @param {Object} params An Object containing parameters to send to the server.
* @param {Object} callback Handler to trigger.
*/
RDMTests.prototype.query_server = function(request, params, callback) {
$.ajax({
url: request,
type: 'GET',
data: params,
dataType: 'json',
error: function(jqXHR, textStatus, errorThrown) {
rdmtests.display_dialog_message(
'Server Down',
'The RDM Test Server is not responding. Restart it and try again');
},
success: function(data) {
if (data['status'] == true) {
callback(data);
} else {
rdmtests.display_dialog_message('Server Error', data['error']);
}
},
cache: false
});
};
/**
* Updates the universe selector with available universes fetched
* from RDM Tests Server.
*/
RDMTests.prototype.update_universe_list = function() {
var t = this;
this.query_server('/GetUnivInfo', {},
function(data) { t.new_universe_list(data); });
};
/**
* Called when we receive a list of universes. This updates the universe lists.
*/
RDMTests.prototype.new_universe_list = function(data) {
var universes = data.universes;
this._update_universe_select($('#universe_options'), universes);
this._update_universe_select($('#publisher-universe-list'), universes);
if (universes.length == 0) {
rdmtests.set_notification({
'title': 'No universes found',
'message': ('Go to the <a href="http://' + location.hostname +
':9090" target="_blank">OLA Web UI</a> ' +
'and patch a device to a universe'),
'buttons': [{'label': 'Retry',
'on_click': function() {
rdmtests.clear_notification();
rdmtests.update_universe_list()
},
}
],
});
} else {
rdmtests.update_device_list();
}
};
/**
* Triggers Full Discovery of devices via AJAX request
* and updates the universe list.
*/
RDMTests.prototype.run_discovery = function() {
var universe = $('#universe_options').val();
if (universe == null || universe == undefined) {
rdmtests.display_dialog_message(
'No universe selected',
'Please select a universe to run discovery on.');
return;
}
rdmtests.set_notification({
'title': 'Running Full Discovery',
'message': RDMTests.ajax_loader
});
rdmtests.query_server('/RunDiscovery', {'u': universe}, function(data) {
var devices_list = $('#devices_list');
devices_list.empty();
if (data['status'] == true) {
var uids = data.uids;
$.each(uids, function(item) {
devices_list.append($('<option />').val(uids[item])
.text(uids[item]));
});
rdmtests.clear_notification();
}
});
};
/**
* Updates the patched devices list for selected universe.
*/
RDMTests.prototype.update_device_list = function() {
var universe_options = $('#universe_options');
var devices_list = $('#devices_list');
this.query_server('/GetDevices', {
'u': universe_options.val() }, function(data) {
if (data['status'] == true) {
devices_list.empty();
var uids = data.uids;
$.each(uids, function(item) {
devices_list.append($('<option />').val(uids[item]).text(uids[item]));
});
}
});
};
/**
* Called when the selected device changes.
*/
RDMTests.prototype.device_list_changed = function() {
$('#rdm-tests-selection-subset').attr('checked', true);
this._reset_failed_tests_list();
};
/**
* Fetches all Test Definitions available from the RDM Tests Server.
* Initializes the multiselect widget with definitions.
*/
RDMTests.prototype.fetch_test_defs = function() {
this.query_server('/GetTestDefs', {'c': 0}, function(data) {
var tests_selector = $('#rdm-tests-selection-tests_list');
var test_defs = data.test_defs;
$.each(data.test_defs, function(item) {
tests_selector.append($('<option />').val(test_defs[item])
.text(test_defs[item]));
});
$('#rdm-tests-selection-tests_list').multiselect({
sortable: false,
searchable: true
});
});
};
/**
* Triggers an AJAX call to run the tests with given Test Filter.
* @param {Array} test_filter An array of tests to run.
*/
RDMTests.prototype.run_tests = function(test_filter) {
this.tests_running = true;
this.set_notification({
'title': 'Running ' + test_filter.length + ' tests',
'message': '<div id="progressbar"></div>',
});
$('#progressbar').progressbar({});
this.selected_tests = test_filter;
this.query_server(
'/RunTests',
{
'u': $('#universe_options').val(),
'uid': $('#devices_list').val(),
'broadcast_write_delay': $('#write_delay').val(),
'inter_test_delay': $('#inter_test_delay').val(),
'dmx_frame_rate': ($('#rdm-tests-send_dmx_in_bg').attr('checked') ?
$('#dmx_frame_rate').val() : 0),
'slot_count': ($('#rdm-tests-send_dmx_in_bg').attr('checked') ?
$('#slot_count').val() : 0),
't': test_filter.join(',')
},
function(data) {
window.setTimeout(function() { rdmtests.stat_tests(); },
RDMTests.poll_delay);
}
);
};
/**
* Check if the tests are complete yet.
*/
RDMTests.prototype.stat_tests = function() {
this.query_server(
'/StatTests',
{},
function(data) {
rdmtests._stat_tests_response(data);
});
};
/**
* Resets the test results screen by clearing all the DOMs contents
* and hiding them.
*/
RDMTests.prototype.reset_results = function() {
$.each(['#rdm-tests-results-uid',
'#rdm-tests-results-duration',
'#rdm-tests-results-stats-figures',
'#rdm-tests-results-summary-by_catg-content',
'#rdm-tests-results-warnings-content',
'#rdm-tests-results-advisories-content',
'#rdm-tests-results-list'], function(i, dom) {
$(dom).html('');
});
$('#rdm-tests-results-summary-filter-by_state').val('All');
for (definition in this.test_results) {
delete this.test_results[definition];
}
};
/**
* Adds CSS class to the DOM based on the given state.
* This CSS class usually adds appropriate color to the text in the DOM.
* @param {String} state A valid test result state
* -- 'Passed', 'Failed', 'Broken', 'Not Run'.
* @param {Object} dom A jQuery object representation of the DOM
* to which the class needs to be added.
*/
RDMTests.prototype.add_state_class = function(state, dom) {
$(dom).removeClass($(dom).attr('class'));
switch (state) {
case 'Passed':
$(dom).addClass('test-state-passed');
break;
case 'Failed':
$(dom).addClass('test-state-failed');
break;
case 'Broken':
$(dom).addClass('test-state-broken');
break;
case 'Not Run':
$(dom).addClass('test-state-not_run');
break;
}
};
/**
* Initializes all the result screen DOMs and displays the results.
* @param {Object} results The response Object from the RDM Tests Server.
* which contains results.
*/
RDMTests.prototype.display_results = function(results) {
$('#tests_control_frame').hide();
rdmtests.reset_results();
$('#rdm-tests-results-uid').html(results['UID']);
var duration = Math.ceil(results['duration']);
if (duration == 1) {
$('#rdm-tests-results-duration').html(duration + ' second');
} else {
$('#rdm-tests-results-duration').html(duration + ' seconds');
}
for (key in results['stats']) {
$('#rdm-tests-results-stats-figures')
.append($('<td />').html(results['stats'][key]));
}
var category_lists = [$('#rdm-tests-results-summary-filter-by_catg'),
$('#rdm-tests-save-catg')];
$.each(category_lists,
function(i, dom) {
dom.html('');
dom.append($('<option />').val('All').html('All'));
});
// Summary of results by category
for (key in results['stats_by_catg']) {
var passed = results['stats_by_catg'][key]['passed'];
var total = results['stats_by_catg'][key]['total'];
if (total != 0) {
var percent = ' (' +
Math.ceil(passed / total * 100).toString() +
'%) </span>';
} else {
var percent = ' - </span>';
}
$('#rdm-tests-results-summary-by_catg-content')
.append($('<li />')
.html('<span>' +
key +
'</span>' +
'<span class="stats_by_catg">' +
passed.toString() +
' / ' +
total.toString() +
percent));
// update the lists as well
$.each(category_lists,
function(i, dom) {
dom.append($('<option />').val(key).html(key));
});
}
var number_of_warnings = 0;
var number_of_advisories = 0;
for (index in results['test_results']) {
var warnings = results['test_results'][index]['warnings'];
var advisories = results['test_results'][index]['advisories'];
var definition = results['test_results'][index]['definition'];
var state = results['test_results'][index]['state'];
//Populating a global variable with test results for faster lookups
this.test_results[definition] = results['test_results'][index];
number_of_warnings += warnings.length;
for (var i = 0; i < warnings.length; i++) {
$('#rdm-tests-results-warnings-content')
.append($('<li />')
.html(definition + ': ' + warnings[i]));
}
number_of_advisories += advisories.length;
for (var i = 0; i < advisories.length; i++) {
$('#rdm-tests-results-advisories-content')
.append($('<li />')
.html(definition + ': ' + advisories[i]));
}
var test_option = $('<option />').val(definition).text(definition);
rdmtests.add_state_class(state, test_option);
$('#rdm-tests-results-list').append(test_option);
}
//Update the Warnings and Advisories counter
$('#rdm-tests-results-warning-count').html(number_of_warnings.toString());
$('#rdm-tests-results-advisory-count').html(number_of_advisories.toString());
$('#rdm-tests-results-list').change(function() {
rdmtests.result_list_changed();
});
// select the first item
$('#rdm-tests-results-list').val(results['test_results'][0]['definition']);
rdmtests.result_list_changed();
$('#rdm-tests-results').show();
//Hide/Show Download Logs button
if (results['logs_disabled'] == true) {
$('#rdm-tests-results-button-save-options').hide();
} else {
$('#rdm-tests-results-button-save-options').show();
}
};
/**
* This is triggered when a definition in results summary is selected.
* The corresponding 'doc', 'debug' and category is updated in the info div.
*/
RDMTests.prototype.result_list_changed = function() {
var definition = $('#rdm-tests-results-list option:selected').text();
var state = this.test_results[definition]['state'];
$('#rdm-tests-results-info-title').html(definition);
rdmtests.add_state_class(state, $('#rdm-tests-results-info-state')
.html(state));
$('#rdm-tests-results-info-catg')
.html(this.test_results[definition]['category']);
$('#rdm-tests-results-info-doc')
.html(this.test_results[definition]['doc']);
var debug = this.test_results[definition]['debug'];
$('#rdm-tests-results-info-debug').html(debug.join('<br />'));
};
/**
* Validates the user input on Test Control Frame upon submission.
* Checks for proper threshold values and other parameters.
* @return {Boolean} True on successful validation.
*/
RDMTests.prototype.validate_form = function() {
this.isNumberField = function(dom) {
var value = $(dom).val();
if (value === '') {
return true;
}
if (isNaN(parseFloat(value)) || !isFinite(value)) {
var message = ($(dom).attr('id').replace('_', ' ').toUpperCase() +
' must be a number');
rdmtests.display_dialog_message('Error', message);
return false;
} else {
return true;
}
};
if ($('#devices_list option').size() < 1) {
rdmtests.display_dialog_message(
'Error',
'There are no devices patched to the selected universe!');
return false;
}
if (!this.isNumberField($('#write_delay')) ||
!this.isNumberField($('#inter_test_delay')) ||
($('#rdm-tests-send_dmx_in_bg').attr('checked') &&
(!this.isNumberField($('#dmx_frame_rate')) ||
!this.isNumberField($('#slot_count'))))) {
rdmtests.display_dialog_message('Error', 'Invalid options entered');
return false;
}
var slot_count_val = parseFloat($('#slot_count').val());
if ($('#rdm-tests-send_dmx_in_bg').attr('checked') &&
(slot_count_val < 1 || slot_count_val > 512)) {
rdmtests.display_dialog_message(
'Error',
'Invalid number of slots (expected: [1-512])');
return false;
}
var test_filter = ['all'];
if ($('#rdm-tests-selection-subset').attr('checked')) {
if ($('select[name="subset_test_defs"]').val() == null) {
rdmtests.display_dialog_message('Error',
'There are no tests selected to run');
return false;
} else {
test_filter = $('select[name="subset_test_defs"]').val();
}
} else if ($('#rdm-tests-selection-previously_failed').attr('checked')) {
if ($('select[name="failed_test_defs"]').val() == null) {
rdmtests.display_dialog_message(
'Error',
'There are no failed tests selected to run');
return false;
} else {
test_filter = $('select[name="failed_test_defs"]').val();
}
}
rdmtests.run_tests(test_filter);
};
/**
* Collect information for the RDM devices present on a universe.
*/
RDMTests.prototype.collect_data = function() {
$('#publisher-output').html('');
rdmtests.set_notification({
'title': 'Collecting Responder Data',
'message': RDMTests.ajax_loader
});
this.query_server(
'/RunCollector',
{ 'u': $('#publisher-universe-list').val(),
'skip_queued': $('#publisher-skip-queued-messages').attr('checked') ? true : false,
},
function(data) {
window.setTimeout(function() { rdmtests.stat_collector(); },
RDMTests.poll_delay);
}
);
};
/**
* Check if the collector is complete yet.
*/
RDMTests.prototype.stat_collector = function() {
this.query_server(
'/StatCollector',
{},
function(data) {
rdmtests._stat_collector_response(data);
});
};
/**
* Handle the response from a /StatCollector call
*/
RDMTests.prototype._stat_collector_response = function(data) {
if (data['completed']) {
rdmtests.clear_notification();
var exception = data['exception'];
if (exception != undefined) {
this.error_notification.dialog('option', 'title', 'Server Error');
$('#error-message').html(exception)
$('#traceback').html(data['traceback'])
this.error_notification.dialog('open');
this.exception = exception;
this.traceback = data['traceback'];
return;
}
$('#publisher-output').html(data['output']);
$('#publisher_upload_data').val(data['output']);
$('#publisher-upload-button').button('enable');
$('#publisher-download-button').button('enable');
} else {
window.setTimeout(function() { rdmtests.stat_collector()},
RDMTests.poll_delay);
}
};
/**
* Upload the collected responder data.
*/
RDMTests.prototype.upload_responder_info = function() {
$('#publisher-upload-form').submit();
}
/**
* Download the collected responder data for offline use.
*/
RDMTests.prototype.download_responder_info = function() {
$('#publisher-upload-form').attr("action", "/DownloadModelData");
$('#publisher-upload-form').submit();
$('#publisher-upload-form').attr('action', RDMTests.publisher_url);
}
/**
* Open the bug report window using the most recent exception & traceback.
*/
RDMTests.prototype.report_bug = function() {
var comments = 'Error: ' + this.exception + '\n\n' + this.traceback;
var url = (
'https://github.com/OpenLightingProject/ola/issues/new?' +
'title=Bug%20Report%20From%20RDM%20Tests' +
'&body=' + encodeURIComponent(comments));
window.open(url, '_blank');
};
/**
* Handle the response from a /StatTests call
*/
RDMTests.prototype._stat_tests_response = function(data) {
if (data['completed']) {
this.tests_running = false;
var exception = data['exception'];
if (exception != undefined) {
rdmtests.clear_notification();
this.error_notification.dialog('option', 'title', 'Server Error');
$('#error-message').html(exception)
$('#traceback').html(data['traceback'])
this.error_notification.dialog('open');
this.exception = exception;
this.traceback = data['traceback'];
return;
}
this.timestamp = data['timestamp'];
var failed_defs = new Array();
for (i in data['test_results']) {
switch (data['test_results'][i]['state']) {
case 'Failed':
failed_defs.push(data['test_results'][i]['definition']);
break;
}
}
this._reset_failed_tests_list();
var failed_tests = $('#rdm-tests-selection-failed_tests');
for (var i = 0; i < failed_defs.length; ++i) {
failed_tests.append($('<option />')
.val(failed_defs[i])
.text(failed_defs[i]));
}
failed_tests.multiselect();
rdmtests.clear_notification();
rdmtests.display_results(data);
} else {
// update progress here
var percent = data['tests_completed'] / data['total_tests'] * 100;
$('#progressbar').progressbar('option', 'value', percent);
window.setTimeout(function() { rdmtests.stat_tests()},
RDMTests.poll_delay);
}
};
/**
* Update a Universe <select> with new data.
*/
RDMTests.prototype._update_universe_select = function(select, universes) {
select.empty();
$.each(universes, function(i) {
var text = universes[i]._name + ' (' + universes[i]._id + ')';
select.append(
$('<option />').val(universes[i]._id).text(text));
});
};
/**
* Reset failed tests
*/
RDMTests.prototype._reset_failed_tests_list = function() {
var failed_tests = $('#rdm-tests-selection-failed_tests');
if (failed_tests.next().length > 0) {
failed_tests.multiselect('destroy');
}
failed_tests.html('');
};
/**
* Called once the page has loaded and we're ready to go.
*/
$(document).ready(function() {
rdmtests = new RDMTests();
rdmtests.bind_events_to_doms();
rdmtests.update_universe_list();
rdmtests.fetch_test_defs();
});
|