now classified and field filters are working

This commit is contained in:
Cameron Dawson 2014-02-25 15:49:16 -08:00
Родитель dd4d09f5fb
Коммит c690b464fa
4 изменённых файлов: 95 добавлений и 18 удалений

Просмотреть файл

@ -30,16 +30,23 @@ treeherder.controller('StatusFilterPanelCtrl',
/**
* Handle checking the "all" button for a result status group
*/
$scope.toggleGroup = function(group) {
var check = function(rs) {$scope.resultStatusFilters[rs] = group.allChecked;};
$scope.toggleResultStatusGroup = function(group) {
var check = function(rs) {
$scope.resultStatusFilters[rs] = group.allChecked;
};
_.each(group.resultStatuses, check);
thJobFilters.toggleFilters(thJobFilters.resultStatus, group.resultStatuses, group.allChecked);
thJobFilters.toggleFilters(
thJobFilters.resultStatus,
group.resultStatuses,
group.allChecked
);
$rootScope.$broadcast(thEvents.globalFilterChanged,
{target: group, newValue: group.allChecked});
showCheck();
};
$scope.toggleFilter = function(group, filter) {
$scope.toggleResultStatusFilter = function(group, filter) {
if (!$scope.resultStatusFilters[filter]) {
group.allChecked = false;
thJobFilters.removeFilter(thJobFilters.resultStatus, filter);
@ -51,6 +58,28 @@ treeherder.controller('StatusFilterPanelCtrl',
showCheck();
};
/**
* Toggle the filters to show either unclassified or classified jobs,
* neither or both.
* @param isClassified - whether to toggle the filter on/off for
* ``classified`` (when true) or ``unclassified``
* (when false)
*/
$scope.toggleClassificationFilter = function(isClassified) {
var field = "failure_classification_id";
// this function is called before the checkbox value has actually
// changed the scope model value, so change to the inverse.
var isChecked = !(isClassified? $scope.classifiedFilter: $scope.unClassifiedFilter);
var func = isChecked? thJobFilters.addFilter: thJobFilters.removeFilter;
var target = isClassified? "classified": "unclassified";
func(field, isClassified);
$rootScope.$broadcast(thEvents.globalFilterChanged,
{target: target, newValue: isChecked});
showCheck();
};
$scope.createFieldFilter = function() {
$scope.newFieldFilter = {field: "", value: ""};
};
@ -73,6 +102,7 @@ treeherder.controller('StatusFilterPanelCtrl',
value: $scope.newFieldFilter.value
});
$scope.newFieldFilter = null;
showCheck();
};
@ -81,6 +111,7 @@ treeherder.controller('StatusFilterPanelCtrl',
thJobFilters.removeFilter(ff.field, ff.value);
});
$scope.fieldFilters = [];
showCheck();
};
$scope.removeFilter = function(index) {
@ -90,20 +121,36 @@ treeherder.controller('StatusFilterPanelCtrl',
$scope.fieldFilters[index].value
);
$scope.fieldFilters.splice(index, 1);
showCheck();
};
/*
@@@ TODO: CAMD: test code, remove before merge.
*/
var jobs = [];
$scope.filterGroups.inProgress.resultStatuses.forEach(function(rs) {jobs.push({state: rs, result: "unknown"});});
$scope.filterGroups.failures.resultStatuses.forEach(function(rs) {jobs.push({state: "completed", result: rs});});
$scope.filterGroups.nonfailures.resultStatuses.forEach(function(rs) {jobs.push({state: "completed", result: rs});});
$scope.filterGroups.inProgress.resultStatuses.forEach(function(rs) {jobs.push({
state: rs,
result: "unknown",
failure_classification_id: null
});});
$scope.filterGroups.failures.resultStatuses.forEach(function(rs) {jobs.push({
state: "completed",
result: rs,
job_type_symbol: "A",
job_group_symbol: "M",
failure_classification_id: "bird"
});});
$scope.filterGroups.nonfailures.resultStatuses.forEach(function(rs) {jobs.push({
state: "completed",
result: rs
});});
var showCheck = function() {
jobs.forEach(function(job) {
$log.debug("show job: " + job.result + " " + job.state + ": " + thJobFilters.showJob(job));
$log.debug("show job: " + JSON.stringify(job) + ": " + thJobFilters.showJob(job));
});
$log.debug(JSON.stringify(thJobFilters.getFilters()));
};
// END test code
@ -112,7 +159,11 @@ treeherder.controller('StatusFilterPanelCtrl',
$scope.resultStatusFilters[$scope.filterOptions[i]] = true;
}
// whether or not to show classified jobs
// these are a special case of filtering because we're not checking
// for a value, just whether the job has any value set or not.
// just a boolean check either way
$scope.classifiedFilter = true;
$scope.unClassifiedFilter = true;
// field filters
$scope.newFieldFilter = null;

Просмотреть файл

@ -37,12 +37,17 @@ treeherder.factory('thJobFilters', function(thResultStatusList, $log) {
* ]
*/
var filters = {
resultStatus: thResultStatusList
resultStatus: thResultStatusList.slice(),
failure_classification_id: [true, false]
};
/**
* If a custom resultStatusList is passed in (like for individual
* resultSets, then use that. Otherwise, fall back to the global one.
*
* if the filter value is just ``true`` or ``false`` then simply check
* whether or not the field of ``job`` has a value set or not. ``true``
* means it must have a value set, ``false`` means it must be null.
*/
var checkFilter = function(field, job, resultStatusList) {
// resultStatus is a special case that spans two job fields
@ -51,7 +56,11 @@ treeherder.factory('thJobFilters', function(thResultStatusList, $log) {
return _.contains(filterList, job.result) ||
_.contains(filterList, job.state);
} else {
return _.contains(filters[field], job[field]);
var jobFieldValue = job[field];
if (_.every(filters[field], _.isBoolean)) {
jobFieldValue = !_.isNull(jobFieldValue);
}
return _.contains(filters[field], jobFieldValue);
}
};
@ -64,7 +73,7 @@ treeherder.factory('thJobFilters', function(thResultStatusList, $log) {
} else {
filters[field] = [value];
}
$log.debug("adding " + value);
$log.debug("adding " + field + ": " + value);
$log.debug(filters);
},
removeFilter: function(field, value) {
@ -109,14 +118,20 @@ treeherder.factory('thJobFilters', function(thResultStatusList, $log) {
*/
showJob: function(job, resultStatusList) {
var fields = _.keys(filters);
if (filters.length === 0) {
return false;
}
for(var i = 0; i < fields.length; i++) {
if (checkFilter(fields[i], job)) {
return true;
if (!checkFilter(fields[i], job)) {
return false;
}
}
return false;
return true;
},
resultStatus: "resultStatus"
resultStatus: "resultStatus",
getFilters: function() {
return filters;
}
};
return api;

Просмотреть файл

@ -2,5 +2,5 @@
<input type="checkbox"
id="{{filterName}}"
ng-model="resultStatusFilters[filterName]"
ng-change="toggleFilter(group, filterName)"> {{filterName}}
ng-change="toggleResultStatusFilter(group, filterName)"> {{filterName}}
</label>

Просмотреть файл

@ -2,6 +2,8 @@
class="th-top-nav-options-panel model-body"
ng-controller="StatusFilterPanelCtrl">
<div class="well"><h5>Specify which jobs to show based on this filter criteria.</h5></div>
<!-- result status filters -->
<span ng-repeat="group in filterGroups"
class="panel panel-default th-option-group th-inline-option-group">
@ -10,7 +12,7 @@
<span class="pull-right">
<input type="checkbox"
ng-model="group.allChecked"
ng-change="toggleGroup(group)"> all
ng-change="toggleResultStatusGroup(group)"> all
</span>
</div>
<!--content for each group-->
@ -20,13 +22,22 @@
</span>
</div>
</span>
<!-- classified / unclassified -->
<span class="panel panel-default th-option-group th-inline-option-group">
<div class="panel-heading th-option-heading">classified</div>
<div class="panel-body">
<label class="checkbox-inline">
<input type="checkbox"
id="classified"
ng-model="classifiedFilter"> classified
ng-model="classifiedFilter"
ng-click="toggleClassificationFilter(true)"> classified
</label>
<label class="checkbox-inline">
<input type="checkbox"
id="unclassified"
ng-model="unClassifiedFilter"
ng-click="toggleClassificationFilter(false)"> un-classified
</label>
</div>
</span>