diff options
| author | PliablePixels <pliablepixels@gmail.com> | 2015-07-10 10:51:25 -0400 |
|---|---|---|
| committer | PliablePixels <pliablepixels@gmail.com> | 2015-07-10 10:51:25 -0400 |
| commit | 5f6b169c321722e51f1e0b7ac0eaea7d7e47e433 (patch) | |
| tree | e1633fa74673566df283bef3f19ba035abb5c617 /www/js/MontageCtrl.js | |
| parent | 2559905b54b77668361d8a1325a46d5183e61aa5 (diff) | |
You can now rerrange and hide monitors in montage
Diffstat (limited to 'www/js/MontageCtrl.js')
| -rw-r--r-- | www/js/MontageCtrl.js | 417 |
1 files changed, 327 insertions, 90 deletions
diff --git a/www/js/MontageCtrl.js b/www/js/MontageCtrl.js index 9bee1a89..66c87b23 100644 --- a/www/js/MontageCtrl.js +++ b/www/js/MontageCtrl.js @@ -4,7 +4,7 @@ /* global cordova,StatusBar,angular,console,ionic */ -angular.module('zmApp.controllers').controller('zmApp.MontageCtrl', ['$scope', '$rootScope', 'ZMDataModel', 'message', '$ionicSideMenuDelegate', '$timeout', '$interval', '$ionicModal', '$ionicLoading', '$http', '$state', '$stateParams','$ionicHistory','$ionicScrollDelegate', '$ionicPlatform', function ($scope, $rootScope, ZMDataModel, message, $ionicSideMenuDelegate, $timeout, $interval, $ionicModal, $ionicLoading, $http,$state, $stateParams, $ionicHistory,$ionicScrollDelegate) { +angular.module('zmApp.controllers').controller('zmApp.MontageCtrl', ['$scope', '$rootScope', 'ZMDataModel', 'message', '$ionicSideMenuDelegate', '$timeout', '$interval', '$ionicModal', '$ionicLoading', '$http', '$state', '$ionicPopup', '$stateParams', '$ionicHistory', '$ionicScrollDelegate', '$ionicPlatform', function ($scope, $rootScope, ZMDataModel, message, $ionicSideMenuDelegate, $timeout, $interval, $ionicModal, $ionicLoading, $http, $state, $ionicPopup, $stateParams, $ionicHistory, $ionicScrollDelegate) { //--------------------------------------------------------------------- // Controller main @@ -13,13 +13,15 @@ angular.module('zmApp.controllers').controller('zmApp.MontageCtrl', ['$scope', ' document.addEventListener("pause", onPause, false); - var timestamp = new Date().getUTCMilliseconds(); $scope.minimal = $stateParams.minimal; $scope.isRefresh = $stateParams.isRefresh; var sizeInProgress = false; + $ionicSideMenuDelegate.canDragContent(false); + 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 @@ -29,47 +31,120 @@ angular.module('zmApp.controllers').controller('zmApp.MontageCtrl', ['$scope', ' $scope.slider = {}; $scope.slider.monsize = ZMDataModel.getMontageSize(); - console.log ("******** HAVE ALL MONITORS"); + console.log("******** HAVE ALL MONITORS"); $scope.monitors = message; + // 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 - // Do we have a saved montage array size? No? - if (window.localStorage.getItem("montageArraySize") == undefined) - { + var oldMonitors = []; // To keep old order if user cancels after sort; - for ( var i = 0; i<$scope.monitors.length; i++) - { - $scope.monitorSize.push(ZMDataModel.getMontageSize() ); - $scope.scaleDirection.push(1); + // 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 + + + // First let's check if the user already has a saved monitor order + var i; + if (window.localStorage.getItem("montageOrder") == undefined) { + + for (i = 0; i < $scope.monitors.length; i++) { + montageOrder[i] = i; // order to show is order ZM returns + hiddenOrder[i] = 0; // don't hide them } + console.log("Order string is " + montageOrder.toString()); + console.log("Hiddent string is " + hiddenOrder.toString()); + + ZMDataModel.zmLog("Stored montage order does not exist"); + } else + // there is a saved order + { + var myorder = window.localStorage.getItem("montageOrder"); + var myhiddenorder = window.localStorage.getItem("montageHiddenOrder"); + + console.log("Montage order is " + myorder); + console.log("Hidden order is " + myhiddenorder); + montageOrder = myorder.split(","); + hiddenOrder = myhiddenorder.split(","); + + // at this stage, the monitor arrangement is not matching + // the montage order. Its in true order. Let us first process the hiddenOrder part + // now + + for (i = 0; i < montageOrder.length; i++) { + montageOrder[i] = parseInt(montageOrder[i]); + hiddenOrder[i] = parseInt(hiddenOrder[i]); + // $scope.monitors[i].Monitor.sortOrder = montageOrder[i]; + // FIXME: This will briefly show and then hide + // disabled monitors + if (hiddenOrder[i] == 1) { + // $scope.monitors[i].Monitor.listDisplay='noshow'; + $scope.monitors[i].Monitor.listDisplay = 'noshow'; + ZMDataModel.zmLog("Monitor " + i + " is marked as hidden in montage"); + } else { + $scope.monitors[i].Monitor.listDisplay = 'show'; + } + } + // now arrange monitors according to montage order + // FIXME: Incredibly horrible logic + // I really need to organize this properly into one structure + + // empty out monitors as I'll need to insert them as per montageOrder + // remember to assign + $scope.MontageMonitors = []; + + for (i = 0; i < montageOrder.length; i++) { + for (j = 0; j < montageOrder.length; j++) { + if (montageOrder[j] == i) { + $scope.MontageMonitors.push($scope.monitors[j]); + } + } + } + + + ZMDataModel.zmLog("After reloading saved order, view order is " + montageOrder.toString() + " and hidden order is " + hiddenOrder.toString()); + } - else // recover previous settings + + + // Do we have a saved montage array size? No? + if (window.localStorage.getItem("montageArraySize") == undefined) { + + for (i = 0; i < $scope.monitors.length; i++) { + $scope.monitorSize.push(ZMDataModel.getMontageSize()); + $scope.scaleDirection.push(1); + } + } else // recover previous settings { var msize = window.localStorage.getItem("montageArraySize"); - console.log ("MontageArrayString is=>"+msize); - $scope.monitorSize= msize.split(":"); + console.log("MontageArrayString is=>" + msize); + $scope.monitorSize = msize.split(":"); var j; - for ( j = 0; j<$scope.monitorSize.length; 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]); + console.log("Montage size for monitor " + j + " is " + $scope.monitorSize[j]); } } - console.log ("******** SETTING VARS"); - // $scope.monitorSize = monitorSize; - // $scope.scaleDirection = scaleDirection; + console.log("******** SETTING VARS"); + // $scope.monitorSize = monitorSize; + // $scope.scaleDirection = scaleDirection; $scope.LoginData = ZMDataModel.getLogin(); $scope.monLimit = $scope.LoginData.maxMontage; console.log("********* Inside Montage Ctrl, MAX LIMIT=" + $scope.monLimit); - // I was facing a lot of problems with Chrome/crosswalk getting stuck with + // 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 @@ -87,72 +162,242 @@ angular.module('zmApp.controllers').controller('zmApp.MontageCtrl', ['$scope', ' var intervalHandle = $interval(function () { this.loadNotifications(); - // console.log ("Refreshing Image..."); + // console.log ("Refreshing Image..."); }.bind(this), 1000); this.loadNotifications(); + //------------------------------------------------------------- + // Called when user taps on the reorder button + //------------------------------------------------------------- + + $scope.toggleReorder = function () { + $scope.isReorder = !$scope.isReorder; + + var i; + oldMonitors = angular.copy($scope.monitors); + /*for (i=0; i<$scope.monitors.length; i++) + { + $scope.monitors[i].Monitor.listDisplay="show"; + }*/ + + + var getConfig = $ionicPopup.show({ + scope: $scope, + template: '<ion-scroll><ion-list show-delete="true" show-reorder="true">' + + '<ion-item class="item-remove-animate" ng-repeat="item in MontageMonitors"> ' + + '{{item.Monitor.Name}}' + + '<ion-delete-button ng-class="' + + '{\'ion-eye\':item.Monitor.listDisplay==\'show\',' + + '\'ion-eye-disabled\':item.Monitor.listDisplay!=\'show\'}"' + + 'ng-click="deleteItem($index)">' + + '</ion-delete-button>' + + '<ion-reorder-button class="ion-navicon" ' + + 'on-reorder="reorderItem(item, $fromIndex, $toIndex)">' + + '</ion-reorder-button></ion-item></ion-list></ion-scroll>', + + title: "Edit Montage", + buttons: [ + { + // user tapped Ok + type: 'button-block icon ion-checkmark-round', + onTap: function (e) { + window.localStorage.setItem("montageOrder", montageOrder.toString()); + window.localStorage.setItem("montageHiddenOrder", hiddenOrder.toString()); + console.log("Saved " + montageOrder.toString()); + ZMDataModel.zmLog("User press OK. Saved Monitor Order as: " + montageOrder.toString() + " and hidden order as " + hiddenOrder.toString()); + } + }, + { + type: 'button-block icon ion-close-round', + onTap: function (e) { + // user tapped cancel + var i; + 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()); + ZMDataModel.zmLog("User press Cancel. Reset Monitor Order to: " + montageOrder.toString()); + } else { + var myorder = window.localStorage.getItem("montageOrder"); + var myhiddenorder = window.localStorage.getItem("montageHiddenOrder"); + console.log("Montage order is " + myorder + " and hidden order is " + myhiddenorder); + montageOrder = myorder.split(","); + hiddenOrder = myhiddenorder.split(","); + for (i = 0; i < montageOrder.length; i++) { + montageOrder[i] = parseInt(montageOrder[i]); + hiddenOrder[i] = parseInt(hiddenOrder[i]); + } + + $scope.MontageMonitors = oldMonitors; + ZMDataModel.zmLog("User press Cancel. Restored Monitor Order as: " + montageOrder.toString() + " and hidden order as: " + hiddenOrder.toString()); + + } + + } + }, + { + type: 'button-block icon ion-loop', + onTap: function (e) { + // user tapped refresh, so don't close this dialog + e.preventDefault(); + + // FIXME: list visually expands then resets + // why? + var refresh = ZMDataModel.getMonitors(1); + refresh.then(function (data) { + $scope.monitors = data; + oldMonitors = angular.copy($scope.monitors); + var i; + montageOrder = []; + for (i = 0; i < $scope.monitors.length; i++) { + montageOrder[i] = i; + hiddenOrder[i] = 0; + } + window.localStorage.setItem("montageOrder", montageOrder.toString()); + window.localStorage.setItem("montageHiddenOrder", hiddenOrder.toString()); + ZMDataModel.zmLog("Montage order saved on refresh: " + montageOrder.toString() + " and hidden order: " + hiddenOrder.toString()); + + }); + } + } + ] + }); + }; + + //--------------------------------------------------------------------- + // This marks a monitor as hidden in montage view + //--------------------------------------------------------------------- + + $scope.deleteItem = function (index) { + var findindex = montageOrder.indexOf(index); + // $scope.monitors[index].Monitor.Function = 'None'; + if ($scope.monitors[index].Monitor.listDisplay == 'show') { + $scope.monitors[index].Monitor.listDisplay = 'noshow'; + hiddenOrder[findindex] = 1; + } else { + $scope.monitors[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 + + 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()); + ZMDataModel.zmLog("Marked monitor " + findindex + " as " + $scope.monitors[index].Monitor.listDisplay + " in montage"); + + }; + + //--------------------------------------------------------------------- + // When we re-arrange the montage, all the ordering index moves + // horrible horrible code + //--------------------------------------------------------------------- + + function reorderItem(item, from, to, reorderHidden) { + + console.log("FROM " + from + " TO " + to); + $scope.MontageMonitors.splice(from, 1); + $scope.MontageMonitors.splice(to, 0, item); + + // Now we need to re-arrange the montageOrder + // hiddenOrder remains the same + + 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; + } + } + } + ZMDataModel.zmLog("New Montage Order is: " + montageOrder.toString()); + + } + + + $scope.reorderItem = function (item, from, to) { + reorderItem(item, from, to, true); + }; //--------------------------------------------------------------------- // Triggered when you enter/exit full screen //--------------------------------------------------------------------- - $scope.switchMinimal = function() - { + $scope.switchMinimal = function () { $scope.minimal = !$scope.minimal; - console.log ("Hide Statusbar"); - ionic.Platform.fullScreen($scope.minimal,!$scope.minimal); - $interval.cancel(intervalHandle); //we will renew on reload + 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}); - }; + disableAnimate: true, + disableBack: true + }); + $state.go("montage", { + minimal: $scope.minimal, + isRefresh: true + }); + }; //--------------------------------------------------------------------- // Show/Hide PTZ control in monitor view //--------------------------------------------------------------------- - $scope.togglePTZ = function () { + $scope.togglePTZ = function () { $scope.showPTZ = !$scope.showPTZ; }; + $scope.callback = function () { + console.log("dragging"); + }; + + + $scope.onDropComplete = function (index, obj, event) { + console.log("dragged"); + var otherObj = $scope.monitors[index]; + var otherIndex = $scope.monitors.indexOf(obj); + $scope.monitors[index] = obj; + $scope.monitors[otherIndex] = otherObj; + }; + + //--------------------------------------------------------------------- // main monitor modal open //--------------------------------------------------------------------- - $scope.openModal = function (mid, controllable, controlid) { - console.log("Open Monitor Modal with monitor Id=" + mid + " and Controllable:" + controllable + " with control ID:"+controlid); + $scope.openModal = function (mid, controllable, controlid) { + console.log("Open Monitor Modal with monitor Id=" + mid + " and Controllable:" + controllable + " with control ID:" + controlid); // Note: no need to setAwake(true) as its already awake // in montage view $scope.monitorId = mid; $scope.LoginData = ZMDataModel.getLogin(); $scope.rand = Math.floor(Math.random() * (999999 - 111111 + 1)) + 111111; - $scope.ptzMoveCommand = ""; + $scope.ptzMoveCommand = ""; // This is a modal to show the monitor footage // We need to switch to always awake if set so the feed doesn't get interrupted ZMDataModel.setAwake(ZMDataModel.getKeepAwake()); - // if its controllable, lets get the control command - if (controllable == '1') - { + // if its controllable, lets get the control command + if (controllable == '1') { var apiurl = $scope.LoginData.apiurl; - var myurl = apiurl+"/controls/"+controlid+".json"; - console.log ("getting control details:"+myurl); + var myurl = apiurl + "/controls/" + controlid + ".json"; + console.log("getting control details:" + myurl); $http.get(myurl) - .success(function(data) { - $scope.ptzMoveCommand = (data.control.Control.CanMoveCon == '1')? 'moveCon':'move'; - console.log("***moveCommand: " +$scope.ptzMoveCommand ); - ZMDataModel.zmLog ("ControlDB reports PTZ command to be " + $scope.ptzMoveCommand ); - }) - .error(function(data) { - console.log ("** Error retrieving move PTZ command"); - ZMDataModel.zmLog ("Error retrieving PTZ command " + JSON.stringify(data),"error"); - }); + .success(function (data) { + $scope.ptzMoveCommand = (data.control.Control.CanMoveCon == '1') ? 'moveCon' : 'move'; + console.log("***moveCommand: " + $scope.ptzMoveCommand); + ZMDataModel.zmLog("ControlDB reports PTZ command to be " + $scope.ptzMoveCommand); + }) + .error(function (data) { + console.log("** Error retrieving move PTZ command"); + ZMDataModel.zmLog("Error retrieving PTZ command " + JSON.stringify(data), "error"); + }); } // This is a modal to show the monitor footage @@ -168,7 +413,7 @@ angular.module('zmApp.controllers').controller('zmApp.MontageCtrl', ['$scope', ' noBackdrop: true, duration: 15000 }); - $scope.isControllable = controllable; + $scope.isControllable = controllable; $scope.showPTZ = false; $scope.modal.show(); }); @@ -190,29 +435,27 @@ angular.module('zmApp.controllers').controller('zmApp.MontageCtrl', ['$scope', ' //--------------------------------------------------------------------- // allows you to resize individual montage windows //--------------------------------------------------------------------- - function scaleMontage() - { + function scaleMontage() { var index = montageIndex; - console.log (" MONTAGE INDEX === " + montageIndex); - console.log ("Scaling Monitor " + index); - if ($scope.monitorSize[index] == 6) + console.log(" MONTAGE INDEX === " + montageIndex); + console.log("Scaling Monitor " + index); + if ($scope.monitorSize[index] == 6) $scope.scaleDirection[index] = -1; if ($scope.monitorSize[index] == 1) $scope.scaleDirection[index] = 1; - $scope.monitorSize[index] += $scope.scaleDirection[index] ; + $scope.monitorSize[index] += $scope.scaleDirection[index]; - console.log ("Changed size to "+$scope.monitorSize[index]); + console.log("Changed size to " + $scope.monitorSize[index]); var monsizestring = ""; var i; - for ( i = 0; i<$scope.monitors.length; i++) - { - monsizestring = monsizestring + $scope.monitorSize[i]+':'; + for (i = 0; i < $scope.monitors.length; i++) { + monsizestring = monsizestring + $scope.monitorSize[i] + ':'; } - monsizestring = monsizestring.slice(0,-1); // kill last : - console.log ("Setting monsize string:"+monsizestring); + monsizestring = monsizestring.slice(0, -1); // kill last : + console.log("Setting monsize string:" + monsizestring); window.localStorage.setItem("montageArraySize", monsizestring); } @@ -220,11 +463,10 @@ angular.module('zmApp.controllers').controller('zmApp.MontageCtrl', ['$scope', ' // if you long press on a montage window, it calls scale montage // at a 200ms freq //--------------------------------------------------------------------- - $scope.onHold = function (index) - { + $scope.onHold = function (index) { montageIndex = index; isLongPressActive = true; - intervalHandleMontage = $interval(function () { + intervalHandleMontage = $interval(function () { scaleMontage(); }.bind(this), 200); @@ -234,9 +476,8 @@ angular.module('zmApp.controllers').controller('zmApp.MontageCtrl', ['$scope', ' //--------------------------------------------------------------------- // stop scaling montage window on release //--------------------------------------------------------------------- - $scope.onRelease = function (index) - { - console.log ("Press release on " + index); + $scope.onRelease = function (index) { + console.log("Press release on " + index); isLongPressActive = false; $interval.cancel(intervalHandleMontage); }; @@ -275,7 +516,7 @@ angular.module('zmApp.controllers').controller('zmApp.MontageCtrl', ['$scope', ' $scope.$on('$ionicView.enter', function () { console.log("**VIEW ** Montage Ctrl Entered"); - console.log ("Setting Awake to "+ZMDataModel.getKeepAwake()); + console.log("Setting Awake to " + ZMDataModel.getKeepAwake()); ZMDataModel.setAwake(ZMDataModel.getKeepAwake()); }); @@ -292,28 +533,26 @@ angular.module('zmApp.controllers').controller('zmApp.MontageCtrl', ['$scope', ' // and stores current size to persistent memory //--------------------------------------------------------- - function processSliderChanged(val) - { + function processSliderChanged(val) { if (sizeInProgress) return; sizeInProgress = true; console.log('Size has changed'); ZMDataModel.setMontageSize(val); console.log("ZMData Montage is " + ZMDataModel.getMontageSize() + - " and slider montage is " + $scope.slider.monsize); + " and slider montage is " + $scope.slider.monsize); // Now go ahead and reset sizes of entire monitor array - var monsizestring=""; + var monsizestring = ""; var i; - for ( i = 0; i<$scope.monitors.length; i++) - { + for (i = 0; i < $scope.monitors.length; i++) { $scope.monitorSize[i] = parseInt(ZMDataModel.getMontageSize()); - console.log ("Resetting Monitor "+i+" size to " +$scope.monitorSize[i]); + console.log("Resetting Monitor " + i + " size to " + $scope.monitorSize[i]); $scope.scaleDirection[i] = 1; - monsizestring = monsizestring + $scope.monitorSize[i]+':'; + monsizestring = monsizestring + $scope.monitorSize[i] + ':'; } - monsizestring = monsizestring.slice(0,-1); // kill last : - console.log ("Setting monsize string:"+monsizestring); + monsizestring = monsizestring.slice(0, -1); // kill last : + console.log("Setting monsize string:" + monsizestring); window.localStorage.setItem("montageArraySize", monsizestring); sizeInProgress = false; } @@ -323,14 +562,13 @@ angular.module('zmApp.controllers').controller('zmApp.MontageCtrl', ['$scope', ' // as slider is hidden //--------------------------------------------------------- - $scope.changeSize = function (val) - { - var newSize = parseInt($scope.slider.monsize) + val; + $scope.changeSize = function (val) { + var newSize = parseInt($scope.slider.monsize) + val; - $scope.slider.monsize = newSize; - if ($scope.slider.monsize < "1") $scope.slider.monsize = "1"; - if ($scope.slider.monsize > "6") $scope.slider.monsize = "6"; - processSliderChanged($scope.slider.monsize); + $scope.slider.monsize = newSize; + if ($scope.slider.monsize < "1") $scope.slider.monsize = "1"; + if ($scope.slider.monsize > "6") $scope.slider.monsize = "6"; + processSliderChanged($scope.slider.monsize); }; @@ -341,9 +579,8 @@ angular.module('zmApp.controllers').controller('zmApp.MontageCtrl', ['$scope', ' // a copy and the value never changes //--------------------------------------------------------- - $scope.sliderChanged = function () - { - processSliderChanged($scope.slider.monsize); + $scope.sliderChanged = function () { + processSliderChanged($scope.slider.monsize); }; $scope.$on('$ionicView.afterEnter', function () { |
