only scroll if already on bottom in console
and cleaned some code
This commit is contained in:
+53
-12
@@ -65,23 +65,52 @@ function ConsoleController( $scope, rconService, $timeout )
|
|||||||
$scope.OnMessage = function( msg )
|
$scope.OnMessage = function( msg )
|
||||||
{
|
{
|
||||||
|
|
||||||
if ( msg.Message.startsWith( "[rcon] " ) ) return;
|
if ( msg.Message.startsWith( "[rcon] " ) ) {
|
||||||
if ( msg.Type != "Generic" && msg.Type != "Log" && msg.Type != "Error" && msg.Type != "Warning" )
|
|
||||||
{
|
|
||||||
console.log( msg );
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.Class = msg.Type;
|
switch(msg.Type) {
|
||||||
$scope.Output.push( msg );
|
case 'Generic':
|
||||||
|
case 'Log':
|
||||||
|
case 'Error':
|
||||||
|
case 'Warning':
|
||||||
|
$scope.addOutput(msg);
|
||||||
|
break;
|
||||||
|
|
||||||
$timeout( $scope.ScrollToBottom, 50 );
|
default:
|
||||||
|
console.log( msg );
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.ScrollToBottom = function()
|
$scope.ScrollToBottom = function()
|
||||||
{
|
{
|
||||||
// TODO - don't scroll if we're not at the bottom !
|
var element = $( "#ConsoleController .Output" );
|
||||||
$( "#ConsoleController .Output" ).scrollTop( $( "#ConsoleController .Output" )[0].scrollHeight );
|
|
||||||
|
$timeout( function() {
|
||||||
|
element.scrollTop( element.prop('scrollHeight') );
|
||||||
|
}, 50 );
|
||||||
|
}
|
||||||
|
|
||||||
|
$scope.isOnBottom = function()
|
||||||
|
{
|
||||||
|
// get jquery element
|
||||||
|
var element = $( "#ConsoleController .Output" );
|
||||||
|
|
||||||
|
// height of the element
|
||||||
|
var height = element.height();
|
||||||
|
|
||||||
|
// scroll position from top position
|
||||||
|
var scrollTop = element.scrollTop();
|
||||||
|
|
||||||
|
// full height of the element
|
||||||
|
var scrollHeight = element.prop('scrollHeight');
|
||||||
|
|
||||||
|
if((scrollTop + height) > (scrollHeight - 10)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -90,14 +119,26 @@ function ConsoleController( $scope, rconService, $timeout )
|
|||||||
//
|
//
|
||||||
$scope.GetHistory = function ()
|
$scope.GetHistory = function ()
|
||||||
{
|
{
|
||||||
console.log( "GetHistory" );
|
|
||||||
|
|
||||||
rconService.Request( "console.tail 128", $scope, function ( msg )
|
rconService.Request( "console.tail 128", $scope, function ( msg )
|
||||||
{
|
{
|
||||||
var messages = JSON.parse( msg.Message );
|
var messages = JSON.parse( msg.Message );
|
||||||
|
|
||||||
messages.forEach( function ( x ) { $scope.OnMessage( x ); } );
|
messages.forEach( function ( msg ) {
|
||||||
|
$scope.OnMessage( msg );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$scope.ScrollToBottom();
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
$scope.addOutput = function (msg)
|
||||||
|
{
|
||||||
|
msg.Class = msg.Type;
|
||||||
|
$scope.Output.push( msg );
|
||||||
|
|
||||||
|
if($scope.isOnBottom()) {
|
||||||
|
$scope.ScrollToBottom();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rconService.InstallService( $scope, $scope.GetHistory )
|
rconService.InstallService( $scope, $scope.GetHistory )
|
||||||
|
|||||||
Reference in New Issue
Block a user