<commit_before>//services.factory('reportService', function($q,ReportPrograms){
//
//  var programs = function(ReportPrograms){
//    var deferred = $q.defer();
//
//    $timeout(function(){
//      ReportPrograms.get(function (data) {
//        var ps = data.programs;
//
//        ps.unshift({
//          'name': '-- Select Programs --'
//        });
//
//        deferred.resolve(ps);
//      });
//      return deferred.promise();
//    },100);
//  };
//
//  return {
//    programs: programs
//  }
//
//});



app.directive('filterContainer', ['$routeParams', '$location',function ($location) {
  return {
    restrict: 'EA',
    scope: true,
    controller: function($scope, $routeParams, $location){
      $scope.filter = angular.copy($routeParams);
      //$scope.OnFilterChanged();

      $scope.filterChanged = function(){
        // update the url so users could take it, book mark it etc...
        angular.forEach($scope.requiredFilters, function(value){

          if(isUndefined($scope.filter[value]) || $scope.filter[value] === '' || $scope.filter[value] === 0 ){

            return;
          }
        });

        if(JSON.stringify($scope.filter) !== JSON.stringify($routeParams)){
          var url = $location.url();
          url = url.substring(0, url.indexOf('?'));
          url = url + '?' + jQuery.param($scope.filter);
          $location.url(url);
        }
        $scope.$parent.filter = $scope.filter;
        $scope.$parent.OnFilterChanged();
      };

      $scope.filterChanged();
    },
    link: function (scope, elm, attrs) {
      angular.extend(scope, {
        //filter: {},
        requiredFilters: {},
        showMoreFilters: false,
        toggleMoreFilters: function () {
          scope.showMoreFilters = !scope.showMoreFilters;
        }
      });
    }
  };
}]);

// now comes the program filter
app.directive('programFilter', ['ReportPrograms',
  function (ReportPrograms) {
    return {
      restrict: 'E',
      require: '^filterContainer',
      link: function (scope, elm, attr) {

        if (attr.required) {
          scope.requiredFilters.program = 'program';
        }
        scope.$evalAsync(function(){
          ReportPrograms.get(function (data) {
            scope.programs = data.programs;
            scope.programs.unshift({
              'name': '-- Select Programs --'
            });
          });
        });
      },
      templateUrl: 'filter-program-template'
    };
}]);

app.directive('yearFilter', ['OperationYears',
  function (OperationYears) {
    return {
      restrict: 'E',
      controller: function($scope){

      },
      require: '^filterContainer',
      link: function (scope, elm, attr) {

        if (attr.required) {
          scope.requiredFilters.year = 'year';
        }
        scope.$evalAsync(function() {
          OperationYears.get(function (data) {
            scope.years = data.years;
            scope.filter.year = data.years[0];
          });
        });
      },
      templateUrl: 'filter-year-template'
    };
}]);

app.directive('facilityTypeFilter', ['ReportFacilityTypes',
  function (ReportFacilityTypes) {
    return {
      restrict: 'E',
      link: function (scope, elm, attr) {

        scope.facilityTypes = [];
        scope.facilityTypes.unshift({
          'name': '-- All Facility Types --'
        });

        if (attr.required) {
          scope.requiredFilters.facilityType = 'facilityType';
        }

        ReportFacilityTypes.get(function (data) {
          scope.facilityTypes = data.facilityTypes;
          scope.facilityTypes.unshift({
            'name': '-- All Facility Types --'
          });
        });
      },
      templateUrl: 'filter-facility-type-template'
    };
}]);

app.directive('scheduleFilter', ['ReportSchedules','$routeParams',
  function (ReportSchedules, $routeParams) {
    return {
      restrict: 'E',
      require: '^filterContainer',
      link: function (scope, elm, attr) {

        scope.schedules = [];
        scope.schedules.unshift({
          name: '-- Select Group --'
        });
        scope.filter.schedule = $routeParams.schedule;

        if (attr.required) {
          scope.requiredFilters.schedule = 'schedule';
        }
        scope.$evalAsync(function() {
          ReportSchedules.get(function (data) {
            scope.schedules = data.schedules;
            scope.schedules.unshift({
              name: '-- Select Group --'
            });
          });
        });
      },
      templateUrl: 'filter-schedule-template'
    };
}]);


app.directive('periodFilter', ['ReportPeriods', 'ReportPeriodsByScheduleAndYear','$routeParams',
  function (ReportPeriods, ReportPeriodsByScheduleAndYear, $routeParams) {

    var onCascadedVarsChanged = function ($scope, newValue) {
      // don't call the server if you don't have all that it takes.
      if (isUndefined($scope.filter) || isUndefined($scope.filter.year) || isUndefined($scope.filter.schedule))
        return;

      if (angular.isDefined($scope.filter) && $scope.filter.year !== undefined && $scope.filter.schedule !== undefined) {
        ReportPeriodsByScheduleAndYear.get({
          scheduleId: $scope.filter.schedule,
          year: $scope.filter.year
        }, function (data) {
          $scope.periods = data.periods;
          if (data.periods !== undefined && data.periods.length > 0)
            $scope.periods.unshift({
              'name': '-- Select a Period --',
              'id': '0'
            });
          $scope.filter.period = $routeParams.period;
        });

      } else {
        if (angular.isDefined($scope.filter) && angular.isDefined($scope.filter.schedule)) {
          scope.$evalAsync(function() {
            ReportPeriods.get({
              scheduleId: $scope.filter.schedule
            }, function (data) {
              $scope.periods = data.periods;
              if (data.periods !== undefined && data.periods.length > 0)
                $scope.periods.unshift({
                  'name': '-- Select a Period --',
                  'id': '0'
                });
            });
          });
        }

      }

    };

    return {
      restrict: 'E',
      require: '^filterContainer',
      link: function (scope, elm, attr) {

        scope.periods = [];
        scope.periods.push({
          name: '-- Select Period --'
        });

        if (attr.required) {
          scope.requiredFilters.period = 'period';
        }

        scope.$watch('filter.year', function (value) {
          onCascadedVarsChanged(scope, value);
        });
        scope.$watch('filter.schedule', function (value) {
          onCascadedVarsChanged(scope, value);
        });

      },
      templateUrl: 'filter-period-template'
    };
}]);


app.directive('requisitionGroupFilter', ['RequisitionGroupsByProgram',
  function (RequisitionGroupsByProgram) {

    var onRgCascadedVarsChanged = function ($scope, newValue) {

      if (isUndefined($scope.filter) || isUndefined($scope.filter.program) || $scope.filter.program === 0)
        return;

        RequisitionGroupsByProgram.get({
          program: $scope.filter.program
        }, function (data) {
          $scope.requisitionGroups = data.requisitionGroupList;
          if ($scope.requisitionGroups === undefined || $scope.requisitionGroups.length === 0) {
            $scope.requisitionGroups = [];
            $scope.requisitionGroups.push({
              'name': '-- All Requisition Groups --'
            });
          } else {
            $scope.requisitionGroups.unshift({
              'name': '-- All Requisition Groups --'
            });
          }
        });
    };

    return {
      restrict: 'E',
      require: '^filterContainer',
      link: function (scope, elm, attr) {

        scope.requisitionGroups = [];
        scope.requisitionGroups.unshift({
          'name': '-- All Requisition Groups --',
          id: 0
        });
        scope.filter.requisitionGroup = 0;

        if (attr.required) {
          scope.requiredFilters.requisitionGroup = 'requisitionGroup';
        }

        scope.$watch('filter.program', function (value) {
          onRgCascadedVarsChanged(scope, value);
        });
      },
      templateUrl: 'filter-requisition-group-template'
    };
}]);


app.directive('adjustmentTypeFilter',['AdjustmentTypes', function(AdjustmentTypes){

  return {
    restrict: 'E',
    require: '^filterContainer',
    link: function (scope, elm, attr) {

      AdjustmentTypes.get(function (data) {
        scope.adjustmentTypes = data.adjustmentTypeList;
        scope.adjustmentTypes.unshift({'description': '--All Adjustment Types --'});
      });

      if (attr.required) {
        scope.requiredFilters.adjustmentType = 'adjustmentType';
      }
    },
    templateUrl: 'filter-adjustment-type-template'
  };

}]);


app.directive('productCategoryFilter', ['ProductCategoriesByProgram',
  function (ProductCategoriesByProgram) {

    var onPgCascadedVarsChanged = function ($scope, newValue) {

      if (isUndefined($scope.filter) || isUndefined($scope.filter.program) || $scope.filter.program === 0)
        return;

      // load the program-product categories
      ProductCategoriesByProgram.get({
        programId: $scope.filter.program
      }, function (data) {
        $scope.productCategories = data.productCategoryList;
        $scope.productCategories.unshift({
          'name': '-- All Product Categories --'
        });
      });
    };

    return {
      restrict: 'E',
      require: '^filterContainer',
      link: function (scope, elm, attr) {

        scope.productCategories = [];
        scope.productCategories.unshift({
          'name': '-- All Product Categories --'
        });

        if (attr.required) {
          scope.requiredFilters.productCategory = 'productCategory';
        }

        scope.$watch('filter.program', function (value) {
          onPgCascadedVarsChanged(scope, value);
        });
      },
      templateUrl: 'filter-product-category-template'
    };
}]);

app.directive('facilityFilter', ['FacilitiesByProgramParams',
  function (FacilitiesByProgramParams) {

    var onPgCascadedVarsChanged = function ($scope, newValue) {

      if (isUndefined($scope.filter) || isUndefined($scope.filter.program) || $scope.filter.program === 0)
        return;

      var program = (angular.isDefined($scope.filter) && angular.isDefined($scope.filter.program)) ? $scope.filter.program : 0;
      var schedule = (angular.isDefined($scope.filter) && angular.isDefined($scope.filter.schedule)) ? $scope.filter.schedule : 0;
      var facilityType = (angular.isDefined($scope.filter) && angular.isDefined($scope.filter.facilityType)) ? $scope.filter.facilityType : 0;
      var requisitionGroup = (angular.isDefined($scope.filter) && angular.isDefined($scope.filter.requisitionGroup)) ? $scope.filter.requisitionGroup : 0;
      // load facilities
      FacilitiesByProgramParams.get({
        program: program,
        schedule: schedule,
        type: facilityType,
        requisitionGroup: requisitionGroup
      }, function (data) {
        $scope.facilities = data.facilities;
        if (isUndefined($scope.facilities)) {
          $scope.facilities = [];
        }
        $scope.facilities.unshift({
          name: '-- All Facilities --'
        });
      });
    };

    return {
      restrict: 'E',
      require: '^filterContainer',
      link: function (scope, elm, attr) {

        scope.facilities = [];
        scope.facilities.push({
          name: '-- All Facilities --'
        });

        if (attr.required) {
          scope.requiredFilters.facility = 'facility';
        }

        scope.$watch('filter.requisitionGroup', function (value) {
          onPgCascadedVarsChanged(scope, value);
        });

        scope.$watch('filter.program', function (value) {
          onPgCascadedVarsChanged(scope, value);
        });
        scope.$watch('filter.schedule', function (value) {
          onPgCascadedVarsChanged(scope, value);
        });
        scope.$watch('filter.facilityType', function (value) {
          onPgCascadedVarsChanged(scope, value);
        });
      },
      templateUrl: 'filter-facility-template'
    };
}]);

app.directive('productFilter', ['ReportProductsByProgram',
  function (ReportProductsByProgram) {

    var onPgCascadedVarsChanged = function ($scope, newValue) {

      if (isUndefined($scope.filter) || isUndefined($scope.filter.program) || $scope.filter.program === 0)
        return;

      var program = (angular.isDefined($scope.filter) && angular.isDefined($scope.filter.program)) ? $scope.filter.program : 0;
      ReportProductsByProgram.get({
        programId: program
      }, function (data) {
        $scope.products = data.productList;
        $scope.products.unshift({
          'name': '-- Indicator Products --',
          id: 0
        });
        $scope.products.unshift({
          'name': '-- All Products --',
          id: -1
        });

      });

    };


    return {
      restrict: 'E',
      link: function (scope, elm, attr) {

        scope.products = [];
        scope.products.push({
          'name': '-- All Products --',
          id: -1
        });

        scope.filter.product = -1;

        if (attr.required) {
          scope.requiredFilters.product = 'product';
        }

        scope.productCFilter = function (option) {
          return (!angular.isDefined(scope.filter) || !angular.isDefined(scope.filter.productCategory) || scope.filter.productCategory === '' || option.categoryId == scope.filter.productCategory);
        };


        scope.$watch('filter.program', function (value) {
          onPgCascadedVarsChanged(scope, value);
        });
      },
      templateUrl: 'filter-product-template'
    };

}]);


app.directive('clientSideSortPagination', ['$filter', 'ngTableParams',
  function ($filter, ngTableParams) {

    return {
      restrict: 'A',
      link: function (scope, elm, attr) {

        // the grid options
        scope.tableParams = new ngTableParams({
          page: 1, // show first page
          total: 0, // length of data
          count: 25 // count per page
        });

        scope.paramsChanged = function (params) {

          // slice array data on pages
          if (scope.data === undefined) {<commit_msg>enhance deep linking on reports<commit_after>//services.factory('reportService', function($q,ReportPrograms){
//
//  var programs = function(ReportPrograms){
//    var deferred = $q.defer();
//
//    $timeout(function(){
//      ReportPrograms.get(function (data) {
//        var ps = data.programs;
//
//        ps.unshift({
//          'name': '-- Select Programs --'
//        });
//
//        deferred.resolve(ps);
//      });
//      return deferred.promise();
//    },100);
//  };
//
//  return {
//    programs: programs
//  }
//
//});



app.directive('filterContainer', ['$routeParams', '$location',function ($location) {
  return {
    restrict: 'EA',
    scope: true,
    controller: function($scope, $routeParams, $location){
      $scope.filter = angular.copy($routeParams);
      //$scope.OnFilterChanged();

      $scope.filterChanged = function(){
        // update the url so users could take it, book mark it etc...
        angular.forEach($scope.requiredFilters, function(value){

          if(isUndefined($scope.filter[value]) || $scope.filter[value] === '' || $scope.filter[value] === 0 ){

            return;
          }
        });

        if(JSON.stringify($scope.filter) !== JSON.stringify($routeParams)){
          var url = $location.url();
          url = url.substring(0, url.indexOf('?'));
          url = url + '?' + jQuery.param($scope.filter);
          $location.url(url);
        }
        $scope.$parent.filter = $scope.filter;
        $scope.$parent.OnFilterChanged();
      };

      $scope.filterChanged();
    },
    link: function (scope, elm, attrs) {
      angular.extend(scope, {
        //filter: {},
        requiredFilters: {},
        showMoreFilters: false,
        toggleMoreFilters: function () {
          scope.showMoreFilters = !scope.showMoreFilters;
        }
      });
    }
  };
}]);

// now comes the program filter
app.directive('programFilter', ['ReportPrograms',
  function (ReportPrograms) {
    return {
      restrict: 'E',
      require: '^filterContainer',
      link: function (scope, elm, attr) {

        if (attr.required) {
          scope.requiredFilters.program = 'program';
        }
        scope.$evalAsync(function(){
          ReportPrograms.get(function (data) {
            scope.programs = data.programs;
            scope.programs.unshift({
              'name': '-- Select Programs --'
            });
          });
        });
      },
      templateUrl: 'filter-program-template'
    };
}]);

app.directive('yearFilter', ['OperationYears',
  function (OperationYears) {
    return {
      restrict: 'E',
      controller: function($scope){

      },
      require: '^filterContainer',
      link: function (scope, elm, attr) {

        if (attr.required) {
          scope.requiredFilters.year = 'year';
        }
        scope.$evalAsync(function() {
          OperationYears.get(function (data) {
            scope.years = data.years;
            scope.filter.year = data.years[0];
          });
        });
      },
      templateUrl: 'filter-year-template'
    };
}]);

app.directive('facilityTypeFilter', ['ReportFacilityTypes', '$routeParams',
  function (ReportFacilityTypes, $routeParams) {
    return {
      restrict: 'E',
      link: function (scope, elm, attr) {

        scope.facilityTypes = [];
        scope.facilityTypes.unshift({
          'name': '-- All Facility Types --', id: 0
        });

        if (attr.required) {
          scope.requiredFilters.facilityType = 'facilityType';
        }

          scope.filter.facilityType = (isUndefined($routeParams.facilityType) || $routeParams.facilityType === '')? 0: $routeParams.facilityType;


          ReportFacilityTypes.get(function (data) {
          scope.facilityTypes = data.facilityTypes;
          scope.facilityTypes.unshift({
            'name': '-- All Facility Types --', id: 0
          });
        });
      },
      templateUrl: 'filter-facility-type-template'
    };
}]);

app.directive('scheduleFilter', ['ReportSchedules','$routeParams',
  function (ReportSchedules, $routeParams) {
    return {
      restrict: 'E',
      require: '^filterContainer',
      link: function (scope, elm, attr) {

        scope.schedules = [];
        scope.schedules.unshift({
          name: '-- Select Group --'
        });
        scope.filter.schedule = $routeParams.schedule;

        if (attr.required) {
          scope.requiredFilters.schedule = 'schedule';
        }
        scope.$evalAsync(function() {
          ReportSchedules.get(function (data) {
            scope.schedules = data.schedules;
            scope.schedules.unshift({
              name: '-- Select Group --'
            });
          });
        });
      },
      templateUrl: 'filter-schedule-template'
    };
}]);


app.directive('periodFilter', ['ReportPeriods', 'ReportPeriodsByScheduleAndYear','$routeParams',
  function (ReportPeriods, ReportPeriodsByScheduleAndYear, $routeParams) {

    var onCascadedVarsChanged = function ($scope, newValue) {
      // don't call the server if you don't have all that it takes.
      if (isUndefined($scope.filter) || isUndefined($scope.filter.year) || isUndefined($scope.filter.schedule))
        return;

      if (angular.isDefined($scope.filter) && $scope.filter.year !== undefined && $scope.filter.schedule !== undefined) {
        ReportPeriodsByScheduleAndYear.get({
          scheduleId: $scope.filter.schedule,
          year: $scope.filter.year
        }, function (data) {
          $scope.periods = data.periods;
          if (data.periods !== undefined && data.periods.length > 0)
            $scope.periods.unshift({
              'name': '-- Select a Period --',
              'id': '0'
            });
          $scope.filter.period = $routeParams.period;
        });

      } else {
        if (angular.isDefined($scope.filter) && angular.isDefined($scope.filter.schedule)) {
          scope.$evalAsync(function() {
            ReportPeriods.get({
              scheduleId: $scope.filter.schedule
            }, function (data) {
              $scope.periods = data.periods;
              if (data.periods !== undefined && data.periods.length > 0)
                $scope.periods.unshift({
                  'name': '-- Select a Period --',
                  'id': '0'
                });
            });
          });
        }

      }

    };

    return {
      restrict: 'E',
      require: '^filterContainer',
      link: function (scope, elm, attr) {

        scope.periods = [];
        scope.periods.push({
          name: '-- Select Period --'
        });

        if (attr.required) {
          scope.requiredFilters.period = 'period';
        }

        scope.$watch('filter.year', function (value) {
          onCascadedVarsChanged(scope, value);
        });
        scope.$watch('filter.schedule', function (value) {
          onCascadedVarsChanged(scope, value);
        });

      },
      templateUrl: 'filter-period-template'
    };
}]);


app.directive('requisitionGroupFilter', ['RequisitionGroupsByProgram','$routeParams',
  function (RequisitionGroupsByProgram, $routeParams) {

    var onRgCascadedVarsChanged = function ($scope, newValue) {

      if (isUndefined($scope.filter) || isUndefined($scope.filter.program) || $scope.filter.program === 0)
        return;

        RequisitionGroupsByProgram.get({
          program: $scope.filter.program
        }, function (data) {
          $scope.requisitionGroups = data.requisitionGroupList;
          if ($scope.requisitionGroups === undefined || $scope.requisitionGroups.length === 0) {
            $scope.requisitionGroups = [];
            $scope.requisitionGroups.push({
              'name': '-- All Requisition Groups --', id: 0
            });
          } else {
            $scope.requisitionGroups.unshift({
              'name': '-- All Requisition Groups --', id: 0
            });
          }
        });
    };

    return {
      restrict: 'E',
      require: '^filterContainer',
      link: function (scope, elm, attr) {

        scope.requisitionGroups = [];
        scope.requisitionGroups.unshift({
          'name': '-- All Requisition Groups --',
          id: 0
        });
          scope.filter.requisitionGroup = (isUndefined($routeParams.requisitionGroup) || $routeParams.requisitionGroup === '')? 0: $routeParams.requisitionGroup;

          if (attr.required) {
          scope.requiredFilters.requisitionGroup = 'requisitionGroup';
        }

        scope.$watch('filter.program', function (value) {
          onRgCascadedVarsChanged(scope, value);
        });
      },
      templateUrl: 'filter-requisition-group-template'
    };
}]);


app.directive('adjustmentTypeFilter',['AdjustmentTypes', function(AdjustmentTypes){

  return {
    restrict: 'E',
    require: '^filterContainer',
    link: function (scope, elm, attr) {

      AdjustmentTypes.get(function (data) {
        scope.adjustmentTypes = data.adjustmentTypeList;
        scope.adjustmentTypes.unshift({'description': '--All Adjustment Types --',id:0});
      });

      if (attr.required) {
        scope.requiredFilters.adjustmentType = 'adjustmentType';
      }
    },
    templateUrl: 'filter-adjustment-type-template'
  };

}]);


app.directive('productCategoryFilter', ['ProductCategoriesByProgram','$routeParams',
  function (ProductCategoriesByProgram, $routeParams) {

    var onPgCascadedVarsChanged = function ($scope, newValue) {

      if (isUndefined($scope.filter) || isUndefined($scope.filter.program) || $scope.filter.program === 0)
        return;

      // load the program-product categories
      ProductCategoriesByProgram.get({
        programId: $scope.filter.program
      }, function (data) {
        $scope.productCategories = data.productCategoryList;
        $scope.productCategories.unshift({
          'name': '-- All Product Categories --', id: 0
        });
        scope.filter.productCategory = (isUndefined($routeParams.productCategory) || $routeParams.productCategory === '')? 0: $routeParams.productCategory;
      });
    };

    return {
      restrict: 'E',
      require: '^filterContainer',
      link: function (scope, elm, attr) {

        scope.productCategories = [];
        scope.productCategories.unshift({
          'name': '-- All Product Categories --', id: 0
        });

        if (attr.required) {
          scope.requiredFilters.productCategory = 'productCategory';
        }

        scope.filter.productCategory = (isUndefined($routeParams.productCategory) || $routeParams.productCategory === '')? 0: $routeParams.productCategory;

        scope.$watch('filter.program', function (value) {
          onPgCascadedVarsChanged(scope, value);
        });
      },
      templateUrl: 'filter-product-category-template'
    };
}]);

app.directive('facilityFilter', ['FacilitiesByProgramParams', '$routeParams',
  function (FacilitiesByProgramParams, $routeParams) {

    var onPgCascadedVarsChanged = function ($scope, newValue) {

      if (isUndefined($scope.filter) || isUndefined($scope.filter.program) || $scope.filter.program === 0)
        return;

      var program = (angular.isDefined($scope.filter) && angular.isDefined($scope.filter.program)) ? $scope.filter.program : 0;
      var schedule = (angular.isDefined($scope.filter) && angular.isDefined($scope.filter.schedule)) ? $scope.filter.schedule : 0;
      var facilityType = (angular.isDefined($scope.filter) && angular.isDefined($scope.filter.facilityType)) ? $scope.filter.facilityType : 0;
      var requisitionGroup = (angular.isDefined($scope.filter) && angular.isDefined($scope.filter.requisitionGroup)) ? $scope.filter.requisitionGroup : 0;
      // load facilities
      FacilitiesByProgramParams.get({
        program: program,
        schedule: schedule,
        type: facilityType,
        requisitionGroup: requisitionGroup
      }, function (data) {
        $scope.facilities = data.facilities;
        if (isUndefined($scope.facilities)) {
          $scope.facilities = [];
        }
        $scope.facilities.unshift({
          name: '-- All Facilities --',id: 0
        });
      });
    };

    return {
      restrict: 'E',
      require: '^filterContainer',
      link: function (scope, elm, attr) {

        scope.facilities = [];
        scope.facilities.push({
          name: '-- All Facilities --', id: 0
        });

        scope.filter.facility = (isUndefined($routeParams.facility) || $routeParams.facility === '')? 0: $routeParams.facility;

          if (attr.required) {
          scope.requiredFilters.facility = 'facility';
        }

        scope.$watch('filter.requisitionGroup', function (value) {
          onPgCascadedVarsChanged(scope, value);
        });

        scope.$watch('filter.program', function (value) {
          onPgCascadedVarsChanged(scope, value);
        });
        scope.$watch('filter.schedule', function (value) {
          onPgCascadedVarsChanged(scope, value);
        });
        scope.$watch('filter.facilityType', function (value) {
          onPgCascadedVarsChanged(scope, value);
        });
      },
      templateUrl: 'filter-facility-template'
    };
}]);

app.directive('productFilter', ['ReportProductsByProgram','$routeParams',
  function (ReportProductsByProgram, $routeParams) {

    var onPgCascadedVarsChanged = function ($scope, newValue) {

      if (isUndefined($scope.filter) || isUndefined($scope.filter.program) || $scope.filter.program === 0)
        return;

      var program = (angular.isDefined($scope.filter) && angular.isDefined($scope.filter.program)) ? $scope.filter.program : 0;
      ReportProductsByProgram.get({
        programId: program
      }, function (data) {
        $scope.products = data.productList;
        $scope.products.unshift({
          'name': '-- Indicator Products --',
          id: 0
        });
        $scope.products.unshift({
          'name': '-- All Products --',
          id: -1
        });

      });

    };


    return {
      restrict: 'E',
      link: function (scope, elm, attr) {

        scope.products = [];
        scope.products.push({
          'name': '-- All Products --',
          id: -1
        });

          scope.filter.product = (isUndefined($routeParams.product) || $routeParams.product === '')? -1: $routeParams.product;

          if (attr.required) {
          scope.requiredFilters.product = 'product';
        }

        scope.productCFilter = function (option) {
          return (!angular.isDefined(scope.filter) || !angular.isDefined(scope.filter.productCategory) || scope.filter.productCategory === '' || scope.filter.productCategory === '0' || option.categoryId == scope.filter.productCategory);
        };


        scope.$watch('filter.program', function (value) {
          onPgCascadedVarsChanged(scope, value);
        });
      },
      templateUrl: 'filter-product-template'
    };

}]);


app.directive('clientSideSortPagination', ['$filter', 'ngTableParams',
  function ($filter, ngTableParams) {

    return {
      restrict: 'A',
      link: function (scope, elm, attr) {

        // the grid options
        scope.tableParams = new ngTableParams({
          page: 1, // show first page
          total: 0, // length of data
          count: 25 // count per page
        });

        scope.paramsChanged = function (params) {

          // slice array data on pages
          if (scope.data === undefined) {
{'fraction_non_alphanumeric': 0.14921095225249528, 'fraction_numerical': 0.0024952792015106554, 'mean_word_length': 2.223236604716879, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6724184', 'n_tokens_mistral': 8594, 'n_tokens_neox': 8357, 'n_words': 1490}