diff options
Diffstat (limited to 'www/js/MontageHistoryCtrl.js')
| -rw-r--r-- | www/js/MontageHistoryCtrl.js | 1276 |
1 files changed, 738 insertions, 538 deletions
diff --git a/www/js/MontageHistoryCtrl.js b/www/js/MontageHistoryCtrl.js index 1fb1f09c..897572b9 100644 --- a/www/js/MontageHistoryCtrl.js +++ b/www/js/MontageHistoryCtrl.js @@ -1,23 +1,24 @@ // Controller for the montage view /* jshint -W041 */ /* jslint browser: true*/ -/* global cordova,StatusBar,angular,console,ionic,Masonry,moment */ +/* global cordova,StatusBar,angular,console,ionic,Masonry,moment,Packery, Draggabilly, imagesLoaded */ // FIXME: This is a copy of montageCtrl - needs a lot of code cleanup angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$scope', '$rootScope', 'NVRDataModel', 'message', '$ionicSideMenuDelegate', '$timeout', '$interval', '$ionicModal', '$ionicLoading', '$http', '$state', '$ionicPopup', '$stateParams', '$ionicHistory', '$ionicScrollDelegate', '$ionicPlatform', 'zm', '$ionicPopover', '$controller', 'imageLoadingDataShare', '$window', '$translate', function ($scope, $rootScope, NVRDataModel, message, $ionicSideMenuDelegate, $timeout, $interval, $ionicModal, $ionicLoading, $http, $state, $ionicPopup, $stateParams, $ionicHistory, $ionicScrollDelegate, $ionicPlatform, zm, $ionicPopover, $controller, imageLoadingDataShare, $window, $translate) { - - + + + //-------------------------------------------------------------------------------------- // Handles bandwidth change, if required // //-------------------------------------------------------------------------------------- - $rootScope.$on("bandwidth-change", function (e,data) { - // nothing to do for now - // eventUrl will use lower BW in next query cycle + $rootScope.$on("bandwidth-change", function (e, data) { + // nothing to do for now + // eventUrl will use lower BW in next query cycle }); @@ -26,6 +27,10 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc // formats events dates in a nice way //--------------------------------------- + $scope.prettifyDateTimeFirst = function (str) { + return moment(str).format(NVRDataModel.getTimeFormat() + '/MMM Do'); + + }; $scope.prettifyDate = function (str) { return moment(str).format('MMM Do, YYYY ' + NVRDataModel.getTimeFormat()); }; @@ -46,6 +51,22 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc + + function orientationChanged() { + NVRDataModel.debug("Detected orientation change, redoing packery resize"); + $timeout(function () { + pckry.onresize(); + }); + } + + $scope.toggleSizeButtons = function () { + + $scope.showSizeButtons = !$scope.showSizeButtons; + + NVRDataModel.debug("toggling size buttons:" + $scope.showSizeButtons); + if ($scope.showSizeButtons) $ionicScrollDelegate.$getByHandle("montage-delegate").scrollTop(); + }; + //-------------------------------------- // pause/unpause nph-zms //--------------------------------------- @@ -70,6 +91,10 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc }; + $scope.humanizeTime = function (str) { + return moment(str).fromNow(); + + }; //-------------------------------------- // Called when ion-footer collapses @@ -98,6 +123,10 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc return; } + + + $scope.dragBorder = ""; + $scope.isDragabillyOn = false; $ionicSideMenuDelegate.canDragContent(true); NVRDataModel.stopNetwork("MontageHistory-footerCollapse"); @@ -107,7 +136,9 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc //NVRDataModel.debug ("Playback rate is:" + $scope.sliderVal.realRate); var TimeObjectFrom = moment($scope.datetimeValueFrom.value).format("YYYY-MM-DD HH:mm"); - var TimeObjectTo = moment($scope.datetimeValueTo.value).format('YYYY-MM-DD HH:mm'); + + //var TimeObjectTo = moment($scope.datetimeValueTo.value).format('YYYY-MM-DD HH:mm'); + var TimeObjectTo = moment().format('YYYY-MM-DD HH:mm'); // console.log ("TIME START: " + TimeObjectFrom + " " + TimeObjectTo); //console.log ("TIME START: " + TimeObjectFrom + " " + TimeObjectTo); @@ -117,9 +148,12 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc // release all active streams for (var i = 0; i < $scope.MontageMonitors.length; i++) { + $scope.MontageMonitors[i].Monitor.selectStyle = ""; // generate new connKeys if timeline changes if ($scope.MontageMonitors[i].Monitor.eventUrl != 'img/noevent.png') { - NVRDataModel.log("footerCollapse: Calling kill with " + $scope.MontageMonitors[i].Monitor.connKey + " because url is " + $scope.MontageMonitors[i].Monitor.eventUrl); + // this means this mid was showing a message, now we need to change it + // so kill prev. stream first + NVRDataModel.log("footerCollapse: Calling kill with " + $scope.MontageMonitors[i].Monitor.connKey + " for Monitor:"+$scope.MontageMonitors[i].Monitor.Name); var tmpCK = angular.copy($scope.MontageMonitors[i].Monitor.connKey); timedControlEventStream(2500, 17, "", tmpCK, -1); $scope.MontageMonitors[i].Monitor.eventUrl = "img/noevent.png"; @@ -129,16 +163,18 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc //console.log ("footerCollapse: Skipped kill: connkey:"+$scope.MontageMonitors[i].Monitor.connKey + " function " + $scope.MontageMonitors[i].Monitor.Function + " listDisplay " + $scope.MontageMonitors[i].Monitor.lisDisplay + " enabled " + $scope.MontageMonitors[i].Monitor.Enabled + " eventURL " + $scope.MontageMonitors[i].Monitor.eventUrl); } - - - } + // grab events that start on or before the time and end on or after the time // this should only bring up events that span that time - apiurl = ld.apiurl + "/events/index/StartTime >=:" + TimeObjectFrom + "/EndTime <=:" + TimeObjectTo + ".json"; + //apiurl = ld.apiurl + "/events/index/StartTime >=:" + TimeObjectFrom + "/EndTime <=:" + TimeObjectTo + ".json"; + apiurl = ld.apiurl + "/events/index/StartTime >=:" + TimeObjectFrom + "/AlarmFrames >=:" + (ld.enableAlarmCount ? ld.minAlarmCount : 0)+ ".json"; + NVRDataModel.log("Event timeline API is " + apiurl); + // make sure there are no more than 5 active streams (noevent is ok) + $scope.currentLimit = $scope.monLimit; $http.get(apiurl) .success(function (data) { @@ -152,6 +188,7 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc // only take the first one for each monitor for (var j = 0; j < $scope.MontageMonitors.length; j++) { + $scope.MontageMonitors[j].Monitor.isPaused = false; // that's the earliest match and play gapless from there if ($scope.MontageMonitors[j].Monitor.Id == mid) { @@ -159,9 +196,10 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc // console.log ("Old value of event url " + $scope.MontageMonitors[j].eventUrl); //console.log ("ldurl is " + ld.streamingurl); + + var bw = NVRDataModel.getBandwidth() == "lowbw" ? zm.eventMontageQualityLowBW : ld.montageHistoryQuality; + $scope.MontageMonitors[j].Monitor.eventUrl = ld.streamingurl + "/nph-zms?source=event&mode=jpeg&event=" + eid + "&frame=1&replay=gapless&rate=" + $scope.sliderVal.realRate + "&connkey=" + $scope.MontageMonitors[j].Monitor.connKey + "&scale=" + bw + "&rand=" + $rootScope.rand; - var bw = NVRDataModel.getBandwidth()=="lowbw"? zm.eventMontageQualityLowBW: ld.montageHistoryQuality ; - $scope.MontageMonitors[j].Monitor.eventUrl = ld.streamingurl + "/nph-zms?source=event&mode=jpeg&event=" + eid + "&frame=1&replay=gapless&rate=" + $scope.sliderVal.realRate + "&connkey=" + $scope.MontageMonitors[j].Monitor.connKey + "&scale=" + bw+ "&rand=" + $rootScope.rand; //console.log ("Setting event URL to " +$scope.MontageMonitors[j].Monitor.eventUrl); // console.log ("SWITCHING TO " + $scope.MontageMonitors[j].eventUrl); @@ -169,6 +207,7 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc $scope.MontageMonitors[j].Monitor.eventUrlTime = stime; } + } } } @@ -178,10 +217,13 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc NVRDataModel.log("Making sure all monitors have a fair chance..."); for (i = 0; i < $scope.MontageMonitors.length; i++) { + + console.log ("Fair chance check for " + $scope.MontageMonitors[i].Monitor.Name); + if ($scope.MontageMonitors[i].Monitor.eventUrl == 'img/noevent.png') { - var indivGrab = ld.apiurl + "/events/index/MonitorId:" + $scope.MontageMonitors[i].Monitor.Id + "/StartTime >=:" + TimeObjectFrom + "/EndTime <=:" + TimeObjectTo + ".json"; + var indivGrab = ld.apiurl + "/events/index/MonitorId:" + $scope.MontageMonitors[i].Monitor.Id + "/StartTime >=:" + TimeObjectFrom + "/AlarmFrames >=:" + (ld.enableAlarmCount ? ld.minAlarmCount : 0) + ".json"; NVRDataModel.debug("Monitor " + $scope.MontageMonitors[i].Monitor.Id + ":" + $scope.MontageMonitors[i].Monitor.Name + " does not have events, trying " + indivGrab); @@ -189,8 +231,27 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc } } + console.log("REDOING PACKERY & DRAG"); + if (pckry !== undefined) + { + + // remove current draggies + draggies.forEach(function (drag) { + drag.destroy(); + }); + + draggies = []; + // destroy existing packery object + pckry.destroy(); + + initPackery(); + + + + + - + } }) @@ -210,8 +271,8 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc if (!NVRDataModel.isBackground()) { - var bw = NVRDataModel.getBandwidth()=="lowbw"? zm.eventMontageQualityLowBW: ld.montageHistoryQuality ; - + var bw = NVRDataModel.getBandwidth() == "lowbw" ? zm.eventMontageQualityLowBW : ld.montageHistoryQuality; + $scope.MontageMonitors[i].Monitor.eventUrl = ld.streamingurl + "/nph-zms?source=event&mode=jpeg&event=" + data.events[0].Event.Id + "&frame=1&replay=gapless&rate=" + $scope.sliderVal.realRate + "&connkey=" + $scope.MontageMonitors[i].Monitor.connKey + "&scale=" + bw + "&rand=" + $rootScope.rand; @@ -413,7 +474,7 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc $http.get(apiurl) .success(function (data) { var currentEventTime = moment(data.event.Event.StartTime); - var maxTime = moment($scope.datetimeValueTo.value); + var maxTime = moment(); //NVRDataModel.debug ("Monitor: " + $scope.MontageMonitors[ndx].Monitor.Id + " max time="+maxTime + "("+$scope.datetimeValueTo.value+")"+ " current="+currentEventTime + "("+data.event.Event.StartTime+")"); if ($scope.MontageMonitors[ndx].Monitor.eventUrlTime != data.event.Event.StartTime && currentEventTime.diff(maxTime) <= 0) { @@ -426,7 +487,7 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc element.addClass('animated flipInX'); $scope.MontageMonitors[ndx].Monitor.eventUrlTime = data.event.Event.StartTime; - var bw = NVRDataModel.getBandwidth()=="lowbw"? zm.eventMontageQualityLowBW: ld.montageHistoryQuality ; + var bw = NVRDataModel.getBandwidth() == "lowbw" ? zm.eventMontageQualityLowBW : ld.montageHistoryQuality; $scope.MontageMonitors[ndx].Monitor.eventUrl = ld.streamingurl + "/nph-zms?source=event&mode=jpeg&event=" + data.event.Event.Id + "&frame=1&replay=gapless&rate=" + $scope.sliderVal.realRate + "&connkey=" + $scope.MontageMonitors[ndx].Monitor.connKey + "&scale=" + bw + "&rand=" + $rootScope.rand; }, 700); @@ -451,329 +512,8 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc }); } - //--------------------------------------------------------------------- - // Controller main - //--------------------------------------------------------------------- - - document.addEventListener("pause", onPause, false); - document.addEventListener("resume", onResume, false); - - $scope.timeFormat = "yyyy-MM-dd " + NVRDataModel.getTimeFormat(); - $scope.displayDateTimeSliders = true; - $scope.showtimers = true; - $scope.loginData = NVRDataModel.getLogin(); - - - - var curYear = new Date().getFullYear(); - - var readyToRun = false; - var i; - - $scope.sliderVal = { - - rate: 1, - realRate: 100, - hideNoEvents: false, - enableGapless: true, - exactMatch: false, - showTimeline: true - - }; - - - - // default = start of day - var timeto = moment(); - var timefrom = moment().startOf('day'); - - $scope.sliderVal.rate = 1; - $scope.sliderVal.realRate = $scope.sliderVal.rate * 100; - - - - //var tdatetimeValueFrom = new Date(); - //tdatetimeValueFrom.setDate(tdatetimeValueFrom.getDate()-1); - - $scope.datetimeValueFrom = { - value: "" - }; - $scope.datetimeValueTo = { - value: "" - }; - - $scope.datetimeValueFrom.value = timefrom.toDate(); - $scope.datetimeValueTo.value = timeto.toDate(); - - $rootScope.eventQueryInterval = ""; - - - var commonCss = { - - background: { - "background-color": "silver" - }, - before: { - "background-color": "purple" - }, - default: { - "background-color": "white" - }, // default value: 1px - after: { - "background-color": "green" - }, // zone after default value - pointer: { - "background-color": "red" - }, // circle pointer - range: { - "background-color": "red" - } // use it if double value - }; - - - $scope.slider_modal_options_rate = { - from: 1, - to: 10, - realtime: true, - step: 1, - className: "mySliderClass", - //modelLabels:function(val) {return "";}, - smooth: false, - css: commonCss, - dimension: 'X' - - }; - - - - var isLongPressActive = false; - $scope.isReorder = false; - var intervalHandleMontage; // will hold image resize timer on long press - var montageIndex = 0; // will hold monitor ID to scale in timer - - var gridcontainer; - - $scope.monitorSize = []; // array with montage sizes per monitor - $scope.scaleDirection = []; // 1 = increase -1 = decrease - - $scope.slider = {}; - - //console.log ("************ HISTORY " + NVRDataModel.getMontageSize()); - $scope.slider.monsize = NVRDataModel.getMontageSize(); - $scope.revMonSize = 11 - parseInt($scope.slider.monsize); - - // The difference between old and original is this: - // old will have a copy of the last re-arranged monitor list - // while original will have a copy of the order returned by ZM - - var oldMonitors = []; // To keep old order if user cancels after sort; - - // Montage display order may be different so don't - // mangle monitors as it will affect other screens - // in Montage screen we will work with this local copy - //$scope.MontageMonitors = angular.copy ($scope.monitors); - - var montageOrder = []; // This array will keep the ordering in montage view - var hiddenOrder = []; // 1 = hide, 0 = don't hide - - var tempMonitors = message; - if (tempMonitors.length == 0) { - $rootScope.zmPopup = $ionicPopup.alert({ - title: $translate.instant('kNoMonitors'), - template: $translate.instant('kPleaseCheckCredentials') - }); - $ionicHistory.nextViewOptions({ - disableBack: true - }); - $state.go("login"); - return; - } - - // console.log ("TEMP MONITORS IS " + JSON.stringify(tempMonitors)); - var tempResponse = NVRDataModel.applyMontageMonitorPrefs(message, 0); - $scope.monitors = tempResponse[0]; - montageOrder = tempResponse[1]; - hiddenOrder = tempResponse[2]; - - NVRDataModel.log("Inside MontageHistoryCtrl:We found " + $scope.monitors.length + " monitors"); - - $scope.MontageMonitors = NVRDataModel.applyMontageMonitorPrefs(message, 1)[0]; - - var loginData = NVRDataModel.getLogin(); - - $scope.packMontage = loginData.packMontage; - - - // init monitors - NVRDataModel.debug(">>Initializing connkeys and images..."); - for (i = 0; i < $scope.MontageMonitors.length; i++) { - //$scope.MontageMonitors[i].Monitor.connKey=''; - - - - $scope.MontageMonitors[i].Monitor.connKey = (Math.floor((Math.random() * 999999) + 1)).toString(); - $scope.MontageMonitors[i].Monitor.eventUrl = 'img/noevent.png'; - $scope.MontageMonitors[i].Monitor.eventUrlTime = ""; - $scope.MontageMonitors[i].Monitor.isPaused = false; - - - } - readyToRun = true; - - - - // -------------------------------------------------------- - // Handling of back button in case modal is open should - // close the modal - // -------------------------------------------------------- - - $ionicPlatform.registerBackButtonAction(function (e) { - e.preventDefault(); - if ($scope.modal && $scope.modal.isShown()) { - // switch off awake, as liveview is finished - NVRDataModel.debug("Modal is open, closing it"); - NVRDataModel.setAwake(false); - $scope.modal.remove(); - $scope.isModalActive = false; - } else { - NVRDataModel.debug("Modal is closed, so toggling or exiting"); - if (!$ionicSideMenuDelegate.isOpenLeft()) { - $ionicSideMenuDelegate.toggleLeft(); - - } else { - navigator.app.exitApp(); - } - - } - - }, zm.eventHistoryTimer); - - - - - $scope.showSizeButtons = false; - $ionicPopover.fromTemplateUrl('templates/help/montage-help.html', { - scope: $scope, - }).then(function (popover) { - $scope.popover = popover; - }); - - var timestamp = new Date().getUTCMilliseconds(); - $scope.minimal = $stateParams.minimal; - $scope.zmMarginTop = $scope.minimal ? 0 : 15; - //console.log ("********* MARGIN IS " + $scope.zmMarginTop); - - $scope.isRefresh = $stateParams.isRefresh; - var sizeInProgress = false; - $scope.imageStyle = true; - - $ionicSideMenuDelegate.canDragContent(true); - - - - // Do we have a saved montage array size? No? - // if (window.localStorage.getItem("montageArraySize") == undefined) { - if (loginData.montageArraySize == '0') { - - for (i = 0; i < $scope.monitors.length; i++) { - $scope.monitorSize.push(NVRDataModel.getMontageSize()); - $scope.scaleDirection.push(1); - } - } else // recover previous settings - { - var msize = loginData.montageArraySize; - //console.log("MontageArrayString is=>" + msize); - $scope.monitorSize = msize.split(":"); - var j; - - for (j = 0; j < $scope.monitorSize.length; j++) { - // convert to number other wise adding to it concatenates :-) - $scope.monitorSize[j] = parseInt($scope.monitorSize[j]); - $scope.scaleDirection.push(1); - //console.log("Montage size for monitor " + j + " is " + $scope.monitorSize[j]); - - } - - } - // $scope.monitorSize = monitorSize; - // $scope.scaleDirection = scaleDirection; - - $scope.LoginData = NVRDataModel.getLogin(); - $scope.monLimit = $scope.LoginData.maxMontage; - - if ($rootScope.platformOS != 'ios') { - NVRDataModel.log("Limiting montage to 5, thanks to Chrome's stupid connection limit"); - $scope.monLimit = 5; - } - - //console.log("********* Inside MontageHistoryCtrl, MAX LIMIT=" + $scope.monLimit); - - - $rootScope.authSession = "undefined"; - $ionicLoading.show({ - template: $translate.instant('kNegotiatingStreamAuth'), - animation: 'fade-in', - showBackdrop: true, - duration: zm.loadingTimeout, - maxWidth: 300, - showDelay: 0 - }); - - - var ld = NVRDataModel.getLogin(); - - //console.log ("MONITORS " + JSON.stringify($scope.monitors)); - $rootScope.validMonitorId = $scope.monitors[0].Monitor.Id; - NVRDataModel.getAuthKey($rootScope.validMonitorId) - .then(function (success) { - $ionicLoading.hide(); - //console.log(success); - $rootScope.authSession = success; - NVRDataModel.log("Stream authentication construction: " + - $rootScope.authSession); - - }, - function (error) { - - $ionicLoading.hide(); - NVRDataModel.debug("MontageHistoryCtrl: Error in authkey retrieval " + error); - //$rootScope.authSession=""; - NVRDataModel.log("MontageHistoryCtrl: Error returned Stream authentication construction. Retaining old value of: " + $rootScope.authSession); - }); - - - // I was facing a lot of problems with Chrome/crosswalk getting stuck with - // pending HTTP requests after a while. There is a problem with chrome handling - // multiple streams of always open HTTP get's (image streaming). This problem - // does not arise when the image is streamed for a single monitor - just multiple - - // To work around this I am taking a single snapshot of ZMS and have implemented a timer - // to reload the snapshot every 1 second. Seems to work reliably even thought its a higer - // load. Will it bonk with many monitors? Who knows. I have tried with 5 and 1280x960@32bpp - - - function loadNotifications() { - - //$rootScope.rand = Math.floor((Math.random() * 100000) + 1); - - //console.log ("Inside Montage timer..."); - - } - - var intervalHandle; - $scope.isModalActive = false; - var modalIntervalHandle; - - - $scope.closeReorderModal = function () { - //console.log("Close & Destroy Monitor Modal"); - // switch off awake, as liveview is finished - //NVRDataModel.setAwake(false); - $scope.modal.remove(); - - }; - + $scope.isBackground = function () { return NVRDataModel.isBackground(); }; @@ -832,225 +572,94 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc return NVRDataModel.isBackground(); }; - //------------------------------------------------------------- - // Called when user taps on the reorder button - //------------------------------------------------------------- - - $scope.reorderList = function () { - //console.log("REORDER"); - $scope.data.showDelete = false; - $scope.data.showReorder = !$scope.data.showReorder; - }; - - $scope.deleteList = function () { - //console.log("DELETE"); - $scope.data.showDelete = !$scope.data.showDelete; - $scope.data.showReorder = false; - }; - - $scope.reloadReorder = function () { - var refresh = NVRDataModel.getMonitors(1); + - refresh.then(function (data) { - $scope.monitors = data; - $scope.MontageMonitors = data; - oldMonitors = angular.copy($scope.monitors); - var i; - montageOrder = []; - for (i = 0; i < $scope.monitors.length; i++) { - montageOrder[i] = i; - hiddenOrder[i] = 0; - } - loginData.montageOrder = montageOrder.toString(); - loginData.montageHiddenOrder = hiddenOrder.toString(); - NVRDataModel.setLogin(loginData); - //window.localStorage.setItem("montageOrder", montageOrder.toString()); - //window.localStorage.setItem("montageHiddenOrder", hiddenOrder.toString()); - NVRDataModel.log("Montage order saved on refresh: " + montageOrder.toString() + " and hidden order: " + hiddenOrder.toString()); + //--------------------------------------------------------------------- + // Triggered when you enter/exit full screen + //--------------------------------------------------------------------- + $scope.switchMinimal = function () { + $scope.minimal = !$scope.minimal; + NVRDataModel.debug("MontageHistoryCtrl: switch minimal is " + $scope.minimal); + //console.log("Hide Statusbar"); + ionic.Platform.fullScreen($scope.minimal, !$scope.minimal); + $interval.cancel(intervalHandle); //we will renew on reload + // We are reloading this view, so we don't want entry animations + $ionicHistory.nextViewOptions({ + disableAnimate: true, + disableBack: true + }); + $state.go("montage", { + minimal: $scope.minimal, + isRefresh: true }); }; - $scope.saveReorder = function () { - loginData.montageOrder = montageOrder.toString(); - loginData.montageHiddenOrder = hiddenOrder.toString(); - NVRDataModel.setLogin(loginData); - //window.localStorage.setItem("montageOrder", montageOrder.toString()); - // window.localStorage.setItem("montageHiddenOrder", - // hiddenOrder.toString()); - //console.log("Saved " + montageOrder.toString()); - NVRDataModel.log("User press OK. Saved Monitor Order as: " + - montageOrder.toString() + - " and hidden order as " + hiddenOrder.toString()); - $scope.modal.remove(); - }; - - $scope.cancelReorder = function () { - // user tapped cancel - var i, myhiddenorder; - if (loginData.montageOrder == '') { - //if (window.localStorage.getItem("montageOrder") == undefined) { - for (i = 0; i < $scope.MontageMonitors.length; i++) { - montageOrder[i] = i; - hiddenOrder[i] = 0; - } - //console.log("Order string is " + montageOrder.toString()); - NVRDataModel.log("User press Cancel. Reset Monitor Order to: " + montageOrder.toString()); - } else // montageOrder exists - { - var myorder = loginData.montageOrder; - - if (loginData.montageHiddenOrder == '') { - for (i = 0; i < $scope.MontageMonitors.length; i++) { - hiddenOrder[i] = 0; - } - } else { - myhiddenorder = loginData.montageHiddenOrder; - hiddenOrder = myhiddenorder.split(","); - } - - //console.log("Montage order is " + myorder + " and hidden order is " + myhiddenorder); - montageOrder = myorder.split(","); - - for (i = 0; i < montageOrder.length; i++) { - montageOrder[i] = parseInt(montageOrder[i]); - hiddenOrder[i] = parseInt(hiddenOrder[i]); - } - - $scope.MontageMonitors = oldMonitors; - NVRDataModel.log("User press Cancel. Restored Monitor Order as: " + montageOrder.toString() + " and hidden order as: " + hiddenOrder.toString()); - - } - $scope.modal.remove(); - }; - - $scope.toggleReorder = function () { - $scope.isReorder = !$scope.isReorder; - $scope.data = {}; - $scope.data.showDelete = false; - $scope.data.showReorder = false; - - var i; - oldMonitors = angular.copy($scope.monitors); - /*for (i=0; i<$scope.monitors.length; i++) - { - $scope.monitors[i].Monitor.listDisplay="show"; - }*/ - ld = NVRDataModel.getLogin(); - if (ld.enableDebug) { - // Lets show the re-order list - for (i = 0; i < $scope.MontageMonitors.length; i++) { - NVRDataModel.debug("Montage reorder list: " + $scope.MontageMonitors[i].Monitor.Name + - ":listdisplay->" + $scope.MontageMonitors[i].Monitor.listDisplay); + $scope.toggleSelectItem = function (ndx) { - } + if ($scope.MontageMonitors[ndx].Monitor.selectStyle !== "undefined" && $scope.MontageMonitors[ndx].Monitor.selectStyle == "dragborder-selected") { + $scope.MontageMonitors[ndx].Monitor.selectStyle = ""; + } else { + $scope.MontageMonitors[ndx].Monitor.selectStyle = "dragborder-selected"; } - - $ionicModal.fromTemplateUrl('templates/reorder-modal.html', { - scope: $scope, - animation: 'slide-in-up' - }) - .then(function (modal) { - $scope.modal = modal; - $scope.modal.show(); - }); - - - + //console.log ("Switched value to " + $scope.MontageMonitors[ndx].Monitor.selectStyle); }; - - /* - $scope.onSwipeLeft = function ($index) { - $scope.showSizeButtons = true; - }; - - $scope.onSwipeRight = function ($index) { - $timeout(function () { - $scope.showSizeButtons = false; - }, 1000); - - };*/ - //--------------------------------------------------------------------- - // This marks a monitor as hidden in montage view + // Called when you enable/disable dragging //--------------------------------------------------------------------- - $scope.deleteItem = function (index) { - var findindex = montageOrder.indexOf(index); - // $scope.monitors[index].Monitor.Function = 'None'; - if ($scope.MontageMonitors[index].Monitor.listDisplay == 'show') { - $scope.MontageMonitors[index].Monitor.listDisplay = 'noshow'; - hiddenOrder[findindex] = 1; - } else { - $scope.MontageMonitors[index].Monitor.listDisplay = 'show'; - // we need to find the index of Montage Order that contains index - // because remember, hiddenOrder does not change its orders as monitors - // move + $scope.dragToggle = function () { + dragToggle(); - hiddenOrder[findindex] = 0; - } - //window.localStorage.setItem("montageOrder", montageOrder.toString()); - //console.log("DELETE: Order Array now is " + montageOrder.toString()); - //console.log("DELETE: Hidden Array now is " + hiddenOrder.toString()); - NVRDataModel.log("Marked monitor " + findindex + " as " + $scope.MontageMonitors[index].Monitor.listDisplay + " in montage"); }; - //--------------------------------------------------------------------- - // When we re-arrange the montage, all the ordering index moves - // horrible horrible code - //--------------------------------------------------------------------- + function dragToggle() { + var i; + $scope.isDragabillyOn = !$scope.isDragabillyOn; - function reorderItem(item, from, to, reorderHidden) { + $ionicSideMenuDelegate.canDragContent($scope.isDragabillyOn ? false : true); - NVRDataModel.debug("MontageHistoryCtrl: Reorder from " + from + " to " + to); - $scope.MontageMonitors.splice(from, 1); - $scope.MontageMonitors.splice(to, 0, item); + //$timeout(function(){pckry.reloadItems();},10); + NVRDataModel.debug("setting dragabilly to " + $scope.isDragabillyOn); + if ($scope.isDragabillyOn) { + $scope.showSizeButtons = true; - // Now we need to re-arrange the montageOrder - // hiddenOrder remains the same + $scope.dragBorder = "dragborder"; + NVRDataModel.debug("Enabling drag for " + draggies.length + " items"); + for (i = 0; i < draggies.length; i++) { + draggies[i].enable(); + draggies[i].bindHandles(); + } - var i, j; - for (i = 0; i < $scope.monitors.length; i++) { - for (j = 0; j < $scope.MontageMonitors.length; j++) { - if ($scope.monitors[i].Monitor.Id == $scope.MontageMonitors[j].Monitor.Id) { - montageOrder[i] = j; - break; - } + // reflow and reload as some may be hidden + // $timeout(function(){pckry.reloadItems();$timeout(function(){pckry.layout();},300);},100); + } else { + $scope.dragBorder = ""; + NVRDataModel.debug("Disabling drag for " + draggies.length + " items"); + for (i = 0; i < draggies.length; i++) { + draggies[i].disable(); + draggies[i].unbindHandles(); } - } - NVRDataModel.log("New Montage Order is: " + montageOrder.toString()); + for (i = 0; i < $scope.MontageMonitors.length; i++) { + $scope.MontageMonitors[i].Monitor.selectStyle = ""; + } + // reflow and reload as some may be hidden + $timeout(function () { + $timeout(function () { + pckry.shiftLayout(); + /*var positions = pckry.getShiftPositions('data-item-id'); + //console.log ("POSITIONS MAP " + JSON.stringify(positions)); + var ld = NVRDataModel.getLogin(); + ld.packeryPositions = JSON.stringify(positions); + NVRDataModel.setLogin(ld);*/ + }, 300); + }, 100); + } } - - - $scope.reorderItem = function (item, from, to) { - reorderItem(item, from, to, true); - }; - - - //--------------------------------------------------------------------- - // Triggered when you enter/exit full screen - //--------------------------------------------------------------------- - $scope.switchMinimal = function () { - $scope.minimal = !$scope.minimal; - NVRDataModel.debug("MontageHistoryCtrl: switch minimal is " + $scope.minimal); - //console.log("Hide Statusbar"); - ionic.Platform.fullScreen($scope.minimal, !$scope.minimal); - $interval.cancel(intervalHandle); //we will renew on reload - // We are reloading this view, so we don't want entry animations - $ionicHistory.nextViewOptions({ - disableAnimate: true, - disableBack: true - }); - $state.go("montage", { - minimal: $scope.minimal, - isRefresh: true - }); - }; - //--------------------------------------------------------------------- // Show/Hide PTZ control in monitor view //--------------------------------------------------------------------- @@ -1156,7 +765,7 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc }); $scope.$on('$ionicView.enter', function () { - NVRDataModel.debug("**VIEW ** MontageHistory Ctrl Entered, Starting loadNotifications"); + NVRDataModel.debug("**VIEW ** MontageHistory Ctrl Entered"); var ld = NVRDataModel.getLogin(); //console.log("Setting Awake to " + NVRDataModel.getKeepAwake()); NVRDataModel.setAwake(NVRDataModel.getKeepAwake()); @@ -1232,6 +841,9 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc } } + pckry.destroy(); + window.removeEventListener("resize", orientationChanged, false); + NVRDataModel.log("Forcing a window.stop() here"); NVRDataModel.stopNetwork("MontageHistory-beforeLeave"); @@ -1244,6 +856,130 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc }); + + $scope.sliderChanged = function (dirn) { + console.log("SLIDER CHANGED"); + if ($scope.sliderChanging) { + // console.log ("too fast my friend"); + //$scope.slider.monsize = oldSliderVal; + // return; + } + + $scope.sliderChanging = true; + + var somethingReset = false; + + // this only changes items that are selected + for (var i = 0; i < $scope.MontageMonitors.length; i++) { + + var curVal = parseInt($scope.MontageMonitors[i].Monitor.gridScale); + curVal = curVal + (10 * dirn); + if (curVal < 10) curVal = 10; + if (curVal > 100) curVal = 100; + //console.log ("For Index: " + i + " From: " + $scope.MontageMonitors[i].Monitor.gridScale + " To: " + curVal); + + if ($scope.isDragabillyOn) { + // only do this for selected monitors + if ($scope.MontageMonitors[i].Monitor.selectStyle == "dragborder-selected") { + + $scope.MontageMonitors[i].Monitor.gridScale = curVal; + somethingReset = true; + } + } else { + $scope.MontageMonitors[i].Monitor.gridScale = curVal; + //somethingReset = true; + + } + + } + + // this changes all items if none were selected + if (!somethingReset && $scope.isDragabillyOn) // nothing was selected + { + for (i = 0; i < $scope.MontageMonitors.length; i++) { + var cv = parseInt($scope.MontageMonitors[i].Monitor.gridScale); + cv = cv + (10 * dirn); + if (cv < 10) cv = 10; + if (cv > 100) cv = 100; + $scope.MontageMonitors[i].Monitor.gridScale = cv; + } + } + + + //pckry.reloadItems(); + + pckry.once('layoutComplete', function () { + /* $timeout(function () { + var positions = pckry.EHgetShiftPositions('eh-data-item-id'); + //console.log ("POSITIONS MAP " + JSON.stringify(positions)); + var ld = NVRDataModel.getLogin(); + ld.EHpackeryPositions = JSON.stringify(positions); + NVRDataModel.setLogin(ld); + $ionicLoading.hide(); + $scope.sliderChanging = false; + }, zm.packeryTimer);*/ + }); + + + + if (!somethingReset) { + //console.log (">>>SOMETHING NOT RESET"); + $timeout(function () { + pckry.layout(); + }, zm.packeryTimer); + } else { + + //console.log (">>>SOMETHING RESET"); + $timeout(function () { + layout(pckry); + }, zm.packeryTimer); + } + + + + + }; + + function layout(pckry) { + pckry.shiftLayout(); + } + + + + $scope.resetSizes = function () { + var somethingReset = false; + for (var i = 0; i < $scope.MontageMonitors.length; i++) { + if ($scope.isDragabillyOn) { + if ($scope.MontageMonitors[i].Monitor.selectStyle == "dragborder-selected") { + $scope.MontageMonitors[i].Monitor.gridScale = "50"; + somethingReset = true; + } + } else { + $scope.MontageMonitors[i].Monitor.gridScale = "50"; + // somethingReset = true; + } + } + if (!somethingReset && $scope.isDragabillyOn) // nothing was selected + { + for (i = 0; i < $scope.MontageMonitors.length; i++) { + $scope.MontageMonitors[i].Monitor.gridScale = "50"; + } + } + + $timeout(function () { + pckry.reloadItems(); + + + $timeout(function () { + pckry.layout(); + }, zm.packeryTimer); // force here - no shiftlayout + + + }, 100); + + }; + + //--------------------------------------------------------- // This function readjusts montage size // and stores current size to persistent memory @@ -1275,8 +1011,165 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc sizeInProgress = false; } + function isEmpty(obj) { + for (var prop in obj) { + return false; + } + return true; + } + + // called by afterEnter to load Packery + function initPackery() { + + console.log(">>>>>>>>>>>>>>>>> HIT INIT"); + $ionicLoading.show({ + template: $translate.instant('kArrangingImages'), + noBackdrop: true, + duration: zm.loadingTimeout + }); + + var progressCalled = false; + draggies = []; + var layouttype = true; + var ld = NVRDataModel.getLogin(); + + + var positionsStr = ld.packeryPositions; + var positions = {}; + + // if (positionsStr == '') { + if (1) { + + NVRDataModel.log("Did NOT find a EHpackery layout"); + layouttype = true; + } else { + + //console.log ("POSITION STR IS " + positionsStr); + positions = JSON.parse(positionsStr); + NVRDataModel.log("found a EHpackery layout"); + console.log(positionsStr); + layouttype = false; + } + + + var cnt = 0; + $scope.MontageMonitors.forEach(function (elem) { + + if ((elem.Monitor.Enabled != '0') && (elem.Monitor.Function != 'None')) + cnt++; + }); + + NVRDataModel.log("Monitors that are active and not DOM hidden: " + cnt + " while grid has " + positions.length); + + if (cnt > NVRDataModel.getLogin().maxMontage) { + cnt = NVRDataModel.getLogin().maxMontage; + NVRDataModel.log("restricting monitor count to " + cnt + " due to max-montage setting"); + } + + /*if (cnt != positions.length) { + + NVRDataModel.log("Whoops!! Monitors have changed. I'm resetting layouts, sorry!"); + layouttype = true; + positions = {}; + }*/ + + var elem = angular.element(document.getElementById("mygrid")); + + //console.log ("**** mygrid is " + JSON.stringify(elem)); + + imagesLoaded(elem).on('progress', function (instance, img) { + + progressCalled = true; + + // if (layouttype) $timeout (function(){layout(pckry);},100); + }); + + imagesLoaded(elem).once('always', function () { + console.log("******** ALL IMAGES LOADED"); + NVRDataModel.debug("All images loaded"); + + + $ionicLoading.hide(); + + pckry = new Packery('.grid', { + itemSelector: '.grid-item', + percentPosition: true, + columnWidth: '.grid-sizer', + gutter: 0, + initLayout: layouttype + + }); + if (!progressCalled) { + NVRDataModel.log("*** BUG PROGRESS WAS NOT CALLED"); + pckry.reloadItems(); + + } + + $timeout(function () { + var cnt = 0; + pckry.getItemElements().forEach(function (itemElem) { + console.log("DRAG ADD " + cnt++); + draggie = new Draggabilly(itemElem); + pckry.bindDraggabillyEvents(draggie); + draggies.push(draggie); + draggie.disable(); + draggie.unbindHandles(); + }); + pckry.on('dragItemPositioned', itemDragged); + + + + if (!isEmpty(positions)) { + NVRDataModel.log("Arranging as per packery grid"); + + for (var i = 0; i < $scope.MontageMonitors.length; i++) { + for (var j = 0; j < positions.length; j++) { + if ($scope.MontageMonitors[i].Monitor.Id == positions[j].attr) { + $scope.MontageMonitors[i].Monitor.gridScale = positions[j].size; + $scope.MontageMonitors[i].Monitor.listDisplay = positions[j].display; + NVRDataModel.debug("Setting monitor ID: " + $scope.MontageMonitors[i].Monitor.Id + " to size: " + positions[j].size + " and display:" + positions[j].display); + } + //console.log ("Index:"+positions[j].attr+ " with size: " + positions[j].size); + } + } + + + NVRDataModel.debug("All images loaded, doing image layout"); + /* $timeout(function () { + pckry.initShiftLayout(positions, 'eh-data-item-id'); + }, 0);*/ + } + $timeout(function () { + NVRDataModel.log("Force calling resize"); + pckry.layout(); + $scope.allImagesLoaded = true; + }, zm.packeryTimer); // don't ask + + + + }, zm.packeryTimer); + + }); + + function itemDragged(item) { + NVRDataModel.debug("drag complete"); + + //pckry.getItemElements().forEach(function (itemElem) { + + //console.log (itemElem.attributes['data-item-id'].value+" size "+itemElem.attributes['data-item-size'].value ); + // }); + + /* var positions = pckry.EHgetShiftPositions('eh-data-item-id'); + //console.log ("POSITIONS MAP " + JSON.stringify(positions)); + var ld = NVRDataModel.getLogin(); + ld.EHpackeryPositions = JSON.stringify(positions); + NVRDataModel.setLogin(ld);*/ + } + + + } $scope.$on('$ionicView.afterEnter', function () { @@ -1284,6 +1177,10 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc // I am making sure the image in montage view is always fresh // I don't think I am using this anymore FIXME: check and delete if needed // $rootScope.rand = Math.floor((Math.random() * 100000) + 1); + + $timeout(function () { + initPackery(); + }, zm.packeryTimer); }); $scope.reloadView = function () { @@ -1309,5 +1206,308 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc }); }; + //--------------------------------------------------------------------- + // Controller main + //--------------------------------------------------------------------- + + + + var intervalHandle; + $scope.isModalActive = false; + var modalIntervalHandle; + + window.addEventListener("resize", orientationChanged, false); + + document.addEventListener("pause", onPause, false); + document.addEventListener("resume", onResume, false); + + $scope.timeFormat = "yyyy-MM-dd " + NVRDataModel.getTimeFormat(); + $scope.displayDateTimeSliders = true; + $scope.showtimers = true; + $scope.loginData = NVRDataModel.getLogin(); + + var curYear = new Date().getFullYear(); + + var readyToRun = false; + var i; + + $scope.sliderVal = { + + rate: 1, + realRate: 100, + hideNoEvents: false, + enableGapless: true, + exactMatch: false, + showTimeline: true + + }; + + + + // default = start of day + var timeto = moment(); + var timefrom = moment().startOf('day'); + + $scope.sliderVal.rate = 1; + $scope.sliderVal.realRate = $scope.sliderVal.rate * 100; + + + + //var tdatetimeValueFrom = new Date(); + //tdatetimeValueFrom.setDate(tdatetimeValueFrom.getDate()-1); + + $scope.datetimeValueFrom = { + value: "" + }; + $scope.datetimeValueTo = { + value: "" + }; + + $scope.datetimeValueFrom.value = timefrom.toDate(); + $scope.datetimeValueTo.value = timeto.toDate(); + + $rootScope.eventQueryInterval = ""; + + + var commonCss = { + + background: { + "background-color": "silver" + }, + before: { + "background-color": "purple" + }, + default: { + "background-color": "white" + }, // default value: 1px + after: { + "background-color": "green" + }, // zone after default value + pointer: { + "background-color": "red" + }, // circle pointer + range: { + "background-color": "red" + } // use it if double value + }; + + + $scope.slider_modal_options_rate = { + from: 1, + to: 10, + realtime: true, + step: 1, + className: "mySliderClass", + //modelLabels:function(val) {return "";}, + smooth: false, + css: commonCss, + dimension: 'X' + + }; + + + + var isLongPressActive = false; + $scope.isReorder = false; + var intervalHandleMontage; // will hold image resize timer on long press + var montageIndex = 0; // will hold monitor ID to scale in timer + + var gridcontainer, pckry, draggie, draggies; + + $scope.monitorSize = []; // array with montage sizes per monitor + $scope.scaleDirection = []; // 1 = increase -1 = decrease + + $scope.slider = {}; + + //console.log ("************ HISTORY " + NVRDataModel.getMontageSize()); + $scope.slider.monsize = NVRDataModel.getMontageSize(); + $scope.revMonSize = 11 - parseInt($scope.slider.monsize); + + // The difference between old and original is this: + // old will have a copy of the last re-arranged monitor list + // while original will have a copy of the order returned by ZM + + var oldMonitors = []; // To keep old order if user cancels after sort; + + // Montage display order may be different so don't + // mangle monitors as it will affect other screens + // in Montage screen we will work with this local copy + //$scope.MontageMonitors = angular.copy ($scope.monitors); + + var montageOrder = []; // This array will keep the ordering in montage view + var hiddenOrder = []; // 1 = hide, 0 = don't hide + + var tempMonitors = message; + if (tempMonitors.length == 0) { + $rootScope.zmPopup = $ionicPopup.alert({ + title: $translate.instant('kNoMonitors'), + template: $translate.instant('kPleaseCheckCredentials') + }); + $ionicHistory.nextViewOptions({ + disableBack: true + }); + $state.go("login"); + return; + } + + // console.log ("TEMP MONITORS IS " + JSON.stringify(tempMonitors)); + + $scope.monitors = tempMonitors; + + NVRDataModel.log("Inside MontageHistoryCtrl:We found " + $scope.monitors.length + " monitors"); + + // $scope.MontageMonitors = NVRDataModel.applyMontageMonitorPrefs(message, 1)[0]; + + $scope.MontageMonitors = message; + var loginData = NVRDataModel.getLogin(); + + $scope.packMontage = loginData.packMontage; + + + // init monitors + NVRDataModel.debug(">>Initializing connkeys and images..."); + for (i = 0; i < $scope.MontageMonitors.length; i++) { + //$scope.MontageMonitors[i].Monitor.connKey=''; + + + $scope.MontageMonitors[i].Monitor.connKey = (Math.floor((Math.random() * 999999) + 1)).toString(); + $scope.MontageMonitors[i].Monitor.eventUrl = 'img/noevent.png'; + $scope.MontageMonitors[i].Monitor.eventUrlTime = ""; + $scope.MontageMonitors[i].Monitor.isPaused = false; + $scope.MontageMonitors[i].Monitor.gridScale = "50"; + $scope.MontageMonitors[i].Monitor.selectStyle = ""; + $scope.MontageMonitors[i].Monitor.alarmState = 'color:rgba(0,0,0,0);'; + + } + readyToRun = true; + + + + // -------------------------------------------------------- + // Handling of back button in case modal is open should + // close the modal + // -------------------------------------------------------- + + $ionicPlatform.registerBackButtonAction(function (e) { + e.preventDefault(); + if ($scope.modal && $scope.modal.isShown()) { + // switch off awake, as liveview is finished + NVRDataModel.debug("Modal is open, closing it"); + NVRDataModel.setAwake(false); + $scope.modal.remove(); + $scope.isModalActive = false; + } else { + NVRDataModel.debug("Modal is closed, so toggling or exiting"); + if (!$ionicSideMenuDelegate.isOpenLeft()) { + $ionicSideMenuDelegate.toggleLeft(); + + } else { + navigator.app.exitApp(); + } + + } + + }, 1000); + + + + + $scope.showSizeButtons = false; + $ionicPopover.fromTemplateUrl('templates/help/montage-help.html', { + scope: $scope, + }).then(function (popover) { + $scope.popover = popover; + }); + + var timestamp = new Date().getUTCMilliseconds(); + $scope.minimal = $stateParams.minimal; + $scope.zmMarginTop = $scope.minimal ? 0 : 15; + //console.log ("********* MARGIN IS " + $scope.zmMarginTop); + + $scope.isRefresh = $stateParams.isRefresh; + var sizeInProgress = false; + $scope.imageStyle = true; + + $ionicSideMenuDelegate.canDragContent(true); + + + + // Do we have a saved montage array size? No? + // if (window.localStorage.getItem("montageArraySize") == undefined) { + if (loginData.montageArraySize == '0') { + + for (i = 0; i < $scope.monitors.length; i++) { + $scope.monitorSize.push(NVRDataModel.getMontageSize()); + $scope.scaleDirection.push(1); + } + } else // recover previous settings + { + var msize = loginData.montageArraySize; + //console.log("MontageArrayString is=>" + msize); + $scope.monitorSize = msize.split(":"); + var j; + + for (j = 0; j < $scope.monitorSize.length; j++) { + // convert to number other wise adding to it concatenates :-) + $scope.monitorSize[j] = parseInt($scope.monitorSize[j]); + $scope.scaleDirection.push(1); + //console.log("Montage size for monitor " + j + " is " + $scope.monitorSize[j]); + + } + + } + // $scope.monitorSize = monitorSize; + // $scope.scaleDirection = scaleDirection; + + $scope.LoginData = NVRDataModel.getLogin(); + $scope.monLimit = $scope.LoginData.maxMontage; + $scope.currentLimit = $scope.LoginData.maxMontage; + + if ($rootScope.platformOS != 'ios') { + NVRDataModel.log("Limiting montage to 5, thanks to Chrome's stupid connection limit"); + $scope.monLimit = 5; + $scope.currentLimit = 5; + } + + //console.log("********* Inside MontageHistoryCtrl, MAX LIMIT=" + $scope.monLimit); + + + $rootScope.authSession = "undefined"; + $ionicLoading.show({ + template: $translate.instant('kNegotiatingStreamAuth'), + animation: 'fade-in', + showBackdrop: true, + duration: zm.loadingTimeout, + maxWidth: 300, + showDelay: 0 + }); + + + var ld = NVRDataModel.getLogin(); + + //console.log ("MONITORS " + JSON.stringify($scope.monitors)); + $rootScope.validMonitorId = $scope.monitors[0].Monitor.Id; + NVRDataModel.getAuthKey($rootScope.validMonitorId) + .then(function (success) { + $ionicLoading.hide(); + //console.log(success); + $rootScope.authSession = success; + NVRDataModel.log("Stream authentication construction: " + + $rootScope.authSession); + + }, + function (error) { + + $ionicLoading.hide(); + NVRDataModel.debug("MontageHistoryCtrl: Error in authkey retrieval " + error); + //$rootScope.authSession=""; + NVRDataModel.log("MontageHistoryCtrl: Error returned Stream authentication construction. Retaining old value of: " + $rootScope.authSession); + }); + + + + + + }]);
\ No newline at end of file |
