Skip to content

Commit

Permalink
have a shared service for the filters so all pages can use the same s…
Browse files Browse the repository at this point in the history
…ettings (#417)
  • Loading branch information
jmazzitelli authored and jshaughn committed Jul 28, 2017
1 parent 9ddacb7 commit 3010559
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 34 deletions.
30 changes: 17 additions & 13 deletions ui/src/main/ui/src/alerts/alerts-controller.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
angular.module('hwk.alertsModule').controller( 'hwk.alertsController', ['$scope', '$rootScope', '$resource', '$location', '$window', '$interval', '$q', '$modal', 'hwk.alertsService',
function ($scope, $rootScope, $resource, $location, $window, $interval, $q, $modal, alertsService) {
angular.module('hwk.alertsModule').controller( 'hwk.alertsController', ['$scope', '$rootScope', '$resource', '$location', '$window', '$interval', '$q', '$modal', 'hwk.alertsService', 'hwk.filterService',
function ($scope, $rootScope, $resource, $location, $window, $interval, $q, $modal, alertsService, filterService) {
'use strict';

$scope.filter = alertsService.filter;
$scope.filter = {
'date': filterService.dateFilter,
'alert': filterService.alertFilter,
'tag': filterService.tagFilter
};

$scope.lifecycleModal = {
user: null,
Expand Down Expand Up @@ -105,24 +109,24 @@ angular.module('hwk.alertsModule').controller( 'hwk.alertsController', ['$scope'
var alertsCriteria = {
'thin': false // TODO: we need to add this, we should not initially fetch fat alerts
};
if ( $scope.filter.start ) {
var startTime = $scope.filter.start;
if ( $scope.filter.date.start ) {
var startTime = $scope.filter.date.start;
startTime.setHours(0,0,0,0);
alertsCriteria.startTime = startTime.getTime();
}
if ( $scope.filter.end ) {
var endTime = $scope.filter.end;
if ( $scope.filter.date.end ) {
var endTime = $scope.filter.date.end;
endTime.setHours(23,59,59,999);
alertsCriteria.endTime = endTime.getTime();
}
if ( $scope.filter.tagQuery && $scope.filter.tagQuery.length > 0 ) {
alertsCriteria.tags = $scope.filter.tagQuery;
if ( $scope.filter.tag.tagQuery && $scope.filter.tag.tagQuery.length > 0 ) {
alertsCriteria.tags = $scope.filter.tag.tagQuery;
}
if ( $scope.filter.severity && $scope.filter.severity !== 'All Severity' ) {
alertsCriteria.severities = $scope.filter.severity.toUpperCase();
if ( $scope.filter.alert.severity && $scope.filter.alert.severity !== 'All Severity' ) {
alertsCriteria.severities = $scope.filter.alert.severity.toUpperCase();
}
if ( $scope.filter.status && $scope.filter.status !== 'All Status' ) {
alertsCriteria.statuses = $scope.filter.status.toUpperCase();
if ( $scope.filter.alert.status && $scope.filter.alert.status !== 'All Status' ) {
alertsCriteria.statuses = $scope.filter.alert.status.toUpperCase();
}

var alertsPromise = alertsService.Query($rootScope.selectedTenant, alertsCriteria).query();
Expand Down
10 changes: 0 additions & 10 deletions ui/src/main/ui/src/alerts/alerts-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@ angular.module('hwk.alertsModule').service('hwk.alertsService', ['$resource', '$
function ($resource, $rootScope) {
'use strict';

this.filter = {
start: new Date(),
end: new Date(),
severity: 'All Severity',
severityOptions: ['All Severity', 'Low', 'Medium', 'High', 'Critical'],
status: 'All Status',
statusOptions: ['All Status', 'Open', 'Acknowledged', 'Resolved'],
tagQuery: null
};

this.Alert = function (tenantId, alertId) {
return $resource($rootScope.appConfig.server.baseUrl + "/alert/:" + alertId, {
alertId: alertId
Expand Down
14 changes: 7 additions & 7 deletions ui/src/main/ui/src/alerts/alerts.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<div class="form-group" ng-style="{'width':'40%'}">
<div>Date Range</div>
<div class="input-group input-daterange">
<input id="start" type="date" class="form-control bootstrap-datepicker" ng-model="filter.start" ng-change="updateFilter()" readonly />
<input id="start" type="date" class="form-control bootstrap-datepicker" ng-model="filter.date.start" ng-change="updateFilter()" readonly />
<div class="input-group-addon">to</div>
<input id="end" type="date" class="form-control bootstrap-datepicker" ng-model="filter.end" ng-change="updateFilter()" readonly />
<input id="end" type="date" class="form-control bootstrap-datepicker" ng-model="filter.date.end" ng-change="updateFilter()" readonly />
</div>
</div>
</form>
Expand All @@ -35,20 +35,20 @@
<li class="selected"><a href="#/alerts">Tag Query</a></li>
</ul>
</div>
<input type="text" class="form-control" ng-model="filter.tagQuery" id="filter.tagQuery" placeholder="Filter By Tag Query..." />
<input type="text" class="form-control" ng-model="filter.tag.tagQuery" id="filter.tag.tagQuery" placeholder="Filter By Tag Query..." />
</div>
</div>
<div class="form-group toolbar-pf-filter">
<label class="col-md-5 control-label" for="filter.severity">Severity:</label>
<label class="col-md-5 control-label" for="filter.alert.severity">Severity:</label>
<div class="input-group">
<select class="btn btn-default combobox" id="filter.severity" ng-options="opt as opt for opt in filter.severityOptions" ng-model="filter.severity"
<select class="btn btn-default combobox" id="filter.alert.severity" ng-options="opt as opt for opt in filter.alert.severityOptions" ng-model="filter.alert.severity"
ng-change="updateFilter()"></select>
</div>
</div>
<div class="form-group toolbar-pf-filter">
<label class="col-md-4 control-label" for="filter.status">Status:</label>
<label class="col-md-4 control-label" for="filter.alert.status">Status:</label>
<div class="input-group">
<select class="btn btn-default combobox" id="filter.status" ng-options="opt as opt for opt in filter.statusOptions" ng-model="filter.status"
<select class="btn btn-default combobox" id="filter.alert.status" ng-options="opt as opt for opt in filter.alert.statusOptions" ng-model="filter.alert.status"
ng-change="updateFilter()"></select>
</div>
</div>
Expand Down
22 changes: 22 additions & 0 deletions ui/src/main/ui/src/app/services/filter-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
angular.module('hwk.appModule').service('hwk.filterService', ['$rootScope',
function ($rootScope) {
'use strict';

this.dateFilter = {
start: new Date(),
end: new Date(),
};

this.alertFilter = {
severity: 'All Severity',
severityOptions: ['All Severity', 'Low', 'Medium', 'High', 'Critical'],
status: 'All Status',
statusOptions: ['All Status', 'Open', 'Acknowledged', 'Resolved'],
};

this.tagFilter = {
tagQuery: null
};

}
]);
8 changes: 4 additions & 4 deletions ui/src/main/ui/src/dashboard/dashboard-controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
angular.module('hwk.dashboardModule').controller( 'hwk.dashboardController', ['$scope', '$rootScope', '$resource', '$window', '$location', '$interval', '$q', 'hwk.dashboardService', 'hwk.alertsService',
function ($scope, $rootScope, $resource, $window, $location, $interval, $q, dashboardService, alertsService) {
angular.module('hwk.dashboardModule').controller( 'hwk.dashboardController', ['$scope', '$rootScope', '$resource', '$window', '$location', '$interval', '$q', 'hwk.dashboardService', 'hwk.filterService',
function ($scope, $rootScope, $resource, $window, $location, $interval, $q, dashboardService, filterService) {
'use strict';

console.log("[Dashboard] Start: " + new Date());
Expand Down Expand Up @@ -391,8 +391,8 @@ angular.module('hwk.dashboardModule').controller( 'hwk.dashboardController', ['$
};

$scope.linkAlerts = function (statusFilter, severityFilter) {
alertsService.filter.severity = severityFilter;
alertsService.filter.status = statusFilter;
filterService.alertFilter.severity = severityFilter;
filterService.alertFilter.status = statusFilter;
$location.url("/alerts");
};
}
Expand Down

0 comments on commit 3010559

Please sign in to comment.