1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-06 03:50:04 +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) {
$localForageProvider.config({
//driver: 'localStorageWrapper',
driver: 'localStorageWrapper',
name: 'stf-v0',
version: 1.0,
storeName: 'settings',

View file

@ -9,8 +9,14 @@ module.exports = function PortForwardingCtrl($scope, ngTableParams, SettingsServ
storeName: 'PortForwarding.forwarding'
})
// SettingsService.bind($scope, {
// key: 'portSets',
// storeName: 'PortForwarding.portSets'
// })
function getPortSets() {
return $scope.portSets.slice(0,-1) // Last item is empty
return $scope.portSets.slice(0, -1) // Last item is empty
}
function forwardPorts() {
@ -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 = [
{
targetHost: 'localhost',
@ -56,30 +67,47 @@ module.exports = function PortForwardingCtrl($scope, ngTableParams, SettingsServ
}
]
function portFieldsAreEmpty(ports) {
return (_.isEmpty(ports.targetHost) && _.isEmpty(ports.targetPort) && _.isEmpty(ports.devicePort))
}
// SettingsService.getItem('PortForwarding.portSets').then(function (result) {
// 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
$scope.$watch('portSets', function (newValue, oldValue) {
// Remove all empty sets from the middle
_.remove(newValue, function (ports, index) {
// Skip last and remove empty fields
return !!(newValue.length !== index + 1 && portFieldsAreEmpty(ports))
})
if (newValue) {
// Remove all empty sets from the middle
_.remove(newValue, function (ports, index) {
// Skip last and remove empty fields
return !!(newValue.length !== index + 1 && portFieldsAreEmpty(ports))
})
var last = _.last(newValue)
if (!portFieldsAreEmpty(last)) {
var empty = {
//targetLocal: null,
targetHost: null,
targetPort: null,
devicePort: null
var last = _.last(newValue)
if (!portFieldsAreEmpty(last)) {
createEmptyField()
}
$scope.portSets.push(empty)
} else {
// createEmptyField()
}
//SettingsService.setItem('PortForwarding.portSets', angular.copy($scope.portSets))
}, true)
$scope.portsTable = new ngTableParams({