diff --git a/treeherder/webapp/api/performance_serializers.py b/treeherder/webapp/api/performance_serializers.py index bbecb2185..02133c630 100644 --- a/treeherder/webapp/api/performance_serializers.py +++ b/treeherder/webapp/api/performance_serializers.py @@ -21,6 +21,9 @@ class TestOptionsSerializer(serializers.JSONField): class PerformanceSignatureSerializer(serializers.ModelSerializer): + framework_id = serializers.SlugRelatedField( + slug_field="id", source="framework", + queryset=PerformanceFramework.objects.all()) option_collection_hash = serializers.SlugRelatedField( read_only=True, slug_field="option_collection_hash", source="option_collection") @@ -32,9 +35,9 @@ class PerformanceSignatureSerializer(serializers.ModelSerializer): class Meta: model = PerformanceSignature - fields = ['signature_hash', 'machine_platform', 'suite', 'test', - 'lower_is_better', 'option_collection_hash', - 'test_options'] + fields = ['framework_id', 'signature_hash', 'machine_platform', + 'suite', 'test', 'lower_is_better', + 'option_collection_hash', 'test_options'] class PerformanceDecimalField(serializers.DecimalField): diff --git a/ui/js/controllers/perf/alerts.js b/ui/js/controllers/perf/alerts.js index 3c8b54537..6cb9ad92b 100644 --- a/ui/js/controllers/perf/alerts.js +++ b/ui/js/controllers/perf/alerts.js @@ -83,16 +83,16 @@ perf.controller( perf.controller('AlertsCtrl', [ '$state', '$stateParams', '$scope', '$rootScope', '$http', '$q', '$modal', - 'thUrl', 'ThRepositoryModel', 'ThOptionCollectionModel', 'ThResultSetModel', - 'thDefaultRepo', 'PhSeries', 'PhAlerts', 'phTimeRanges', 'phDefaultTimeRangeValue', - 'phAlertResolutionMap', 'dateFilter', 'thDateFormat', + 'thUrl', 'ThOptionCollectionModel', 'ThResultSetModel', + 'PhFramework', 'PhSeries', 'PhAlerts', 'phTimeRanges', + 'phDefaultTimeRangeValue', 'phAlertResolutionMap', 'dateFilter', + 'thDateFormat', function AlertsCtrl($state, $stateParams, $scope, $rootScope, $http, $q, - $modal, - thUrl, ThRepositoryModel, ThOptionCollectionModel, - ThResultSetModel, thDefaultRepo, PhSeries, PhAlerts, - phTimeRanges, phDefaultTimeRangeValue, - phAlertResolutionMap, dateFilter, thDateFormat) { - + $modal, thUrl, ThOptionCollectionModel, + ThResultSetModel, PhFramework, + PhSeries, PhAlerts, phTimeRanges, + phDefaultTimeRangeValue, phAlertResolutionMap, + dateFilter, thDateFormat) { $scope.alertSummaries = []; $scope.getMoreAlertSummariesHref = null; $scope.getCappedMagnitude = function(percent) { @@ -102,7 +102,6 @@ perf.controller('AlertsCtrl', [ }; $scope.phAlertResolutionMap = phAlertResolutionMap; - // these methods $scope.changeAlertSummaryStatus = function(alertSummary, status) { PhAlerts.changeAlertSummaryStatus( alertSummary.id, status).then(function() { @@ -110,6 +109,41 @@ perf.controller('AlertsCtrl', [ }); }; + function updateAlertVisibility() { + _.forEach($scope.alertSummaries, function(alertSummary) { + _.forEach(alertSummary.alerts, function(alert) { + // only show alert if it passes all filter criteria + alert.visible = + (alert.series_signature.framework_id === $scope.filterOptions.framework.id) && + (!$scope.filterOptions.hideImprovements || alert.is_regression) && + _.every($scope.filterOptions.filter.split(' '), + function(matchText) { + return !matchText || + alert.title.toLowerCase().indexOf( + matchText.toLowerCase()) > (-1); + }); + }); + alertSummary.anyVisible = _.any(alertSummary.alerts, + 'visible'); + }); + $scope.numFilteredAlertSummaries = _.filter($scope.alertSummaries, { anyVisible: false }).length; + + } + + $scope.filtersUpdated = function() { + $state.transitionTo('alerts', { + framework: $scope.filterOptions.framework.id, + filter: $scope.filterOptions.filter, + hideImprovements: Boolean($scope.filterOptions.hideImprovements) ? undefined : 0, + }, { + location: true, + inherit: true, + relative: $state.$current, + notify: false + }); + updateAlertVisibility(); + }; + // these methods handle the business logic of alert selection and // unselection $scope.anySelected = function(alerts) { @@ -274,6 +308,7 @@ perf.controller('AlertsCtrl', [ })).then(function() { $scope.alertSummaries = _.union($scope.alertSummaries, alertSummaries); + updateAlertVisibility(); }); } @@ -284,27 +319,33 @@ perf.controller('AlertsCtrl', [ }); }; - ThRepositoryModel.get_list().then(function(response) { - $scope.projects = response.data; - $scope.selectedProject = _.findWhere($scope.projects, { - name: thDefaultRepo ? thDefaultRepo : thDefaultRepo - }); - ThOptionCollectionModel.get_map().then( - function(optionCollectionMap) { - $scope.optionCollectionMap = optionCollectionMap; - if ($stateParams.id) { - PhAlerts.getAlertSummary($stateParams.id).then( - function(data) { - addAlertSummaries([data], null); - }); - } else { - PhAlerts.getAlertSummaries().then(function(data) { - addAlertSummaries(data.results, data.next); - }); - } - }); - - }); - + $q.all([PhFramework.getFrameworkList().then( + function(frameworks) { + $scope.frameworks = frameworks.data; + }), + ThOptionCollectionModel.get_map().then( + function(optionCollectionMap) { + $scope.optionCollectionMap = optionCollectionMap; + })] + ).then(function() { + $scope.filterOptions = { + framework: _.find($scope.frameworks, { + id: parseInt($stateParams.framework) + }) || $scope.frameworks[0], + filter: $stateParams.filter || "", + hideImprovements: $stateParams.hideImprovements === undefined || + parseInt($stateParams.hideImprovements) + }; + if ($stateParams.id) { + PhAlerts.getAlertSummary($stateParams.id).then( + function(data) { + addAlertSummaries([data], null); + }); + } else { + PhAlerts.getAlertSummaries().then(function(data) { + addAlertSummaries(data.results, data.next); + }); + } + }); } ]); diff --git a/ui/js/perfapp.js b/ui/js/perfapp.js index c306424a8..8472bfd6d 100644 --- a/ui/js/perfapp.js +++ b/ui/js/perfapp.js @@ -12,7 +12,7 @@ perf.config(function($compileProvider, $httpProvider, $stateProvider, $urlRouter $stateProvider.state('alerts', { title: 'Perfherder Alerts', templateUrl: 'partials/perf/alertsctrl.html', - url: '/alerts?id', + url: '/alerts?id&framework&filter&hideImprovements', controller: 'AlertsCtrl' }).state('graphs', { title: 'Perfherder Graphs', diff --git a/ui/partials/perf/alertsctrl.html b/ui/partials/perf/alertsctrl.html index 34bdd3ebc..797e6e47f 100644 --- a/ui/partials/perf/alertsctrl.html +++ b/ui/partials/perf/alertsctrl.html @@ -1,144 +1,164 @@