<commit_before>﻿(function (controllers, undefined) {
   
    /**
     * @ngdoc controller
     * @name Merchello.Dashboards.Report.SalesByItemController
     * @function
     * 
     * @description
     * The controller for the reports SalesByItem page
     */
    controllers.SalesByItemController = function ($scope, $element, assetsService, angularHelper, merchelloPluginReportSalesByItemService) {

        $scope.loaded = false;
        $scope.preValuesLoaded = true;
        $scope.results = [];
        $scope.itemsPerPage = 0;
        $scope.totalItems = 0;
        $scope.filterStartDate = '';
        $scope.filterEndDate = '';

        /**
         * @ngdoc method
         * @name setupDatePicker
         * @function
         * 
         * @description
         * Sets up the datepickers
        */
        $scope.setupDatePicker = function (pickerId) {

            // Open the datepicker and add a changeDate eventlistener
            $element.find(pickerId).datetimepicker();

            //Ensure to remove the event handler when this instance is destroyted
            $scope.$on('$destroy', function () {
                $element.find(pickerId).datetimepicker("destroy");
            });
        };

        assetsService.loadCss('/App_Plugins/Merchello/Common/Css/merchello.css');
        assetsService.loadCss('lib/datetimepicker/bootstrap-datetimepicker.min.css').then(function () {
            var filesToLoad = ["lib/datetimepicker/bootstrap-datetimepicker.min.js"];
            assetsService.load(filesToLoad).then(
                function () {
                    //The Datepicker js and css files are available and all components are ready to use.
                    $scope.setupDatePicker("#filterStartDate");
                    $element.find("#filterStartDate").datetimepicker().on("changeDate", $scope.applyDateStart);

                    $scope.setupDatePicker("#filterEndDate");
                    $element.find("#filterEndDate").datetimepicker().on("changeDate", $scope.applyDateEnd);
                });
        });


        //handles the date changing via the api
        $scope.applyDateStart = function (e) {
            angularHelper.safeApply($scope, function () {
                // when a date is changed, update the model
                if (e.localDate) {
                    $scope.filterStartDate = e.localDate.toIsoDateString();
                }
            });
        }

        //handles the date changing via the api
        $scope.applyDateEnd = function (e) {
            angularHelper.safeApply($scope, function () {
                // when a date is changed, update the model
                if (e.localDate) {
                    $scope.filterEndDate = e.localDate.toIsoDateString();
                }
            });
        }

        $scope.setDefaultDates = function(actual) {
            var month = actual.getMonth() == 0 ? 11 : actual.getMonth() - 1;

            var start = new Date(actual.getFullYear(), month, actual.getDay());
            $scope.applyDateStart(start.toIsoDateString());
            $scope.applyDateEnd(actual.toIsoDateString());
        }

        
        $scope.defaultData = function () {
            
            var promise = merchelloPluginReportSalesByItemService.getDefaultData();
            promise.then(function (data) {
                $scope.loaded = true;
                $scope.results = _.map(data.items, function(resultFromServer) {
                    return new merchello.Models.SaleByItemResult(resultFromServer, true);
                });
                $scope.itemsPerPage = data.itemsPerPage;
                $scope.totalItems = data.totalItems;
            });

        };

        $scope.init = function () {
            $scope.setDefaultDates(new Date());
            $scope.defaultData();
            $scope.loaded = true;
        };

        $scope.init();
    };


    angular.module("umbraco").controller("Merchello.Plugins.Reports.SalesByItemController", ['$scope', '$element', 'assetsService', 'angularHelper', 'merchelloPluginReportSalesByItemService', merchello.Controllers.SalesByItemController]);


}(window.merchello.Controllers = window.merchello.Controllers || {}));
<commit_msg>Initial work on report date filters.<commit_after>﻿(function (controllers, undefined) {
   
    /**
     * @ngdoc controller
     * @name Merchello.Dashboards.Report.SalesByItemController
     * @function
     * 
     * @description
     * The controller for the reports SalesByItem page
     */
    controllers.SalesByItemController = function ($scope, $element, assetsService, angularHelper, merchelloPluginReportSalesByItemService) {

        $scope.loaded = false;
        $scope.preValuesLoaded = true;
        $scope.results = [];
        $scope.itemsPerPage = 0;
        $scope.totalItems = 0;
        $scope.filterStartDate = '';
        $scope.filterEndDate = '';

        /**
         * @ngdoc method
         * @name setupDatePicker
         * @function
         * 
         * @description
         * Sets up the datepickers
        */
        $scope.setupDatePicker = function (pickerId) {

            // Open the datepicker and add a changeDate eventlistener
            $element.find(pickerId).datetimepicker();

            //Ensure to remove the event handler when this instance is destroyted
            $scope.$on('$destroy', function () {
                $element.find(pickerId).datetimepicker("destroy");
            });
        };

        assetsService.loadCss('/App_Plugins/Merchello/Common/Css/merchello.css');
        assetsService.loadCss('lib/datetimepicker/bootstrap-datetimepicker.min.css').then(function () {
            var filesToLoad = ["lib/datetimepicker/bootstrap-datetimepicker.min.js"];
            assetsService.load(filesToLoad).then(
                function () {
                    //The Datepicker js and css files are available and all components are ready to use.
                    $scope.setupDatePicker("#filterStartDate");
                    $element.find("#filterStartDate").datetimepicker().on("changeDate", $scope.applyDateStart);

                    $scope.setupDatePicker("#filterEndDate");
                    $element.find("#filterEndDate").datetimepicker().on("changeDate", $scope.applyDateEnd);
                });
        });


        //handles the date changing via the api
        $scope.applyDateStart = function (e) {
            angularHelper.safeApply($scope, function () {
                // when a date is changed, update the model
                if (e.localDate) {
                    $scope.filterStartDate = e.localDate.toIsoDateString();
                }
            });
        }

        //handles the date changing via the api
        $scope.applyDateEnd = function (e) {
            angularHelper.safeApply($scope, function () {
                // when a date is changed, update the model
                if (e.localDate) {
                    $scope.filterEndDate = e.localDate.toIsoDateString();
                }
            });
        }

        $scope.setDefaultDates = function(actual) {
            var month = actual.getMonth() == 0 ? 11 : actual.getMonth() - 1;

            var start = new Date(actual.getFullYear(), month, actual.getDay());
            $scope.applyDateStart(start);
            $scope.applyDateEnd(actual);
        }

        
        $scope.defaultData = function () {
            
            var promise = merchelloPluginReportSalesByItemService.getDefaultData();
            promise.then(function (data) {
                $scope.loaded = true;
                $scope.results = _.map(data.items, function(resultFromServer) {
                    return new merchello.Models.SaleByItemResult(resultFromServer, true);
                });
                $scope.itemsPerPage = data.itemsPerPage;
                $scope.totalItems = data.totalItems;
            });

        };

        $scope.init = function () {
            $scope.setDefaultDates(new Date());
            $scope.defaultData();
            $scope.loaded = true;
        };

        $scope.init();
    };


    angular.module("umbraco").controller("Merchello.Plugins.Reports.SalesByItemController", ['$scope', '$element', 'assetsService', 'angularHelper', 'merchelloPluginReportSalesByItemService', merchello.Controllers.SalesByItemController]);


}(window.merchello.Controllers = window.merchello.Controllers || {}));

{'fraction_non_alphanumeric': 0.11668847389080528, 'fraction_numerical': 0.0014273819436184131, 'mean_word_length': 1.9636940430031724, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6895500', 'n_tokens_mistral': 2234, 'n_tokens_neox': 2139, 'n_words': 405}