From 90c60f9fa9534c5aa1bd2ed4f0e1ed0f3f3df674 Mon Sep 17 00:00:00 2001 From: alexfriesen Date: Thu, 19 May 2016 18:58:36 +0200 Subject: [PATCH] renamed rconService.getUsers() to rconService.getPlayers() to be consistent console History rotates correctly up and down --- js/console.js | 21 +++++++++++++++++++-- js/playerInfo.js | 13 ++++++++----- js/playerlist.js | 4 ++-- js/rconService.js | 2 +- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/js/console.js b/js/console.js index 1bd5537..abd19c2 100644 --- a/js/console.js +++ b/js/console.js @@ -11,8 +11,25 @@ function ConsoleController( $scope, rconService, $timeout ) { switch(event.keyCode) { - // Arrow Up Key + // Arrow Key Up case 38: + + // rotate through commandHistory + $scope.commandHistoryIndex--; + if($scope.commandHistoryIndex < 0) { + $scope.commandHistoryIndex = $scope.commandHistory.length; + } + + // set command from history + if($scope.commandHistory[$scope.commandHistoryIndex]) { + $scope.Command = $scope.commandHistory[$scope.commandHistoryIndex]; + } + + break; + + // Arrow Key Down + case 40: + // rotate through commandHistory $scope.commandHistoryIndex++; if($scope.commandHistoryIndex >= $scope.commandHistory.length) { @@ -28,7 +45,7 @@ function ConsoleController( $scope, rconService, $timeout ) default: // reset command history index - $scope.commandHistoryIndex = 0; + $scope.commandHistoryIndex = $scope.commandHistory.length; break; } } diff --git a/js/playerInfo.js b/js/playerInfo.js index 87c2dc8..24f594f 100644 --- a/js/playerInfo.js +++ b/js/playerInfo.js @@ -9,29 +9,32 @@ function PlayerInfoController( $scope, rconService, $routeParams ) $scope.refresh = function () { - rconService.getUsers($scope, function(users) { + rconService.getPlayers($scope, function(players) { - for(var i in users) { - if(users[i].SteamID === $scope.userid){ + for(var i in players) { + if(players[i].SteamID === $scope.userid){ // set player data - $scope.info = users[i]; + $scope.info = players[i]; return; } } - // info not found + // player not found + // reset data to null $scope.info = null; }); } $scope.getUsername = function () { + // try to find players name in info if($scope.info && $scope.info.DisplayName) { return $scope.info.DisplayName; } + // otherwise show the id return $scope.userid; } diff --git a/js/playerlist.js b/js/playerlist.js index 45955d2..820faea 100644 --- a/js/playerlist.js +++ b/js/playerlist.js @@ -8,9 +8,9 @@ function PlayerListController( $scope, rconService, $interval ) $scope.Refresh = function () { - rconService.getUsers($scope, function ( users ) + rconService.getPlayers($scope, function ( players ) { - $scope.Players = users; + $scope.Players = players; }); } diff --git a/js/rconService.js b/js/rconService.js index 4703e69..15853fb 100644 --- a/js/rconService.js +++ b/js/rconService.js @@ -102,7 +102,7 @@ function RconService() } } - s.getUsers = function(scope, success) { + s.getPlayers = function(scope, success) { this.Request( "playerlist", scope, function ( response ) { var players = JSON.parse( response.Message );