From 78400509994ff47cf3b66005330f6baf48669ecb Mon Sep 17 00:00:00 2001 From: IgorA100 Date: Sun, 19 May 2024 00:09:46 +0300 Subject: [PATCH 01/10] Moved list of preset Layouts to montage.php (montage.js) --- web/skins/classic/views/js/montage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/skins/classic/views/js/montage.js b/web/skins/classic/views/js/montage.js index d4e044fff..a8b9eb274 100644 --- a/web/skins/classic/views/js/montage.js +++ b/web/skins/classic/views/js/montage.js @@ -53,7 +53,7 @@ function stringToNumber(str) { } function isPresetLayout(name) { - return (( name=='Freeform' || name=='1 Wide' || name=='2 Wide' || name=='3 Wide' || name=='4 Wide' || name=='6 Wide' || name=='8 Wide' || name=='12 Wide' || name=='16 Wide' ) ? true : false); + return ((ZM_PRESET_LAYOUT_NAMES.indexOf(name) != -1) ? true : false); } function getCurrentNameLayout() { From 67ab1c39f3b0f7dcf009a079bc57122e4b05c882 Mon Sep 17 00:00:00 2001 From: IgorA100 Date: Sun, 19 May 2024 00:21:12 +0300 Subject: [PATCH 02/10] Preset Layouts should be first in the Layots list (montage.php) Moved preset Layouts from montage.js Changed the definition of the default Layout --- web/skins/classic/views/montage.php | 74 ++++++++++++++++++----------- 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/web/skins/classic/views/montage.php b/web/skins/classic/views/montage.php index 9ef9dc97c..cc2d8b529 100644 --- a/web/skins/classic/views/montage.php +++ b/web/skins/classic/views/montage.php @@ -60,6 +60,18 @@ $monitorStatusPositon = array( $monitorStatusPositonSelected = 'outsideImgBottom'; +$presetLayoutsNames = array( //Order matters! + 'Freeform', + '1 Wide', + '2 Wide', + '3 Wide', + '4 Wide', + '6 Wide', + '8 Wide', + '12 Wide', + '16 Wide' +); + if (isset($_REQUEST['monitorStatusPositonSelected'])) { $monitorStatusPositonSelected = $_REQUEST['monitorStatusPositonSelected']; } else if (isset($_COOKIE['zmMonitorStatusPositonSelected'])) { @@ -69,16 +81,30 @@ if (isset($_REQUEST['monitorStatusPositonSelected'])) { $layouts = ZM\MontageLayout::find(NULL, array('order'=>"lower('Name')")); $layoutsById = array(); $FreeFormLayoutId = 0; + +/* Create an array "Name"=>"Id" to make it easier to find IDs by name*/ +$arrNameId = array(); +foreach ($layouts as $l) { + $arrNameId[$l->Name()] = $l->Id(); +} + +/* Fill with preinstalled Layouts. They should always come first */ +foreach ($presetLayoutsNames as $name) { + if ($arrNameId[$name]) // Layout may be missing in BD (rare case during update process) + $layoutsById[$arrNameId[$name]] = $name; //We will only assign a name, which is necessary for the sorting order. We will replace it with an object in the next loop. +} + +/* For some reason $layouts is already sorted by ID and requires analysis. But just in case, we will sort by ID */ +uasort($layouts, function($a, $b) { + return $a->Id <=> $b->Id; +}); + +/* Add custom Layouts & assign objects instead of names for preset Layouts */ foreach ( $layouts as $l ) { if ( $l->Name() == 'Freeform' ) { $FreeFormLayoutId = $l->Id(); - $layoutsById[$l->Id()] = $l; - break; } -} -foreach ( $layouts as $l ) { - if ( $l->Name() != 'Freeform' ) - $layoutsById[$l->Id()] = $l; + $layoutsById[$l->Id()] = $l; } zm_session_start(); @@ -175,28 +201,18 @@ foreach ($displayMonitors as &$row) { if (!$layout_id) { $default_layout = ''; - if (!$default_layout) { - if ((count($monitors) > 5) and (count($monitors)%5 == 0)) { - $default_layout = '5 Wide'; - } else if ((count($monitors) > 4) and (count($monitors)%4 == 0)) { - $default_layout = '4 Wide'; - } else if (count($monitors)%3 == 0) { - $default_layout = '3 Wide'; - } else { - $default_layout = '2 Wide'; - } - } - foreach ($layouts as $l) { - if ($l->Name() == $default_layout) { - $layout_id = $l->Id(); - } + if (count($monitors) > 6) { + $default_layout = '6 Wide'; + } else if (count($monitors) > 4) { + $default_layout = '4 Wide'; + } else { + $default_layout = '2 Wide'; } + $layout_id = $arrNameId[$default_layout]; } -$Layout = ''; -$Positions = ''; + if ( $layout_id and is_numeric($layout_id) and isset($layoutsById[$layout_id]) ) { - $Layout = $layoutsById[$layout_id]; - $Positions = json_decode($Layout->Positions(), true); + } else { ZM\Debug('Layout not found'); } @@ -252,15 +268,15 @@ if (canView('System')) { 'ratio', 'data-on-change'=>'changeRatioForAll', 'class'=>'chosen')); ?> -