Skip to content

Commit 1991682

Browse files
committed
Added hearbeats list #41
1 parent a527a9a commit 1991682

File tree

15 files changed

+97
-136
lines changed

15 files changed

+97
-136
lines changed

src/Pulse.Host/Pulse.Host.csproj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
</Content>
7373
<Content Include="app\img\ie7-forbidden-logo.jpg" />
7474
<Content Include="app\img\ServicePulseLogo.png" />
75+
<Content Include="app\lib\angular-cache-1.1.0.min.js" />
7576
<Content Include="app\lib\jquery-1.10.2.min.js">
7677
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7778
</Content>
@@ -103,9 +104,6 @@
103104
<Content Include="app\fonts\glyphicons-halflings-regular.svg">
104105
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
105106
</Content>
106-
<Content Include="app\index-async.html">
107-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
108-
</Content>
109107
<Content Include="app\index.html">
110108
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
111109
</Content>
@@ -160,11 +158,12 @@
160158
<Content Include="app\lib\bootstrap.min.js">
161159
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
162160
</Content>
161+
<Content Include="app\lib\moment.min.js" />
163162
<Content Include="app\NoIE.html" />
164-
<Content Include="app\partials\partial1.html">
163+
<Content Include="app\partials\heartbeatsStats.html">
165164
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
166165
</Content>
167-
<Content Include="app\partials\partial2.html">
166+
<Content Include="app\partials\heartbeats.html">
168167
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
169168
</Content>
170169
</ItemGroup>

src/Pulse.Host/app/css/app.css

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
11
/* app css stylesheet */
22

3-
.menu {
4-
list-style: none;
5-
border-bottom: 0.1em solid black;
6-
margin-bottom: 2em;
7-
padding: 0 0 0.5em;
8-
}
9-
10-
.menu:before {
11-
content: "[";
12-
}
13-
14-
.menu:after {
15-
content: "]";
16-
}
17-
18-
.menu > li {
19-
display: inline;
20-
}
21-
22-
.menu > li:before {
23-
content: "|";
24-
padding-right: 0.3em;
25-
}
26-
27-
.menu > li:nth-child(1):before {
28-
content: "";
29-
padding: 0;
3+
body {
4+
margin-right: 15px;
5+
margin-left: 15px;
306
}

src/Pulse.Host/app/index-async.html

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/Pulse.Host/app/index.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<html lang="en" ng-app="myApp">
2+
<html lang="en" ng-app="sc">
33
<head>
44
<title>ServicePulse</title>
55

@@ -24,7 +24,7 @@
2424
<span class="icon-bar"></span>
2525
<span class="icon-bar"></span>
2626
</button>
27-
<a class="navbar-brand" href="#">ServicePulse</a>
27+
<a href="/"><img src="/img/ServicePulseLogo.png" alt="ServicePulse Logo" /></a>
2828
</div>
2929

3030
<!-- Collect the nav links, forms, and other content for toggling -->
@@ -39,8 +39,8 @@
3939
<div class="row">
4040
<div class="col-md-2">
4141
<ul class="nav nav-pills nav-stacked">
42-
<li><a href="#/view1">Issue 40</a></li>
43-
<li><a href="#/view2">view2</a></li>
42+
<li><a href="#/heartbeatsStats">Heartbeats Stats</a></li>
43+
<li><a href="#/heartbeats">Heartbeats List</a></li>
4444
</ul>
4545
</div>
4646
<div class="col-md-10" ng-view></div>
@@ -49,7 +49,9 @@
4949
<script src="lib/jquery-1.10.2.min.js"></script>
5050
<script src="lib/jquery.signalR-1.1.3.min.js"></script>
5151
<script src="lib/angular/angular.min.js"></script>
52+
<script src="lib/angular-cache-1.1.0.min.js"></script>
5253
<script src="lib/bootstrap.min.js"></script>
54+
<script src="lib/moment.min.js"></script>
5355
<script src="js/app.js"></script>
5456
<script src="js/services.js"></script>
5557
<script src="js/controllers.js"></script>

src/Pulse.Host/app/js/app.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33

44
// Declare app level module which depends on filters, and services
5-
angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives', 'myApp.controllers'])
5+
angular.module('sc', ['sc.filters', 'sc.services', 'sc.directives', 'sc.controllers'])
66
.config(['$routeProvider', function($routeProvider) {
7-
$routeProvider.when('/view1', {templateUrl: 'partials/partial1.html', controller: 'MyCtrl1'});
8-
$routeProvider.when('/view2', {templateUrl: 'partials/partial2.html', controller: 'MyCtrl2'});
9-
$routeProvider.otherwise({redirectTo: '/view1'});
7+
$routeProvider.when('/heartbeatsStats', { templateUrl: 'partials/heartbeatsStats.html', controller: 'heartbeatsStats' });
8+
$routeProvider.when('/heartbeats', { templateUrl: 'partials/heartbeats.html', controller: 'heartbeats' });
9+
$routeProvider.otherwise({ redirectTo: '/heartbeatsStats' });
1010
}])
1111
.run(['$rootScope', '$log', function ($rootScope, $log) {
1212
$rootScope.$log = $log;

src/Pulse.Host/app/js/controllers.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
/* Controllers */
44

5-
angular.module('myApp.controllers', [])
6-
.controller('MyCtrl1', ['$scope', 'streamService', 'serviceControlService', function ($scope, streamService, serviceControlService) {
5+
angular.module('sc.controllers', [])
6+
.controller('heartbeatsStats', ['$scope', 'streamService', 'serviceControlService', function ($scope, streamService, serviceControlService) {
77

88
$scope.model = {active_endpoints: '?', number_of_failing_endpoints: '?'};
99

@@ -13,15 +13,24 @@ angular.module('myApp.controllers', [])
1313
});
1414

1515
streamService.subscribe($scope, 'HeartbeatSummaryChanged', function (message) {
16-
$scope.$apply(function (scope) {
17-
scope.model.active_endpoints = message.active_endpoints;
18-
scope.model.number_of_failing_endpoints = message.number_of_failing_endpoints;
19-
});
16+
$scope.model.active_endpoints = message.active_endpoints;
17+
$scope.model.number_of_failing_endpoints = message.number_of_failing_endpoints;
2018
});
2119

2220
}])
23-
.controller('MyCtrl2', ['$scope', 'serviceControlService', function($scope, serviceControlService) {
24-
serviceControlService.getEndpointsWithSla().then(function(endpoints) {
25-
$scope.endpoints = endpoints;
21+
.controller('heartbeats', ['$scope', 'serviceControlService', 'streamService', function ($scope, serviceControlService, streamService) {
22+
23+
$scope.model = [];
24+
25+
function refresh() {
26+
serviceControlService.getHeartbeatsList().then(function(heartbeats) {
27+
$scope.model = heartbeats;
28+
});
29+
}
30+
31+
refresh();
32+
33+
streamService.subscribe($scope, 'HeartbeatSummaryChanged', function (_) {
34+
refresh();
2635
});
2736
}]);

src/Pulse.Host/app/js/directives.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
/* Directives */
44

55

6-
angular.module('myApp.directives', []).
7-
directive('appVersion', ['version', function(version) {
8-
return function(scope, elm, attrs) {
9-
elm.text(version);
10-
};
6+
angular.module('sc.directives', []).
7+
directive('moment', ['$timeout', function($timeout) {
8+
return {
9+
restrict: 'C',
10+
link: function(scope, element, attr) {
11+
//$timeout.setTimeout();
12+
}
13+
};
1114
}]);

src/Pulse.Host/app/js/filters.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
/* Filters */
44

5-
angular.module('myApp.filters', []).
6-
filter('interpolate', ['version', function(version) {
7-
return function(text) {
8-
return String(text).replace(/\%VERSION\%/mg, version);
9-
}
5+
angular.module('sc.filters', []).
6+
filter('moment', [function() {
7+
return function(text) {
8+
return moment(text).fromNow();
9+
};
1010
}]);

src/Pulse.Host/app/js/services.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,52 @@
44

55
// Demonstrate how to register services
66
// In this case it is a simple value service.
7-
angular.module('myApp.services', [])
7+
angular.module('sc.services', ['angular-cache'])
88
.constant('serviceControlUrl', 'http://localhost:33333/api')
9-
.factory('streamService', ['$log', '$rootScope', 'serviceControlUrl', function($log, $rootScope, serviceControlUrl) {
9+
.run(function ($http, $angularCacheFactory) {
10+
$angularCacheFactory('defaultCache', {
11+
capacity: 1000, // This cache can hold 1000 items,
12+
maxAge: 90000, // Items added to this cache expire after 15 minutes
13+
aggressiveDelete: true, // Items will be actively deleted when they expire
14+
cacheFlushInterval: 3600000, // This cache will clear itself every hour,
15+
storageMode: 'localStorage'
16+
});
1017

18+
//$http.defaults.cache = $angularCacheFactory.get('defaultCache');
19+
})
20+
.factory('streamService', ['$log', '$rootScope', 'serviceControlUrl', function($log, $rootScope, serviceControlUrl) {
21+
var prefix = 'signalr::';
1122
var connection = $.connection(serviceControlUrl + '/messagestream');
12-
23+
var registrations = {};
24+
1325
connection.received(function(data) {
1426
$log.info('SignalR data received');
1527
$log.info(data);
16-
$rootScope.$broadcast(data.type, data.message);
28+
$rootScope.$broadcast(prefix + data.type, data.message);
1729
});
1830

1931
connection.start().done(function() {
2032
$log.info('SignalR started');
2133
});
2234

2335
var onSubscribe = function($scope, messageType, handler) {
24-
$scope.$on(messageType, function(event, message) {
25-
handler(message);
36+
var deregFunc = $scope.$on(prefix + messageType, function (event, message) {
37+
$scope.$apply(function(_) {
38+
handler(message);
39+
});
2640
});
41+
42+
registrations[messageType + $scope.$id] = deregFunc;
2743
};
2844

2945
var onUnsubscribe = function($scope, messageType) {
46+
var deregFunc = registrations[messageType + $scope.$id];
3047

48+
if (deregFunc !== null) {
49+
deregFunc();
50+
}
51+
52+
delete registrations[messageType + $scope.$id];
3153
};
3254

3355
return {

src/Pulse.Host/app/lib/angular-cache-1.1.0.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)