app-reports.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. $(function() {
  2. var dataTable = $("#projects-table").DataTable({
  3. dom: "tp",
  4. data: projectData,
  5. paging: false,
  6. order: [[1, "desc"]],
  7. scrollY: 250,
  8. columns: [
  9. {
  10. data: "id",
  11. class: "text-right",
  12. orderable: false,
  13. render: function(data, type) {
  14. if(type === "display") {
  15. var checked = (selectedProjectIds.indexOf(data) !== -1) ? "checked" : "";
  16. return "<input type=\"checkbox\" name=\"exclude_project_ids[]\" value=\"" + data + "\" " + checked + " /> ";
  17. }
  18. return data;
  19. }
  20. },
  21. {
  22. data: "id",
  23. class: "text-right"
  24. },
  25. {
  26. data: "name"
  27. },
  28. {
  29. data: "timeOfDay"
  30. },
  31. {
  32. data: "testCount",
  33. class: "text-right"
  34. },
  35. {
  36. data: "reportMonth",
  37. class: "text-right",
  38. render: function(data, type, row) {
  39. if(type === "display" || type === "filter") {
  40. return data;
  41. }
  42. return row.unixReport;
  43. }
  44. }
  45. ]
  46. });
  47. $(document).on("click", "#projects-table tbody tr", function(event) {
  48. if(!event.target.type || event.target.type !== "checkbox") {
  49. var checkbox = $(this).find("input[type=checkbox]").get(0);
  50. checkbox.checked = !checkbox.checked;
  51. }
  52. });
  53. $("#show-projects-list-button").click(function() {
  54. $("#projects-table-wrapper").toggle();
  55. dataTable.columns.adjust();
  56. });
  57. $("input[data-date-range-radio-input]").change(function() {
  58. let value = $(this).val();
  59. if(value === "custom") {
  60. $("#date-range-custom-fields").slideDown("fast");
  61. }
  62. else {
  63. $("#date-range-custom-fields").slideUp("fast");
  64. }
  65. });
  66. $("#export-pptx-action").click(function() {
  67. exportCharts("pptx");
  68. return true;
  69. });
  70. $("#export-odp-action").click(function() {
  71. exportCharts("odp");
  72. return true;
  73. });
  74. $("#date-range").daterangepicker({
  75. locale: {
  76. format: "DD/MM/YYYY"
  77. }
  78. }, function(start, end) {
  79. var startValue = start.format('YYYY-MM-DD');
  80. var endValue = end.format('YYYY-MM-DD');
  81. $("#date-start").val(startValue);
  82. $("#date-end").val(endValue);
  83. });
  84. });
  85. function testsByStageFormatter(value, context) {
  86. let dataset = context.dataset;
  87. let data = dataset.data;
  88. let total = data.reduce((total, value) => { return total + value; });
  89. let percentage = Math.round((value * 10000) / total) / 100;
  90. let suffix = "Test";
  91. if(parseInt(value) !== 1) {
  92. suffix += "s";
  93. }
  94. let label = "Stage " + (context.dataIndex + 1) + "\n";
  95. label += value + " " + suffix + "\n";
  96. label += percentage + "%";
  97. return label;
  98. }
  99. function exportCharts(action) {
  100. let formId = "";
  101. if(action === "pptx") {
  102. formId = "form-pptx";
  103. }
  104. if(action === "odp") {
  105. formId = "form-odp";
  106. }
  107. let form = $("#" + formId);
  108. let rendered = parseInt($(form).data("rendered"));
  109. if(rendered === 0) {
  110. for(var i in Chart.instances) {
  111. if(!Chart.instances.hasOwnProperty(i)) continue;
  112. let chart = Chart.instances[i];
  113. let base64 = chart.toBase64Image();
  114. $(form).append("<input type=\"hidden\" name=\"charts_b64[]\" value=\"" + base64 + "\" />");
  115. }
  116. $(form).data("rendered", "1");
  117. }
  118. $(form).find("input[type=submit]").click();
  119. }