$(function() { var dataTable = $("#projects-table").DataTable({ dom: "tp", data: projectData, paging: false, order: [[1, "desc"]], scrollY: 250, columns: [ { data: "id", orderable: false, render: function(data, type) { if(type === "display") { var checked = (selectedProjectIds.indexOf(data) !== -1) ? "checked" : ""; return " "; } return data; } }, { data: "id", class: "text-right" }, { data: "name" }, { data: "timeOfDay" }, { data: "testCount", class: "text-right" }, { data: "reportMonth", class: "text-right", render: function(data, type, row) { if(type === "display" || type === "filter") { return data; } return row.unixReport; } } ] }); $(document).on("click", "#projects-table tbody tr", function(event) { if(!event.target.type || event.target.type !== "checkbox") { var checkbox = $(this).find("input[type=checkbox]").get(0); checkbox.checked = !checkbox.checked; } }); $("#show-projects-list-button").click(function() { $("#projects-table-wrapper").toggle(); dataTable.columns.adjust(); }); $("input[data-date-range-radio-input]").change(function() { let value = $(this).val(); if(value === "custom") { $("#date-range-custom-fields").slideDown("fast"); } else { $("#date-range-custom-fields").slideUp("fast"); } }); $("#export-pptx-action").click(function() { exportCharts("pptx"); return true; }); $("#export-odp-action").click(function() { exportCharts("odp"); return true; }); $("#date-range").daterangepicker({ locale: { format: "DD/MM/YYYY" } }, function(start, end) { var startValue = start.format('YYYY-MM-DD'); var endValue = end.format('YYYY-MM-DD'); $("#date-start").val(startValue); $("#date-end").val(endValue); }); $("#exclude-projects-header-checkbox").on("change", event => { const checked = event.currentTarget.checked; $("#projects-table > tbody").find("input:checkbox").prop("checked", checked); }); }); function testsByStageFormatter(value, context) { let dataset = context.dataset; let data = dataset.data; let total = data.reduce((total, value) => { return total + value; }); let percentage = Math.round((value * 10000) / total) / 100; let suffix = "Test"; if(parseInt(value) !== 1) { suffix += "s"; } let label = "Stage " + (context.dataIndex + 1) + "\n"; label += value + " " + suffix + "\n"; label += percentage + "%"; return label; } function exportCharts(action) { let formId = ""; if(action === "pptx") { formId = "form-pptx"; } if(action === "odp") { formId = "form-odp"; } let form = $("#" + formId); let rendered = parseInt($(form).data("rendered")); if(rendered === 0) { for(var i in Chart.instances) { if(!Chart.instances.hasOwnProperty(i)) continue; let chart = Chart.instances[i]; let base64 = chart.toBase64Image(); $(form).append(""); } $(form).data("rendered", "1"); } $(form).find("input[type=submit]").click(); }