juci-icwmp: refetch ubus objects if icwmp status object is missing from ubus
authorReidar Cederqvist <reidar.cederqvist@gmail.com>
Thu, 12 Jul 2018 12:37:16 +0000 (14:37 +0200)
committerSukru Senli <sukru.senli@inteno.se>
Sat, 1 Sep 2018 09:23:00 +0000 (11:23 +0200)
juci/src/js/rpc.js
plugins/juci-icwmp/src/pages/icwmp-config.html
plugins/juci-icwmp/src/pages/icwmp-config.js

index ba84b4c..dd7aed9 100644 (file)
                        var self = this;
                        var deferred = $.Deferred();
                        self.$list().done(function(result){
+                               Object.keys(result).map(function(obj){
+                                       Object.keys(result[obj]).map(function(method){
+                                               if(! self.$has(obj, method))
+                                                       self.$register(obj, method);
+                                       });
+                               });
                                deferred.resolve();
                        }).fail(function(){
                                deferred.reject();
index 88af479..23a368a 100644 (file)
@@ -62,7 +62,7 @@
                                        </juci-config-lines>
                                </juci-config-section>
                        </tab>
-                       <tab heading="{{'Status'|translate}}" ng-show="onTR069ObjectAvailable">
+                       <tab heading="{{'Status'|translate}}" ng-show='statusAvailable()'>
                                <juci-config-section>
                                        <juci-config-line title="{{ 'Send connection request to ACS' | translate }}">
                                                <button class="btn btn-lg btn-default" ng-click="contactACS()">{{'Send'|translate}}</button>
index 17462cb..3c60d01 100644 (file)
@@ -46,12 +46,13 @@ JUCI.app
                { label: $tr(gettext("Debug")),         value: 'DEBUG' }
        ];
 
+       $scope.status = [];
+
        $scope.onTR069ObjectAvailable=$rpc.$has("tr069", "inform");
-       if($rpc.$has("tr069", "status")) {
-               JUCI.interval.repeat("icwmp-status-update", 5000, function(next){
+       JUCI.interval.repeat("icwmp-status-update", 5000, function(next){
+               function reload_status(){
                        $rpc.$call("tr069", "status").done(function(data){
                                if(!data) return;
-                               $scope.status = [];
                                if(data.cwmp){
                                        $scope.status.push({
                                                title: $tr(gettext("CWMP")),
@@ -92,14 +93,24 @@ JUCI.app
                                                ]
                                        });
                                }
-                               $scope.$apply();
                        }).fail(function(e){
-                               console.error("couldn't call tr069 status", e);
+                               $scope.status = [];
                        }).always(function(){
+                               $scope.$apply();
                                next();
                        });
-               });
-       }
+               }
+               if($rpc.$has("tr069", "status")) {
+                       reload_status();
+               } else {
+                       // $isConnected will add any new ubus object that was not there when page was loaded
+                       $rpc.$isConnected().always(function(){
+                               reload_status();
+                       });
+               }
+       });
+
+       $scope.statusAvailable = function(){ return $scope.status.length; };
 
        $scope.contactACS = function() {
                $rpc.$call("tr069", "inform", {"event":"connection request"}).done(function(data){