From 7613d937e3c5b0cc704cbb564dbf43d35eaee4f6 Mon Sep 17 00:00:00 2001 From: pliablepixels Date: Sun, 1 May 2016 17:25:43 -0400 Subject: #234 - mostly working, needs more testing. Former-commit-id: 80ac0f72b66cfec1dc14353e010658acb176fa2c --- www/js/EventCtrl.js | 2 +- www/js/FirstUseCtrl.js | 2 +- www/js/LoginCtrl.js | 26 ++++++++- www/js/MonitorCtrl.js | 2 +- www/js/MontageCtrl.js | 2 +- www/js/PortalLoginCtrl.js | 6 +- www/js/WizardCtrl.js | 142 +++++++++++++++++++++++++++++++++------------- www/js/app.js | 4 +- 8 files changed, 135 insertions(+), 51 deletions(-) (limited to 'www/js') diff --git a/www/js/EventCtrl.js b/www/js/EventCtrl.js index e9cd22b7..28b64adc 100644 --- a/www/js/EventCtrl.js +++ b/www/js/EventCtrl.js @@ -172,7 +172,7 @@ angular.module('zmApp.controllers') $ionicHistory.nextViewOptions({ disableBack: true }); - $state.go("login"); + $state.go("login" ,{"wizard": false}); return; } diff --git a/www/js/FirstUseCtrl.js b/www/js/FirstUseCtrl.js index 7e36160e..f774534b 100644 --- a/www/js/FirstUseCtrl.js +++ b/www/js/FirstUseCtrl.js @@ -25,7 +25,7 @@ $scope.openMenu = function () { disableAnimate: false, disableBack: true }); - $state.go ("login"); + $state.go("login" ,{"wizard": false}); }; diff --git a/www/js/LoginCtrl.js b/www/js/LoginCtrl.js index ea96233d..eb2e5583 100644 --- a/www/js/LoginCtrl.js +++ b/www/js/LoginCtrl.js @@ -2,7 +2,7 @@ /* jslint browser: true*/ /* global cordova,StatusBar,angular,console,alert,URI */ -angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$rootScope', 'zm', '$ionicModal', 'ZMDataModel', '$ionicSideMenuDelegate', '$ionicPopup', '$http', '$q', '$ionicLoading', 'zmAutoLogin', '$cordovaPinDialog', 'EventServer', '$ionicHistory', '$state', '$ionicActionSheet', 'SecuredPopups', '$localstorage', function ($scope, $rootScope, zm, $ionicModal, ZMDataModel, $ionicSideMenuDelegate, $ionicPopup, $http, $q, $ionicLoading, zmAutoLogin, $cordovaPinDialog, EventServer, $ionicHistory, $state, $ionicActionSheet, SecuredPopups, $localstorage) { +angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$rootScope', 'zm', '$ionicModal', 'ZMDataModel', '$ionicSideMenuDelegate', '$ionicPopup', '$http', '$q', '$ionicLoading', 'zmAutoLogin', '$cordovaPinDialog', 'EventServer', '$ionicHistory', '$state', '$ionicActionSheet', 'SecuredPopups', '$localstorage', '$stateParams', function ($scope, $rootScope, zm, $ionicModal, ZMDataModel, $ionicSideMenuDelegate, $ionicPopup, $http, $q, $ionicLoading, zmAutoLogin, $cordovaPinDialog, EventServer, $ionicHistory, $state, $ionicActionSheet, SecuredPopups, $localstorage, $stateParams) { $scope.openMenu = function () { $ionicSideMenuDelegate.toggleLeft(); }; @@ -105,7 +105,7 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r var zmServers = ZMDataModel.getServerGroups(); $scope.loginData = zmServers[serverbuttons[index].text]; - console.log ("NEW LOOGIN OBJECT IS " + JSON.stringify($scope.loginData)); + console.log ("NEW LOGIN OBJECT IS " + JSON.stringify($scope.loginData)); $scope.check.isUseAuth = ($scope.loginData.isUseAuth == '1') ? true : false; @@ -203,6 +203,28 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r } + ZMDataModel.zmDebug ("Does login need to hear the wizard? " + $stateParams.wizard); + + if ($stateParams.wizard == "true") + { + ZMDataModel.zmLog ("Creating new login entry for wizard"); + $scope.loginData = angular.copy(ZMDataModel.getDefaultLoginObject()); + $scope.loginData.url = $rootScope.wizard.loginURL; + $scope.loginData.apiurl = $rootScope.wizard.apiURL; + $scope.loginData.streamingurl = $rootScope.wizard.streamingURL; + if ($rootScope.wizard.useauth && $rootScope.wizard.usezmauth) + { + $scope.loginData.username = $rootScope.wizard.zmuser; + $scope.loginData.password = $rootScope.wizard.zmpassword; + if ((/^https:\/\//i.test($scope.loginData.url))) + { + $scope.loginData.useSSL = true; + } + } + + } + + }); diff --git a/www/js/MonitorCtrl.js b/www/js/MonitorCtrl.js index 1fb24a67..2fe04cd3 100644 --- a/www/js/MonitorCtrl.js +++ b/www/js/MonitorCtrl.js @@ -32,7 +32,7 @@ angular.module('zmApp.controllers') $ionicHistory.nextViewOptions({ disableBack: true }); - $state.go("login"); + $state.go("login" ,{"wizard": false}); return; } diff --git a/www/js/MontageCtrl.js b/www/js/MontageCtrl.js index 46699655..ab7d5260 100644 --- a/www/js/MontageCtrl.js +++ b/www/js/MontageCtrl.js @@ -49,7 +49,7 @@ angular.module('zmApp.controllers').controller('zmApp.MontageCtrl', ['$scope', ' $ionicHistory.nextViewOptions({ disableBack: true }); - $state.go("login"); + $state.go("login" ,{"wizard": false}); return; } diff --git a/www/js/PortalLoginCtrl.js b/www/js/PortalLoginCtrl.js index abd4641a..5ac5aed6 100644 --- a/www/js/PortalLoginCtrl.js +++ b/www/js/PortalLoginCtrl.js @@ -89,7 +89,7 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic disableAnimate: true, disableBack: true }); - $state.go('login'); + $state.go("login" ,{"wizard": false}); } else { @@ -221,13 +221,13 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic disableAnimate: true, disableBack: true }); - $state.go('login'); + $state.go("login" ,{"wizard": false}); } else { // if user cancelled auth I guess we go to login $rootScope.userCancelledAuth = false; - $state.go('login'); + $state.go("login" ,{"wizard": false}); } }); } diff --git a/www/js/WizardCtrl.js b/www/js/WizardCtrl.js index 24b5b93e..9f662adf 100644 --- a/www/js/WizardCtrl.js +++ b/www/js/WizardCtrl.js @@ -56,13 +56,45 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ d.reject(false); return d.promise; } - }); + }) + .error (function (error) { + console.log("************ERROR"); + $scope.wizard.portalValidText = "Portal login was unsuccessful"; + $scope.wizard.portalColor = "#e74c3c"; + d.reject(false); + return d.promise; + + }); return d.promise; } + function getFirstMonitor() + { + var d=$q.defer(); $http.get($scope.wizard.apiURL+"/monitors.json") + .then (function (success) { + if (success.data.monitors.length > 0) + { + + ZMDataModel.zmDebug("zmWizard - getFirstMonitor returned " + success.data.monitors[0].Monitor.Id); d.resolve(success.data.monitors[0].Monitor.Id); + return d.promise; + + } + else + { + d.reject(false); + return d.promise; + } + }, + function (error) { + d.reject(false); + return d.promise; + }); + return d.promise; + } + //-------------------------------------------------------------------------- // Utility function - iterates through a list of URLs //-------------------------------------------------------------------------- @@ -133,27 +165,38 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ function continueCgi (urls) { - var tail = "/nph-zms?mode=single&monitor=1"; - if ($scope.wizard.useauth && $scope.wizard.usezmauth) - { - tail+= "&user="+$scope.wizard.zmuser+"&pass="+$scope.wizard.zmpassword; - } - findFirstReachableUrl(urls,tail ) - .then (function (success) { - ZMDataModel.zmLog ("Valid cgi-bin found with: " + success); - $scope.wizard.streamingURL = success; - $scope.wizard.streamingValidText = "cgi-bin detection succeeded: "+$scope.wizard.streamingURL; - $scope.wizard.streamingColor = "#16a085"; - d.resolve(true); - return d.promise; - + getFirstMonitor() + .then (function (success){ + + var tail = "/nph-zms?mode=single&monitor="+success; + if ($scope.wizard.useauth && $scope.wizard.usezmauth) + { + tail+= "&user="+$scope.wizard.zmuser+"&pass="+$scope.wizard.zmpassword; + } + findFirstReachableUrl(urls,tail ) + .then (function (success) { + ZMDataModel.zmLog ("Valid cgi-bin found with: " + success); + $scope.wizard.streamingURL = success; + $scope.wizard.streamingValidText = "cgi-bin detection succeeded: "+$scope.wizard.streamingURL; + $scope.wizard.streamingColor = "#16a085"; + d.resolve(true); + return d.promise; + + }, + function (error) { + console.log ("No cgi-bin found: " + error); + $scope.wizard.streamingValidText = "cgi-bin detection failed"; + $scope.wizard.streamingColor = "#e74c3c"; + d.reject (false); + return (d.promise); + }); }, - function (error) { - console.log ("No cgi-bin found: " + error); - $scope.wizard.streamingValidText = "cgi-bin detection failed"; - $scope.wizard.streamingColor = "#e74c3c"; - d.reject (false); - return (d.promise); + function (error){ + $scope.wizard.streamingValidText = "cgi-bin detection failed. No configured monitor found."; + $scope.wizard.streamingColor = "#e74c3c"; + d.reject (false); + return (d.promise); + }); } @@ -172,7 +215,7 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ { var u = $scope.wizard.loginURL; var d = $q.defer(); - var api1 = u ; + var api1 = u+"/api" ; var c = URI.parse(u); // lets also try without the path @@ -180,16 +223,20 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ if (c.userinfo) api2+= c.userinfo+"@"; api2 +=c.host; if (c.port) api2+= ":"+c.port; + api2+="/api"; // lets try both /zm/api and /api. What else is there? var apilist = [api1, api2]; - findFirstReachableUrl(apilist, '/api/host/getVersion.json') + findFirstReachableUrl(apilist, '/host/getVersion.json') .then (function (success) { ZMDataModel.zmLog ("Valid API response found with:" + success); $scope.wizard.apiURL = success; + + + $scope.wizard.apiValidText = "API detection succeeded: "+$scope.wizard.apiURL; $scope.wizard.apiColor = "#16a085"; d.resolve(true); @@ -235,16 +282,22 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ view: "login" } }) - .finally(function (ans) { - return d.resolve(true); - - }); - + .then (function (success) {console.log ("ZMlogout success"); d.resolve(true); return d.promise;}, function (error) {console.log ("ZMlogout success");d.resolve(true); return d.promise;}); + return d.promise; } + + $scope.enterResults = function() + { + $scope.portalValidText = ""; + $scope.apiValidateText = ""; + $scope.streamingValidateText = ""; + $scope.wizard.fqportal = ""; + return true; + }; //-------------------------------------------------------------------------- // tries to log into the portal and then discover api and cgi-bin //-------------------------------------------------------------------------- @@ -310,7 +363,16 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ detectapi() .then (function (success) { ZMDataModel.zmLog ("zmWizard: API succeeded"); - return d.resolve(true); + // CGI detection + detectcgi () + .then (function (success) { + // return true here because we want to progress + return d.resolve(true); + }, + function (error) { + // return true here because we want to progress + return d.resolve(true); + }); }, function (error) { ZMDataModel.zmLog("zmWizard: api failed"); @@ -319,16 +381,7 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ return d.resolve(true); }); - // CGI detection - detectcgi () - .then (function (success) { - // return true here because we want to progress - return d.resolve(true); - }, - function (error) { - // return true here because we want to progress - return d.resolve(true); - }); + }, // if login failed, don't progress in the wizard @@ -336,7 +389,7 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ ZMDataModel.zmLog("zmWizard: login failed"); $scope.wizard.portalValidText = "Portal login was unsuccessful. Please go back and review your settings"; $scope.wizard.portalColor = "#e74c3c"; - return d.resolve(false); + return d.resolve(true); }); @@ -499,6 +552,14 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ $scope.wizard.tiptext = "show tip"; }; + $scope.gotoLoginState = function() + { + $rootScope.wizard = angular.copy($scope.wizard); + $ionicHistory.nextViewOptions({ + disableBack: true + }); + $state.go("login", {"wizard":true}); + }; //-------------------------------------------------------------------------- // initial @@ -506,6 +567,7 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ $scope.$on('$ionicView.beforeEnter', function () { //console.log("**VIEW ** Help Ctrl Entered"); + var monId = -1; $scope.wizard = { tipshow: false, tiptext: "show tip", diff --git a/www/js/app.js b/www/js/app.js index 18fdc820..664511be 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -1106,7 +1106,7 @@ angular.module('zmApp', [ disableBack: true }); $rootScope.userCancelledAuth = true; - $state.go("login"); + $state.go("login" ,{"wizard": false}); }; @@ -1419,7 +1419,7 @@ angular.module('zmApp', [ data: { requireLogin: false }, - url: "/login", + url: "/login/:wizard", templateUrl: "templates/login.html", controller: 'zmApp.LoginCtrl', -- cgit v1.2.3