summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Klinger2016-08-09 11:28:54 +0200
committerChristian Klinger2016-08-09 11:28:54 +0200
commite5c173de496fc99ca73e2da20152d11a3dd58018 (patch)
tree801616d82907578f2c73b137e46aee29cbf9dbc8
parenthide json textarea. (diff)
downloadslx-admin-e5c173de496fc99ca73e2da20152d11a3dd58018.tar.gz
slx-admin-e5c173de496fc99ca73e2da20152d11a3dd58018.tar.xz
slx-admin-e5c173de496fc99ca73e2da20152d11a3dd58018.zip
loading & saving of roomconfig.
-rw-r--r--modules-available/roomplanner/clientscript.js18
-rw-r--r--modules-available/roomplanner/config.json2
-rw-r--r--modules-available/roomplanner/js/init.js5
-rw-r--r--modules-available/roomplanner/page.inc.php91
-rw-r--r--modules-available/roomplanner/style.css5
5 files changed, 113 insertions, 8 deletions
diff --git a/modules-available/roomplanner/clientscript.js b/modules-available/roomplanner/clientscript.js
index c19e63ec..25495995 100644
--- a/modules-available/roomplanner/clientscript.js
+++ b/modules-available/roomplanner/clientscript.js
@@ -9,14 +9,25 @@ machineCache = {};
selectMachinInitialized = false;
+placedMachines = [];
+
function renderMachineEntry(item, escape) {
machineCache[item.machineuuid] = item;
- return '<div class="machine-entry">'
+ // console.log('rendering ' + item.machineuuid);
+ // console.log('used uuids is ');
+ // console.log(placedMachines);
+
+ var isUsed = $.inArray(item.machineuuid, placedMachines) > -1;
+ var extra = isUsed ? ' used ' : '';
+ if (isUsed) {
+ console.log('rendering used');
+ }
+ return '<div class="machine-entry ' + extra +'">'
//+ ' <div class="machine-logo"><i class="glyphicon glyphicon-hdd"></i></div>'
+ ' <div class="machine-body">'
- + ' <div class="machine-entry-header"> ' + escape(item.hostname) + '</div>'
+ + ' <div class="machine-entry-header"> ' + escape(item.hostname) + (isUsed ? ' (already placed)' : '') + '</div>'
+ ' <table class="table table-sm">'
+ '<tr><td>UUID:</td> <td>' + escape(item.machineuuid) + '</td></tr>'
+ '<tr><td>MAC:</td> <td>' + escape(item.macaddr) + '</td></tr>'
@@ -51,9 +62,11 @@ function loadMachines(query, callback) {
function clearSearchBox() {
$selectizeSearch[0].selectize.setValue([], true);
+ $selectizeSearch[0].selectize.clearCache();
}
function clearSubnetBox() {
$selectizeSubnet[0].selectize.setValue([], true);
+ $selectizeSubnet[0].selectize.clearCache();
}
function initSelectize() {
@@ -120,6 +133,7 @@ function onBtnSelect() {
function selectMachine(usedUuids, callback) {
initSelectize();
currentCallback = callback;
+ placedMachines = usedUuids;
$modal.modal('show');
}
diff --git a/modules-available/roomplanner/config.json b/modules-available/roomplanner/config.json
index 83e4ca30..48ddbb30 100644
--- a/modules-available/roomplanner/config.json
+++ b/modules-available/roomplanner/config.json
@@ -1,4 +1,4 @@
{
"category":"main.content",
- "dependencies": ["js_jqueryui", "js_selectize"]
+ "dependencies": ["js_jqueryui", "js_selectize", "bootstrap_dialog"]
}
diff --git a/modules-available/roomplanner/js/init.js b/modules-available/roomplanner/js/init.js
index e1a619aa..825a5245 100644
--- a/modules-available/roomplanner/js/init.js
+++ b/modules-available/roomplanner/js/init.js
@@ -20,6 +20,11 @@ function initRoomplanner() {
$("#serializeButton").click(function() {
$('#serializedRoom').val(roomplanner.serialize());
});
+
+ $("#saveBtn").click(function() {
+ $('#serializedRoom').val(roomplanner.serialize());
+ $('#roomForm').submit();
+ });
}
var translation = {
diff --git a/modules-available/roomplanner/page.inc.php b/modules-available/roomplanner/page.inc.php
index 222192c1..b1869443 100644
--- a/modules-available/roomplanner/page.inc.php
+++ b/modules-available/roomplanner/page.inc.php
@@ -14,16 +14,36 @@ class Page_Roomplanner extends Page
protected function doRender()
{
+
$locationid = Request::get('locationid', null, 'integer');
- if ($locationid === null) {
- die('please specify locationid');
- }
+ if ($locationid === null) { die('please specify locationid'); }
+
+ $furniture = $this->getFurniture($locationid);
$subnetMachines = $this->getPotentialMachines($locationid);
+ $machinesOnPlan = $this->getMachinesOnPlan($locationid);
+
+ $action = Request::any('action', 'show', 'string');
+
+ $roomConfig = array_merge($furniture, $machinesOnPlan);
+
+
+ if ($action === 'show') {
+ /* do nothing */
+ Render::addTemplate('page', [
+ 'subnetMachines' => json_encode($subnetMachines),
+ 'locationid' => $locationid,
+ 'roomConfiguration' => json_encode($roomConfig, JSON_PRETTY_PRINT)]);
+ } else if ($action === 'save') {
+ /* save */
+ $config = Request::post('serializedRoom', null, 'string');
+ $config = json_decode($config, true);
+ $this->saveRoomConfig($locationid, $config['furniture']);
+ $this->saveComputerConfig($locationid, $config['computers'], $machinesOnPlan);
+ Util::redirect("?do=roomplanner&locationid=$locationid&action=show");
+ }
- Render::addTemplate('page', ['subnetMachines' => json_encode($subnetMachines),
- ]);
}
protected function doAjax()
@@ -58,6 +78,67 @@ class Page_Roomplanner extends Page
}
}
+ protected function saveComputerConfig($locationid, $computers, $oldComputers) {
+
+ $oldUuids = [];
+ /* collect all uuids from the old computers */
+ foreach($oldComputers['computers'] as $c) {
+ $oldUuids[] = $c['muuid'];
+ }
+
+ $newUuids = [];
+ foreach($computers as $computer) {
+ $newUuids[] = $computer['muuid'];
+
+ $position = json_encode(['gridRow' => $computer['gridRow'],
+ 'gridCol' => $computer['gridCol'],
+ 'itemlook' => $computer['itemlook']], JSON_PRETTY_PRINT);
+
+ Database::exec('UPDATE machine SET position = :position, locationid = :locationid WHERE machineuuid = :muuid',
+ ['locationid' => $locationid, 'muuid' => $computer['muuid'], 'position' => $position]);
+ }
+
+ $toDelete = array_diff($oldUuids, $newUuids);
+
+ foreach($toDelete as $d) {
+ Database::exec("UPDATE machine SET position = '', locationid = NULL WHERE machineuuid = :uuid", ['uuid' => $d]);
+ }
+ }
+ protected function saveRoomConfig($locationid, $furniture) {
+ $obj = json_encode(['furniture' => $furniture], JSON_PRETTY_PRINT);
+ Database::exec('INSERT INTO location_roomplan (locationid, roomplan) VALUES (:locationid, :roomplan) ON DUPLICATE KEY UPDATE roomplan=:roomplan',
+ ['locationid' => $locationid,
+ 'roomplan' => $obj]);
+ }
+
+ protected function getFurniture($locationid) {
+ $config = Database::queryFirst('SELECT roomplan FROM location_roomplan WHERE locationid = :locationid', ['locationid' => $locationid]);
+ if ($config == null) { return null; }
+ $config = json_decode($config['roomplan'], true);
+ return $config;
+ }
+ protected function getMachinesOnPlan($locationid) {
+ $result = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, hostname, position FROM machine WHERE locationid = :locationid',
+ ['locationid' => $locationid]);
+ $machines = [];
+ while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
+ $machine = [];
+ $pos = json_decode($row['position'], true);
+
+ $machine['muuid'] = $row['machineuuid'];
+ $machine['ip'] = $row['clientip'];
+ $machine['mac_address'] = $row['macaddr'];
+ $machine['hostname'] = $row['hostname'];
+ $machine['gridRow'] = (int) $pos['gridRow'];
+ $machine['gridCol'] = (int) $pos['gridCol'];
+ $machine['itemlook'] = $pos['itemlook'];
+ $machine['data-width'] = 100;
+ $machine['data-height'] = 100;
+ $machines[] = $machine;
+ }
+ return ['computers' => $machines];
+ }
+
protected function getPotentialMachines($locationid)
{
$result = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, hostname '
diff --git a/modules-available/roomplanner/style.css b/modules-available/roomplanner/style.css
index 7ad7407b..1e434237 100644
--- a/modules-available/roomplanner/style.css
+++ b/modules-available/roomplanner/style.css
@@ -729,6 +729,11 @@ div.draggable:hover .deleteHandle {
padding: 5px 10px 5px 10px;
}
+/* in case it is already in the sketchboard */
+.machine-entry.used {
+ color: #666;
+}
+
.machine-entry .table {
font-size:12px;
margin-bottom: -5px;