<commit_before>"use strict";


module.exports = function()
{
    function controller(kauReportsData, $timeout)
    {
        var self = this;
        var sections = [];
        var requiredReportConfigParameters =["reportId", "data.reportType"];
        var areAllSectionsLoaded = false;

        function notifyOnEvent(name, context)
        {
            _.forEach(sections,function(section)
            {
                if (section.on)
                {
                    section.on.call(null,name,context);
                }
            });
        }

        function updateStatus(statusType, context)
        {
            switch (statusType)
            {
                case "error":
                    self.reportStatus.errorMessage = context.errorMessage;
                    break;
                case "loading":
                    self.reportStatus.isLoading = context.isLoading;
                    break;
            }
        }

        function loadData() {
            if (!areAllSectionsLoaded)
            {
                return;
            }

            self.reportStatus.isLoading = true;
            self.reportStatus.errorMessage = '';


            var filters = { reportType : self.reportConfig.data.reportType };

            _.forEach(sections,function(section)
            {
                if (section.assignFilters)
                {
                    section.assignFilters.call(section,filters);
                }
            });

            kauReportsData.getReportData(filters).then(function (result) {

                self.reportData = result.data;
                self.reportStatus.hasData = true;

                _.forEach(sections,function(section)
                {
                    if (section.loadReportData)
                    {
                        section.loadReportData.call(section, result.data);
                    }
                });

                self.reportStatus.isLoading = false;
            }, function (reason) {
                self.reportData = null;
                self.reportStatus.hasData = false;
                self.reportStatus.errorMessage = "Failed to load data : '" + reason.errorMessage + "'";
                self.reportStatus.isLoading = false;
            });
        }

        function addSection(section)
        {
            sections.push(section);

            // extend section api with functions that can trigger report actions
            $.extend(section,{refreshReport : loadData});

            // wait until all sections were added to load data
            if (sections.length=== self.reportConfig.sections.length)
            {
                areAllSectionsLoaded = true;

                $timeout(function()
                {
                    // Loads the report data after all sections where registered in the next digest cycle
                    // TODO - should use more common technique.
                    loadData();
                },200);

            }
        }

        function buildReport(reportId)
        {<commit_msg>handle unexpected scenario of invalid date typed by user<commit_after>"use strict";


module.exports = function()
{
    function controller(kauReportsData, $timeout)
    {
        var self = this;
        var sections = [];
        var requiredReportConfigParameters =["reportId", "data.reportType"];
        var areAllSectionsLoaded = false;

        function notifyOnEvent(name, context)
        {
            _.forEach(sections,function(section)
            {
                if (section.on)
                {
                    section.on.call(null,name,context);
                }
            });
        }

        function updateStatus(statusType, context)
        {
            switch (statusType)
            {
                case "error":
                    self.reportStatus.errorMessage = context.errorMessage;
                    break;
                case "loading":
                    self.reportStatus.isLoading = context.isLoading;
                    break;
            }
        }

        function loadData() {
            if (!areAllSectionsLoaded)
            {
                return;
            }

            self.reportStatus.isLoading = true;
            self.reportStatus.errorMessage = '';


            var filters = { reportType : self.reportConfig.data.reportType };

            _.forEach(sections,function(section)
            {
                if (section.assignFilters)
                {
                    section.assignFilters.call(section,filters);
                }
            });

            kauReportsData.getReportData(filters).then(function (result) {

                self.reportData = result.data;
                self.reportStatus.hasData = true;

                _.forEach(sections,function(section)
                {
                    if (section.loadReportData)
                    {
                        section.loadReportData.call(section, result.data);
                    }
                });

                self.reportStatus.isLoading = false;
            }, function (reason) {
                self.reportData = null;
                self.reportStatus.hasData = false;
                self.reportStatus.errorMessage = "Failed to load data : '" + reason.errorMessage + "'";
                self.reportStatus.isLoading = false;
            });
        }

        function clearReportData()
        {
            self.reportData = null;

            _.forEach(sections,function(section)
            {
                if (section.loadReportData)
                {
                    section.loadReportData.call(section, self.reportData);
                }
            });
        }

        function addSection(section)
        {
            sections.push(section);

            // extend section api with functions that can trigger report actions
            $.extend(section,{refreshReport : loadData, clearReportData:clearReportData});

            // wait until all sections were added to load data
            if (sections.length=== self.reportConfig.sections.length)
            {
                areAllSectionsLoaded = true;

                $timeout(function()
                {
                    // Loads the report data after all sections where registered in the next digest cycle
                    // TODO - should use more common technique.
                    loadData();
                },200);

            }
        }

        function buildReport(reportId)
        {
{'fraction_non_alphanumeric': 0.08570112117954232, 'fraction_numerical': 0.0009215174320380894, 'mean_word_length': 1.251728907330567, 'pattern_counts': {'":': 4, '<': 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': '2276462', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1426, 'n_words': 294}