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 )
|
||||
{
|
||||
|
||||
if ( msg.Message.startsWith( "[rcon] " ) ) return;
|
||||
if ( msg.Type != "Generic" && msg.Type != "Log" && msg.Type != "Error" && msg.Type != "Warning" )
|
||||
{
|
||||
console.log( msg );
|
||||
if ( msg.Message.startsWith( "[rcon] " ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.Class = msg.Type;
|
||||
$scope.Output.push( msg );
|
||||
switch(msg.Type) {
|
||||
case 'Generic':
|
||||
case 'Log':
|
||||
case 'Error':
|
||||
case 'Warning':
|
||||
$scope.addOutput(msg);
|
||||
break;
|
||||
|
||||
$timeout( $scope.ScrollToBottom, 50 );
|
||||
default:
|
||||
console.log( msg );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$scope.ScrollToBottom = function()
|
||||
{
|
||||
// TODO - don't scroll if we're not at the bottom !
|
||||
$( "#ConsoleController .Output" ).scrollTop( $( "#ConsoleController .Output" )[0].scrollHeight );
|
||||
var element = $( "#ConsoleController .Output" );
|
||||
|
||||
$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,15 +119,27 @@ function ConsoleController( $scope, rconService, $timeout )
|
||||
//
|
||||
$scope.GetHistory = function ()
|
||||
{
|
||||
console.log( "GetHistory" );
|
||||
|
||||
rconService.Request( "console.tail 128", $scope, function ( msg )
|
||||
{
|
||||
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 )
|
||||
}
|
||||
Reference in New Issue
Block a user