Skip to content

Commit

Permalink
you can now cycle in montage view between saved profiles. Still needs…
Browse files Browse the repository at this point in the history
… testing, but I never really test thoroughly. Where is the fun in that? #419
  • Loading branch information
pliablepixels committed Jan 8, 2017
1 parent 7d019a5 commit ccdf366
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 17 deletions.
29 changes: 28 additions & 1 deletion www/js/DataModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ angular.module('zmApp.controllers')
'enableBlog': true,
'use24hr': false,
'packeryPositions': '',
'currentMontageProfile': '',
'packeryPositionsArray': {},
'EHpackeryPositions': '',
'packerySizes': '',
Expand All @@ -133,6 +134,8 @@ angular.module('zmApp.controllers')
'vibrateOnPush': true,
'soundOnPush': true,
'cycleMonitors': false,
'cycleMontage': false,
'cycleMontageInterval': 10, // 10sec
'cycleMonitorsInterval': 10, // 10sec
'enableLowBandwidth': false,
'autoSwitchBandwidth': false,
Expand Down Expand Up @@ -262,8 +265,11 @@ angular.module('zmApp.controllers')
var positionsStr = loginData.packeryPositions;
//console.log ("positionStr="+positionsStr);
var positions = {};
if (loginData.packeryPositions != '')
if (loginData.packeryPositions != '' && loginData.packeryPositions != undefined)
{
console.log ("positions="+loginData.packeryPositions);


positions = JSON.parse(positionsStr);
for (var m = 0; m < monitors.length; m++)
{
Expand Down Expand Up @@ -861,6 +867,20 @@ angular.module('zmApp.controllers')

}

if (typeof loginData.cycleMontage == 'undefined')
{

loginData.cycleMontage = false;

}

if (typeof loginData.cycleMontageInterval == 'undefined')
{

loginData.cycleMontageInterval = 10;

}

if (typeof loginData.enableLowBandwidth == 'undefined')
{

Expand Down Expand Up @@ -908,6 +928,13 @@ angular.module('zmApp.controllers')

}

if (typeof loginData.currentMontageProfile == 'undefined')
{

loginData.currentMontageProfile = '';

}

if (typeof loginData.followTimeLine == 'undefined')
{

Expand Down
166 changes: 151 additions & 15 deletions www/js/MontageCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ angular.module('zmApp.controllers')

var intervalHandleMontage; // image re-load handler
var intervalHandleAlarmStatus; // status of each alarm state
var intervalHandleMontageCycle;

var gridcontainer;
var pckry, draggie;
Expand Down Expand Up @@ -45,12 +46,21 @@ angular.module('zmApp.controllers')
NVRDataModel.displayBanner('net', [ds]);
var ld = NVRDataModel.getLogin();
refreshSec = (NVRDataModel.getBandwidth() == 'lowbw') ? ld.refreshSecLowBW : ld.refreshSec;

$interval.cancel(intervalHandleMontage);
$interval.cancel(intervalHandleMontageCycle);


intervalHandleMontage = $interval(function()
{
loadNotifications();
}.bind(this), refreshSec * 1000);

intervalHandleMontageCycle = $interval(function()
{
cycleMontageProfiles();
}.bind(this), NVRDataModel.getLogin().cycleMontageInterval* 1000);

if (NVRDataModel.getBandwidth() == 'lowbw')
{
NVRDataModel.debug("Enabling low bandwidth parameters");
Expand Down Expand Up @@ -126,7 +136,7 @@ angular.module('zmApp.controllers')
var positionsStr = ld.packeryPositions;
var positions = {};

if (positionsStr == '')
if (positionsStr == '' || positionsStr == undefined)
{
NVRDataModel.log("Did NOT find a packery layout");
layouttype = true;
Expand Down Expand Up @@ -338,6 +348,60 @@ angular.module('zmApp.controllers')
return attr;
};


function findNext (key,obj)
{
var size = Object.keys(obj).length;
var i;
for (i=0; i<size; i++)
{
if (Object.keys(obj)[i] == key)
break;
}
i = (i + 1) % size;
return Object.keys(obj)[i];

}

//----------------------------------------------
// cycle profiles
//-----------------------------------------------

function cycleMontageProfiles()
{

var ld = NVRDataModel.getLogin();

if (!ld.cycleMontageProfiles)
{
// NVRDataModel.debug ("cycling disabled");
return;

}

if ($scope.isDragabillyOn)
{
NVRDataModel.debug ("not cycling, edit in progress");
return;

}

var nextProfile = findNext(ld.currentMontageProfile, ld.packeryPositionsArray);

if (nextProfile == ld.currentMontageProfile)
{
NVRDataModel.debug ("Not cycling profiles, looks like you only have one");
}
else
{
NVRDataModel.debug ("Cycling profile from: "+ld.currentMontageProfile+" to:"+nextProfile);
switchMontageProfile(nextProfile);

}


}

//-----------------------------------------------------------------------
// cycle through all displayed monitors and check alarm status
//-----------------------------------------------------------------------
Expand Down Expand Up @@ -499,6 +563,22 @@ angular.module('zmApp.controllers')

};

$scope.getCycleStatus = function()
{
var c = NVRDataModel.getLogin().cycleMontageProfiles;
var str = (c) ? $translate.instant('kOn'):$translate.instant('kOff');
return str;
};

$scope.toggleCycle = function()
{
var ld = NVRDataModel.getLogin();
ld.cycleMontageProfiles = !ld.cycleMontageProfiles;
NVRDataModel.setLogin(ld);
NVRDataModel.debug ("cycle="+ld.cycleMontageProfiles);

};

$scope.toggleHide = function(i)
{

Expand Down Expand Up @@ -611,6 +691,7 @@ angular.module('zmApp.controllers')
ionic.Platform.fullScreen($scope.minimal, !$scope.minimal);
//console.log ("alarms:Cancelling timer");
$interval.cancel(intervalHandleMontage);
$interval.cancel(intervalHandleMontageCycle);
$interval.cancel(intervalHandleAlarmStatus);

if (!$rootScope.isAlarm)
Expand Down Expand Up @@ -656,6 +737,7 @@ angular.module('zmApp.controllers')
ionic.Platform.fullScreen($scope.minimal, !$scope.minimal);
//console.log ("minimal switch:Cancelling timer");
$interval.cancel(intervalHandleMontage); //we will renew on reload
$interval.cancel(intervalHandleMontageCycle);
$interval.cancel(intervalHandleAlarmStatus);
// We are reloading this view, so we don't want entry animations
$ionicHistory.nextViewOptions(
Expand Down Expand Up @@ -876,6 +958,7 @@ angular.module('zmApp.controllers')
// NVRDataModel.log("Starting Modal timer");
//console.log ("openModal:Cancelling timer");
$interval.cancel(intervalHandleMontage);
$interval.cancel(intervalHandleMontageCycle);
$interval.cancel(intervalHandleAlarmStatus);

$scope.monitor = monitor;
Expand Down Expand Up @@ -954,6 +1037,7 @@ angular.module('zmApp.controllers')
// console.log ("closeModal: Cancelling timer");
$interval.cancel(intervalHandleMontage);
$interval.cancel(intervalHandleAlarmStatus);
$interval.cancel(intervalHandleMontageCycle);

intervalHandleMontage = $interval(function()
{
Expand All @@ -967,6 +1051,13 @@ angular.module('zmApp.controllers')
// console.log ("Refreshing Image...");
}.bind(this), 5000);

intervalHandleMontageCycle = $interval(function()
{
cycleMontageProfiles();
// console.log ("Refreshing Image...");
}.bind(this), 5000);


// $timeout (function() {pckry.shiftLayout();},zm.packeryTimer);

}
Expand All @@ -992,6 +1083,7 @@ angular.module('zmApp.controllers')
{
NVRDataModel.debug("MontageCtrl: onpause called");
$interval.cancel(intervalHandleMontage);
$interval.cancel(intervalHandleMontageCycle);
$interval.cancel(intervalHandleAlarmStatus);
// $interval.cancel(modalIntervalHandle);

Expand Down Expand Up @@ -1099,12 +1191,52 @@ angular.module('zmApp.controllers')
delete posArray[$scope.data.selectedVal];
var ld = NVRDataModel.getLogin();
ld.packeryPositionsArray = posArray;

if (ld.currentMontageProfile == $scope.data.selectedVal)
{
ld.currentMontageProfile = "";

}

if ($scope.currentMontageProfile == $scope.data.selectedVal)
$scope.currentProfileName = $translate.instant('kMontage');

NVRDataModel.setLogin(ld);

});

};


function switchMontageProfile (mName)
{
$interval.cancel(intervalHandleMontageCycle);
intervalHandleMontageCycle = $interval(function()
{
cycleMontageProfiles();
// console.log ("Refreshing Image...");
}.bind(this), NVRDataModel.getLogin().cycleMontageInterval* 1000);


//console.log ("SELECTED " + $scope.data.selectedVal);
var ld = NVRDataModel.getLogin();
//console.log ("OLD POS="+ld.packeryPositions);
ld.packeryPositions = ld.packeryPositionsArray[mName];
ld.currentMontageProfile = mName;
$scope.currentProfileName =mName;
//console.log ("NEW POS="+ld.packeryPositions);
NVRDataModel.setLogin(ld);
//console.log ("SAVING "+ld.packeryPositions.name+ " but "+$scope.data.selectedVal);
NVRDataModel.reloadMonitorDisplayStatus();
draggies.forEach(function(drag)
{
drag.destroy();
});
draggies = [];
pckry.destroy();
initPackery();

}
// switch to another montage profile
$scope.switchMontageProfile = function()
{
Expand Down Expand Up @@ -1168,20 +1300,11 @@ angular.module('zmApp.controllers')
{
if (res)
{
//console.log ("SELECTED " + $scope.data.selectedVal);
var ld = NVRDataModel.getLogin();
//console.log ("OLD POS="+ld.packeryPositions);
ld.packeryPositions = ld.packeryPositionsArray[$scope.data.selectedVal];
//console.log ("NEW POS="+ld.packeryPositions);
NVRDataModel.setLogin(ld);
NVRDataModel.reloadMonitorDisplayStatus();
draggies.forEach(function(drag)
{
drag.destroy();
});
draggies = [];
pckry.destroy();
initPackery();
// destroy cycle timer and redo it
//
switchMontageProfile($scope.data.selectedVal);


//pckry.reloadItems();
}

Expand Down Expand Up @@ -1217,7 +1340,9 @@ angular.module('zmApp.controllers')
var pos = JSON.stringify(pckry.getShiftPositions('data-item-id'));
ld.packeryPositionsArray[$scope.data.montageName] = pos;
NVRDataModel.debug("Saving " + $scope.data.montageName + " with:" + pos);
ld.currentMontageProfile =$scope.data.montageName ;
NVRDataModel.setLogin(ld);
$scope.currentProfileName = $scope.data.montageName;
}

}
Expand Down Expand Up @@ -1306,6 +1431,7 @@ angular.module('zmApp.controllers')
sizeInProgress = false;
$scope.imageStyle = true;
intervalHandleMontage = "";
intervalHandleMontageCycle = "";
$scope.isModalActive = false;
$scope.isReorder = false;

Expand All @@ -1322,6 +1448,7 @@ angular.module('zmApp.controllers')
NVRDataModel.setAwake(NVRDataModel.getKeepAwake());

$interval.cancel(intervalHandleMontage);
$interval.cancel(intervalHandleMontageCycle);
$interval.cancel(intervalHandleAlarmStatus);

intervalHandleMontage = $interval(function()
Expand All @@ -1330,6 +1457,12 @@ angular.module('zmApp.controllers')
// console.log ("Refreshing Image...");
}.bind(this), refreshSec * 1000);

intervalHandleMontageCycle = $interval(function()
{
cycleMontageProfiles();
// console.log ("Refreshing Image...");
}.bind(this), NVRDataModel.getLogin().cycleMontageInterval* 1000);

intervalHandleAlarmStatus = $interval(function()
{
loadAlarmStatus();
Expand Down Expand Up @@ -1425,6 +1558,7 @@ angular.module('zmApp.controllers')

//console.log ("beforeLeave:Cancelling timer");
$interval.cancel(intervalHandleMontage);
$interval.cancel(intervalHandleMontageCycle);
$interval.cancel(intervalHandleAlarmStatus);
pckry.destroy();
window.removeEventListener("resize", orientationChanged, false);
Expand Down Expand Up @@ -1659,6 +1793,8 @@ angular.module('zmApp.controllers')
// $rootScope.rand = Math.floor((Math.random() * 100000) + 1);
});

$scope.currentProfileName = NVRDataModel.getLogin().currentMontageProfile || $translate.instant ('kMontage');

$scope.reloadView = function()
{
$rootScope.rand = Math.floor((Math.random() * 100000) + 1);
Expand Down
7 changes: 6 additions & 1 deletion www/templates/montage.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<ion-view view-title="{{'kMontage' | translate}}" cache-view="false" hide-nav-bar="{{minimal}}">
<ion-view cache-view="false" hide-nav-bar="{{minimal}}">
<ion-nav-title>{{currentProfileName}}</ion-nav-title>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" ng-click="openMenu()"></button>
<button class="button button-icon button-clear ion-eye" ng-click="hideUnhide();">&nbsp;
Expand Down Expand Up @@ -34,6 +35,10 @@
<li>
<a href="" ng-click="sliderChanged(-1)"> <i class="ion-minus-circled"></i></a>
</li>

<li ng-if="!isDragabillyOn">
<a href="" ng-click="toggleCycle()"> <i class="ion-android-bicycle"></i>:{{getCycleStatus()}}</a>
</li>

<li ng-if="isDragabillyOn">
<a href="" ng-click="hideMonitor(monitor.Monitor.Id)"> <i class="ion-close-circled"></i></a>
Expand Down

0 comments on commit ccdf366

Please sign in to comment.