compucorp / uk.co.compucorp.civicrm.pivotreport

CiviCRM Pivot table reporting solution
Other
8 stars 13 forks source link

PCHR-3846: Add leave report filter #117

Closed reneolivo closed 3 years ago

reneolivo commented 6 years ago

Overview

This PR adds date filters to the admin's leave report.

Before

leave reports hr17 9000 20

After

anim

Technical details

The way default values for the custom filters are generated changed since for the leave report they depend on the current period provided by the API. The new sequence is as follows:

PivotTable.prototype.resolveCustomFilterDefaultValues = function () { var dateInputsDefaultValues = this.getDefaultValuesForDateInputs();

return $.when() .then(function () { return this.config.resolveCustomFilterDefaultValues ? this.config.resolveCustomFilterDefaultValues() : {}; }.bind(this)) .then(function (defaultValues) { // it also passes the date input default values so it's not necessary to define a // resolver just for date inputs of which their default is today: this.customFilterDefaultValues = _.extend({}, dateInputsDefaultValues, defaultValues); }.bind(this)); };

PivotTable.prototype.getDefaultValuesForDateInputs = function () { var defaultValues = {}; var today = moment().format(this.DEFAULT_DATE_FORMAT);

this.customFilterForm.find('.crm-ui-datepicker').each(function () { var inputName = $(this).attr('name');

defaultValues[inputName] = today;

});

return defaultValues; };

* After loading the pivot table data and the custom field default values, and during the post render sequence, the default values are assigned to the custom field inputs:
```js
PivotTable.prototype.initCustomFilterDefaultValues = function () {
  this.customFilterForm.find('input, select, textarea')
    .each(function (index, element) {
      var input = $(element);
      var inputName = input.attr('name');
      var inputDefaultValue = this.customFilterDefaultValues[inputName];

      if (!inputDefaultValue) {
        return;
      }

      input.on('change', function () {
        var isValueEmpty = _.isEmpty(input.val());

        if (isValueEmpty) {
          input.val(inputDefaultValue).change();
        }
      });
      input.change();
    }.bind(this));
};

If the input changes and the value is empty, it will use the default value instead.

Comments

tunbola commented 3 years ago

Not needed anymore.