From 12c58af9affaeaf325e9f0585a19db9666adec7f Mon Sep 17 00:00:00 2001 From: alexfriesen Date: Wed, 18 May 2016 14:16:27 +0200 Subject: [PATCH] Added Command History to console --- html/console.html | 8 ++++---- js/console.js | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/html/console.html b/html/console.html index 89d066c..acb194b 100644 --- a/html/console.html +++ b/html/console.html @@ -1,11 +1,11 @@
-
{{line.Message}}
+
+
{{line.Message}}
+
-
- -
+
\ No newline at end of file diff --git a/js/console.js b/js/console.js index 02ce256..1bd5537 100644 --- a/js/console.js +++ b/js/console.js @@ -3,16 +3,46 @@ app.controller( 'ConsoleController', ConsoleController ); function ConsoleController( $scope, rconService, $timeout ) { - $scope.Output = new Array(); + $scope.Output = []; + $scope.commandHistory = []; + $scope.commandHistoryIndex = 0; + + $scope.KeyUp = function (event) + { + switch(event.keyCode) { + + // Arrow Up Key + case 38: + // rotate through commandHistory + $scope.commandHistoryIndex++; + if($scope.commandHistoryIndex >= $scope.commandHistory.length) { + $scope.commandHistoryIndex = 0; + } + + // set command from history + if($scope.commandHistory[$scope.commandHistoryIndex]) { + $scope.Command = $scope.commandHistory[$scope.commandHistoryIndex]; + } + + break; + + default: + // reset command history index + $scope.commandHistoryIndex = 0; + break; + } + } $scope.SubmitCommand = function () { - $scope.OnMessage( { Message: $scope.Command, Type: 'Command' } ) + $scope.OnMessage( { Message: $scope.Command, Type: 'Command' } ); + + $scope.commandHistory.push($scope.Command); rconService.Command( $scope.Command, 1 ); $scope.Command = ""; + $scope.commandHistoryIndex = 0; } - $scope.$on( "OnMessage", function ( event, msg ) { $scope.OnMessage( msg ); } ); $scope.OnMessage = function( msg )