Skip to content

Commit

Permalink
Merge pull request #280 from mozilla/server-hidden-jobs
Browse files Browse the repository at this point in the history
Bug 1074851 - Implement server side job filtering
  • Loading branch information
camd committed Dec 4, 2014
2 parents c9b2eb9 + 9c277ef commit 2262be1
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 227 deletions.
5 changes: 0 additions & 5 deletions ui/js/controllers/jobs.js
Expand Up @@ -225,11 +225,6 @@ treeherder.controller('ResultSetCtrl', [
return thJobFilters.showJob(job, $scope.resultStatusFilters);
};

$scope.totalExcluded = function() {
return thJobFilters.getCountExcluded($scope.resultset.id, "total");
};


$scope.cancelAllJobs = function(revision) {
if (!window.confirm('This will cancel all pending and running jobs for revision ' + revision + '!\n\nAre you sure?')) {
return;
Expand Down
29 changes: 11 additions & 18 deletions ui/js/controllers/main.js
Expand Up @@ -129,20 +129,18 @@ treeherder.controller('MainCtrl', [

};

$scope.isSkippingExclusionProfiles = function() {
return thJobFilters.isSkippingExclusionProfiles();
};

$scope.getUnclassifiedFailureCount = function(repoName) {
return ThResultSetModel.getUnclassifiedFailureCount(repoName);
};

$scope.getTimeWindowUnclassifiedFailureCount = function(repoName) {
return thJobFilters.getCountExcludedForRepo(repoName);
};
$scope.isSkippingExclusionProfiles = $location.search().exclusion_state === 'all';

$scope.toggleExcludedJobs = function() {
thJobFilters.toggleSkipExclusionProfiles();
var newState = 'all';
if ($scope.isSkippingExclusionProfiles) {
newState = null;
}
$location.search('exclusion_state', newState);
};

$scope.toggleUnclassifiedFailures = thJobFilters.toggleUnclassifiedFailures;
Expand Down Expand Up @@ -250,21 +248,16 @@ treeherder.controller('MainCtrl', [

$scope.isSheriffPanelShowing = false;
$scope.setSheriffPanelShowing = function(tf) {
if (tf) {
// lazy fetching of exclusion profiles, because we don't
// need them unless you're editing them on this page
$rootScope.$emit(thEvents.initSheriffPanel);
}
$scope.isSheriffPanelShowing = tf;
};

$scope.pinboardCount = thPinboard.count;
$scope.pinnedJobs = thPinboard.pinnedJobs;

// get a cached version of the exclusion profiles
ThExclusionProfileModel.get_list({}, true).then(function(profiles){
$scope.exclusion_profiles = profiles;
thJobFilters.setActiveExclusionProfile(_.find(
$scope.exclusion_profiles,
function(elem){
return elem.is_default;
}
));
}, null);
}
]);
67 changes: 43 additions & 24 deletions ui/js/controllers/sheriff.js
Expand Up @@ -6,22 +6,37 @@
treeherder.controller('SheriffCtrl', [
'$scope', '$rootScope', 'ThBuildPlatformModel', 'ThJobTypeModel',
'thEvents', 'ThRepositoryModel', 'ThOptionModel', 'ThJobExclusionModel',
'ThExclusionProfileModel', 'thJobFilters',
'ThExclusionProfileModel', 'thNotify',
function SheriffController(
$scope, $rootScope, ThBuildPlatformModel, ThJobTypeModel, thEvents,
ThRepositoryModel, ThOptionModel, ThJobExclusionModel,
ThExclusionProfileModel, thJobFilters) {
ThExclusionProfileModel, thNotify) {

// fetch the reference data
$scope.exclusions = [];
$scope.exclusions_map = {};
$scope.profiles = [];

ThJobExclusionModel.get_list().then(function(data) {
$scope.exclusions = data;
$scope.exclusions_map = _.indexBy($scope.exclusions, 'id');
});
// load the values needed for this page.
// this won't be needed all that often, so we should
// only load it on-demand.
var init = function() {
// only load once, otherwise rely on refreshing
if (!$scope.initComplete) {
ThJobExclusionModel.get_list().then(function (data) {
$scope.exclusions = data;
$scope.exclusions_map = _.indexBy($scope.exclusions, 'id');
});
ThExclusionProfileModel.get_list({}, false).then(function (data) {
$scope.profiles = data;
});
$scope.initComplete = true;
}
};

$scope.profiles = [];
$rootScope.$on(thEvents.initSheriffPanel, function() {
init();
});

$scope.refreshExclusionProfileList = function() {
// this is a bit brute force for some circumstances. But the list
Expand All @@ -31,17 +46,19 @@ treeherder.controller('SheriffCtrl', [

ThExclusionProfileModel.get_list({}, false).then(function(data) {
$scope.profiles = data;
thJobFilters.setActiveExclusionProfile(_.find(
$scope.profiles,
function(elem){
return elem.is_default;
}
));
// don't force the user to refresh, in case they want to make
// several changes.
thNotify.send("Refresh the page to see changes reflected.");
});

};

$scope.refreshExclusionProfileList();
/**
* Used to allow for selection of "platform (arch)" or
* "job_type (job_symbol)"
*/
var getJobComboField = function(field1, field2) {
return field1 + " (" + field2 + ")";
};

$scope.view = 'exclusion_profile_list';
$scope.switchView = function(newView) {
Expand All @@ -54,10 +71,10 @@ treeherder.controller('SheriffCtrl', [
.then(function(data) {
for (var i = 0; i < data.length; i++) {
$scope.master_platforms.push(
thJobFilters.getJobComboField(data[i].platform, data[i].architecture)
getJobComboField(data[i].platform, data[i].architecture)
);
}
$scope.master_platforms.sort()
$scope.master_platforms.sort();
$scope.form_platforms = angular.copy($scope.master_platforms);
});

Expand All @@ -67,10 +84,10 @@ treeherder.controller('SheriffCtrl', [
.then(function(data) {
for (var i = 0; i < data.length; i++) {
$scope.master_job_types.push(
thJobFilters.getJobComboField(data[i].name, data[i].symbol)
getJobComboField(data[i].name, data[i].symbol)
);
}
$scope.master_job_types.sort()
$scope.master_job_types.sort();
$scope.form_job_types = angular.copy($scope.master_job_types);
});

Expand All @@ -81,7 +98,7 @@ treeherder.controller('SheriffCtrl', [
for (var i = 0; i < data.length; i++) {
$scope.master_repos.push(data[i].name);
}
$scope.master_repos.sort()
$scope.master_repos.sort();
$scope.form_repos = angular.copy($scope.master_repos);
});

Expand All @@ -92,7 +109,7 @@ treeherder.controller('SheriffCtrl', [
for (var i = 0; i < data.length; i++) {
$scope.master_options.push(data[i].name);
}
$scope.master_options.sort()
$scope.master_options.sort();
$scope.form_options = angular.copy($scope.master_options);
});

Expand Down Expand Up @@ -141,7 +158,7 @@ treeherder.controller('SheriffCtrl', [

$scope.delete_exclusion = function(exclusion) {
exclusion.delete().then(function() {
// update the visibility profiles
// update the exclusion profiles
// since some of them may keep an old relationship
// with the exclusion just deleted
ThExclusionProfileModel.get_list().then(function(data) {
Expand Down Expand Up @@ -217,13 +234,15 @@ treeherder.controller('SheriffCtrl', [

$scope.set_default_profile = function(profile) {
profile.is_default = true;
profile.update().then(function(data) {
profile.update().then(function() {
angular.forEach($scope.profiles, function(elem) {
if (elem.is_default && elem.id !== profile.id) {
elem.is_default = false;
}
});
thJobFilters.setActiveExclusionProfile(profile);
// don't force the user to refresh, in case they want to make
// several changes.
thNotify.send("Refresh the page to see changes reflected.");
}, null);
};

Expand Down
1 change: 0 additions & 1 deletion ui/js/directives/persona.js
Expand Up @@ -65,7 +65,6 @@ treeherder.directive('personaButtons', [
$rootScope.user.loggedin = true;
$rootScope.user.email = response.data.email;
// retrieve the current user's info from the api
// including the exclusion profile
ThUserModel.get().then(function(user){
angular.extend($rootScope.user, user);
}, null);
Expand Down
10 changes: 2 additions & 8 deletions ui/js/directives/resultsets.js
Expand Up @@ -55,7 +55,7 @@ treeherder.directive('thResultCounts', [
var setTotalCount = function() {
if (scope.resultset.job_counts) {
$(element).find('.result-status-total-value').html(
scope.resultset.job_counts.total - scope.totalExcluded()
scope.resultset.job_counts.total
);
}
};
Expand All @@ -81,8 +81,7 @@ treeherder.directive('thResultStatusCount', [
var updateResultCount = function(scope, rsCountEl) {
if(scope.resultset.job_counts) {

scope.resultCount = (scope.resultset.job_counts[scope.resultStatus] || 0) -
thJobFilters.getCountExcluded(scope.resultset.id, scope.resultStatus);
scope.resultCount = (scope.resultset.job_counts[scope.resultStatus] || 0);
rsCountEl.find(".rs-count-number").html(scope.resultCount);

if (scope.resultCount) {
Expand Down Expand Up @@ -111,11 +110,6 @@ treeherder.directive('thResultStatusCount', [
rsCountEl.prop('title', resultCountTitleText);
rsCountEl.find('.rs-count-text').html(resultCountText);

// so that when you toggle skipping the exclusion profiles,
// we update the counts to reflect what is seen.
$rootScope.$on(thEvents.globalFilterChanged, function(evt) {
updateResultCount(scope, rsCountEl);
});
$rootScope.$on(thEvents.applyNewJobs, function(evt) {
updateResultCount(scope, rsCountEl);
});
Expand Down
14 changes: 14 additions & 0 deletions ui/js/directives/top_nav_bar.js
Expand Up @@ -163,3 +163,17 @@ treeherder.directive('thRepoMenuItem', [
templateUrl: 'partials/main/thRepoMenuItem.html'
};
}]);

// which class to show for the show/hide excluded jobs button.
// this allows us to do one-time binding in the html.
treeherder.directive('thExclusionState', function () {
return {
restrict: "A",
link: function(scope, element, attrs) {
scope.exclusionStateClass = 'fa-square-o';
if (scope.isSkippingExclusionProfiles) {
scope.exclusionStateClass = 'fa-square';
}
}
};
});
1 change: 0 additions & 1 deletion ui/js/models/exclusion_profile.js
Expand Up @@ -85,7 +85,6 @@ treeherder.factory('ThExclusionProfileModel', [
)
.then(
function(response){
angular.extend(exclusion_profile, response.data.id);
thNotify.send("Exclusion profile successfully updated", "success");
},
function(reason){
Expand Down
2 changes: 0 additions & 2 deletions ui/js/models/repository.js
Expand Up @@ -50,7 +50,6 @@ treeherder.factory('ThRepositoryModel', [
repos[repo.name] = {
treeStatus: null,
unclassifiedFailureCount: 0,
unclassifiedFailureCountExcluded: 0,
groupName: repo.repository_group.name
};
};
Expand All @@ -63,7 +62,6 @@ treeherder.factory('ThRepositoryModel', [
_.extend(repos[repoName], {
treeStatus: {status: "not retrieved yet", message_of_the_day: ""},
unclassifiedFailureCount: 0,
unclassifiedFailureCountExcluded: 0,
groupName: repos[repoName].groupName
});
watchedRepos[repoName] = repos[repoName];
Expand Down
9 changes: 5 additions & 4 deletions ui/js/models/resultsets.js
Expand Up @@ -55,7 +55,8 @@ treeherder.factory('ThResultSetModel', [
'fromchange',
'tochange',
'startdate',
'enddate'
'enddate',
'exclusion_state'
];

var registerResultSetPollers = function(){
Expand Down Expand Up @@ -363,8 +364,7 @@ treeherder.factory('ThResultSetModel', [
var getUnclassifiedFailureCount = function(repoName) {
if (_.has(repositories, repoName)) {

return _.size(repositories[repoName].unclassifiedFailureMap) -
_.size(thJobFilters.excludedUnclassifiedFailures);
return _.size(repositories[repoName].unclassifiedFailureMap);

}
return 0;
Expand Down Expand Up @@ -794,6 +794,7 @@ treeherder.factory('ThResultSetModel', [
*/
repositories[repoName].loadingStatus.appending = true;
var resultsets;
var exclusion_state = $location.search().exclusion_state;
var loadRepositories = ThRepositoryModel.load(repoName);
var loadResultsets = thResultSets.getResultSets(repoName,
repositories[repoName].rsMapOldestTimestamp,
Expand All @@ -817,7 +818,7 @@ treeherder.factory('ThResultSetModel', [
appendResultSets(repoName, {results: []});
}).
then(function(){
thResultSets.getResultSetJobs(resultsets, repoName);
thResultSets.getResultSetJobs(resultsets, repoName, exclusion_state);
});
};

Expand Down
4 changes: 3 additions & 1 deletion ui/js/providers.js
Expand Up @@ -237,7 +237,9 @@ treeherder.provider('thEvents', function() {

mapResultSetJobs: "map-result-set-jobs-EVT",

applyNewJobs: "apply-new-jobs-EVT"
applyNewJobs: "apply-new-jobs-EVT",

initSheriffPanel: "init-sheriff-panel-EVT"
};
};
});
Expand Down

0 comments on commit 2262be1

Please sign in to comment.