juci-minidlna: remove db_dir option because its use is removed due to security issue...
[juci.git] / plugins / juci-wireless / src / pages / wireless-devices.js
1 /*
2  * Copyright (C) 2015 Inteno Broadband Technology AB. All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * version 2 as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16  * 02110-1301 USA
17  */
18
19 JUCI.app
20 .controller("wirelessDevicesPage", function($tr, gettext, $scope, $uci, $wireless, $rpc, $juciAlert){
21         var show_button = true;
22         JUCI.interval.repeat("update-radios-information", 5000, function(done){
23                 $wireless.getDevices().done(function(devices){
24                         $scope.devices = devices.map(function(dev){
25                                 if(!dev || !dev.$info)
26                                         return dev;
27                                 dev.$statusList = [
28                                         { label: $tr(gettext("Bandwidth")), value: dev.$info.bandwidth || $tr(gettext("N/A")) },
29                                         { label: $tr(gettext("Channel")), value: dev.$info.channel || $tr(gettext("N/A")) },
30                                         { label: $tr(gettext("Noise")), value: dev.$info.noise + $tr(gettext("dBm")) || $tr(gettext("N/A")) },
31                                         { label: $tr(gettext("Rate")), value: dev.$info.rate || $tr(gettext("N/A")) },
32                                 ];
33                                 set_buttons(dev);
34                                 return dev;
35                         });
36                         $scope.$apply();
37                 }).always(function(){
38                         done();
39                 });
40         });
41         function set_buttons(dev){
42                 dev.$buttons =  [
43                         {
44                                 label: (dev.disabled.value) ? $tr(gettext("Enable")) : $tr(gettext("Disable")),
45                                 on_click: function(){dev.disabled.value = !dev.disabled.value; set_buttons(dev);}
46                         }
47                 ];
48                 if(show_button){
49                         if(dev.channel.value !== "auto")
50                                 return;
51                         dev.$buttons.push({
52                                 label: $tr(gettext("Force Channel Selection")),
53                                 on_click: function(){
54                                         show_button = false;
55                                         set_buttons(dev);
56                                         $rpc.$call("router.wireless", "autochannel", { "radio": dev[".name"] }).done(function(ret){
57                                                 if(ret.code === 0 && ret.new_channel)
58                                                         $juciAlert($tr(gettext("Force Channel Selection is complete. New channel is")) + " " + ret.new_channel);
59                                                 else if(ret.code === 0)
60                                                         $juciAlert($tr(gettext("Force Channel Selection is complete.")));
61                                                 else if(dev.$info && dev.$info.channel >= 50 && dev.$info && dev.$info.channel <= 144)
62                                                         $juciAlert($tr(gettext("Force Channel Selection has failed because the radio is operating at DFS channel.")));
63                                                 else
64                                                         $juciAlert($tr(gettext("Force Channel Selection has failed.")));
65                                         }).fail(function(e){
66                                                 console.log(e);
67                                         }).always(function(){
68                                                 show_button = true;
69                                                 set_buttons(dev);
70                                         });
71                                 }
72                         })
73                 }
74         }
75 });