reworked the connection view

- use bootstrap styling
- connections will save the date
- connection duplicates will be removed on a new connection
- saved connections can be toggled between 5 items and all
This commit is contained in:
alexfriesen
2016-06-02 15:40:54 +02:00
parent b6558c68e8
commit 7697c6baac
2 changed files with 85 additions and 43 deletions
+18 -24
View File
@@ -1,6 +1,6 @@
<div ng-controller="ConnectionController" class="row"> <div ng-controller="ConnectionController" class="row">
<div class="col-md-offset-4 col-md-6 panel" style="margin-top: 128px"> <div class="col-md-offset-4 col-md-6 panel jumbotron" style="margin-top: 128px">
<h2>Connect</h2> <h2>Connect</h2>
@@ -11,47 +11,41 @@
<form ng-submit="Connect()"> <form ng-submit="Connect()">
<div class="md-inline-form"> <div class="md-inline-form">
<div class="md-block form-group" flex-gt-xs>
<div class="md-block" flex-gt-xs> <label for="conncetion-adress">Address</label>
<label>Address</label> <input required minlength=5 ng-model="Address" name="Address" class="form-control" placeholder="xxx.xxx.xxx.xxx:28016" id="conncetion-adress">
<input required minlength=5 ng-model="Address" name="Address" class="form-control">
</div> </div>
<div class="md-block" flex-gt-xs> <div class="md-block form-group" flex-gt-xs>
<label>Password</label> <label for="conncetion-password">Password</label>
<input required minlength=2 type="password" ng-model="Password" name="Password" class="form-control"> <input required minlength=2 type="password" ng-model="Password" name="Password" class="form-control" id="conncetion-password">
</div> </div>
<div class="right"> <div class="checkbox right">
<input type="checkbox" ng-model="SaveConnection"> <label>
Save Connection <input type="checkbox" ng-model="SaveConnection"> Save Connection
</label>
</div> </div>
<br /> <br /> <button type="submit" class="btn btn-primary btn-block" ng-click="Connect()">Connect</button>
<div class="center">
<button class="btn btn-primary" ng-click="Connect()">Connect</button>
</div>
<br />
</div> </div>
</form> </form>
</div> </div>
<div class="col-md-offset-4 col-md-6 panel" style="margin-top: 64px"> <div class="col-md-offset-4 col-md-6 panel jumbotron">
<div ng-show="PreviousConnects.length > 0"> <div ng-show="PreviousConnects.length > 0">
<h2>Saved Connections</h2> <h2>Saved Connections</h2>
<ul ng-repeat="c in PreviousConnects"> <ul ng-repeat="c in PreviousConnects | orderBy:array:true | limitTo:connectionsLimit">
<li><a ng-click="ConnectTo( c )" href="#">{{c.Address}}</a></li> <li><a ng-click="ConnectTo( c )" href="#/{{c.Address}}/info">{{c.Address}}</a> - {{c.date | date:'short'}}</li>
</ul> </ul>
<div ng-show="PreviousConnects.length > connectionsLimit || connectionsLimit === undefined">
<button type="submit" class="btn btn-primary btn-block" ng-click="toggleConnectionsLimit()">Show {{(connectionsLimit === undefined) ? 'less' : 'more'}}</button>
</div>
</div> </div>
</div> </div>
</div>
</div> </div>
+54 -6
View File
@@ -7,11 +7,51 @@ function ConnectionController( $scope, rconService, $routeParams, $timeout, $loc
$scope.Password = ""; $scope.Password = "";
$scope.SaveConnection = true; $scope.SaveConnection = true;
if ( localStorage.previousConnections != null ) $scope.connectionsLimit = 5;
$scope.PreviousConnects = angular.fromJson( localStorage.previousConnections );
if ( $scope.PreviousConnects == null ) function _loadFromLocalStorage() {
$scope.PreviousConnects = new Array(); var connections = [];
// load and parse from local storage
if ( localStorage && localStorage.previousConnections ) {
connections = angular.fromJson( localStorage.previousConnections );
}
// double check
if ( !connections ) {
connections = [];
}
return connections;
}
function _addWithoutDuplicates(connections, connection) {
// prepare new array
var filteredConnections = [];
for(var i in connections) {
if(connections[i].Address !== connection.Address && connections[i].Password !== connection.Password) {
// add old connection info to our new array
filteredConnections.push(connections[i]);
}
}
// add new connection
filteredConnections.push(connection);
return filteredConnections;
}
$scope.toggleConnectionsLimit = function ()
{
// toggle limit between undefined and 5
// undefined sets limit to max
if($scope.connectionsLimit === undefined) {
$scope.connectionsLimit = 5;
} else {
$scope.connectionsLimit = undefined;
}
}
$scope.Connect = function () $scope.Connect = function ()
{ {
@@ -42,11 +82,19 @@ function ConnectionController( $scope, rconService, $routeParams, $timeout, $loc
{ {
if ( $scope.SaveConnection ) if ( $scope.SaveConnection )
{ {
$scope.PreviousConnects.push( { Address: $scope.Address, Password: $scope.Password } ); // new connection to add
var connection = { Address: $scope.Address, Password: $scope.Password, date: new Date() };
// remove old entries and add our new connection info
var connections = _addWithoutDuplicates(_loadFromLocalStorage(), connection);
// push to scope and save data
$scope.PreviousConnects = connections;
localStorage.previousConnections = angular.toJson( $scope.PreviousConnects ); localStorage.previousConnections = angular.toJson( $scope.PreviousConnects );
} }
} ); } );
$scope.PreviousConnects = _loadFromLocalStorage();
// //
// If a server address is passed in.. try to connect if we have a saved entry // If a server address is passed in.. try to connect if we have a saved entry
@@ -83,5 +131,5 @@ function ConnectionController( $scope, rconService, $routeParams, $timeout, $loc
} }
}, 20 ); }, 20 );
}
}