From 9fd3c694a90da3065bdcae47272a930430bddf2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Schr=C3=B6der?= Date: Wed, 13 May 2015 12:26:03 +0200 Subject: [PATCH] Minor fixes to make unit testing easier. --- luciexpress/htdocs/index.html | 6 ++-- luciexpress/htdocs/js/juci.js | 30 ++++++++++++------- luciexpress/htdocs/js/rpc.js | 29 +++++++++++++----- luciexpress/htdocs/js/session.js | 14 +++++---- luciexpress/htdocs/js/uci.js | 22 +++++++++----- .../plugins/wifi/pages/wifi.schedule.html | 2 +- .../wifi/widgets/wifi.signal.indicator.js | 4 +-- 7 files changed, 68 insertions(+), 39 deletions(-) diff --git a/luciexpress/htdocs/index.html b/luciexpress/htdocs/index.html index 695706085..ee71cd075 100644 --- a/luciexpress/htdocs/index.html +++ b/luciexpress/htdocs/index.html @@ -21,7 +21,7 @@
- + @@ -40,17 +40,17 @@ + + - - diff --git a/luciexpress/htdocs/js/juci.js b/luciexpress/htdocs/js/juci.js index 1b3d55935..3a5f64d68 100644 --- a/luciexpress/htdocs/js/juci.js +++ b/luciexpress/htdocs/js/juci.js @@ -1,6 +1,9 @@ -var JUCI = {}, $juci = JUCI; +//var JUCI = {}, $juci = JUCI; -(function(){ +(function(scope){ + var $uci = scope.UCI; + var $rpc = scope.UBUS; + function JUCIMain(){ this.plugins = {}; } @@ -38,7 +41,7 @@ var JUCI = {}, $juci = JUCI; var deferred = $.Deferred(); async.series([ function(next){ - $juci.ubus.$init().fail(function(){ + scope.UBUS.$init().fail(function(){ console.error("UBUS failed to initialize!"); }).always(function(){ next(); }); }, @@ -124,7 +127,7 @@ var JUCI = {}, $juci = JUCI; $juci.session.$init().done(function(){ // here we get router info part of the config. It will allow us to // pick the correct theme in the init script. TODO: perhaps do this somewhere else? - $juci.ubus.router.info().done(function(info){ + $rpc.router.info().done(function(info){ //console.log("Router info: "+JSON.stringify(info.system)); if(info && info.system) $juci.config.system = info.system; next(); @@ -138,7 +141,7 @@ var JUCI = {}, $juci = JUCI; }); }, function(next){ - $juci.uci.$init().fail(function(){ + $uci.$init().fail(function(){ console.error("UCI failed to initialize!"); }).always(function(){ next(); }); }, @@ -168,7 +171,6 @@ var JUCI = {}, $juci = JUCI; }); }, function(next){ - var $rpc = $juci.ubus; // get the menu navigation if($rpc.luci2){ console.log("Getting menu.."); @@ -205,10 +207,9 @@ var JUCI = {}, $juci = JUCI; return deferred.promise(); } - JUCI = window.juci = $juci = new JUCIMain(); - - JUCI.app = - angular.module("luci", [ + scope.JUCI = scope.$juci = new JUCIMain(); + if(typeof angular !== "undefined"){ + var app = scope.JUCI.app = angular.module("luci", [ "ui.bootstrap", "ui.router", 'ui.select', @@ -218,4 +219,11 @@ var JUCI = {}, $juci = JUCI; "gettext", "checklist-model" ]); -})(); + app.factory('$rpc', function(){ + return scope.UBUS; + }); + app.factory('$uci', function(){ + return scope.UCI; + }); + } +})(typeof exports === 'undefined'? this : exports); diff --git a/luciexpress/htdocs/js/rpc.js b/luciexpress/htdocs/js/rpc.js index eace0738f..79f8d32a1 100644 --- a/luciexpress/htdocs/js/rpc.js +++ b/luciexpress/htdocs/js/rpc.js @@ -1,6 +1,6 @@ //! Author: Martin K. Schröder -(function($juci){ +(function(scope){ var RPC_HOST = ""; //(($config.rpc.host)?$config.rpc.host:"") var RPC_SESSION_ID = "00000000000000000000000000000000"; var gettext = function(text){ return text; }; @@ -10,6 +10,7 @@ "local.features", "local.set_rpc_host" ]; + function rpc_request(type, namespace, method, data){ var sid = ""; var deferred = $.Deferred(); @@ -98,8 +99,11 @@ } _find(call.split("."), self); }, - $init: function(){ + $init: function(host){ var self = this; + if(host) { + if(host.host) RPC_HOST = host.host; + } console.log("Init UBUS"); var deferred = $.Deferred(); default_calls.map(function(x){ self.$register(x); }); @@ -139,11 +143,20 @@ } }; - window.rpc = $juci.ubus = rpc; + scope.UBUS = rpc; + /*if(exports.JUCI){ + var JUCI = exports.JUCI; + JUCI.ubus = rpc; + console.log(JSON.stringify(JUCI.app)); + // luci rpc module for communicating with the server + if(JUCI.app) { + JUCI.app.factory('$rpc', function($rootScope, $config, gettext){ + return window.rpc; + }); + } + } else { + console.log("RPC: Not registering as JUCI plugin!"); + }*/ - // luci rpc module for communicating with the server - JUCI.app.factory('$rpc', function($rootScope, $config, gettext){ - return window.rpc; - }); -})(JUCI); +})(typeof exports === 'undefined'? this : exports); diff --git a/luciexpress/htdocs/js/session.js b/luciexpress/htdocs/js/session.js index cf3604bd8..03ee377df 100644 --- a/luciexpress/htdocs/js/session.js +++ b/luciexpress/htdocs/js/session.js @@ -1,13 +1,15 @@ //! Author: Martin K. Schröder // service for managing session data -(function($juci){ +(function(scope){ + var $juci = scope.JUCI; + var $rpc = scope.UBUS; function JUCISession(){ var saved_sid = $juci.localStorage.getItem("sid"); var default_sid = "00000000000000000000000000000000"; if(saved_sid){ - $juci.ubus.$sid(saved_sid); + $rpc.$sid(saved_sid); } this.sid = (saved_sid)?saved_sid:default_sid; @@ -19,7 +21,7 @@ var self = this; var deferred = $.Deferred(); console.log("Checking session key with server: "+saved_sid); - $juci.ubus.session.access({ + $rpc.session.access({ "keys": "" }).done(function(result){ if(result["access-group"] && result["access-group"].unauthenticated && Object.keys(result["access-group"]).length == 1) { @@ -34,7 +36,7 @@ }).fail(function err(result){ self.sid = default_sid; $juci.localStorage.setItem("sid", self.sid); - $juci.ubus.$sid(self.sid); + $rpc.$sid(self.sid); deferred.reject(); }); return deferred.promise(); @@ -47,7 +49,7 @@ "password": obj.password }).done(function(result){ self.sid = result.ubus_rpc_session; - $juci.ubus.$sid(self.sid); + $rpc.$sid(self.sid); self.data = result; self._loggedIn = true; $juci.localStorage.setItem("sid", self.sid); @@ -77,4 +79,4 @@ JUCI.app.factory('$session', function($rpc, $rootScope, $localStorage) { return $juci.session; }); -})(JUCI); +})(typeof exports === 'undefined'? this : global); diff --git a/luciexpress/htdocs/js/uci.js b/luciexpress/htdocs/js/uci.js index 06c637cfb..3dd69f1c8 100644 --- a/luciexpress/htdocs/js/uci.js +++ b/luciexpress/htdocs/js/uci.js @@ -1,7 +1,8 @@ //! Author: Martin K. Schröder -(function($juci){ - $rpc = $juci.ubus; +(function(scope){ + //var JUCI = exports.JUCI; + var $rpc = scope.UBUS; // just for the extractor var gettext = function(str) { return str; }; @@ -724,10 +725,15 @@ return deferred.promise(); } - $juci.uci = window.uci = new UCI(); + scope.UCI = new UCI(); - JUCI.app.factory('$uci', function(){ - return $juci.uci; - }); - -})(JUCI); + /*if(exports.JUCI){ + var JUCI = exports.JUCI; + JUCI.uci = exports.uci = new UCI(); + if(JUCI.app){ + JUCI.app.factory('$uci', function(){ + return $juci.uci; + }); + } + }*/ +})(typeof exports === 'undefined'? this : exports); diff --git a/luciexpress/htdocs/plugins/wifi/pages/wifi.schedule.html b/luciexpress/htdocs/plugins/wifi/pages/wifi.schedule.html index 73f0d6161..f56cfcea9 100644 --- a/luciexpress/htdocs/plugins/wifi/pages/wifi.schedule.html +++ b/luciexpress/htdocs/plugins/wifi/pages/wifi.schedule.html @@ -7,7 +7,7 @@ - + {{ 'Setup Scheduling' | translate }} diff --git a/luciexpress/htdocs/plugins/wifi/widgets/wifi.signal.indicator.js b/luciexpress/htdocs/plugins/wifi/widgets/wifi.signal.indicator.js index f97e5fe03..3014d270a 100644 --- a/luciexpress/htdocs/plugins/wifi/widgets/wifi.signal.indicator.js +++ b/luciexpress/htdocs/plugins/wifi/widgets/wifi.signal.indicator.js @@ -1,6 +1,6 @@ -$juci.module("core") +$juci.app .directive("wifiSignalIndicator", function($compile, $parse){ - var plugin_root = $juci.module("core").plugin_root; + var plugin_root = $juci.module("wifi").plugin_root; return { templateUrl: plugin_root+"/widgets/wifi.signal.indicator.html", scope: {