1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-06 12:00:08 +02:00

Fixing port forwarding. Saving for port sets is not enabled.

This commit is contained in:
Gunther Brunner 2014-05-28 23:02:47 +09:00
parent 8b058ec52e
commit 2ff05fdd74
2 changed files with 46 additions and 18 deletions

View file

@ -6,7 +6,7 @@ module.exports = angular.module('stf/settings', [
]) ])
.config(['$localForageProvider', function ($localForageProvider) { .config(['$localForageProvider', function ($localForageProvider) {
$localForageProvider.config({ $localForageProvider.config({
//driver: 'localStorageWrapper', driver: 'localStorageWrapper',
name: 'stf-v0', name: 'stf-v0',
version: 1.0, version: 1.0,
storeName: 'settings', storeName: 'settings',

View file

@ -9,6 +9,12 @@ module.exports = function PortForwardingCtrl($scope, ngTableParams, SettingsServ
storeName: 'PortForwarding.forwarding' storeName: 'PortForwarding.forwarding'
}) })
// SettingsService.bind($scope, {
// key: 'portSets',
// storeName: 'PortForwarding.portSets'
// })
function getPortSets() { function getPortSets() {
return $scope.portSets.slice(0, -1) // Last item is empty return $scope.portSets.slice(0, -1) // Last item is empty
} }
@ -48,6 +54,11 @@ module.exports = function PortForwardingCtrl($scope, ngTableParams, SettingsServ
} }
}) })
function portFieldsAreEmpty(ports) {
return (_.isEmpty(ports.targetHost) && _.isEmpty(ports.targetPort) && _.isEmpty(ports.devicePort))
}
$scope.portSets = [ $scope.portSets = [
{ {
targetHost: 'localhost', targetHost: 'localhost',
@ -56,13 +67,31 @@ module.exports = function PortForwardingCtrl($scope, ngTableParams, SettingsServ
} }
] ]
function portFieldsAreEmpty(ports) { // SettingsService.getItem('PortForwarding.portSets').then(function (result) {
return (_.isEmpty(ports.targetHost) && _.isEmpty(ports.targetPort) && _.isEmpty(ports.devicePort)) // if (result) {
// $scope.portSets = result
// } else {
// console.log('here')
// }
// console.log(result)
// })
function createEmptyField() {
if (!$scope.portSets) {
$scope.portSets = []
}
var empty = {
targetHost: null,
targetPort: null,
devicePort: null
} }
$scope.portSets.push(empty)
}
// Adds a new row whenever necessary // Adds a new row whenever necessary
$scope.$watch('portSets', function (newValue, oldValue) { $scope.$watch('portSets', function (newValue, oldValue) {
if (newValue) {
// Remove all empty sets from the middle // Remove all empty sets from the middle
_.remove(newValue, function (ports, index) { _.remove(newValue, function (ports, index) {
// Skip last and remove empty fields // Skip last and remove empty fields
@ -71,15 +100,14 @@ module.exports = function PortForwardingCtrl($scope, ngTableParams, SettingsServ
var last = _.last(newValue) var last = _.last(newValue)
if (!portFieldsAreEmpty(last)) { if (!portFieldsAreEmpty(last)) {
var empty = { createEmptyField()
//targetLocal: null,
targetHost: null,
targetPort: null,
devicePort: null
} }
$scope.portSets.push(empty) } else {
// createEmptyField()
} }
//SettingsService.setItem('PortForwarding.portSets', angular.copy($scope.portSets))
}, true) }, true)
$scope.portsTable = new ngTableParams({ $scope.portsTable = new ngTableParams({