<commit_before>"use strict";

perf.controller('CompareChooserCtrl', [
    '$state', '$stateParams', '$scope', 'ThRepositoryModel', 'ThResultSetModel',
    'phCompareDefaultNewRepo', 'phCompareDefaultOriginalRepo', 'JsonPushes',
    'thPerformanceBranches',
    function CompareChooserCtrl($state, $stateParams, $scope,
                                ThRepositoryModel, ThResultSetModel,
                                phCompareDefaultNewRepo,
                                phCompareDefaultOriginalRepo,
                                JsonPushes, thPerformanceBranches) {
        ThRepositoryModel.get_list().success(function(projects) {
            $scope.projects = projects;
            $scope.originalTipList = [];
            $scope.newTipList = [];

            $scope.originalProject = _.findWhere(projects, {
                name: ($stateParams.originalProject ?
                       $stateParams.originalProject : phCompareDefaultOriginalRepo)
            }) || projects[0];
            $scope.newProject = _.findWhere(projects, {
                name: ($stateParams.newProject ?
                       $stateParams.newProject : phCompareDefaultNewRepo)
            }) || projects[0];

            $scope.originalRevision = ($stateParams.originalRevision ?
                                       $stateParams.originalRevision : '');
            $scope.newRevision = ($stateParams.newRevision ?
                                  $stateParams.newRevision : '');

            var getRevisionTips = function(projectName, list) {
                // due to we push the revision data into list,
                // so we need clear the data before we push new data into it.
                list.splice(0, list.length);
                ThResultSetModel.getResultSets(projectName).then(function(response) {
                    var resultsets = response.data.results;
                    resultsets.forEach(function(revisionSet) {
                        list.push({
                            revision: revisionSet.revision,
                            author: revisionSet.author
                        });
                    });
                });
            };

            $scope.updateOriginalgRevisionTips = function() {
                getRevisionTips($scope.originalProject.name, $scope.originalTipList);
            };
            $scope.updateNewRevisionTips = function() {
                getRevisionTips($scope.newProject.name, $scope.newTipList);
            };
            $scope.updateOriginalgRevisionTips();
            $scope.updateNewRevisionTips();

            $scope.getOriginalTipRevision = function(tip) {
                $scope.originalRevision = tip;
            };

            $scope.getNewTipRevision = function(tip) {
                $scope.newRevision = tip;
            };

            $scope.getPreviousRevision = function() {
                $scope.proposedRevision = $scope.newRevisionError = null;

                // only check for a full revision
                if ($scope.newRevision.length != 12) return;

                $scope.proposedRevisionLoading = true;

                var promise;
                if ($scope.newProject.name === "try") {
                    // try require some special logic
                    var iProjs = _.filter($scope.projects, function(proj) {
                        return _.includes(thPerformanceBranches,
                                          proj.name);
                    });
                    promise = JsonPushes.getPreviousRevisionFrom(
                        $scope.newProject,
                        $scope.newRevision,
                        iProjs
                    );
                } else {
                    // any other branch
                    promise = JsonPushes.getPreviousRevision(
                        $scope.newProject,
                        $scope.newRevision
                    ).then(function (revision) {
                        return {
                            revision:revision,
                            project: $scope.newProject,
                        };
                    });
                }

                promise.then(
                    function(result) {
                        $scope.proposedRevision = {
                            revision: result.revision.slice(0, 12),
                            project: result.project
                        };
                    },
                    function(error) {
                        $scope.newRevisionError = error.toString();
                    }
                ).finally(function() {
                    $scope.proposedRevisionLoading = false;
                });
            };

            $scope.setProposedRevision = function() {
                var rev = $scope.proposedRevision;
                $scope.proposedRevision = null;
                $scope.originalProject = rev.project;
                $scope.originalRevision = rev.revision;
            };

            $scope.runCompare = function() {
                ThResultSetModel.getResultSetsFromRevision($scope.originalProject.name, $scope.originalRevision).then(
                    function(resultSets) {
                        $scope.originalRevisionError = undefined;
                    },
                    function(error) {
                        $scope.originalRevisionError = error;
                    }
                );

                ThResultSetModel.getResultSetsFromRevision($scope.newProject.name, $scope.newRevision).then(
                    function (resultSets) {
                        $scope.newRevisionError = undefined;
                        if ($scope.originalRevisionError === undefined && $scope.newRevisionError === undefined) {
                            $state.go('compare', {
                                originalProject: $scope.originalProject.name,
                                originalRevision: $scope.originalRevision,
                                newProject: $scope.newProject.name,
                                newRevision: $scope.newRevision
                            });
                        }
                    },
                    function (error) {
                        $scope.newRevisionError = error;
                    }
                );
            };
        });
    }]);
<commit_msg>Bug 1246398 - Automatically offer to set base revision when preloading perf compare chooser<commit_after>"use strict";

perf.controller('CompareChooserCtrl', [
    '$state', '$stateParams', '$scope', 'ThRepositoryModel', 'ThResultSetModel',
    'phCompareDefaultNewRepo', 'phCompareDefaultOriginalRepo', 'JsonPushes',
    'thPerformanceBranches',
    function CompareChooserCtrl($state, $stateParams, $scope,
                                ThRepositoryModel, ThResultSetModel,
                                phCompareDefaultNewRepo,
                                phCompareDefaultOriginalRepo,
                                JsonPushes, thPerformanceBranches) {
        ThRepositoryModel.get_list().success(function(projects) {
            $scope.projects = projects;
            $scope.originalTipList = [];
            $scope.newTipList = [];

            $scope.originalProject = _.findWhere(projects, {
                name: ($stateParams.originalProject ?
                       $stateParams.originalProject : phCompareDefaultOriginalRepo)
            }) || projects[0];
            $scope.newProject = _.findWhere(projects, {
                name: ($stateParams.newProject ?
                       $stateParams.newProject : phCompareDefaultNewRepo)
            }) || projects[0];

            $scope.originalRevision = ($stateParams.originalRevision ?
                                       $stateParams.originalRevision : '');
            $scope.newRevision = ($stateParams.newRevision ?
                                  $stateParams.newRevision : '');

            var getRevisionTips = function(projectName, list) {
                // due to we push the revision data into list,
                // so we need clear the data before we push new data into it.
                list.splice(0, list.length);
                ThResultSetModel.getResultSets(projectName).then(function(response) {
                    var resultsets = response.data.results;
                    resultsets.forEach(function(revisionSet) {
                        list.push({
                            revision: revisionSet.revision,
                            author: revisionSet.author
                        });
                    });
                });
            };

            $scope.updateOriginalgRevisionTips = function() {
                getRevisionTips($scope.originalProject.name, $scope.originalTipList);
            };
            $scope.updateNewRevisionTips = function() {
                getRevisionTips($scope.newProject.name, $scope.newTipList);
            };
            $scope.updateOriginalgRevisionTips();
            $scope.updateNewRevisionTips();

            $scope.getOriginalTipRevision = function(tip) {
                $scope.originalRevision = tip;
            };

            $scope.getNewTipRevision = function(tip) {
                $scope.newRevision = tip;
            };

            $scope.getPreviousRevision = function() {
                $scope.proposedRevision = $scope.newRevisionError = null;

                // only check for a full revision
                if ($scope.newRevision.length != 12) return;

                $scope.proposedRevisionLoading = true;

                var promise;
                if ($scope.newProject.name === "try") {
                    // try require some special logic
                    var iProjs = _.filter($scope.projects, function(proj) {
                        return _.includes(thPerformanceBranches,
                                          proj.name);
                    });
                    promise = JsonPushes.getPreviousRevisionFrom(
                        $scope.newProject,
                        $scope.newRevision,
                        iProjs
                    );
                } else {
                    // any other branch
                    promise = JsonPushes.getPreviousRevision(
                        $scope.newProject,
                        $scope.newRevision
                    ).then(function (revision) {
                        return {
                            revision:revision,
                            project: $scope.newProject,
                        };
                    });
                }

                promise.then(
                    function(result) {
                        $scope.proposedRevision = {
                            revision: result.revision.slice(0, 12),
                            project: result.project
                        };
                    },
                    function(error) {
                        $scope.newRevisionError = error.toString();
                    }
                ).finally(function() {
                    $scope.proposedRevisionLoading = false;
                });
            };

            $scope.setProposedRevision = function() {
                var rev = $scope.proposedRevision;
                $scope.proposedRevision = null;
                $scope.originalProject = rev.project;
                $scope.originalRevision = rev.revision;
            };

            $scope.runCompare = function() {
                ThResultSetModel.getResultSetsFromRevision($scope.originalProject.name, $scope.originalRevision).then(
                    function(resultSets) {
                        $scope.originalRevisionError = undefined;
                    },
                    function(error) {
                        $scope.originalRevisionError = error;
                    }
                );

                ThResultSetModel.getResultSetsFromRevision($scope.newProject.name, $scope.newRevision).then(
                    function (resultSets) {
                        $scope.newRevisionError = undefined;
                        if ($scope.originalRevisionError === undefined && $scope.newRevisionError === undefined) {
                            $state.go('compare', {
                                originalProject: $scope.originalProject.name,
                                originalRevision: $scope.originalRevision,
                                newProject: $scope.newProject.name,
                                newRevision: $scope.newRevision
                            });
                        }
                    },
                    function (error) {
                        $scope.newRevisionError = error;
                    }
                );
            };

            // if we have a try push prepopulated, automatically offer a new revision
            if ($scope.newRevision.length === 12) {
                $scope.updateNewRevisionTips();
                $scope.getPreviousRevision();
            }
        });
    }]);

{'fraction_non_alphanumeric': 0.08910054535678623, 'fraction_numerical': 0.0019202703740686688, 'mean_word_length': 1.1996958945767866, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4103129', 'n_tokens_mistral': 3028, 'n_tokens_neox': 2721, 'n_words': 459}