reports.js.html

About this file

This file contains the scripts to draw the reports in a chart form, used for displaying the number of requests assigned to a specific agency from the database. The scripts also draw the reports dependent on the changes made in filters.

Code Issues

  • drawChart(labels, values) needs a docstring.
  • The code below has a triangle formation appearing on the left. In addition, the click event handler for the submit button runs from liens 116 to 221. Recommend refactoring some of the functions used for AJAX success into functions with function names.
                
                submit.click(function () {
                    // Behavior when user is agency agency admin/super user and the user filter is visible
                    if ((agencyAdmin || superUser) && userFilterDiv.is(":visible")) {
                        $.ajax({
                            url: "/report/",
                            type: "GET",
                            data: {
                                user_guid: agencyUserFilter.val(),
                                agency_ein: agencyFilter.val()
                            },
                            success: function (data) {
                                if (data.is_visible) {
                                    for (var i = 0; i < (data.values).length; ++i) {
                                        reportChart.data.datasets[0].data[i] = data.values[i]
                                    }
                                    var maxTicks = Math.min(Math.max.apply(null, data.values), 10);
                                    reportChart.options.scales.yAxes[0].ticks.maxTicksLimit = 10;
                                    reportChart.options.scales.yAxes[0].ticks.stepSize = maxTicks < 10 ? 1 : false;
                                    reportChart.update();
                                    if ($("#agency-user-filter option:selected").text() === "") {
    
                
            
  • Some of the code in the submit click handler that is seen in the first if statement is repeated in the else statement paired that if statement. For example:
                
                    for (var i = 0; i < (data.values).length; ++i) {
                        reportChart.data.datasets[0].data[i] = data.values[i]
                    }
                    var maxTicks = Math.min(Math.max.apply(null, data.values), 10);
                    reportChart.options.scales.yAxes[0].ticks.maxTicksLimit = 10;
                    reportChart.options.scales.yAxes[0].ticks.stepSize = maxTicks < 10 ? 1 : false;
                    reportChart.update();
                
            
    The chunk of code above is repeated and can be refactored.
  • $("#reportChart")'s attribute is set many times with a repeating constant message: "Bar graph of all FOIL requests in OpenRecords.". Recommend storing the constant message inside a variable.
  • Similar to above, chartDescription's html is set with a constant string: "This chart represents the aggregate data of all requests opened on OpenRecords, " + "along with the status of all requests.". Recommend storing the string inside a variable to make it easier to read the html that is being set.

Code Check Report


                        

Documentation drawn from source code

  function drawChart(labels, values) {
   success: function (data) {
  agencyFilter.change(function () {
    success: function (data) {
  submit.click(function () {
     success: function (data) {
     success: function (data) {
  clearFilter.click(function () {
    success: function (data) {
   .keydown(function (e) {
  ack_date_from.change(function () {

Source code