URLs include address, automatically connected to if password is present

This commit is contained in:
Garry Newman
2016-03-03 12:53:56 +00:00
parent 5fa14a3247
commit e4452d48ab
7 changed files with 85 additions and 62 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
Info about player {{userid}} Info about player {{userid}}
<p>View <a href="#/player/{{userid}}/xp">XP info for this player</a></p> <p>View <a href="#/{{address}}/player/{{userid}}/xp">XP info for this player</a></p>
Show info about this player here Show info about this player here
</div> </div>
+1 -1
View File
@@ -3,7 +3,7 @@
<md-content flex layout-padding> <md-content flex layout-padding>
<h2>Statistics for player <a href="#/player/{{userid}}/">{{userid}}</a></h2> <h2>Statistics for player <a href="#/{{address}}/player/{{userid}}/">{{userid}}</a></h2>
<div layout="row" layout-sm="column"> <div layout="row" layout-sm="column">
+3 -3
View File
@@ -1,10 +1,10 @@
<div ng-controller="PlayerListController" flex layout="column" id="PlayerListController"> <div ng-controller="PlayerListController" flex layout="column" id="PlayerListController">
<md-content flex id="vertical-container"> <md-content flex id="vertical-container">
<md-list> <md-list>
<md-list-item class="" ng-repeat="line in Players | filter : FilterText" href="#/player/{{line.SteamID}}/"> <md-list-item class="" ng-repeat="line in Players | filter : FilterText" href="#/{{address}}/player/{{line.SteamID}}/">
<div flex layout="row"> <div flex layout="row">
<div flex class="md-list-item-text"> <div flex class="md-list-item-text">
<h3><a href="#/player/{{line.SteamID}}/">{{line.DisplayName}}</a></h3> <h3><a href="#/{{address}}/player/{{line.SteamID}}/">{{line.DisplayName}}</a></h3>
</div> </div>
</div> </div>
@@ -21,7 +21,7 @@
</div> </div>
<div flex="10"style="text-align: right"> <div flex="10"style="text-align: right">
XP: <a href="#/player/{{line.SteamID}}/xp">{{line.UnspentXp}}</a> XP: <a href="#/{{address}}/player/{{line.SteamID}}/xp">{{line.UnspentXp}}</a>
</div> </div>
<div flex="20"style="text-align: right"> <div flex="20"style="text-align: right">
+2 -1
View File
@@ -20,7 +20,7 @@
<md-list> <md-list>
<md-list-item ng-repeat="p in pages | filter: { Nav: '' } "> <md-list-item ng-repeat="p in pages | filter: { Nav: '' } ">
<md-button href="#{{p.originalPath}}" class="menu_button" ng-class="{'selected' : $route.current.Title == p.Title }"> <md-button href="#{{Nav( p.originalPath )}}" class="menu_button" ng-class="{'selected' : $route.current.Title == p.Title }">
{{p.Title}} {{p.Title}}
</md-button> </md-button>
</md-list-item> </md-list-item>
@@ -68,6 +68,7 @@
<!-- Our stuff --> <!-- Our stuff -->
<script src="js/rconService.js"></script> <script src="js/rconService.js"></script>
<script src="js/app.js"></script> <script src="js/app.js"></script>
<script src="js/connection.js"></script>
<script src="js/console.js"></script> <script src="js/console.js"></script>
<script src="js/playerlist.js"></script> <script src="js/playerlist.js"></script>
<script src="js/playerInfo.js"></script> <script src="js/playerInfo.js"></script>
+13 -54
View File
@@ -11,11 +11,12 @@ app.config( function ( $mdThemingProvider, $routeProvider )
'default': '700' 'default': '700'
}).accentPalette( 'blue' ); }).accentPalette( 'blue' );
$routeProvider.when( "/console", { Title: "Console", templateUrl: "html/console.html", Nav: true } ) $routeProvider.when( "/home", { Title: "Home", templateUrl: "html/home.html" } )
$routeProvider.when( "/playerlist", { Title: "Player List", templateUrl: "html/playerlist.html", Nav: true } ) $routeProvider.when( "/:address/console", { Title: "Console", templateUrl: "html/console.html", Nav: true } )
$routeProvider.when( "/player/:userid", { Title: "Player Info", templateUrl: "html/playerInfo.html" } ) $routeProvider.when( "/:address/playerlist", { Title: "Player List", templateUrl: "html/playerlist.html", Nav: true } )
$routeProvider.when( "/player/:userid/xp", { Title: "Player Xp Stats", templateUrl: "html/playerXp.html" } ) $routeProvider.when( "/:address/player/:userid", { Title: "Player Info", templateUrl: "html/playerInfo.html" } )
.otherwise( { redirectTo: '/console' } ); $routeProvider.when( "/:address/player/:userid/xp", { Title: "Player Xp Stats", templateUrl: "html/playerXp.html" } )
$routeProvider.otherwise( { redirectTo: '/home' } );
} ); } );
@@ -24,6 +25,7 @@ app.controller( 'RconController', RconController );
function RconController( $scope, $rootScope, rconService, $mdSidenav, $timeout, $mdDialog, $route ) function RconController( $scope, $rootScope, rconService, $mdSidenav, $timeout, $mdDialog, $route )
{ {
$scope.$route = $route; $scope.$route = $route;
$scope.pages = $.map( $route.routes, function ( value, index ) $scope.pages = $.map( $route.routes, function ( value, index )
{ {
@@ -40,6 +42,11 @@ function RconController( $scope, $rootScope, rconService, $mdSidenav, $timeout,
return rconService.IsConnected(); return rconService.IsConnected();
} }
$rootScope.Nav = function ( url )
{
return url.replace( ":address", rconService.Address );
}
$rootScope.$on( '$stateChangeStart', function ( next, current ) $rootScope.$on( '$stateChangeStart', function ( next, current )
{ {
console.log( next ); console.log( next );
@@ -50,6 +57,7 @@ function RconController( $scope, $rootScope, rconService, $mdSidenav, $timeout,
$scope.Connected = true; $scope.Connected = true;
$scope.$broadcast( "OnConnected" ); $scope.$broadcast( "OnConnected" );
$scope.$digest(); $scope.$digest();
$scope.address = rconService.Address;
} }
rconService.OnClose = function ( ev ) rconService.OnClose = function ( ev )
@@ -73,55 +81,6 @@ function RconController( $scope, $rootScope, rconService, $mdSidenav, $timeout,
} }
} }
app.controller( 'ConnectionController', ConnectionController );
function ConnectionController( $scope, rconService )
{
$scope.Address = "";
$scope.Password = "";
$scope.SaveConnection = true;
if ( localStorage.previousConnections != null )
$scope.PreviousConnects = angular.fromJson( localStorage.previousConnections );
if ( $scope.PreviousConnects == null )
$scope.PreviousConnects = new Array();
$scope.Connect = function ()
{
$scope.LastErrorMessage = null;
rconService.Connect( $scope.Address, $scope.Password );
}
$scope.ConnectTo = function ( c )
{
$scope.SaveConnection = false;
$scope.LastErrorMessage = null;
rconService.Connect( c.Address, c.Password );
}
$scope.$on( "OnDisconnected", function ( x, ev )
{
console.log( ev );
$scope.LastErrorMessage = "Connection was closed - Error " + ev.code;
$scope.$digest();
} );
$scope.$on( "OnConnected", function ( x, ev )
{
if ( $scope.SaveConnection )
{
$scope.PreviousConnects.push( { Address: $scope.Address, Password: $scope.Password } );
localStorage.previousConnections = angular.toJson( $scope.PreviousConnects );
}
} );
}
app.filter( 'SecondsToDuration', [SecondsToDuration] ); app.filter( 'SecondsToDuration', [SecondsToDuration] );
function SecondsToDuration() function SecondsToDuration()
+64
View File
@@ -0,0 +1,64 @@
app.controller( 'ConnectionController', ConnectionController );
function ConnectionController( $scope, rconService, $routeParams, $timeout )
{
$scope.Address = "";
$scope.Password = "";
$scope.SaveConnection = true;
if ( localStorage.previousConnections != null )
$scope.PreviousConnects = angular.fromJson( localStorage.previousConnections );
if ( $scope.PreviousConnects == null )
$scope.PreviousConnects = new Array();
$scope.Connect = function ()
{
$scope.LastErrorMessage = null;
rconService.Connect( $scope.Address, $scope.Password );
}
$scope.ConnectTo = function ( c )
{
$scope.SaveConnection = false;
$scope.LastErrorMessage = null;
rconService.Connect( c.Address, c.Password );
}
$scope.$on( "OnDisconnected", function ( x, ev )
{
console.log( ev );
$scope.LastErrorMessage = "Connection was closed - Error " + ev.code;
$scope.$digest();
} );
$scope.$on( "OnConnected", function ( x, ev )
{
if ( $scope.SaveConnection )
{
$scope.PreviousConnects.push( { Address: $scope.Address, Password: $scope.Password } );
localStorage.previousConnections = angular.toJson( $scope.PreviousConnects );
}
} );
//
// If a server address is passed in.. try to connect if we have a saved entry
//
$timeout( function ()
{
$scope.Address = $routeParams.address;
if ( $scope.Address != null )
{
var foundAddress = Enumerable.From( $scope.PreviousConnects ).Where( function ( x ) { return x.Address == $scope.Address } ).First();
if ( foundAddress != null )
{
$scope.ConnectTo( foundAddress );
}
}
}, 20 );
}
+1 -2
View File
@@ -12,6 +12,7 @@ function RconService()
s.Connect = function ( addr, pass ) s.Connect = function ( addr, pass )
{ {
s.Socket = new WebSocket( "ws://" + addr + "/" + pass ); s.Socket = new WebSocket( "ws://" + addr + "/" + pass );
s.Address = addr;
s.Socket.onmessage = function ( e ) s.Socket.onmessage = function ( e )
{ {
@@ -49,8 +50,6 @@ function RconService()
s.Socket.onopen = s.OnOpen; s.Socket.onopen = s.OnOpen;
s.Socket.onclose = s.OnClose; s.Socket.onclose = s.OnClose;
s.Socket.onerror = s.OnError; s.Socket.onerror = s.OnError;
console.log( s.Socket );
} }
s.Command = function ( msg, identifier ) s.Command = function ( msg, identifier )