Skip to content

Commit f47d61c

Browse files
committed
Session info screen added WIP
1 parent b412775 commit f47d61c

File tree

7 files changed

+63
-14
lines changed

7 files changed

+63
-14
lines changed

src/main/resources/web/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<script src="js/app.js"></script>
7171
<script src="js/services.js"></script>
7272
<script src="js/controllers.js"></script>
73+
<script src="js/utils.js"></script>
7374

7475
</body>
7576
</html>

src/main/resources/web/js/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ akkaFtp.config(function($routeProvider) {
1111
$routeProvider
1212
.when('/', { templateUrl: 'parts/dashboard.html', controller: 'dashboardCtrl' })
1313
.when('/sessions', { templateUrl: 'parts/sessions.html', controller: 'sessionsCtrl' })
14+
.when('/sessions/:id', { templateUrl: 'parts/session.html', controller: 'sessionCtrl' })
1415
.when('/disconnected', { templateUrl: 'parts/disconnected.html', controller: 'disconnectedCtrl' })
1516
.when('/control', { templateUrl: 'parts/control.html', controller: 'controlCtrl' })
1617
.otherwise({ redirectTo: '/' });

src/main/resources/web/js/controllers.js

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ controllers.controller('dashboardCtrl', function($scope, $timeout, dashboardServ
3030
$scope.downloadTotal = bytesToSize(traffic.downloadedBytes);
3131
}
3232

33-
function bytesToSize(bytes) {
34-
var sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
35-
if (bytes == 0) return '0 B';
36-
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
37-
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
38-
}
39-
4033
});
4134

4235
controllers.controller('sessionsCtrl', function($scope, $timeout, sessionService) {
@@ -46,6 +39,7 @@ controllers.controller('sessionsCtrl', function($scope, $timeout, sessionService
4639
sessionService.sessions.get(
4740
function (data) {
4841
$scope.sessions = data.sessions;
42+
trafficToUnits(data.sessions)
4943
promise = $timeout($scope.getSessions, 10*1000);
5044
},
5145
function () {
@@ -58,6 +52,14 @@ controllers.controller('sessionsCtrl', function($scope, $timeout, sessionService
5852
$scope.$on('$destroy', function(){
5953
$timeout.cancel(promise);
6054
});
55+
56+
function trafficToUnits(sessions) {
57+
sessions.forEach(function(x) {
58+
x.uploadTotal = bytesToSize(x.uploadedBytes);
59+
x.downloadTotal = bytesToSize(x.downloadedBytes);
60+
});
61+
}
62+
6163
});
6264

6365
controllers.controller('disconnectedCtrl', function($scope, $timeout, sessionService) {
@@ -67,6 +69,7 @@ controllers.controller('disconnectedCtrl', function($scope, $timeout, sessionSer
6769
sessionService.disconnected.get(
6870
function (data) {
6971
$scope.sessions = data.sessions;
72+
trafficToUnits(data.sessions)
7073
promise = $timeout($scope.getSessions, 10*1000);
7174
},
7275
function () {
@@ -79,6 +82,14 @@ controllers.controller('disconnectedCtrl', function($scope, $timeout, sessionSer
7982
$scope.$on('$destroy', function(){
8083
$timeout.cancel(promise);
8184
});
85+
86+
function trafficToUnits(sessions) {
87+
sessions.forEach(function(x) {
88+
x.uploadTotal = bytesToSize(x.uploadedBytes);
89+
x.downloadTotal = bytesToSize(x.downloadedBytes);
90+
});
91+
}
92+
8293
});
8394

8495
controllers.controller('controlCtrl', function($scope, controlService) {
@@ -124,3 +135,27 @@ controllers.controller('mainNavCtrl', function($scope, $location) {
124135
}
125136

126137
});
138+
139+
controllers.controller('sessionCtrl', function($scope, $timeout, $routeParams, sessionService) {
140+
var promise;
141+
142+
$scope.sessionId = $routeParams.id;
143+
144+
$scope.getSession = function() {
145+
sessionService.session($scope.sessionId).get(
146+
function (data) {
147+
$scope.payload = data;
148+
promise = $timeout($scope.getSession, 2*1000);
149+
},
150+
function () {
151+
console.error('disconneced');
152+
}
153+
)
154+
};
155+
$scope.getSession();
156+
157+
$scope.$on('$destroy', function(){
158+
$timeout.cancel(promise);
159+
});
160+
161+
});

src/main/resources/web/js/services.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ services.factory('sessionService', function($resource) {
1212
service.sessions = $resource('/api/sessions');
1313
service.disconnected = $resource('/api/sessions?disconnected');
1414

15+
service.session = function(id) {
16+
return $resource('/api/sessions/'+id);
17+
};
18+
1519
return service;
1620
});
1721

src/main/resources/web/parts/disconnected.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ <h1 class="page-header">Disconnected sessions</h1>
1616
</thead>
1717
<tbody>
1818
<tr ng-repeat="x in sessions">
19-
<td>{{x.id}}</td>
19+
<td><a href="#/sessions/{{x.id}}">{{x.id}}</a></td>
2020
<td>{{x.username}}</td>
2121
<td>{{x.lastCommand}}</td>
22-
<td>{{x.uploadedBytes}}</td>
23-
<td>{{x.downloadedBytes}}</td>
22+
<td>{{x.uploadTotal}}</td>
23+
<td>{{x.downloadTotal}}</td>
2424
</tr>
2525
</tbody>
2626
</table>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<section id="session">
2+
3+
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
4+
<h1 class="page-header">Session {{sessionId}}</h1>
5+
6+
{{payload}}
7+
8+
</section>

src/main/resources/web/parts/sessions.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<section id="settings">
1+
<section id="sessions">
22

33
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
44
<h1 class="page-header">Active sessions</h1>
@@ -16,11 +16,11 @@ <h1 class="page-header">Active sessions</h1>
1616
</thead>
1717
<tbody>
1818
<tr ng-repeat="x in sessions">
19-
<td>{{x.id}}</td>
19+
<td><a href="#/sessions/{{x.id}}">{{x.id}}</a></td>
2020
<td>{{x.username}}</td>
2121
<td>{{x.lastCommand}}</td>
22-
<td>{{x.uploadedBytes}}</td>
23-
<td>{{x.downloadedBytes}}</td>
22+
<td>{{x.uploadTotal}}</td>
23+
<td>{{x.downloadTotal}}</td>
2424
</tr>
2525
</tbody>
2626
</table>

0 commit comments

Comments
 (0)