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 #401 from vrockai/AlertRedo
Browse files Browse the repository at this point in the history
Console: Alerts refactoring
  • Loading branch information
mtho11 committed Aug 13, 2015
2 parents 9941254 + 10e914c commit ffbea21
Show file tree
Hide file tree
Showing 23 changed files with 1,087 additions and 778 deletions.
73 changes: 33 additions & 40 deletions console/src/main/scripts/plugins/directives/alert/html/alert.html
Original file line number Diff line number Diff line change
@@ -1,54 +1,47 @@
<div>
<div class="panel panel-default alert alert-danger" ng-if="alert.type=='AVAILABILITY'">
<div class="panel panel-default alert alert-danger">
<div class="hk-alert-icon">
<i class="fa fa-flag"></i>
</div>
<div class="hk-date">
{{alert.start | date:'d MMM y HH:mm:ss' }}
</div>
<div class="hk-event">
Server <strong>down</strong> for
<hk-time-interval hk-time="alert.durationTime"></hk-time-interval>
(until
<span ng-show="alert.isThisYear && alert.isToday">{{alert.end | date:'HH:mm' }}).</span>
<span ng-show="alert.isThisYear && !alert.isToday">{{alert.end | date:'d MMM HH:mm:ss' }}).</span>
<span ng-show="!alert.isThisYear">{{alert.end | date:'d MMM y HH:mm:ss' }}).</span>
</div>

<div class="alert-resolver">
<a ng-click="alertResolve(alert, $index)" tooltip="Mark as resolved"
tooltip-placement="top"
tooltip-trigger="mouseenter"
tooltip-popup-delay="500">
<i class="fa" ng-class="{'fa-check-square-o': hover, 'fa-square-o': !hover}"
ng-mouseenter="hover = true"
ng-mouseleave="hover = false">
</i>
</a>
</div>
</div>

<div class="panel panel-default alert alert-danger" ng-if="alert.type=='THRESHOLD'">
<div class="hk-alert-icon">
<i class="fa fa-flag"></i>
</div>
<div class="hk-date">
{{alert.start | date:'d MMM y HH:mm:ss' }}
</div>
<div class="hk-event">
<strong>Response time</strong> was above the threshold ({{alert.threshold | number: 0}} ms) for

<hk-time-interval hk-time="alert.durationTime"></hk-time-interval>

(until
<span ng-show="alert.isThisYear && alert.isToday">{{alert.end | date:'HH:mm' }}).</span>
<span ng-show="alert.isThisYear && !alert.isToday">{{alert.end | date:'d MMM HH:mm:ss' }}).</span>
<span ng-show="!alert.isThisYear">{{alert.end | date:'d MMM y HH:mm:ss' }}).</span>
The average response time was {{alert.avg | number: 0}} ms.
<div class="hk-event" ng-switch on="alert.alertType">
<div ng-switch-when="PINGAVAIL">
Server <strong>down</strong> for
<hk-time-interval hk-time="alert.durationTime"></hk-time-interval>
(until
<span ng-show="alert.isThisYear && alert.isToday">{{alert.end | date:'HH:mm' }}).</span>
<span ng-show="alert.isThisYear && !alert.isToday">{{alert.end | date:'d MMM HH:mm:ss' }}).</span>
<span ng-show="!alert.isThisYear">{{alert.end | date:'d MMM y HH:mm:ss' }}).</span>
</div>
<div ng-switch-when="PINGRESPONSE">
<strong>Response time</strong> was above the threshold ({{alert.threshold | number: 0}} ms) for
<hk-time-interval hk-time="alert.durationTime"></hk-time-interval>
(until
<span ng-show="alert.isThisYear && alert.isToday">{{alert.end | date:'HH:mm' }}).</span>
<span ng-show="alert.isThisYear && !alert.isToday">{{alert.end | date:'d MMM HH:mm:ss' }}).</span>
<span ng-show="!alert.isThisYear">{{alert.end | date:'d MMM y HH:mm:ss' }}).</span>
The average response time was {{alert.avg | number: 0}} ms.
</div>
<div ng-switch-when="PHEAP">
<strong>Heap Memory</strong>: The Heap memory usage was {{alert.avg / 1024 / 1024 | number:2}} MB.
</div>
<div ng-switch-when="NHEAP">
<strong>Non Heap Memory</strong>: The Non Heap memory usage was {{alert.avg / 1024 / 1024 | number:2}} MB.
</div>
<div ng-switch-when="GARBA">
<strong>Garbage collection</strong>: The garbage collection took more than {{alert.avg | number:2}} ms.
</div>
<div ng-switch-default>
<strong>Alert</strong>: <code>{{alert}}</code>
</div>
</div>

<div class="alert-resolver">
<a ng-click="alertResolve()" tooltip="Mark as resolved"
<a ng-click="alertResolve(alert, $index)" tooltip="Mark as resolved"
tooltip-placement="top"
tooltip-trigger="mouseenter"
tooltip-popup-delay="500">
Expand All @@ -59,4 +52,4 @@
</a>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
<fieldset>
<legend>Alert</legend>
<hk-switch ng-show="hkSwitchEnabled"
hk-model="hkSwitch"
id="usage-less-switch" class="pull-right-switch"></hk-switch>
<legend>{{hkTitle || 'Alert'}}</legend>
<div class="form-group">
<label class="col-sm-3 control-label">Create Alert</label>
<div class="col-sm-9">
<div class="radio">
<label for="every-time-heap">
<input type="radio" name="alert-heap" id="every-time-heap" ng-value="false" ng-model="durationEnabled"
ng-click="durationToggle()" checked="">
Every time conditions are met.
ng-click="durationToggle()" checked="" ng-disabled="hkDisabled || (hkSwitchEnabled && !hkSwitch)">
{{hkTitleMet || 'Every time conditions are met.'}}
</label>
</div>
<div class="radio">
<label for="greater-time-heap">
<input type="radio" name="alert-heap" id="greater-time-heap" ng-value="true" ng-model="durationEnabled"
ng-click="durationToggle()">
Only when conditions are met for greater than:
ng-click="durationToggle()" ng-disabled="hkDisabled || (hkSwitchEnabled && !hkSwitch)">
{{hkTitleUnmet || 'Only when conditions are met for greater than:'}}
</label>
</div>
<div class="input-group input-select indented">
<input type="number" class="form-control" placeholder="Duration" ng-model="hkConvertedDuration"
ng-disabled="!durationEnabled" ng-change="durationChange()">
<select pf-select ng-model="responseUnit" id="responseUnit"
ng-disabled="!durationEnabled"
ng-options="item.value as item.label for item in timeUnits"
ng-change="computeTimeInUnits()"></select>
</div>
<hk-time-input hk-duration="hkDuration"
hk-disabled="hkDisabled || !durationEnabled || (hkSwitchEnabled && !hkSwitch)"
hk-change="durationChange()"
id="dw-duration"></hk-time-input>
</div>
</div>
</fieldset>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="form-group">
<label class="col-sm-3 control-label" for="email-heap">Email</label>
<div class="col-sm-6">
<input type="text" id="email-heap" class="form-control" ng-model="hkAlertEmail">
<input type="text" id="email-heap" class="form-control" ng-model="hkAlertEmail" ng-disabled="hkDisabled">
</div>
</div>
</fieldset>
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ module Alert {
public link: (scope: any, element: ng.IAugmentedJQuery, attrs: ng.IAttributes) => void;
public replace = 'true';
public scope = {
hkAlertEmail: '='
hkAlertEmail: '=',
hkDisabled: '='
};
public templateUrl = 'plugins/directives/alert/html/fieldset-notification.html';

Expand Down Expand Up @@ -223,23 +224,20 @@ module Alert {
public link: (scope: any) => void;
public replace = 'true';
public scope = {
hkDuration: '='
hkDuration: '=',
hkSwitch: '=',
hkDisabled: '=',
hkTitle: '@'
};
public templateUrl = 'plugins/directives/alert/html/fieldset-dampening.html';

constructor(private hkTimeUnit: any) {
this.link = (scope: any) => {
var localChange = false;
var durationBackup = scope.hkDuration || 0;

scope.timeUnits = hkTimeUnit.timeUnits;
scope.timeUnitsDict = hkTimeUnit.timeUnitDictionary;

scope.durationChange = (): void => {
scope.hkDuration = scope.hkConvertedDuration * scope.responseUnit;
};

scope.computeTimeInUnits = ():void => {
scope.hkConvertedDuration = scope.hkDuration / scope.responseUnit;
scope.durationChange = ():void => {
localChange = true;
};

scope.durationToggle = ():void => {
Expand All @@ -254,10 +252,15 @@ module Alert {
}
};

scope.$watch('hkDuration', (newDuration, oldDuration) => {
scope.durationEnabled = scope.hkDuration !== 0;
scope.responseUnit = hkTimeUnit.getFittestTimeUnit(scope.hkDuration);
scope.computeTimeInUnits();
scope.$watch('hkDuration', () => {
if (!localChange) {
scope.durationEnabled = scope.hkDuration !== 0;
}
localChange = false;
});

scope.$watch('hkSwitch', () => {
scope.hkSwitchEnabled = (scope.hkSwitch !== undefined);
});
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="onoffswitch" tabindex='0'>
<input type="checkbox"
class="onoffswitch-checkbox"
ng-model="hkModel"
ng-disabled="hkDisabled"
ng-click="hkClick()"
ng-change="hkChange()"
id="{{id}}">
<label class="onoffswitch-label" for="{{id}}">
<span class="onoffswitch-inner">
<span class="onoffswitch-active ng-binding">{{hkOnText}}</span>
<span class="onoffswitch-inactive ng-binding">{{hkOffText}}</span>
</span>
<span class="onoffswitch-switch"></span>
</label>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="input-group input-select indented">
<input type="number" class="form-control" placeholder="Duration" ng-model="hkConvertedDuration"
ng-disabled="hkDisabled" ng-change="durationChange()" id="{{id}}">
<select pf-select ng-model="responseUnit" id="responseUnit"
ng-disabled="hkDisabled"
ng-options="item.value as item.label for item in timeUnits"
ng-change="computeTimeInUnits()"></select>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
///
/// 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="../../includes.ts"/>
module HawkularComponents {

export var _module = angular.module('hawkular-components', []);

export class HkSwitch {

public link:(scope:any, element:any, attrs:any) => void;
public restrict = 'E';
public replace = 'true';
public scope = {
name: '@',
id: '@',
hkModel: '=',
hkDisabled: '=',
hkChange: '&',
hkClick: '&'
};
public templateUrl = 'plugins/directives/components/html/hk-switch.html';

constructor() {
this.link = (scope:any, element:any, attrs:any) => {
element.removeAttr('name');
element.removeAttr('id');

scope.hkOnText = attrs.onText || 'ON';
scope.hkOffText = attrs.offText || 'OFF';

element.bind('keydown', function (e) {
var code = e.keyCode || e.which;
if (code === 32 || code === 13) {
e.stopImmediatePropagation();
e.preventDefault();
$(e.target).find('input').click();
}
});
};
}

public static Factory() {
var directive = () => {
return new HkSwitch();
};

directive['$inject'] = [];

return directive;
}
}

_module.directive('hkSwitch', HawkularComponents.HkSwitch.Factory());

export class HkTimeInput {

public link:(scope:any, attrs:any, element:any) => void;
public replace = 'true';
public restrict = 'E';
public scope = {
id: '@',
hkDuration: '=',
hkDisabled: '=',
hkAutoConvert: '=',
hkChange: '&'
};
public templateUrl = 'plugins/directives/components/html/time-input.html';

constructor(private hkTimeUnit:any) {
this.link = (scope:any, element:any, attrs:any) => {
element.removeAttr('id');

var localChange = false;

scope.timeUnits = hkTimeUnit.timeUnits;
scope.timeUnitsDict = hkTimeUnit.timeUnitDictionary;

scope.durationChange = ():void => {
localChange = true;
scope.hkDuration = scope.hkConvertedDuration * scope.responseUnit;
scope.hkChange();
};

scope.computeTimeInUnits = ():void => {
scope.hkConvertedDuration = scope.hkDuration / scope.responseUnit;
};

scope.$watch('hkDuration', (newDuration, oldDuration) => {
scope.durationEnabled = scope.hkDuration !== 0;
if (!localChange) {
scope.responseUnit = hkTimeUnit.getFittestTimeUnit(scope.hkDuration);
scope.computeTimeInUnits();
}
localChange = false;
});
};
}

public static Factory() {
var directive = (hkTimeUnit:any) => {
return new HkTimeInput(hkTimeUnit);
};

directive['$inject'] = ['hkTimeUnit'];

return directive;
}
}

_module.directive('hkTimeInput', HawkularComponents.HkTimeInput.Factory());
}

0 comments on commit ffbea21

Please sign in to comment.