From 2ff05fdd7418df6aeb74d7ecdbfae23cbb23ccd0 Mon Sep 17 00:00:00 2001 From: Gunther Brunner Date: Wed, 28 May 2014 23:02:47 +0900 Subject: [PATCH] Fixing port forwarding. Saving for port sets is not enabled. --- res/app/components/stf/settings/index.js | 2 +- .../port-forwarding-controller.js | 62 ++++++++++++++----- 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/res/app/components/stf/settings/index.js b/res/app/components/stf/settings/index.js index 8add0ee2..a068450c 100644 --- a/res/app/components/stf/settings/index.js +++ b/res/app/components/stf/settings/index.js @@ -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', diff --git a/res/app/control-panes/advanced/port-forwarding/port-forwarding-controller.js b/res/app/control-panes/advanced/port-forwarding/port-forwarding-controller.js index f5ed7687..635db91e 100644 --- a/res/app/control-panes/advanced/port-forwarding/port-forwarding-controller.js +++ b/res/app/control-panes/advanced/port-forwarding/port-forwarding-controller.js @@ -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({