From d3287595f35e0d96cf6025688aae79938ced63b7 Mon Sep 17 00:00:00 2001 From: Arjun Roychowdhury Date: Fri, 2 Oct 2015 16:35:01 -0400 Subject: added checking for minimum ZM version --- www/js/DataModel.js | 30 +++++++++++++++++++++++++++++ www/js/LowVersionCtrl.js | 24 ++++++++++++++++++++++++ www/js/PortalLoginCtrl.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++- www/js/app.js | 14 ++++++++++++++ 4 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 www/js/LowVersionCtrl.js (limited to 'www/js') diff --git a/www/js/DataModel.js b/www/js/DataModel.js index b5d6cd98..b0fc405b 100644 --- a/www/js/DataModel.js +++ b/www/js/DataModel.js @@ -347,6 +347,36 @@ angular.module('zmApp.controllers').service('ZMDataModel', } }, + //------------------------------------------------------- + // returns API version or none + //------------------------------------------------------- + getAPIversion: function() + { + zmDebug("getAPIversion called"); + var d=$q.defer(); + var apiurl = loginData.apiurl + '/host/getVersion.json'; + $http.get(apiurl) + .then (function(success){ + if (success.data.version) + { + d.resolve(success.data.version); + } + else + { + d.resolve("0.0.0"); + } + return (d.promise); + + }, + function(error){ + zmDebug("getAPIversion error handler " + JSON.stringify(error)); + d.resolve("0.0.0"); + return (d.promise); + }); + return (d.promise); + + + }, displayBanner: function (mytype, mytext, myinterval, mytimer) { diff --git a/www/js/LowVersionCtrl.js b/www/js/LowVersionCtrl.js new file mode 100644 index 00000000..3e93dcd0 --- /dev/null +++ b/www/js/LowVersionCtrl.js @@ -0,0 +1,24 @@ +/* jshint -W041 */ +/* jslint browser: true*/ +/* global cordova,StatusBar,angular,console */ + +angular.module('zmApp.controllers').controller('zmApp.LowVersionCtrl', ['$scope','$ionicSideMenuDelegate', 'zm', '$stateParams', function ($scope,$ionicSideMenuDelegate,zm, $stateParams) { +$scope.openMenu = function () { + $ionicSideMenuDelegate.toggleLeft(); + }; + + + + + //------------------------------------------------------------------------- + // Controller Main + //------------------------------------------------------------------------ + $scope.$on('$ionicView.enter', function () { + console.log("**VIEW ** LowVersion Ctrl Entered"); + $ionicSideMenuDelegate.canDragContent(false); + $scope.requiredVersion = zm.minAppVersion; + $scope.currentVersion = $stateParams.ver; + + }); + +}]); diff --git a/www/js/PortalLoginCtrl.js b/www/js/PortalLoginCtrl.js index cfec3004..ec287cf7 100644 --- a/www/js/PortalLoginCtrl.js +++ b/www/js/PortalLoginCtrl.js @@ -27,6 +27,8 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic if (ZMDataModel.isLoggedIn()) { ZMDataModel.zmLog("User credentials are provided"); + + // You can login either via touch ID or typing in your code if ($ionicPlatform.is('ios') && loginData.usePin) { @@ -72,7 +74,18 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic { ZMDataModel.zmDebug("PortalLogin: auth success"); ZMDataModel.getKeyConfigParams(1); - ZMDataModel.zmDebug("Transitioning state to: " + $rootScope.lastState ? $rootScope.lastState : 'montage'); + ZMDataModel.zmDebug("Transitioning state to: " + + $rootScope.lastState ? $rootScope.lastState : 'montage'); + + ZMDataModel.getAPIversion() + .then (function(data) { + ZMDataModel.zmLog("Got API version: " + data); + if (versionCompare(data,zm.minAppVersion)) + { + + $state.go('lowversion', {"ver":data}); + } + }); $state.go($rootScope.lastState ? $rootScope.lastState : 'montage', $rootScope.lastStateParam); }, @@ -109,6 +122,27 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic $scope.unlock = function () { unlock(false); }; + + //credit: https://gist.github.com/alexey-bass/1115557 + function versionCompare(left, right) { + if (typeof left + typeof right != 'stringstring') + return false; + + var a = left.split('.'); + var b = right.split('.'); + var i = 0; + var len = Math.max(a.length, b.length); + + for (; i < len; i++) { + if ((a[i] && !b[i] && parseInt(a[i]) > 0) || (parseInt(a[i]) > parseInt(b[i]))) { + return 1; + } else if ((b[i] && !a[i] && parseInt(b[i]) > 0) || (parseInt(a[i]) < parseInt(b[i]))) { + return -1; + } + } + + return 0; +} function unlock(touchVerified) { ZMDataModel.zmDebug("Trying to unlock PIN"); @@ -127,6 +161,17 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic $rootScope.lastState = "montage"; } ZMDataModel.zmDebug("PortalLogin: auth success"); + ZMDataModel.getAPIversion() + .then (function(data) { + ZMDataModel.zmLog("Got API version: " + data); + if (versionCompare(data,zm.minAppVersion)) + { + + $state.go('lowversion', {"ver":data}); + } + + + }); ZMDataModel.getKeyConfigParams(1); ZMDataModel.zmDebug("Transitioning state to: " + $rootScope.lastState ? $rootScope.lastState : 'montage'); $state.go($rootScope.lastState ? $rootScope.lastState : 'montage', $rootScope.lastStateParam); @@ -157,6 +202,7 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic //------------------------------------------------------------------------------- console.log("************* ENTERING PORTAL MAIN "); var loginData = ZMDataModel.getLogin(); + $ionicSideMenuDelegate.canDragContent(false); diff --git a/www/js/app.js b/www/js/app.js index 7a624d5b..c5440937 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -25,6 +25,7 @@ angular.module('zmApp', [ //----------------------------------------------- .constant('zm', { + minAppVersion: '1.28.107', httpTimeout: 15000, largeHttpTimeout: 60000, logFile: 'zmNinjaLog.txt', @@ -727,6 +728,19 @@ angular.module('zmApp', [ }) + .state('lowversion', { + data: { + requireLogin: false + }, + + url: "/lowversion/:ver", + templateUrl: "templates/lowversion.html", + controller: 'zmApp.LowVersionCtrl', + + }) + + + .state('events-graphs', { data: { requireLogin: true -- cgit v1.2.3