juci-wireless: make channel selection work based on available channels from the driver
authorRobin Stjerndorff <robin.stjerndorff@inteno.se>
Mon, 5 Mar 2018 17:09:55 +0000 (18:09 +0100)
committerSukru Senli <sukru.senli@inteno.se>
Wed, 14 Mar 2018 16:37:27 +0000 (17:37 +0100)
plugins/juci-wireless/access.json
plugins/juci-wireless/src/widgets/uci.wireless.device.edit.js

index 7b51685..5259cd8 100644 (file)
@@ -15,7 +15,8 @@
                                        "stop"
                                ], 
                                "juci.wireless": [
-                                       "set_credentials"
+                                       "set_credentials",
+                                       "get_channels"
                                ],
                                "router.system": [
                                        "info"
index 45f2b07..15a6d44 100644 (file)
@@ -28,20 +28,48 @@ JUCI.app
                require: "^ngModel"
        };  
 }).controller("WiFiDeviceEditController", function($scope, $config, $rpc, $tr, gettext){
+
        $scope.showExpert = $config.get("local.mode") == "expert";
+       function updateChannels() {
+               $rpc.$call("juci.wireless", "get_channels",{
+                       radio:$scope.device[".name"],
+                       bandwidth:$scope.device.bandwidth.value,
+                       dfsc:$scope.device.dfsc.value
+               }).done(function(result) {
+                       $scope.allChannels = [{ label:$tr(gettext("Auto")), value: "auto" }].concat(result.channels.map(function(x){ return { label: x, value: x }; })); 
+
+                       var maxValue = $scope.allChannels[$scope.allChannels.length-1].value;
+                       var currentValue = $scope.device.channel.value;
+
+                       if(currentValue > maxValue) {
+                               $scope.device.channel.value = maxValue;
+                       }
+
+                       $scope.$apply();
+               }).fail(function(error) {
+                       console.log("Could not get access to juci.wireless get_channels: "+error)
+               });
+       }
+
        $scope.$watch("device", function(device){
-               if(!device) return; 
+               if(!device) return;
+
+               updateChannels();
+
                $rpc.$call("router.wireless", "radios").done(function(result){
                        if(device[".name"] in result){
-                               
-                               
                                var settings = result[device[".name"]]; 
                                if(settings.channels) $scope.allChannels = [{ label:$tr(gettext("Auto")), value: "auto" }].concat(settings.channels.map(function(x){ return { label: x, value: x }; })); 
                                if(settings.hwmodes) $scope.allModes = [{ label:$tr(gettext("Auto")), value: "auto" }].concat(settings.hwmodes.map(function(x){ return { label: $tr(x), value: x }; }));
                                if(settings.bwcaps) $scope.allBandwidths = settings.bwcaps.map(function(x){ return { label: x, value: x }; });
-                       } 
+                       }
                        $scope.$apply(); 
-               }); 
+               });
+
+               $scope.$watchGroup(['device.bandwidth.value', 'device.dfsc.value'], function() {
+                       if(!$scope.device) return;
+                               updateChannels();
+               });
        }); 
        //make these available for translation
        gettext("11a"); // $tr anslated above