From bb20447b48566f5446a36b42f4616f9fccf83993 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Sun, 22 Nov 2026 14:50:45 -0500 Subject: [PATCH] Racks: devices side by side in a holder - a rack item that holds devices across and wraps into rows for stacks, with slots to add to, drag between and Undo, the holder moving and removing what is in it, the slot shown on assets, the export and the API, and database 4.1.3 for rack_units slots, holder and position --- CHANGELOG.md | 5 +- admin/database_updates/4.1.3.php | 51 +++++ agent/asset.php | 3 +- agent/assets.php | 4 +- agent/includes/rack_elevation.php | 75 ++++++- agent/js/rack_drag.js | 84 +++++++- agent/modals/asset/asset.php | 2 +- agent/modals/rack/rack_device_add.php | 9 +- agent/modals/rack/rack_device_edit.php | 12 +- agent/modals/rack/rack_device_form.php | 185 +++++++++++++++-- agent/post/rack.php | 101 ++++++--- agent/rack.php | 28 ++- agent/racks.php | 3 +- api/v1/rack_units/create.php | 5 +- api/v1/rack_units/delete.php | 6 +- api/v1/rack_units/unit_model.php | 29 ++- api/v1/rack_units/update.php | 5 +- api/v1/racks/read.php | 15 +- api/v1/racks/update.php | 2 +- css/itflow_custom.css | 159 +++++++++++++- db.sql | 7 +- functions/asset.php | 2 +- functions/client_export.php | 14 +- functions/rack.php | 273 ++++++++++++++++++++++++- functions/undo.php | 23 +++ 25 files changed, 1002 insertions(+), 100 deletions(-) create mode 100644 admin/database_updates/4.1.3.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 664cf0e27..2f85a72fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This file documents all notable changes made to ITFlow. ### Upgrading -Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's one database change (4.1.1 to 4.1.2) in the same pass. It adds a column to RMM providers for the asset type each kind of device comes in as, and changes nothing that is there. Nothing else is required. +Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's two database changes (4.1.1 to 4.1.3) in the same pass. They add a column to RMM providers for the asset type each kind of device comes in as, and three to rack items for devices side by side in a holder, and change nothing that is there. Nothing else is required. ### New Features & Updates @@ -17,6 +17,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - RMM Providers: Bring back is on the client's row on the RMM Clients page as soon as you delete an asset that came from the RMM, rather than after the next sync, and the message for deleting it says so. - API: assets read through the API come with asset_rmm - each of the asset's devices in an RMM, with its status, when it was last seen, who is signed in, its IPs, and whether it needs a reboot, has patches waiting or has checks failing. - RMM Providers: most of a client's devices gone from the RMM at once - three or more, and at least half of them - are kept as they were for a day instead of being marked gone straight away. That is far more often the RMM, or a change to what its API key can see, than the devices, and marking them gone dropped them from managed device counts on recurring invoices. The provider's row names the client and how many, and the sync shows as failed so it is noticed. Still missing after a day, they are marked gone. A client deleted in the RMM is treated the same way, and agents reinstalled all at once are still matched to their assets. +- Racks: more than one device on a rack row - two Tiny PCs in a 1U bracket, eight PLCs on a shelf, the cards in a media converter chassis. Turn on Holds devices side by side on a rack item - a shelf, bracket or chassis, an asset or not - and say how many fit across. What is in it is drawn side by side in it, and past that many it wraps onto another row, for stacks. Click an empty slot to add something there, or pick the holder under Goes in when you add it. Drag an asset from Not racked yet or an item from the rack onto an empty slot, or a device to another slot, with Undo. Moving the holder moves what is in it, and removing it takes what is in it out of the rack too, after asking - the assets stay. An asset's page and the assets list show its slot, and so do the client export and the API. ### Bug Fixes @@ -47,6 +48,8 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - `js/itflow_select_early.js`, loaded in the `` of `includes/header.php`, `client/includes/header.php`, `agent/client_onboarding.php`, `admin/getting_started.php` and `setup/index.php` (a file, as the portal allows no inline scripts), watches the page as it is parsed and takes the dashes off a `- None -` option of a `select.select2`, marking it `data-none="1"` - before the first paint, so the raw ` + + + + + + + + +
+ +
+ + +
+
.
+
+
+ + +
@@ -125,12 +181,35 @@ $item_types = rackItemTypes();
-
- > - -
+
+
+ > + +
-
+
+ +
+ > + + + + +
+
+
+ + + across +
+
+ How many fit side by side - more than that wrap onto another row, for stacks. + + It holds now. + +
+
+
@@ -153,6 +232,7 @@ $item_types = rackItemTypes(); diff --git a/agent/post/rack.php b/agent/post/rack.php index a23b082b9..88adb0aac 100644 --- a/agent/post/rack.php +++ b/agent/post/rack.php @@ -69,7 +69,7 @@ if (isset($_POST['add_rack']) || isset($_POST['edit_rack'])) { // Shrinking the rack under an item would leave it hanging off the top $sql = mysqli_query($mysqli, "SELECT unit_device, unit_type, unit_end_number, asset_name FROM rack_units LEFT JOIN assets ON asset_id = unit_asset_id - WHERE unit_rack_id = $rack_id AND unit_end_number > $units + WHERE unit_rack_id = $rack_id AND unit_end_number > $units AND unit_parent_id IS NULL ORDER BY unit_end_number DESC LIMIT 1"); if ($row = mysqli_fetch_assoc($sql)) { $blocking_name = rackUnitName($row['asset_name'], $row['unit_device'], $row['unit_type']); @@ -206,14 +206,13 @@ if (isset($_POST['add_rack_unit']) || isset($_POST['edit_rack_unit'])) { $rack_id = intval($_POST['rack_id']); } - $sql = mysqli_query($mysqli, "SELECT rack_name, rack_client_id, rack_units FROM racks WHERE rack_id = $rack_id"); + $sql = mysqli_query($mysqli, "SELECT rack_name, rack_client_id FROM racks WHERE rack_id = $rack_id"); $rack_row = mysqli_fetch_assoc($sql); if (!$rack_row) { flashAlert("That rack no longer exists", 'error'); redirect(); } $rack_name = escapeSql($rack_row['rack_name']); - $rack_units = intval($rack_row['rack_units']); $client_id = intval($rack_row['rack_client_id']); enforceClientAccess(); @@ -230,11 +229,9 @@ if (isset($_POST['add_rack_unit']) || isset($_POST['edit_rack_unit'])) { $power_watts = intval($_POST['power_watts'] ?? 0); $power_watts_sql = $power_watts > 0 ? $power_watts : "NULL"; $notes = escapeSql($_POST['notes'] ?? ''); - - if ($start < 1 || $end > $rack_units) { - flashAlert("That doesn't fit - this rack runs from U1 to U$rack_units", 'error'); - redirect(); - } + // In one of the rack's holders, at a slot - or in the rack, holding devices side by side if it says so + $holder_id = intval($_POST['holder'] ?? 0); + $slots = !$holder_id && intval($_POST['holds'] ?? 0) === 1 ? max(1, intval($_POST['slots'] ?? 1)) : 0; // The asset has to be this client's, and in one place at a time $asset_name = ''; @@ -259,9 +256,11 @@ if (isset($_POST['add_rack_unit']) || isset($_POST['edit_rack_unit'])) { redirect(); } - $conflict = rackUnitConflict($rack_id, $start, $end, $face, $full_depth, $unit_id); - if ($conflict) { - flashAlert(html_entity_decode(rackPositionLabel($start, $end)) . " on the $face is taken by " . strip_tags($conflict['name']) . " (" . html_entity_decode(rackPositionLabel($conflict['start'], $conflict['end'])) . ")", 'error'); + // Units, overlaps and slots - functions/rack.php + $place = rackPlacement($rack_id, $unit_id, ['holder' => $holder_id, 'position' => intval($_POST['slot'] ?? 0), + 'start' => $start, 'end' => $end, 'face' => $face, 'full_depth' => $full_depth, 'slots' => $slots]); + if (isset($place['error'])) { + flashAlert($place['error'], 'error'); redirect(); } @@ -269,23 +268,34 @@ if (isset($_POST['add_rack_unit']) || isset($_POST['edit_rack_unit'])) { // A linked asset is drawn by its own asset type, so only unlinked items keep one $unit_type_sql = $asset_id ? "NULL" : "'" . escapeSql($unit_type) . "'"; - $set = "unit_device = '$label', unit_asset_id = $asset_sql, unit_type = $unit_type_sql, - unit_start_number = $start, unit_end_number = $end, unit_face = '$face', unit_full_depth = $full_depth, - unit_power_watts = $power_watts_sql, unit_notes = '$notes'"; + $set = "unit_device = '$label', unit_asset_id = $asset_sql, unit_type = $unit_type_sql, " . rackPlacementSet($place) . ", + unit_slots = " . intval($place['slots']) . ", unit_power_watts = $power_watts_sql, unit_notes = '$notes'"; $item_name = rackUnitName($asset_name, $_POST['name'] ?? '', $unit_type); $item_name_sql = escapeSql($item_name); $item_name_display = strip_tags($item_name); - $position = html_entity_decode(rackPositionLabel($start, $end)); + $face = $place['face']; + $position = html_entity_decode(rackPositionLabel($place['start'], $place['end'])); + if ($place['holder']) { + $where_log = escapeSql("in slot {$place['position']} of {$place['holder_name']} at $position"); + $where_display = "in slot {$place['position']} of " . strip_tags($place['holder_name']) . ""; + } else { + $where_log = "at $position"; + $where_display = "at $position"; + } if ($is_edit) { mysqli_query($mysqli, "UPDATE rack_units SET $set WHERE unit_id = $unit_id"); - logAudit("Rack", "Edit", "$session_name updated $item_name_sql at $position ($face) in rack $rack_name", $client_id, $rack_id); - flashAlert("$item_name_display saved at $position"); + // What it holds goes where it went + if ($place['slots']) { + rackSyncChildren($unit_id); + } + logAudit("Rack", "Edit", "$session_name updated $item_name_sql $where_log ($face) in rack $rack_name", $client_id, $rack_id); + flashAlert("$item_name_display saved $where_display"); } else { mysqli_query($mysqli, "INSERT INTO rack_units SET $set, unit_rack_id = $rack_id"); - logAudit("Rack", "Edit", "$session_name added $item_name_sql at $position ($face) to rack $rack_name", $client_id, $rack_id); - flashAlert("$item_name_display added at $position"); + logAudit("Rack", "Edit", "$session_name added $item_name_sql $where_log ($face) to rack $rack_name", $client_id, $rack_id); + flashAlert("$item_name_display added $where_display"); } redirect(); @@ -293,7 +303,9 @@ if (isset($_POST['add_rack_unit']) || isset($_POST['edit_rack_unit'])) { } // Dragged to another position on the rack page (agent/js/rack_drag.js) - the -// same item, keeping its height and depth, at a new start and face +// same item, keeping its height and depth, at a new start and face. Dropped on +// an empty slot in a holder instead (holder and slot), it goes in there - a +// holder takes what is in it along wherever it goes. if (isset($_POST['move_rack_unit'])) { validateCSRFToken(); @@ -303,7 +315,7 @@ if (isset($_POST['move_rack_unit'])) { $unit_id = intval($_POST['unit_id'] ?? 0); $sql = mysqli_query($mysqli, "SELECT unit_rack_id, unit_start_number, unit_end_number, unit_face, unit_full_depth, unit_device, unit_type, - asset_name, rack_name, rack_client_id, rack_units, rack_archived_at + unit_slots, unit_parent_id, unit_position, asset_name, rack_name, rack_client_id, rack_units, rack_archived_at FROM rack_units JOIN racks ON rack_id = unit_rack_id LEFT JOIN assets ON asset_id = unit_asset_id @@ -325,6 +337,42 @@ if (isset($_POST['move_rack_unit'])) { $rack_id = intval($row['unit_rack_id']); $rack_name = escapeSql($row['rack_name']); $rack_units = intval($row['rack_units']); + $parent_id = intval($row['unit_parent_id']); + $holder_id = intval($_POST['holder'] ?? 0); + + // Into a slot + if ($holder_id) { + $item_name = rackUnitName($row['asset_name'], $row['unit_device'], $row['unit_type']); + $place = rackPlacement($rack_id, $unit_id, ['holder' => $holder_id, 'position' => max(1, intval($_POST['slot'] ?? 1))]); + if (isset($place['error'])) { + flashAlert($place['error'], 'error'); + redirect(); + } + if ($place['holder'] === $parent_id && $place['position'] === intval($row['unit_position'])) { + redirect(); + } + + mysqli_query($mysqli, "UPDATE rack_units SET " . rackPlacementSet($place) . " WHERE unit_id = $unit_id"); + + logAudit("Rack", "Edit", "$session_name moved " . escapeSql($item_name) . " to slot {$place['position']} of " . escapeSql($place['holder_name']) . " in rack $rack_name", $client_id, $rack_id); + + flashAlert("" . strip_tags($item_name) . " moved to slot {$place['position']} of " . strip_tags($place['holder_name']) . ""); + $was = $parent_id + ? "in slot " . intval($row['unit_position']) . " of " . escapeHtml(strip_tags(rackHolderName($parent_id))) . "" + : "at " . rackPositionLabel($row['unit_start_number'], $row['unit_end_number']) . " on the {$row['unit_face']}"; + undoOffer("" . escapeHtml(strip_tags($item_name)) . " is back $was", + [['rack_place', $unit_id, [$parent_id, intval($row['unit_position']), intval($row['unit_start_number']), intval($row['unit_end_number']), $row['unit_face'], intval($row['unit_full_depth'])], + [$place['holder'], $place['position']]]], 'module_support'); + + redirect(); + } + + // Something in a holder moves to another slot, or out through Edit - it has no units of its own to drag to + if ($parent_id) { + flashAlert("" . strip_tags(rackUnitName($row['asset_name'], $row['unit_device'], $row['unit_type'])) . " is in " . strip_tags(rackHolderName($parent_id)) . " - drop it on an empty slot, or take it out with Edit", 'error'); + redirect(); + } + $height = max(1, intval($row['unit_end_number']) - intval($row['unit_start_number']) + 1); $start = intval($_POST['unit_start'] ?? 0); $end = $start + $height - 1; @@ -349,6 +397,9 @@ if (isset($_POST['move_rack_unit'])) { } mysqli_query($mysqli, "UPDATE rack_units SET unit_start_number = $start, unit_end_number = $end, unit_face = '$face' WHERE unit_id = $unit_id"); + if (intval($row['unit_slots'])) { + rackSyncChildren($unit_id); + } logAudit("Rack", "Edit", "$session_name moved " . escapeSql($item_name) . " to $position ($face) in rack $rack_name", $client_id, $rack_id); @@ -384,11 +435,15 @@ if (isset($_GET['remove_rack_unit'])) { enforceClientAccess(); + // What is in a holder comes out with it (the key cascades) - the assets stay + $children = rackChildCount($unit_id); + $with = $children ? ' and the ' . rackDeviceCount($children) . ' in it' : ''; + mysqli_query($mysqli, "DELETE FROM rack_units WHERE unit_id = $unit_id"); - logAudit("Rack", "Edit", "$session_name removed " . escapeSql($item_name) . " from rack $rack_name", $client_id, $rack_id); + logAudit("Rack", "Edit", "$session_name removed " . escapeSql($item_name) . "$with from rack $rack_name", $client_id, $rack_id); - flashAlert("" . strip_tags($item_name) . " removed from the rack", 'error'); + flashAlert("" . strip_tags($item_name) . "$with removed from the rack", 'error'); redirect(); diff --git a/agent/rack.php b/agent/rack.php index e7b345647..83ae00ef9 100644 --- a/agent/rack.php +++ b/agent/rack.php @@ -9,6 +9,8 @@ * gap a full-depth item could still go in, power against the budget), the * rack's details and photos, the item list for print and search, the * client's network gear that isn't racked anywhere yet, and its history. + * A holder (a bracket, shelf or chassis) draws the devices in it side by side, + * and lists them under it. * Items drag to another position, and the gear not racked yet drags onto * the rack (agent/js/rack_drag.js, move_rack_unit in agent/post/rack.php). */ @@ -184,7 +186,7 @@ if (mysqli_num_rows($sql) == 0) {
$b['start'] : $b['end'] <=> $a['end']; }); + $table_items = []; + foreach ($table_tops as $table_top) { + $table_items[] = $table_top; + foreach ($table_top['children'] as $table_child) { + $table_items[] = $table_child; + } + } foreach ($table_items as $item) { ?> - - + + Slot + + + + >
@@ -247,6 +260,7 @@ if (mysqli_num_rows($sql) == 0) {
+ · holds across · ·
@@ -465,6 +479,8 @@ if (mysqli_num_rows($sql) == 0) { + + diff --git a/agent/racks.php b/agent/racks.php index 27a63596c..cd0802677 100644 --- a/agent/racks.php +++ b/agent/racks.php @@ -230,7 +230,8 @@ foreach ($racks as $rack_id => $row) {