juci-inteno-qos: add overview widget
authorRobin Stjerndorff <robin.stjerndorff@inteno.se>
Fri, 9 Feb 2018 14:50:02 +0000 (15:50 +0100)
committerRobin Stjerndorff <robin.stjerndorff@inteno.se>
Fri, 9 Feb 2018 14:50:02 +0000 (15:50 +0100)
plugins/juci-inteno-qos/src/main.js
plugins/juci-inteno-qos/src/widgets/overview.qos.html [new file with mode: 0644]
plugins/juci-inteno-qos/src/widgets/overview.qos.js [new file with mode: 0644]

index 0bb6ff5..a495b34 100644 (file)
@@ -70,6 +70,11 @@ UCI.qos.$registerSectionType("class", {
        "avgrate":              { dvalue: 0, type: Number},
        "limitrate":            { dvalue: 100, type: Number},
 });
+UCI.qos.$registerSectionType("rate-limit", {
+       "name":                 { dvalue: "", type: String},
+       "download":             { dvalue: 0, type: Number},
+       "upload":               { dvalue: 0, type: Number}
+});
 
 JUCI.app.factory("intenoQos", function($uci, gettext, $tr){
        function Qos(){ }
diff --git a/plugins/juci-inteno-qos/src/widgets/overview.qos.html b/plugins/juci-inteno-qos/src/widgets/overview.qos.html
new file mode 100644 (file)
index 0000000..957d6cc
--- /dev/null
@@ -0,0 +1,30 @@
+<div>
+       <juci-overview-widget title="qos" icon="juci star" href="{{href}}">
+               <juci-config-lines>
+                       <juci-config-line title="{{'Enable QoS'|translate}}">
+                               <switch ng-model="qos.wan.enabled.value" class="green"></switch>
+                       </juci-config-line>
+                       <div ng-show="qos.wan.enabled.value">
+                               <hr/>
+                               <h4>Rate Limiting</h4>
+                               <juci-config-line title="{{'Down'|translate}}">
+                               <div class="input-group">
+                                       <span class="input-group-addon">kbit/s</span>
+                                       <input type="number" min="0" class="form-control" ng-model="qos.wan.download.value" />
+                               </div>
+                               </juci-config-line>
+                               <juci-config-line title="{{'Up'|translate}}">
+                               <div class="input-group">
+                                       <span class="input-group-addon">kbit/s</span>
+                                       <input type="number" min="0" class="form-control" ng-model="qos.wan.upload.value" />
+                               </div>
+                               </juci-config-line>
+                               <hr/>
+                               <h4>{{'Subscription'|translate}}</h4>
+                               <juci-config-line>
+                                       <juci-select ng-items="rate_limits" ng-model="limit_selected.value"></juci-selcet>
+                               </juci-config-line>
+                       </div>
+               </juci-config-lines>
+       </juci-overview-widget>
+</div>
diff --git a/plugins/juci-inteno-qos/src/widgets/overview.qos.js b/plugins/juci-inteno-qos/src/widgets/overview.qos.js
new file mode 100644 (file)
index 0000000..de1c1b8
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2015 Inteno Broadband Technology AB. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+JUCI.app
+.directive("overviewWidget00QoS", function(){
+       return {
+               templateUrl: "widgets/overview.qos.html",
+               controller: "overviewWidgetQoS",
+               replace: true
+       };
+})
+.controller("overviewWidgetQoS", function($scope, $rpc, $uci, $tr, gettext, $juciDialog, $events, $wireless, $config){
+       $scope.qos = {};
+       $scope.limit_selected = {};
+
+       $uci.$sync().done(function() {
+               $scope.qos = $uci.qos;
+               //console.log($scope.qos);
+               $scope.rate_limits = $uci.qos["@rate-limit"].map(function(limit) {
+                       return { value:limit.name.value, label:limit.name.value, download:limit.download.value, upload:limit.upload.value };
+               });
+
+               $scope.rate_limits.forEach(function(y) {
+                       if($scope.qos.wan.download.value === y.download && $scope.qos.wan.upload.value === y.upload) {
+                               $scope.limit_selected.value = y.label;
+                       }
+               });
+
+               $scope.$watch("limit_selected.value", function(x){
+                       if(!x) return;
+
+                       $scope.rate_limits.forEach(function(y) {
+                               if(y.label === x) {
+                                       $scope.qos.wan.download.value = y.download;
+                                       $scope.qos.wan.upload.value = y.upload;
+                               }
+                       });
+               }, false);
+/*
+       $scope.$watch("qos.wan.download.value", function(x){
+                       if(!x) return;
+console.log("hejsan dl bytt");
+                       
+               }, false);
+
+               $scope.$watch("qos.wan.upload.value", function(x){
+                       if(!x) return;
+console.log("hejsan ul bytt");
+                       
+               }, false);
+*/
+       });
+
+       $scope.href = $config.getWidgetLink("overviewWidget00QoS");
+
+});