<commit_before>"use strict";

treeherder.controller('PluginCtrl', [
    '$scope', '$rootScope', 'thUrl', 'ThJobClassificationModel',
    'thClassificationTypes', 'ThJobModel', 'thEvents', 'dateFilter',
    'numberFilter', 'ThBugJobMapModel', 'thResultStatus', 'thSocket',
    'ThResultSetModel', 'ThLog', '$q', 'thPinboard', 'ThJobArtifactModel',
    'thBuildApi', 'thNotify', 'ThJobLogUrlModel',
    function PluginCtrl(
        $scope, $rootScope, thUrl, ThJobClassificationModel,
        thClassificationTypes, ThJobModel, thEvents, dateFilter,
        numberFilter, ThBugJobMapModel, thResultStatus, thSocket,
        ThResultSetModel, ThLog, $q, thPinboard, ThJobArtifactModel,
        thBuildApi, thNotify, ThJobLogUrlModel) {

        var $log = new ThLog("PluginCtrl");

        $scope.job = {};

        var timeout_promise = null;

        var selectJob = function(newValue, oldValue) {
            $scope.artifacts = {};

            // preferred way to get access to the selected job
            if (newValue) {
                $scope.job_detail_loading = true;
                $scope.job = newValue;

                $scope.visibleFields = {
                    "Job Name": $scope.job.job_type_name,
                    "Start time": "",
                    "Duration":  "",
                    "Machine ": "",
                    "Build": ""
                };

                if(timeout_promise !== null){
                    $log.debug("timing out previous job request");
                    timeout_promise.resolve();
                }
                timeout_promise = $q.defer();

                // get the details of the current job
                ThJobModel.get($scope.repoName, $scope.job.id, {
                    timeout: timeout_promise
                }).then(function(data){
                    $scope.job = data;
                    $rootScope.$broadcast(thEvents.jobDetailLoaded);
                    updateVisibleFields();
                    $scope.job_detail_loading = false;
                    $scope.logs = data.logs;
                });

                ThJobArtifactModel.get_list({
                    name: "buildapi",
                    "type": "json",
                    job_id: $scope.job.id
                }, {timeout: timeout_promise})
                .then(function(data) {
                    if (data.length > 0 && _.has(data[0], 'blob')){
                        _.forEach(data, function(item) {
                            $scope.artifacts[item.name] = item;
                        });
                        $scope.visibleFields.Buildername = $scope.artifacts.buildapi.blob.buildername;
                        $log.debug("buildapi artifacts", $scope.artifacts);
                    }
                });

                ThJobLogUrlModel.get_list($scope.job.id)
                .then(function(data){
                    $scope.job_log_urls = data;
                });

                $scope.lvUrl = thUrl.getLogViewerUrl($scope.job.id);
                $scope.resultStatusShading = "result-status-shading-" + thResultStatus($scope.job);

                $scope.updateClassifications();
                $scope.updateBugs();
            }
        };

        var updateVisibleFields = function() {
                var undef = "";
                // fields that will show in the job detail panel
                var duration = ($scope.job.end_timestamp-$scope.job.start_timestamp)/60;
                if (duration) {
                    duration = numberFilter(duration, 0) + " minutes";
                }

                $scope.visibleFields = {
                    "Job Name": $scope.job.job_type_name || undef,
                    "Start time": dateFilter($scope.job.start_timestamp*1000, 'short') || undef,
                    "Duration":  duration || undef,
                    "Machine ": $scope.job.machine_platform_architecture + " " +
                                $scope.job.machine_platform_os || undef,
                    "Build": $scope.job.build_architecture + " " +
                             $scope.job.build_platform  + " " +
                             $scope.job.build_os || undef
                };
                if (_.has($scope.artifacts, "buildapi")) {
                    $scope.visibleFields.Buildername = $scope.artifacts.buildapi.blob.buildername;
                }
        };

        $scope.getCountPinnedJobs = function() {
            return thPinboard.count.numPinnedJobs;
        };

        $scope.togglePinboardVisibility = function() {
            $scope.isPinboardVisible = !$scope.isPinboardVisible;
        };

        $scope.$watch('getCountPinnedJobs()', function(newVal, oldVal) {
            if (oldVal === 0 && newVal > 0) {
                $scope.isPinboardVisible = true;
            }
        });

        $scope.canRetrigger = function() {
            return ($scope.job && $scope.artifacts && _.has($scope.artifacts, "buildapi"));
        };

        $scope.canCancel = function() {
            return $scope.job && $scope.artifacts && _.has($scope.artifacts, "buildapi") &&
                ($scope.job.state === "pending" || $scope.job.state === "running");
        };

        /**
         * Get the build_id needed to cancel or retrigger from the currently<commit_msg>Fix bug 1031858 #2: updated the field name to match suggestion in bug<commit_after>"use strict";

treeherder.controller('PluginCtrl', [
    '$scope', '$rootScope', 'thUrl', 'ThJobClassificationModel',
    'thClassificationTypes', 'ThJobModel', 'thEvents', 'dateFilter',
    'numberFilter', 'ThBugJobMapModel', 'thResultStatus', 'thSocket',
    'ThResultSetModel', 'ThLog', '$q', 'thPinboard', 'ThJobArtifactModel',
    'thBuildApi', 'thNotify', 'ThJobLogUrlModel',
    function PluginCtrl(
        $scope, $rootScope, thUrl, ThJobClassificationModel,
        thClassificationTypes, ThJobModel, thEvents, dateFilter,
        numberFilter, ThBugJobMapModel, thResultStatus, thSocket,
        ThResultSetModel, ThLog, $q, thPinboard, ThJobArtifactModel,
        thBuildApi, thNotify, ThJobLogUrlModel) {

        var $log = new ThLog("PluginCtrl");

        $scope.job = {};

        var timeout_promise = null;

        var selectJob = function(newValue, oldValue) {
            $scope.artifacts = {};

            // preferred way to get access to the selected job
            if (newValue) {
                $scope.job_detail_loading = true;
                $scope.job = newValue;

                $scope.visibleFields = {
                    "Job Name": $scope.job.job_type_name,
                    "Start time": "",
                    "Duration":  "",
                    "Machine ": "",
                    "Build": ""
                };

                if(timeout_promise !== null){
                    $log.debug("timing out previous job request");
                    timeout_promise.resolve();
                }
                timeout_promise = $q.defer();

                // get the details of the current job
                ThJobModel.get($scope.repoName, $scope.job.id, {
                    timeout: timeout_promise
                }).then(function(data){
                    $scope.job = data;
                    $rootScope.$broadcast(thEvents.jobDetailLoaded);
                    updateVisibleFields();
                    $scope.job_detail_loading = false;
                    $scope.logs = data.logs;
                });

                ThJobArtifactModel.get_list({
                    name: "buildapi",
                    "type": "json",
                    job_id: $scope.job.id
                }, {timeout: timeout_promise})
                .then(function(data) {
                    if (data.length > 0 && _.has(data[0], 'blob')){
                        _.forEach(data, function(item) {
                            $scope.artifacts[item.name] = item;
                        });
                        $scope.visibleFields["Buildbot Job Name"] = $scope.artifacts.buildapi.blob.buildername;
                        $log.debug("buildapi artifacts", $scope.artifacts);
                    }
                });

                ThJobLogUrlModel.get_list($scope.job.id)
                .then(function(data){
                    $scope.job_log_urls = data;
                });

                $scope.lvUrl = thUrl.getLogViewerUrl($scope.job.id);
                $scope.resultStatusShading = "result-status-shading-" + thResultStatus($scope.job);

                $scope.updateClassifications();
                $scope.updateBugs();
            }
        };

        var updateVisibleFields = function() {
                var undef = "";
                // fields that will show in the job detail panel
                var duration = ($scope.job.end_timestamp-$scope.job.start_timestamp)/60;
                if (duration) {
                    duration = numberFilter(duration, 0) + " minutes";
                }

                $scope.visibleFields = {
                    "Job Name": $scope.job.job_type_name || undef,
                    "Start time": dateFilter($scope.job.start_timestamp*1000, 'short') || undef,
                    "Duration":  duration || undef,
                    "Machine ": $scope.job.machine_platform_architecture + " " +
                                $scope.job.machine_platform_os || undef,
                    "Build": $scope.job.build_architecture + " " +
                             $scope.job.build_platform  + " " +
                             $scope.job.build_os || undef
                };
                if (_.has($scope.artifacts, "buildapi")) {
                    $scope.visibleFields["Buildbot Job Name"] = $scope.artifacts.buildapi.blob.buildername;
                }
        };

        $scope.getCountPinnedJobs = function() {
            return thPinboard.count.numPinnedJobs;
        };

        $scope.togglePinboardVisibility = function() {
            $scope.isPinboardVisible = !$scope.isPinboardVisible;
        };

        $scope.$watch('getCountPinnedJobs()', function(newVal, oldVal) {
            if (oldVal === 0 && newVal > 0) {
                $scope.isPinboardVisible = true;
            }
        });

        $scope.canRetrigger = function() {
            return ($scope.job && $scope.artifacts && _.has($scope.artifacts, "buildapi"));
        };

        $scope.canCancel = function() {
            return $scope.job && $scope.artifacts && _.has($scope.artifacts, "buildapi") &&
                ($scope.job.state === "pending" || $scope.job.state === "running");
        };

        /**
         * Get the build_id needed to cancel or retrigger from the currently
{'fraction_non_alphanumeric': 0.1226751831673868, 'fraction_numerical': 0.0028179597971068945, 'mean_word_length': 1.5331905781584583, 'pattern_counts': {'":': 22, '<': 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': '5491639', 'n_tokens_mistral': 2918, 'n_tokens_neox': 2708, 'n_words': 503}