Skip to content

Commit

Permalink
#1067 handle new monitors, also handle deleted monitors
Browse files Browse the repository at this point in the history
  • Loading branch information
pliablepixels committed May 24, 2021
1 parent a2ed716 commit 4713bb6
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 37 deletions.
85 changes: 55 additions & 30 deletions www/js/MontageCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,12 @@ angular.module('zmApp.controllers')

//console.log ("POSITION STR IS " + positionsStr);
positions = parsePositions(positionsStr);
matchMonitorsToPositions(positions);
layouttype = matchMonitorsToPositions(positions);
//console.log ('P US NOW '+positions);


// NVR.log("found a packery layout:"+positionsStr);
layouttype = false;
//layouttype = false;
}

var cnt = 0;
Expand All @@ -287,7 +289,7 @@ angular.module('zmApp.controllers')
}
}

NVR.log("Monitors that are active" + cnt + " while grid has " + pos_cnt);
// NVR.log("Monitors that are active " + cnt + " while grid has " + pos_cnt);

if (cnt > NVR.getLogin().maxMontage) {
cnt = NVR.getLogin().maxMontage;
Expand All @@ -310,7 +312,7 @@ angular.module('zmApp.controllers')
//console.log ("**** mygrid is " + JSON.stringify(elem));

if (pckry) pckry.destroy();

NVR.debug ('Calling initPackery() with layout as:'+layouttype);
pckry = new Packery('.grid', {
itemSelector: '.grid-item',
percentPosition: true,
Expand Down Expand Up @@ -1847,21 +1849,22 @@ angular.module('zmApp.controllers')

if (positionsStr == '' || positionsStr == undefined) {
NVR.debug ('No positions stored');
positions = undefined;
positionsStr = undefined;
} else {
positions = parsePositions(positionsStr);
matchMonitorsToPositions(positions);
}

if (!ld.packeryPositions) {
ld.packeryPositions = [];
NVR.setLogin(ld).then(function(data) {
if (!ld.packeryPositions) {
NVR.debug ("This profile doesn't seem to have been saved. Resetting it to defaults...");
$scope.resetSizes(true);
//$scope.resetSizes(true);

}
});


NVR.setLogin(ld);



$timeout(function () { // after render

Expand Down Expand Up @@ -2311,42 +2314,65 @@ angular.module('zmApp.controllers')
};

function matchMonitorsToPositions(positions, mon) {

if (!positions) {return; }
if (!mon) { mon = $scope.MontageMonitors;}

var ld = NVR.getLogin();
var dtype;
var layouttype = false;

console.log ("matchMonitor positions:"+JSON.stringify(positions));
if (!mon) { mon = $scope.MontageMonitors;}
var disabled_display;
// hide disabled monitors when no profile is used
if (!ld.currentMontageProfile || ld.currentMontageProfile == $translate.instant('kMontageDefaultProfile')) {
dtype = 'noshow';
disabled_display = 'noshow';
} else {
dtype = 'blank';
disabled_display = 'blank';
}
NVR.debug ('We are in profile:'+ld.currentMontageProfile+" so disabled monitors is "+dtype);

NVR.debug ('We are in profile:'+ld.currentMontageProfile+" so disabled monitors is "+disabled_display);
NVR.debug ('Passed profile is: '+JSON.stringify(positions));
if (!positions.length) layouttype = true;
var found = false;
var monitor_found = false;
for (var m=0; m < mon.length; m++){
monitor_found = false;
for (var p=0; p < positions.length; p++) {
if (mon[m].Monitor.Id == positions[p].attr) {
found = true;
monitor_found = true;
if ( mon[m].Monitor.Function == 'None' && positions[p].display!='noshow') {
NVR.debug (ld.currentMontageProfile + 'Making positions MID='+positions[p].attr+' to "'+dtype+'" as this is disabled in the current ZM run state');
positions[p].display=dtype;
mon[m].Monitor.listDisplay = dtype;
NVR.debug (ld.currentMontageProfile + '=>None Function: Making '+mon[m].Monitor.Name+' to "'+disabled_display+'" as this is disabled in the current ZM run state');
positions[p].display=disabled_display;
mon[m].Monitor.listDisplay = disabled_display;
}
if ( mon[m].Monitor.Function != 'None' && positions[p].display=='blank') {
NVR.debug (ld.currentMontageProfile + 'Making positions MID='+positions[p].attr+' to show as this is enabled in the current ZM run state');
if ( mon[m].Monitor.Function != 'None' && positions[p].display!='noshow') {
NVR.debug (ld.currentMontageProfile + '=>Making '+mon[m].Monitor.Name+' to show as this is enabled in the current ZM run state');
positions[p].display='show';
mon[m].Monitor.listDisplay = 'show';
}

}

}
} // pos
if (!monitor_found) {
mon[m].Monitor.listDisplay = (ld.currentMontageProfile == $translate.instant('kMontageDefaultProfile')) ?'show':'noshow';
NVR.debug (ld.currentMontageProfile + '=> Making '+mon[m].Monitor.Name+' to '+mon[m].Monitor.listDisplay+' as this monitor was not found in profile');

}
}
/* if (!found) {
NVR.debug ('********************* monitor not in this profile: '+mon[m].Monitor.Name);
layouttype = true;
}*/
} //mon

NVR.debug ('after matchMontageProfile, will packery re-init? '+ layouttype);
NVR.setMonitors(mon);
$scope.monitors = mon;
return layouttype;
}

function parsePositions(ps) {
//var ld = NVR.getLogin();
var positions;
NVR.debug ('parsePositions: got '+JSON.stringify(ps));
if (!ps) return [];
try {
positions = JSON.parse(ps);
}
Expand Down Expand Up @@ -2843,9 +2869,9 @@ angular.module('zmApp.controllers')
$scope.resetSizes = function (unhideAll, percent) {
var somethingReset = false;
if (!percent) percent="50";
console.log ('************** RESET SIZES:'+percent);
for (var i = 0; i < $scope.MontageMonitors.length; i++) {
if (unhideAll) {
NVR.debug ('Setting '+$scope.MontageMonitors[i].Monitor.Name+' to show');
$scope.MontageMonitors[i].Monitor.listDisplay = 'show';
}
if ($scope.isDragabillyOn) {
Expand All @@ -2855,7 +2881,7 @@ angular.module('zmApp.controllers')
}
} else {
$scope.MontageMonitors[i].Monitor.gridScale = percent;
console.log (percent);
// console.log (percent);

// somethingReset = true;
}
Expand All @@ -2866,7 +2892,6 @@ angular.module('zmApp.controllers')
$scope.MontageMonitors[i].Monitor.gridScale = percent;
}
}



$timeout(function () {
Expand Down Expand Up @@ -2897,7 +2922,7 @@ angular.module('zmApp.controllers')
pckry.layout();
//pckry.layout();

}, 20);
}, 100);

};

Expand Down
2 changes: 1 addition & 1 deletion www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ angular.module('zmApp', [

//console.log (item.Monitor.Id+"=>"+item.Monitor.Name+"=>"+item.Monitor.Enabled);
// Can't use enabled anymore - its 0 if analysis is off
if (item.Monitor.Function != 'None' || item.Monitor.listDisplay == 'blank')
if (item.Monitor.Function != 'None' && item.Monitor.listDisplay != 'noshow')
{
out.push(item);
}
Expand Down
8 changes: 2 additions & 6 deletions www/templates/montage.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,11 @@
data-item-size="{{monitor.Monitor.gridScale}}" data-item-listdisplay="{{monitor.Monitor.listDisplay}} ">-->

<div class="grid-item" data-item-id="{{monitor.Monitor.Id}}" ng-style="{'width': monitor.Monitor.gridScale + '%'}"
data-item-size="{{monitor.Monitor.gridScale}}" data-item-listdisplay="{{monitor.Monitor.listDisplay}} ">


data-item-size="{{monitor.Monitor.gridScale}}" data-item-listdisplay="{{monitor.Monitor.listDisplay}} " ng-show="monitor.Monitor.listDisplay!='noshow'">
<div class="row row-no-padding">
<div ng-class="monitor.Monitor.showSidebar?'col col-70 col-no-padding':'col col-no-padding'">
<figure role="group" class="{{dragBorder}}" ng-show="monitor.Monitor.listDisplay!='noshow'">


<div class="montage-image">
<div class="montage-image">
<div ng-if="LoginData.enableMontageOverlays && !$root.LoginData.isKiosk" class="montage-buttons">
<a ng-if="monitor.Monitor.lastEvent" class="button button-small button-assertive icon ion-ios-bell"
ng-click="eventButtonClicked(monitor, true)"></a>&nbsp;&nbsp;<a ng-if="monitor.Monitor.lastEvent"
Expand Down

0 comments on commit 4713bb6

Please sign in to comment.