gatling.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright 2011-2024 GatlingCorp (https://gatling.io)
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. (function ($) {
  17. $.fn.expandable = function () {
  18. var scope = this;
  19. this.find('.expand-button:not([class*=hidden])').addClass('collapse').on('click', function () {
  20. var $this = $(this);
  21. if ($this.hasClass('expand'))
  22. $this.expand(scope);
  23. else
  24. $this.collapse(scope);
  25. });
  26. this.find('.expand-all-button').on('click', function () {
  27. $(this).expandAll(scope);
  28. });
  29. this.find('.collapse-all-button').on('click', function () {
  30. $(this).collapseAll(scope);
  31. });
  32. this.collapseAll(this);
  33. return this;
  34. };
  35. $.fn.expand = function (scope, recursive) {
  36. return this.each(function () {
  37. var $this = $(this);
  38. if (recursive) {
  39. scope.find('*[data-parent=' + $this.attr('id') + ']').find('.expand-button.expand').expand(scope, true);
  40. scope.find('*[data-parent=' + $this.attr('id') + ']').find('.expand-button.expand').expand(scope, true);
  41. }
  42. if ($this.hasClass('expand')) {
  43. $('*[data-parent=' + $this.attr('id') + ']').toggle(true);
  44. $this.toggleClass('expand').toggleClass('collapse');
  45. }
  46. });
  47. };
  48. $.fn.expandAll = function (scope) {
  49. $('*[data-parent=ROOT]').find('.expand-button.expand').expand(scope, true);
  50. $('*[data-parent=ROOT]').find('.expand-button.collapse').expand(scope, true);
  51. };
  52. $.fn.collapse = function (scope) {
  53. return this.each(function () {
  54. var $this = $(this);
  55. scope.find('*[data-parent=' + $this.attr('id') + '] .expand-button.collapse').collapse(scope);
  56. scope.find('*[data-parent=' + $this.attr('id') + ']').toggle(false);
  57. $this.toggleClass('expand').toggleClass('collapse');
  58. });
  59. };
  60. $.fn.collapseAll = function (scope) {
  61. $('*[data-parent=ROOT]').find('.expand-button.collapse').collapse(scope);
  62. };
  63. $.fn.sortable = function (target) {
  64. var table = this;
  65. this.find('thead .sortable').on('click', function () {
  66. var $this = $(this);
  67. if ($this.hasClass('sorted-down')) {
  68. var desc = false;
  69. var style = 'sorted-up';
  70. }
  71. else {
  72. var desc = true;
  73. var style = 'sorted-down';
  74. }
  75. $(target).sortTable($this.attr('id'), desc);
  76. table.find('thead .sortable').removeClass('sorted-up sorted-down');
  77. $this.addClass(style);
  78. return false;
  79. });
  80. return this;
  81. };
  82. $.fn.sortTable = function (col, desc) {
  83. function getValue(line) {
  84. var cell = $(line).find('.' + col);
  85. if (cell.hasClass('value'))
  86. var value = cell.text();
  87. else
  88. var value = cell.find('.value').text();
  89. return parseFloat(value);
  90. }
  91. function sortLines (lines, group) {
  92. var notErrorTable = col.search("error") == -1;
  93. var linesToSort = notErrorTable ? lines.filter('*[data-parent=' + group + ']') : lines;
  94. var sortedLines = linesToSort.sort(function (a, b) {
  95. return desc ? getValue(b) - getValue(a): getValue(a) - getValue(b);
  96. }).toArray();
  97. var result = [];
  98. $.each(sortedLines, function (i, line) {
  99. result.push(line);
  100. if (notErrorTable)
  101. result = result.concat(sortLines(lines, $(line).attr('id')));
  102. });
  103. return result;
  104. }
  105. this.find('tbody').append(sortLines(this.find('tbody tr').detach(), 'ROOT'));
  106. return this;
  107. };
  108. })(jQuery);