app-reports.js 3.2 KB

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