fix bug on port forwarding feature (#629)

* fix bug on port forwarding feature

Signed-off-by: Denis barbaron <denis.barbaron@orange.com>

* fix lint error

Signed-off-by: Denis barbaron <denis.barbaron@orange.com>

Signed-off-by: Denis barbaron <denis.barbaron@orange.com>
This commit is contained in:
Denis Barbaron
2023-01-16 12:38:17 +01:00
committed by GitHub
parent 8b67366b05
commit f04738f9be
5 changed files with 46 additions and 22 deletions

View File

@@ -1,9 +1,11 @@
/**
* Copyright © 2023 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
**/
require('./port-forwarding.css')
module.exports = angular.module('stf.port-forwarding', [
require('stf/common-ui/table').name,
require('stf/settings').name,
require('gettext').name
require('stf/common-ui/table').name
])
.run(['$templateCache', function($templateCache) {
$templateCache.put(

View File

@@ -1,9 +1,12 @@
/**
* Copyright © 2023 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
**/
var uuid = require('uuid')
var Promise = require('bluebird')
module.exports = function PortForwardingCtrl(
$scope
, SettingsService
) {
function defaults(id) {
return {
@@ -17,25 +20,26 @@ module.exports = function PortForwardingCtrl(
$scope.reversePortForwards = [defaults('_default')]
SettingsService.bind($scope, {
target: 'reversePortForwards'
, source: 'reversePortForwards'
})
$scope.$watch('device.reverseForwards', function(newValue) {
var map = Object.create(null)
let map = Object.create(null)
if (newValue) {
newValue.forEach(function(forward) {
map[forward.id] = forward
})
}
$scope.reversePortForwards.forEach(function(forward) {
var deviceForward = map[forward.id]
forward.enabled = !!(deviceForward && deviceForward.id === forward.id &&
deviceForward.devicePort === forward.devicePort)
})
$scope.reversePortForwards.forEach(function(forward) {
let deviceForward = map[forward.id]
if (deviceForward) {
forward.enabled = !!(deviceForward.id === forward.id &&
deviceForward.devicePort === Number(forward.devicePort))
}
else if (forward.enabled) {
$scope.removeRow(forward)
}
})
}
})
$scope.applyForward = function(forward) {

View File

@@ -1,3 +1,7 @@
//
Copyright © 2023 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
//
.widget-container.fluid-height.stf-port-forwarding(ng-controller='PortForwardingCtrl')
.heading
span
@@ -34,13 +38,13 @@
div.input-group.input-group-sm
span.input-group-addon
input(type='checkbox', ng-model='forward.enabled', ng-change='applyForward(forward)')
input.form-control(type='text', min='0', ng-model='forward.devicePort', ng-model-options="{ updateOn: 'default blur' }", placeholder='{{"Port"|translate}}', ng-change='disableForward(forward)')
input.form-control(type='text', min='0', ng-disabled='forward.enabled', ng-model='forward.devicePort', ng-model-options="{ updateOn: 'default blur' }", placeholder='{{"Port"|translate}}', ng-change='disableForward(forward)')
td(width='40%')
input.form-control.input-sm(type='text', ng-model='forward.targetHost', ng-model-options="{ updateOn: 'default blur' }", placeholder='{{"Hostname"|translate}}', ng-change='disableForward(forward)')
input.form-control.input-sm(type='text', ng-disabled='forward.enabled', ng-model='forward.targetHost', ng-model-options="{ updateOn: 'default blur' }", placeholder='{{"Hostname"|translate}}', ng-change='disableForward(forward)')
td
span :
td(width='25%')
input.form-control.input-sm(type='text', min='0', ng-model='forward.targetPort', ng-model-options="{ updateOn: 'default blur' }", placeholder='{{"Port"|translate}}', ng-change='disableForward(forward)')
input.form-control.input-sm(type='text', min='0', ng-disabled='forward.enabled', ng-model='forward.targetPort', ng-model-options="{ updateOn: 'default blur' }", placeholder='{{"Port"|translate}}', ng-change='disableForward(forward)')
td
button.btn.btn-sm.btn-danger-outline(ng-click='removeRow(forward)')
i.fa.fa-trash-o