From 99ae0bdb3b663b2a3c222b7a6413c742f0151dd3 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 6 Dec 2016 19:19:28 +0100 Subject: [roomplanner] Show if PC is already placed in another room --- modules-available/roomplanner/clientscript.js | 13 +++++++++---- modules-available/roomplanner/inc/pvsgenerator.inc.php | 3 +++ modules-available/roomplanner/page.inc.php | 16 ++++++++++++---- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/modules-available/roomplanner/clientscript.js b/modules-available/roomplanner/clientscript.js index 4380b16c..cc149392 100644 --- a/modules-available/roomplanner/clientscript.js +++ b/modules-available/roomplanner/clientscript.js @@ -20,14 +20,19 @@ function renderMachineEntry(item, escape) { // console.log(placedMachines); var isUsed = $.inArray(item.machineuuid, placedMachines) > -1; - var extra = isUsed ? ' used ' : ''; + var extraClass = ''; + var extraText = ''; if (isUsed) { - console.log('rendering used'); + extraText = ' (already placed)'; + extraClass = 'used'; + } else if (item.otherroom) { + extraText = ' (in ' + item.otherroom + ')'; + extraClass = 'used'; } - return '
' + return '
' //+ ' ' + '
' - + '
' + escape(item.hostname) + (isUsed ? ' (already placed)' : '') + '
' + + '
' + escape(item.hostname) + extraText + '
' + ' ' + '' + '' diff --git a/modules-available/roomplanner/inc/pvsgenerator.inc.php b/modules-available/roomplanner/inc/pvsgenerator.inc.php index af090fc3..c00d5439 100644 --- a/modules-available/roomplanner/inc/pvsgenerator.inc.php +++ b/modules-available/roomplanner/inc/pvsgenerator.inc.php @@ -153,6 +153,9 @@ class PvsGenerator while ($row = $ret->fetch(PDO::FETCH_ASSOC)) { $position = json_decode($row['position'], true); + if ($position === false || !isset($position['gridRow']) || !isset($position['gridCol'])) + continue; // TODO: Remove entry/set to NULL? + $machine = array(); $machine['clientip'] = $row['clientip']; $machine['gridRow'] = $position['gridRow']; diff --git a/modules-available/roomplanner/page.inc.php b/modules-available/roomplanner/page.inc.php index de82a985..1ddbdc30 100644 --- a/modules-available/roomplanner/page.inc.php +++ b/modules-available/roomplanner/page.inc.php @@ -234,7 +234,12 @@ class Page_Roomplanner extends Page while ($row = $result->fetch(PDO::FETCH_ASSOC)) { $machine = []; $pos = json_decode($row['position'], true); - // TODO: Check if pos is valid (has required keys) + if ($pos === false || !isset($pos['gridRow']) || !isset($pos['gridCol'])) { + // Missing/incomplete position information - reset + Database::exec("UPDATE machine SET fixedlocationid = NULL, position = '' WHERE machineuuid = :uuid", + array('uuid' => $row['machineuuid'])); + continue; + } $machine['muuid'] = $row['machineuuid']; $machine['ip'] = $row['clientip']; @@ -255,13 +260,16 @@ class Page_Roomplanner extends Page protected function getPotentialMachines() { - $result = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, hostname ' - . 'FROM machine WHERE locationid = :locationid', ['locationid' => $this->locationid]); + $result = Database::simpleQuery('SELECT m.machineuuid, m.macaddr, m.clientip, m.hostname, l.locationname AS otherroom + FROM machine m + LEFT JOIN location l ON (m.fixedlocationid = l.locationid AND m.subnetlocationid <> m.fixedlocationid) + WHERE subnetlocationid = :locationid', ['locationid' => $this->locationid]); $machines = []; while ($row = $result->fetch(PDO::FETCH_ASSOC)) { - $row['combined'] = implode(' ', array_values($row)); + // For searching + $row['combined'] = $row['machineuuid'] . ' ' . $row['macaddr'] . ' ' . $row['clientip'] . ' ' . $row['hostname']; $machines[] = $row; } -- cgit v1.2.3-55-g7522
UUID: ' + escape(item.machineuuid) + '
MAC: ' + escape(item.macaddr) + '