Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ITC-769 Change the size of background images while editing #1493

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions plugins/MapModule/src/Controller/MapeditorsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public function view($id = null) {

$MapForAngular = new MapForAngular($map);
$map = $MapForAngular->toArray();
$config = $MapsTable->getMapeditorSettings($map['Map']['json_data']);
$map['Mapeditor'] = [
'background' => $config['Mapeditor']['background']
];

$acl = [
'hosts' => [
Expand Down Expand Up @@ -2007,6 +2011,10 @@ public function mapDetails($id) {

$MapForAngular = new MapForAngular($map);
$map = $MapForAngular->toArray();
$config = $MapsTable->getMapeditorSettings($map['Map']['json_data']);
$map['Mapeditor'] = [
'background' => $config['Mapeditor']['background']
];

$this->set('map', $map);
$this->viewBuilder()->setOption('serialize', ['map']);
Expand Down
16 changes: 14 additions & 2 deletions plugins/MapModule/src/Model/Table/MapsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2299,6 +2299,12 @@ public function getDefaultMapeditorSettings() {
'helplines' => [
'enabled' => true,
'size' => 15
],
'background' => [
'position_x' => 0,
'position_y' => 0,
'width' => null,
'height' => null
]
]
];
Expand All @@ -2309,9 +2315,15 @@ public function getDefaultMapeditorSettings() {
* @return array|mixed
*/
public function getMapeditorSettings($config) {
$defaults = $this->getDefaultMapeditorSettings();
if (empty($config)) {
return $this->getDefaultMapeditorSettings();
return $defaults;
}
return json_decode($config, true);
$config = json_decode($config, true);

return Hash::merge(
$defaults,
$config
);
}
}
32 changes: 26 additions & 6 deletions plugins/MapModule/templates/Mapeditors/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@
<div id="panel-1" class="panel">
<div class="panel-hdr">
<h2>
<?php echo __('Edit map:'); ?>
<span class="fw-300"><i>{{map.Map.name}}</i></span>
<?= __('Edit map:'); ?>
<span class="fw-300" title="{{map.Map.name}}"><i>{{map.Map.name}}</i></span>
</h2>
<div class="panel-toolbar">
</div>
<div class="panel-hdr">
<div class="panel-toolbar w-100 justify-content-sm-end">
<div role="group">
<label class="checkbox small-checkbox-label margin-right-10 margin-top-2">
<input type="checkbox" name="checkbox" checked="checked"
Expand Down Expand Up @@ -113,9 +115,19 @@
<?php endforeach; ?>
</ul>
</div>
<div role="group">
<span class="italic ml-4">
<?= __('Background options'); ?>:
</span>
<button class="btn btn-primary btn-xs mr-1 shadow-0 waves-effect"
ng-click="resetBackgroundSizeSettings()"
type="button" title="<?= __('Restore the background to its original size'); ?>">
<i class="fa-solid fa-expand"></i> <?= __('Back to original size'); ?>
</button>
</div>
<?php if ($this->Acl->hasPermission('index', 'maps', 'mapmodule')): ?>
<a back-button href="javascript:void(0);" fallback-state='MapsIndex'
class="btn btn-default btn-xs mr-1 shadow-0">
class="btn btn-default btn-xs ml-5 mr-1 shadow-0">
<i class="fas fa-long-arrow-alt-left"></i> <?php echo __('Back'); ?>
</a>
<?php endif; ?>
Expand All @@ -136,8 +148,16 @@ class="btn btn-default btn-xs mr-1 shadow-0">
id="mainMapContainer">
<div id="mapContent" ng-if="Mapeditor.helplines.enabled"
ng-class="getHelplinesClass()"></div>
<img ng-src="/map_module/img/backgrounds/{{map.Map.background}}"
ng-if="map.Map.background"/>
<div class="resizable resizable-background draggable"
ng-style="Mapeditor.background.width === null && {'width':'auto', 'height':'auto'}"
style="position:absolute; top: {{Mapeditor.background.position_y}}px; left: {{Mapeditor.background.position_x}}px; cursor: move;"
ng-if="map.Map.background"
id="backgroundMap" data-type="mapBackground">
<img ng-src="/map_module/img/backgrounds/{{map.Map.background}}"
ng-style="Mapeditor.background.width !== null && {'width':Mapeditor.background.width+'px'}"
ng-if="map.Map.background"/>
</div>

<div ng-repeat="item in map.Mapitems" class="draggable" ng-dblclick="editItem(item)"
style="position:absolute; top: {{item.y}}px; left: {{item.x}}px; z-index: {{item.z_index}}; cursor: move;"
data-id="{{item.id}}" data-type="item" ng-show="item.display">
Expand Down
12 changes: 9 additions & 3 deletions plugins/MapModule/templates/Mapeditors/view_directive.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@
// License agreement and license key will be shipped with the order
// confirmation.
?>
<img ng-src="/map_module/img/backgrounds/{{map.Map.background}}" ng-if="map.Map.background" class="invalid-image-src"
alt="<?= __('{0} Map background image is not available!!!', '⚠'); ?>"/>

<div ng-style="map.Mapeditor.background.width === null && {'width':'auto', 'height':'auto'}"
style="position:absolute; top: {{map.Mapeditor.background.position_y}}px; left: {{map.Mapeditor.background.position_x}}px;"
ng-if="map.Map.background"
id="backgroundMap" data-type="mapBackground">
<img ng-src="/map_module/img/backgrounds/{{map.Map.background}}"
ng-style="map.Mapeditor.background.width !== null && {'width':map.Mapeditor.background.width+'px'}"
ng-if="map.Map.background" class="invalid-image-src"
alt="<?= __('{0} Map background image is not available!!!', '⚠'); ?>"/>
</div>

<div ng-repeat="item in map.Mapitems"
style="position:absolute; top: {{item.y}}px; left: {{item.x}}px; z-index: {{item.z_index}};"
Expand Down
15 changes: 15 additions & 0 deletions plugins/MapModule/webroot/css/MapModule.css
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,18 @@
.invalid-image-src {
color:#CC0000;
}
.resizable-background {
display: inline-block;
overflow: hidden;
line-height: 0;
}

.resizable-background img {
width: 100%;
height: 100%;
}

.ui-resizable-helper {
opacity: 0.5;
border: 2px dashed #4285F4;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ angular.module('openITCOCKPIT')
enabled: true,
size: 15
},
synchronizeGridAndHelplinesSize: true

synchronizeGridAndHelplinesSize: true,
background: {
position_x: 0,
position_y: 0,
width: null,
height: null
}
};

$scope.helplines = {
Expand Down Expand Up @@ -1451,6 +1456,11 @@ angular.module('openITCOCKPIT')
}
};

$scope.resetBackgroundSizeSettings = function(){
$scope.Mapeditor.background.width = null;
$scope.Mapeditor.background.height = null;
};

var makeDraggable = function(){
var options = {
grid: false,
Expand Down Expand Up @@ -1561,6 +1571,11 @@ angular.module('openITCOCKPIT')
$scope.saveSummaryItem('dragstop');
break;

case 'mapBackground':
$scope.Mapeditor.background.position_x = x;
$scope.Mapeditor.background.position_y = y;
break;

default:
console.log('Unknown map object type');
genericError();
Expand Down Expand Up @@ -1623,6 +1638,11 @@ angular.module('openITCOCKPIT')
$scope.saveSummaryItem('resizestop');
break;

case 'mapBackground':
$scope.Mapeditor.background.width = newWidth;
$scope.Mapeditor.background.height = newHeight;
break;

default:
console.log('Unknown map object type');
genericError();
Expand Down Expand Up @@ -1659,6 +1679,11 @@ angular.module('openITCOCKPIT')
$scope.saveGadget('resizestop');
break;

case 'mapBackground':
$scope.Mapeditor.background.width = newWidth;
$scope.Mapeditor.background.height = newHeight;
break;

default:
console.log('Unknown map object type');
genericError();
Expand Down