Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge pull request #313 from vrockai/alertService
Browse files Browse the repository at this point in the history
Console refactoring: Alert service
  • Loading branch information
mtho11 committed Jul 10, 2015
2 parents caf233f + 30b6c53 commit 511aee0
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 44 deletions.
2 changes: 1 addition & 1 deletion console/src/main/scripts/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"angular-resource": "1.3.15",
"angular-scroll": "0.6.5",
"angular-ui-select": "0.11.2",
"angular-toastr": "1.4.1",
"bootstrap-select": "1.6",
"hawkular-charts": "~0.4.6",
"hawkular-ui-services": "0.5.0",
Expand All @@ -29,7 +30,6 @@
"hawtio-oauth": "2.0.7",
"lodash": "3.2.0",
"moment": "2.10.3",
"toastr": "2.1.1",
"patternfly": "1.3.0"
},
"devDependencies": {
Expand Down
12 changes: 8 additions & 4 deletions console/src/main/scripts/plugins/metrics/ts/addUrlPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/// <reference path='alertsManager.ts'/>
/// <reference path='pagination.ts'/>
/// <reference path='errorManager.ts'/>
/// <reference path='alertService.ts'/>

module HawkularMetrics {

Expand All @@ -27,7 +28,7 @@ module HawkularMetrics {
/// this is for minification purposes
public static $inject = ['$location', '$scope', '$rootScope', '$interval', '$log', '$filter', '$modal',
'HawkularInventory', 'HawkularMetric', 'HawkularAlert', 'HawkularAlertsManager','HawkularErrorManager', '$q',
'md5', 'HkHeaderParser'];
'md5', 'HkHeaderParser', 'AlertService'];

private autoRefreshPromise:ng.IPromise<number>;
private httpUriPart = 'http://';
Expand All @@ -54,6 +55,7 @@ module HawkularMetrics {
private $q: ng.IQService,
private md5: any,
private HkHeaderParser: HawkularMetrics.IHkHeaderParser,
private AlertService: HawkularMetrics.IAlertService,
public resourceUrl:string
) {
$scope.vm = this;
Expand Down Expand Up @@ -156,7 +158,8 @@ module HawkularMetrics {
(e) => err(e, 'Error saving threshold trigger.'))

//this.$location.url('/hawkular/' + metricId);
.then(() => toastr.info('Your data is being collected. Please be patient (should be about another minute).'),
.then(() => this.AlertService.info('Your data is being collected. Please be patient (should be about ' +
'another minute).'),
(e) => err(e, 'Error saving availability trigger.'))

.finally(()=> {
Expand Down Expand Up @@ -246,14 +249,15 @@ module HawkularMetrics {
class DeleteResourceModalController {

static $inject = ['$scope', '$rootScope', '$modalInstance', '$q', 'HawkularInventory', 'HawkularAlertsManager',
'resource'];
'AlertService', 'resource'];

constructor(private $scope: any,
private $rootScope: any,
private $modalInstance: any,
private $q: ng.IQService,
private HawkularInventory,
private HawkularAlertsManager: HawkularMetrics.IHawkularAlertsManager,
private AlertService: IAlertService,
public resource) {
$scope.vm = this;
}
Expand All @@ -279,7 +283,7 @@ module HawkularMetrics {
this.HawkularAlertsManager.deleteTrigger(triggerIds[1])])
.then(removeResource)
.then((res) => {
toastr.success('The URL ' + this.resource.properties.url + ' is no longer being monitored.');
this.AlertService.success('The URL ' + this.resource.properties.url + ' is no longer being monitored.');
this.$modalInstance.close(res);
});
}
Expand Down
64 changes: 64 additions & 0 deletions console/src/main/scripts/plugins/metrics/ts/alertService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
///
/// Copyright 2015 Red Hat, Inc. and/or its affiliates
/// and other contributors as indicated by the @author tags.
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///

/// <reference path="metricsPlugin.ts"/>
/*
TODO
Move to shared service location
*/

module HawkularMetrics {

export interface IAlertService {
info(message: string): void;
success(message: string): void;
warning(message: string): void;
error(message: string): void;
}

export class AlertService implements IAlertService {

public static $inject = ['$log', 'toastr'];

constructor(private $log: ng.ILogService,
private toastr: any) {
}

private toastrPop(message, type): void {
this.$log.debug(message);
this.toastr[type](message);
}

public info(message: string): void {
this.toastrPop(message, 'info');
}

public success(message: string): void {
this.toastrPop(message, 'success');
}

public warning(message: string): void {
this.toastrPop(message, 'warning');
}

public error(message: string): void {
this.toastrPop(message, 'error');
}
}

_module.service('AlertService', AlertService);
}
8 changes: 4 additions & 4 deletions console/src/main/scripts/plugins/metrics/ts/errorManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ module HawkularMetrics {

export class HawkularErrorManager implements IHawkularErrorManager {

public static $inject = ['$q', '$log'];
public static $inject = ['$q', '$log', 'AlertService'];

constructor(private $q: ng.IQService,
private $log: ng.ILogService) {
private $log: ng.ILogService,
private AlertService: IAlertService) {
}

private errorToastr(error: any, errorMsg: string): void {
Expand All @@ -45,8 +46,7 @@ module HawkularMetrics {
errorMsgComplete = errorMsg + ' ' + error;
}

this.$log.error(errorMsgComplete);
toastr.error(errorMsgComplete);
this.AlertService.error(errorMsgComplete);
}

public errorHandler(error: any, msg: string, cb?: (error: any, msg: string) => void): ng.IPromise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module HawkularMetrics {
export class MetricsAvailabilityController {
/// for minification only
public static $inject = ['$scope', '$rootScope', '$interval', '$log', 'HawkularMetric', 'HawkularAlert',
'$routeParams', 'HawkularAlertsManager', 'HawkularErrorManager'];
'$routeParams', 'HawkularAlertsManager', 'HawkularErrorManager', 'AlertService'];

private availabilityDataPoints:IChartDataPoint[] = [];
private autoRefreshPromise:ng.IPromise<number>;
Expand All @@ -61,6 +61,7 @@ module HawkularMetrics {
private $routeParams:any,
private HawkularAlertsManager: IHawkularAlertsManager,
private HawkularErrorManager: IHawkularErrorManager,
private AlertService: IAlertService,
public alertList:any,
public startTimeStamp:TimestampInMillis,
public endTimeStamp:TimestampInMillis) {
Expand Down Expand Up @@ -162,8 +163,7 @@ module HawkularMetrics {
}

}, (error) => {
this.$log.error('Error Loading Avail Summary data');
toastr.error('Error Loading Avail Summary Data: ' + error);
this.AlertService.error('Error Loading Avail Summary Data: ' + error);
});

}
Expand Down Expand Up @@ -206,8 +206,7 @@ module HawkularMetrics {
this.uptimeRatio = 1 - downtimeDuration / (+moment() - response[0]['timestamp']);
this.downtimeCount = downtimeCount;
}, (error) => {
this.$log.error('Error Loading Avail data');
toastr.error('Error Loading Avail Data: ' + error);
this.AlertService.error('Error Loading Avail Data: ' + error);
});
}
}
Expand Down
19 changes: 10 additions & 9 deletions console/src/main/scripts/plugins/metrics/ts/metricsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
module HawkularMetrics {

export var _module = angular.module(HawkularMetrics.pluginName, ['ngResource', 'ui.select', 'hawkular.charts',
'hawkular.services', 'ui.bootstrap', 'topbar', 'patternfly.select', 'angular-momentjs', 'angular-md5']);
'hawkular.services', 'ui.bootstrap', 'topbar', 'patternfly.select', 'angular-momentjs', 'angular-md5', 'toastr']);

_module.config(['$httpProvider', '$locationProvider', '$routeProvider',
($httpProvider, $locationProvider, $routeProvider:ng.route.IRouteProvider) => {
Expand Down Expand Up @@ -94,14 +94,14 @@ module HawkularMetrics {
templateUrl: 'plugins/metrics/html/response-time.html',
reloadOnSearch: false,
resolve: {
resource: function ($route, $location, HawkularInventory) {
resource: function ($route, $location, HawkularInventory, AlertService) {
var p = HawkularInventory.Resource.get({environmentId: globalEnvironmentId,
resourceId: $route.current.params.resourceId}).$promise;
p.then((response) => {
return response.properties.url;
},
(error) => {
toastr.info('You were redirected to this page because you requested an invalid URL.');
AlertService.info('You were redirected to this page because you requested an invalid URL.');
$location.path('/');
});
return p;
Expand All @@ -112,14 +112,14 @@ module HawkularMetrics {
templateUrl: 'plugins/metrics/html/availability.html',
reloadOnSearch: false,
resolve: {
resource: function ($route, $location, HawkularInventory) {
resource: function ($route, $location, HawkularInventory, AlertService) {
var p = HawkularInventory.Resource.get({environmentId: globalEnvironmentId,
resourceId: $route.current.params.resourceId}).$promise;
p.then((response) => {
return response.properties.url;
},
(error) => {
toastr.info('You were redirected to this page because you requested an invalid URL.');
AlertService.info('You were redirected to this page because you requested an invalid URL.');
$location.path('/');
});
return p;
Expand All @@ -130,14 +130,14 @@ module HawkularMetrics {
templateUrl: 'plugins/metrics/html/alerts.html',
reloadOnSearch: false,
resolve: {
resource: function ($route, $location, HawkularInventory) {
resource: function ($route, $location, HawkularInventory, AlertService) {
var p = HawkularInventory.Resource.get({environmentId: globalEnvironmentId,
resourceId: $route.current.params.resourceId}).$promise;
p.then((response) => {
return response.properties.url;
},
(error) => {
toastr.info('You were redirected to this page because you requested an invalid URL.');
AlertService.info('You were redirected to this page because you requested an invalid URL.');
$location.path('/');
});
return p;
Expand All @@ -149,9 +149,10 @@ module HawkularMetrics {
templateUrl: 'plugins/metrics/html/app-details/app-server-details.html',
reloadOnSearch: false,
resolve: {
resource: function ($route, $location, HawkularInventory) {
resource: function ($route, $location, HawkularInventory, AlertService) {
var redirectMissingAppServer = function() {
toastr.info('You were redirected to this page because you requested an invalid Application Server.');
AlertService.info('You were redirected to this page because you requested an invalid ' +
'Application Server.');
$location.path('/hawkular-ui/app/app-list');
};
var checkAppServerExists = function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ module HawkularMetrics {
}

export class QuickAlertController implements IQuickAlertController {
public static $inject = ['$scope', 'HawkularAlert', '$log', '$q'];
public static $inject = ['$scope', 'HawkularAlert', '$log', '$q', 'AlertService'];

private metricId:MetricId;
private PROMISE_BREAK: string = 'magicValue1234';

constructor(private $scope:any,
private HawkularAlert:any,
private $log: ng.ILogService,
private $q: ng.IQService) {
private $q: ng.IQService,
private AlertService: IAlertService) {
this.$scope.showQuickAlert = false;
this.$scope.quickTrigger = {
operator: 'LT',
Expand Down Expand Up @@ -71,8 +72,7 @@ module HawkularMetrics {
errorMsgComplete = errorMsg + ' ' + error;
}

this.$log.error(errorMsgComplete);
toastr.error(errorMsgComplete);
this.AlertService.error(errorMsgComplete);
}

private errorHandler(error: any, msg: string) {
Expand Down Expand Up @@ -143,8 +143,7 @@ module HawkularMetrics {
// Success ThresholdCondition save
() => {
this.$log.debug('Success ThresholdCondition save');
this.$log.debug('Alert Created!');
toastr.success('Alert Created!');
this.AlertService.success('Alert Created!');

this.toggleQuickAlert();

Expand All @@ -167,8 +166,7 @@ module HawkularMetrics {
}
);
} else {
this.$log.debug('No metric selected');
toastr.warning('No metric selected');
this.AlertService.warning('No metric selected');
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module HawkularMetrics {
export class MetricsViewController {
/// for minification only
public static $inject = ['$scope', '$rootScope', '$interval', '$log', 'HawkularMetric', 'HawkularAlert',
'$routeParams','HawkularAlertsManager' ,'HawkularErrorManager'];
'$routeParams','HawkularAlertsManager' ,'HawkularErrorManager', 'AlertService'];

private bucketedDataPoints:IChartDataPoint[] = [];
private contextDataPoints:IChartDataPoint[] = [];
Expand All @@ -79,6 +79,7 @@ module HawkularMetrics {
private $routeParams:any,
private HawkularAlertsManager: IHawkularAlertsManager,
private HawkularErrorManager: IHawkularErrorManager,
private AlertService: IAlertService,
public alertList:any,
public startTimeStamp:TimestampInMillis,
public endTimeStamp:TimestampInMillis) {
Expand Down Expand Up @@ -158,7 +159,7 @@ module HawkularMetrics {

private noDataFoundForId(resourceId:ResourceId):void {
this.$log.warn('No Data found for id: ' + resourceId);
///toastr.warning('No Data found for id: ' + id);
///this.AlertService.warning('No Data found for id: ' + id);
}

private refreshChartDataNow(metricId:MetricId, startTime?:TimestampInMillis):void {
Expand All @@ -185,8 +186,7 @@ module HawkularMetrics {
}

}, (error) => {
this.$log.error('Error Loading Threshold data');
toastr.error('Error Loading Threshold Data: ' + error);
this.AlertService.error('Error Loading Threshold Data: ' + error);
});
}

Expand Down Expand Up @@ -221,8 +221,7 @@ module HawkularMetrics {
this.average = Math.round(_.last(dataPoints).avg);

}, (error) => {
this.$log.error('Error Loading Chart data');
toastr.error('Error Loading Chart Data: ' + error);
this.AlertService.error('Error Loading Chart Data: ' + error);
});

}
Expand Down Expand Up @@ -268,8 +267,7 @@ module HawkularMetrics {
}

}, (error) => {
this.$log.error('Error Loading Chart data');
toastr.error('Error Loading Chart Data: ' + error);
this.AlertService.error('Error Loading Chart Data: ' + error);
});
}
}
Expand Down
5 changes: 0 additions & 5 deletions console/src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@

<!-- bower:js -->
<!-- endbower -->

<!-- Remove this line once the eventDrops package is fixed
https://github.com/marmelab/EventDrops/issues/21#issuecomment-75988799
-->
<script src="libs/event-drops/src/eventDrops.js"></script>
</head>

<body style="background-color: #f5f5f5" class="ng-cloak"> <!-- FIXME: Add CSS rule -->
Expand Down

0 comments on commit 511aee0

Please sign in to comment.