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

Commit

Permalink
Remove exposing the Math object to the view. Add additional type safe…
Browse files Browse the repository at this point in the history
…ty around $rootScope with IHawkularRootScope
  • Loading branch information
mtho11 committed Jul 24, 2015
1 parent 54b4b88 commit 8ad4259
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ <h3 class="pull-left">Availability Status</h3>
<!-- Alerts -->
<div class="hk-info-top clearfix">
<h3 class="pull-left" data-toggle="tooltip" data-placement="top" title="" data-original-title="Expand/collapse">
<button class="btn btn-link hk-trigger" ng-click="showAllAlerts = !showAllAlerts"><i class="fa" ng-show="vm.alertList.length > 0" ng-class="showAllAlerts ? 'fa-minus-square-o' : 'fa-plus-square-o'"></i> Alerts <span ng-show="vm.alertList.length > 0">({{showAllAlerts ? vm.alertList.length : vm.math.min(vm.alertList.length, 3)}} of {{vm.alertList.length}})</span></button>
<button class="btn btn-link hk-trigger" ng-click="showAllAlerts = !showAllAlerts"><i class="fa" ng-show="vm.alertList.length > 0" ng-class="showAllAlerts ? 'fa-minus-square-o' : 'fa-plus-square-o'"></i> Alerts <span ng-show="vm.alertList.length > 0">({{showAllAlerts ? vm.alertList.length : MetricsAvailabilityController.min(vm.alertList.length, 3)}} of {{vm.alertList.length}})</span></button>
</h3>
<span class="hk-settings pull-right"><a href="#" ng-controller="MetricsAlertController as mac" ng-click="mac.openSetup()"><i class="fa fa-cog"></i>Alert Settings</a></span>
</div>
Expand Down Expand Up @@ -82,4 +82,4 @@ <h2>Availability</h2>


</section>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module HawkularMetrics {
public chartRespData;

constructor(private $scope: any,
private $rootScope: any,
private $rootScope: IHawkularRootScope,
private $routeParams: any,
private $interval: ng.IIntervalService,
private $q: ng.IQService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module HawkularMetrics {

constructor(private $location: ng.ILocationService,
private $scope: any,
private $rootScope: any,
private $rootScope: IHawkularRootScope,
private $interval: ng.IIntervalService,
private $log: ng.ILogService,
private $filter: ng.IFilterService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ module HawkularMetrics {
export class AppServerJvmDetailsController {
/// this is for minification purposes
public static $inject = ['$location', '$scope', '$rootScope', '$interval', '$log', '$filter', '$routeParams',
'$modal', 'HawkularInventory', 'HawkularMetric', 'HawkularAlert', 'HawkularAlertsManager', 'HawkularErrorManager',
'$q', 'md5'];
'$modal', 'HawkularInventory', 'HawkularMetric', 'HawkularAlert', 'HawkularAlertsManager',
'HawkularErrorManager', '$q', 'md5'];

public static USED_COLOR = '#1884c7'; /// blue
public static MAXIMUM_COLOR = '#f57f20'; /// orange
public static COMMITTED_COLOR = '#515252'; /// dark gray

private resourceList;
private metricsList;
public alertList;
public chartHeapData: IMultiDataPoint[];
public chartNonHeapData: IMultiDataPoint[];
public startTimeStamp:TimestampInMillis;
public endTimeStamp:TimestampInMillis;

constructor(private $location: ng.ILocationService,
private $scope: any,
private $rootScope: any,
private $rootScope: IHawkularRootScope,
private $interval: ng.IIntervalService,
private $log: ng.ILogService,
private $filter: ng.IFilterService,
Expand All @@ -57,10 +57,7 @@ module HawkularMetrics {
private HawkularAlertsManager: HawkularMetrics.IHawkularAlertsManager,
private HawkularErrorManager: HawkularMetrics.IHawkularErrorManager,
private $q: ng.IQService,
private md5: any,
public startTimeStamp:TimestampInMillis,
public endTimeStamp:TimestampInMillis,
public resourceUrl: string) {
private md5: any ) {
$scope.vm = this;

this.startTimeStamp = +moment().subtract(($routeParams.timeOffset || 3600000), 'milliseconds');
Expand All @@ -72,7 +69,8 @@ module HawkularMetrics {
this.getJvmData(this.$rootScope.currentPersona.id);
} else {
// currentPersona hasn't been injected to the rootScope yet, wait for it..
$rootScope.$watch('currentPersona', (currentPersona) => currentPersona && this.getJvmData(currentPersona.id));
$rootScope.$watch('currentPersona',
(currentPersona) => currentPersona && this.getJvmData(currentPersona.id));
}

this.autoRefresh(20);
Expand Down Expand Up @@ -138,7 +136,7 @@ module HawkularMetrics {
this.endTimeStamp = this.$routeParams.endTime || +moment();
this.startTimeStamp = this.endTimeStamp - (this.$routeParams.timeOffset || 3600000);

var tenantId:TenantId = currentTenantId || this.$rootScope.currentPersona.id;
//var tenantId:TenantId = currentTenantId || this.$rootScope.currentPersona.id;
this.HawkularMetric.GaugeMetricData(this.$rootScope.currentPersona.id).queryMetrics({
gaugeId: 'MI~R~[' + this.$routeParams.resourceId + '~/]~MT~WildFly Memory Metrics~Heap Committed',
start: this.startTimeStamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module HawkularMetrics {
private HawkularErrorManager: HawkularMetrics.IHawkularErrorManager,
private $log: ng.ILogService,
private $q: ng.IQService,
private $rootScope: any,
private $rootScope: IHawkularRootScope,
private $routeParams: any,
private $modal: any,
private $interval: ng.IIntervalService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ module HawkularMetrics {
empty:boolean;
}



export class MetricsAvailabilityController {
/// for minification only
public static $inject = ['$scope', '$rootScope', '$interval', '$window', '$log', 'HawkularMetric', 'HawkularAlert',
'$routeParams', '$filter', '$moment', 'HawkularAlertsManager', 'HawkularErrorManager', 'NotificationService'];
public static $inject = ['$scope', '$rootScope', '$interval', '$window', '$log', 'HawkularMetric',
'HawkularAlert', '$routeParams', '$filter', '$moment', 'HawkularAlertsManager',
'HawkularErrorManager', 'NotificationService'];

private availabilityDataPoints:IChartDataPoint[] = [];
private autoRefreshPromise:ng.IPromise<number>;
Expand All @@ -47,25 +50,25 @@ module HawkularMetrics {
public lastDowntime:Date;
public downtimeCount = 0;
public empty = true;
public math;
public alertList:any;
public startTimeStamp:TimestampInMillis;
public endTimeStamp:TimestampInMillis;


constructor(private $scope:any,
private $rootScope:any,
private $rootScope:IHawkularRootScope,
private $interval:ng.IIntervalService,
private $window:any,
private $log:ng.ILogService,
private HawkularMetric:any,
private HawkularAlert:any,
private $routeParams:any,
private $filter:any,
private $filter:ng.IFilterService,
private $moment:any,
private HawkularAlertsManager:IHawkularAlertsManager,
private HawkularErrorManager:IHawkularErrorManager,
private NotificationService:INotificationService,
public alertList:any,
public startTimeStamp:TimestampInMillis,
public endTimeStamp:TimestampInMillis) {
private NotificationService:INotificationService) {
$scope.vm = this;
this.math = $window.Math;

this.startTimeStamp = +$moment().subtract(1, 'hours');
this.endTimeStamp = +$moment();
Expand Down Expand Up @@ -105,13 +108,16 @@ module HawkularMetrics {
});
}

public static min(a:number, b:number):number {
return Math.min(a, b);
}

public refreshAvailPageNow(resourceId:ResourceId, startTime?:number):void {
this.$scope.hkEndTimestamp = +this.$moment();
var adjStartTimeStamp:number = +this.$moment().subtract(this.$scope.hkParams.timeOffset, 'milliseconds');
this.endTimeStamp = this.$scope.hkEndTimestamp;
if (resourceId) {
console.log('*** Updating Availability Page');
this.$log.debug('Updating Availability Page');
this.refreshSummaryAvailabilityData(resourceId, startTime ? startTime : adjStartTimeStamp, this.endTimeStamp);
this.refreshAvailChartData(resourceId, startTime ? startTime : adjStartTimeStamp, this.endTimeStamp);
this.getAlerts(resourceId, startTime ? startTime : adjStartTimeStamp, this.endTimeStamp);
Expand All @@ -123,7 +129,6 @@ module HawkularMetrics {
this.endTimeStamp = this.$scope.hkEndTimestamp;
this.startTimeStamp = this.$scope.hkStartTimestamp;
this.autoRefreshPromise = this.$interval(() => {
console.info('Autorefresh Availabilty for: ' + this.getResourceId());
this.$scope.hkEndTimestamp = +this.$moment();
this.endTimeStamp = this.$scope.hkEndTimestamp;
this.$scope.hkStartTimestamp = +this.$moment().subtract(this.$scope.hkParams.timeOffset, 'milliseconds');
Expand All @@ -149,8 +154,6 @@ module HawkularMetrics {
buckets: 1
}).$promise
.then((availResponse:IAvailabilitySummary[]) => {
console.info('Avail Summary:');
console.dir(availResponse);

if (availResponse && !_.last(availResponse).empty) {

Expand All @@ -172,7 +175,9 @@ module HawkularMetrics {
return this.resourceId;
}

public refreshAvailChartData(metricId:MetricId, startTime:TimestampInMillis, endTime:TimestampInMillis):void {
public refreshAvailChartData(metricId:MetricId,
startTime:TimestampInMillis,
endTime:TimestampInMillis):void {
if (metricId) {
this.HawkularMetric.AvailabilityMetricData(this.$rootScope.currentPersona.id).query({
availabilityId: metricId,
Expand All @@ -182,8 +187,6 @@ module HawkularMetrics {
}).$promise
.then((response) => {

console.log('Availability Data: ');
console.dir(response);
this.availabilityDataPoints = response;

// FIXME: HAWKULAR-347
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module HawkularMetrics {
public endTimeStamp:TimestampInMillis;

constructor(private $scope:any,
private $rootScope:any,
private $rootScope:IHawkularRootScope,
private $interval:ng.IIntervalService,
private $log:ng.ILogService,
private HawkularAlert:any,
Expand Down
30 changes: 18 additions & 12 deletions console/src/main/scripts/plugins/metrics/ts/metricsTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,28 @@ module HawkularMetrics {
/// especially useful for refactoring.

/// ID types
export type TenantId = string;
export type ResourceId = string;
export type MetricId = string;
export type TriggerId = string;
export type ConditionId = string;
export type DampeningId = string;
export type EmailType = string;
export type Persona = string;
export type TenantId = string;
export type ResourceId = string;
export type MetricId = string;
export type TriggerId = string;
export type ConditionId = string;
export type DampeningId = string;
export type EmailType = string;
export type PersonaId = string;
export type Persona = IPersona;

/// Value types
export type TimestampInMillis = number;
export type IntervalInSeconds = number;
export type TimestampInMillis = number;
export type IntervalInSeconds = number;


/// Interface Definitions
export interface IPersona {
id: PersonaId;
}

export type PersonaId = string;

export interface IHawkularRootScope extends ng.IRootScopeService {
currentPersona:IPersona;
}

}

0 comments on commit 8ad4259

Please sign in to comment.