mirror of
https://github.com/itflow-org/itflow
synced 2026-11-23 21:07:22 +00:00
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
This commit is contained in:
@@ -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 `<head>` 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 `<select>` shown until `js/itflow_select.js` runs in the footer already reads the same. It stops at `DOMContentLoaded`. `js/itflow_select.js` treats `data-none="1"` as the "nothing" choice alongside an empty value and the dashed label, and `css/itflow_custom.css` greys a single select showing it until the picker takes over (`:has(option:checked[data-none="1"])`).
|
||||
- `dateFilterLabel($dtf, $dtt)` in `functions/format.php` gives what `js/date_filter.js` shows for a range - `All Time` for 1970-01-01 to 2099-12-31 or no dates, otherwise `Y-m-d — Y-m-d`, a date that isn't one taken as no bound. The 18 pages with a `#dateFilter` write it as the box's `value`, from the same expressions as their hidden `dtf` and `dtt`. `js/date_filter.js` empties the box before it starts Flatpickr, which would otherwise try to read those words as dates, and `setDisplay()` writes them back in the same step.
|
||||
- `reportQuarters($year, $current_year)` in `functions/reports.php` gives a year's quarters - label, months, first and last month, `done`, `now` or `later`, and what each is compared with - and `reportQuarterSum($months, $quarter)` a quarter's share of a year of months. A report puts its `rows` (`label`, `now`, `prev`, `good`, `strong`) on each and `reportQuarterCards($quarters, $whole)` draws them, in the `.itflow-report-stats` strip, laid out by a container query on its own width: four across, two by two, or one a row. `agent/reports/profit_loss.php` and `agent/reports/tax_summary.php` show them on Quarterly in place of the chart, the latter adding up last year's tax paid on purchases for net tax. `reportChartColumns($months, $columns, $months_shown)` sums a year's months into a report's columns for a chart, null for a column still to come.
|
||||
- Database 4.1.3: `rack_units.unit_slots` (how many a holder takes side by side, 0 for any other item), `unit_parent_id` (the holder a device is in - a foreign key to `rack_units` that cascades on delete) and `unit_position` (its slot, 1 the first, counting across and then a row on). Re-runnable. A device in a holder keeps its holder's units, face and depth in its own columns - `rackSyncChildren($holder_id)` after the holder moves or changes - so whatever reads where an asset is racked reads it as before, and `rackOccupancy()` and `rackUnitConflict()` skip devices in a holder. `rackPositionForAsset()` adds `holder_name` and `unit_position`.
|
||||
- `rackPlacement($rack_id, $unit_id, $want)` in `functions/rack.php` checks where an item goes - in the rack (bounds, overlaps, and that a holder with devices in it still holds devices) or in a slot (the holder is in the same rack and holds devices, the item holds none, the slot is free and at most a row past the last one used, `rackSlotLimit()`) - and `rackPlacementSet()` writes it. The rack item form, the drag (`move_rack_unit` with `holder` and `slot`), Undo (`['rack_place', ...]`) and the API's `rack_units` endpoints (`unit_slots`, `unit_parent_id`, `unit_position`) all go through it. `rackNestItems()` and `rackHolderCells()` lay a holder out for `agent/includes/rack_elevation.php`, its rows counting the way the rack's units do.
|
||||
|
||||
## [26.12]
|
||||
|
||||
|
||||
51
admin/database_updates/4.1.3.php
Normal file
51
admin/database_updates/4.1.3.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ITFlow - Database update to version 4.1.3 (from 4.1.2)
|
||||
* Included by admin/database_updates.php - do not access directly
|
||||
*
|
||||
* More than one device on a rack row - two Tiny PCs in a 1U bracket, eight PLCs on
|
||||
* a shelf, a media converter chassis. A holder is a rack item that devices go in
|
||||
* side by side; each device is a rack item of its own, in one of the holder's slots.
|
||||
*
|
||||
* rack_units.unit_slots how many fit side by side, on a holder - 0 for any other item.
|
||||
* Devices past that wrap onto another row, for stacks.
|
||||
* rack_units.unit_parent_id the holder a device sits in, NULL for one in the rack itself.
|
||||
* Removing the holder takes its devices out with it.
|
||||
* rack_units.unit_position the device's slot in its holder - 1 is the first, counting across
|
||||
* and then a row on.
|
||||
*
|
||||
* A device in a holder keeps the holder's units, face and depth in its own columns, so
|
||||
* whatever reads where something is racked reads it the same way.
|
||||
*
|
||||
* Re-runnable: it only adds what isn't there.
|
||||
*/
|
||||
|
||||
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
|
||||
|
||||
$itflow_has = function ($what, $name) use ($mysqli) {
|
||||
$table = $what === 'column' ? 'COLUMNS' : ($what === 'key' ? 'STATISTICS' : 'TABLE_CONSTRAINTS');
|
||||
$field = $what === 'column' ? 'COLUMN_NAME' : ($what === 'key' ? 'INDEX_NAME' : 'CONSTRAINT_NAME');
|
||||
$schema = $what === 'constraint' ? 'CONSTRAINT_SCHEMA' : 'TABLE_SCHEMA';
|
||||
$result = mysqli_query($mysqli, "SELECT 1 FROM information_schema.$table
|
||||
WHERE $schema = DATABASE() AND TABLE_NAME = 'rack_units' AND $field = '$name' LIMIT 1");
|
||||
return $result && mysqli_num_rows($result) > 0;
|
||||
};
|
||||
|
||||
if (!$itflow_has('column', 'unit_slots')) {
|
||||
mysqli_query($mysqli, "ALTER TABLE `rack_units` ADD `unit_slots` int(11) NOT NULL DEFAULT 0 AFTER `unit_notes`");
|
||||
}
|
||||
if (!$itflow_has('column', 'unit_position')) {
|
||||
mysqli_query($mysqli, "ALTER TABLE `rack_units` ADD `unit_position` int(11) NOT NULL DEFAULT 0 AFTER `unit_slots`");
|
||||
}
|
||||
if (!$itflow_has('column', 'unit_parent_id')) {
|
||||
mysqli_query($mysqli, "ALTER TABLE `rack_units` ADD `unit_parent_id` int(11) DEFAULT NULL AFTER `unit_rack_id`");
|
||||
}
|
||||
if (!$itflow_has('key', 'unit_parent_id')) {
|
||||
mysqli_query($mysqli, "ALTER TABLE `rack_units` ADD KEY `unit_parent_id` (`unit_parent_id`)");
|
||||
}
|
||||
if (!$itflow_has('constraint', 'rack_units_ibfk_2')) {
|
||||
mysqli_query($mysqli, "ALTER TABLE `rack_units` ADD CONSTRAINT `rack_units_ibfk_2` FOREIGN KEY (`unit_parent_id`) REFERENCES `rack_units` (`unit_id`) ON DELETE CASCADE");
|
||||
}
|
||||
|
||||
unset($itflow_has);
|
||||
@@ -138,7 +138,8 @@ if (mysqli_num_rows($sql) == 0) {
|
||||
if ($asset_rack) {
|
||||
$asset_rack_id = intval($asset_rack['rack_id']);
|
||||
$asset_rack_name = escapeHtml($asset_rack['rack_name']);
|
||||
$asset_rack_position = rackPositionLabel($asset_rack['unit_start_number'], $asset_rack['unit_end_number']) . ', ' . ($asset_rack['unit_face'] === 'rear' ? 'rear' : 'front');
|
||||
$asset_rack_position = rackPositionLabel($asset_rack['unit_start_number'], $asset_rack['unit_end_number']) . ', ' . ($asset_rack['unit_face'] === 'rear' ? 'rear' : 'front')
|
||||
. escapeHtml(rackSlotText($asset_rack['holder_name'], $asset_rack['unit_position']));
|
||||
}
|
||||
|
||||
// Override Tab Title // No Sanitizing needed as this var will opnly be used in the tab title
|
||||
|
||||
@@ -212,7 +212,7 @@ $assets_tags = tagsForRecords('asset', array_keys($assets));
|
||||
$assets_rmm = $rmm_set_up ? rmmDevicesForAssets(array_keys($assets)) : [];
|
||||
$assets_racked = [];
|
||||
if ($assets) {
|
||||
$sql_racked = mysqli_query($mysqli, "SELECT unit_asset_id, unit_start_number, unit_end_number, rack_id, rack_name FROM rack_units
|
||||
$sql_racked = mysqli_query($mysqli, "SELECT unit_asset_id, unit_start_number, unit_end_number, unit_parent_id, unit_position, rack_id, rack_name FROM rack_units
|
||||
JOIN racks ON rack_id = unit_rack_id
|
||||
WHERE unit_asset_id IN (" . implode(',', array_keys($assets)) . ")");
|
||||
while ($row = mysqli_fetch_assoc($sql_racked)) {
|
||||
@@ -732,7 +732,7 @@ $search_noun = $type_filter ? $asset_type_tabs[$type_filter]['label'] : 'assets'
|
||||
<?php } ?>
|
||||
<?php if ($asset_rack) { ?>
|
||||
<a class="small text-nowrap d-inline-block <?= $can_edit && !$asset_physical_location ? 'mt-1' : '' ?>" href="rack.php?client_id=<?= $client_id ?>&rack_id=<?= intval($asset_rack['rack_id']) ?>" title="Racked">
|
||||
<i class="fas fa-server me-1"></i><?= escapeHtml($asset_rack['rack_name']) ?> · <?= rackPositionLabel($asset_rack['unit_start_number'], $asset_rack['unit_end_number']) ?>
|
||||
<i class="fas fa-server me-1"></i><?= escapeHtml($asset_rack['rack_name']) ?> · <?= rackPositionLabel($asset_rack['unit_start_number'], $asset_rack['unit_end_number']) ?><?= $asset_rack['unit_parent_id'] ? ' · slot ' . intval($asset_rack['unit_position']) : '' ?>
|
||||
</a>
|
||||
<?php } ?>
|
||||
</td>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* front and once for the rear. Expects:
|
||||
*
|
||||
* $elevation_face 'front' | 'rear'
|
||||
* $elevation_items rackUnitView() items for the whole rack
|
||||
* $elevation_items rackUnitView() items for the whole rack, nested (rackNestItems())
|
||||
* $elevation_rack_units rack height in U
|
||||
* $elevation_descending 1 when U1 is at the top
|
||||
* $elevation_can_edit whether empty U and items open the add/edit modals
|
||||
@@ -17,6 +17,12 @@
|
||||
* the bay takes what is dropped on it (agent/js/rack_drag.js) - the data-rack-*
|
||||
* attributes are what that script reads.
|
||||
*
|
||||
* A holder draws what is in it side by side, in rows when it wraps
|
||||
* (rackHolderCells()): each device opens like any other item and drags to an
|
||||
* empty slot, and each empty slot is an "add here" of its own. The holder
|
||||
* itself is its tab at the left - that opens it, and drags it with everything
|
||||
* in it.
|
||||
*
|
||||
* Should not be accessed directly.
|
||||
*/
|
||||
|
||||
@@ -74,6 +80,8 @@ $elevation_rail = $elevation_descending ? range(1, $elevation_rack_units) : rang
|
||||
$block_classes = "itflow-rack-item itflow-rack-tone-{$block['tone']} itflow-rack-h" . min(3, $block['height']);
|
||||
if ($block['ghost']) {
|
||||
$block_classes .= ' is-ghost';
|
||||
} elseif ($block['slots']) {
|
||||
$block_classes .= ' is-holder';
|
||||
}
|
||||
if ($block['asset_archived']) {
|
||||
$block_classes .= ' is-archived';
|
||||
@@ -86,9 +94,70 @@ $elevation_rail = $elevation_descending ? range(1, $elevation_rack_units) : rang
|
||||
?>
|
||||
<div class="<?= $block_classes ?>" style="grid-row: <?= $block_row ?> / span <?= $block['height'] ?>"
|
||||
data-rack-unit="<?= $block['id'] ?>" data-rack-start="<?= $block['start'] ?>" data-rack-end="<?= $block['end'] ?>" data-rack-name="<?= $block['name'] ?>"
|
||||
<?php if ($block_drags) { ?>draggable="true" data-rack-drag="unit" data-rack-id="<?= $block['id'] ?>" data-rack-height="<?= $block['height'] ?>" data-rack-full="<?= $block['full_depth'] ? 1 : 0 ?>" data-rack-from="<?= $block['face'] ?>"<?php } ?>>
|
||||
<?php if ($block_drags) { ?>draggable="true" data-rack-drag="unit" data-rack-id="<?= $block['id'] ?>" data-rack-height="<?= $block['height'] ?>" data-rack-full="<?= $block['full_depth'] ? 1 : 0 ?>" data-rack-from="<?= $block['face'] ?>"<?= $block['slots'] ? ' data-rack-holds="1"' : '' ?><?php } ?>>
|
||||
|
||||
<?php if ($block['ghost']) { ?>
|
||||
<?php if ($block['slots'] && !$block['ghost']) {
|
||||
$holder = rackHolderCells($block, $elevation_descending);
|
||||
$holder_title = $block['name'] . ' - ' . html_entity_decode($block['position']) . ($block['meta'] ? " - {$block['meta']}" : '') . " - holds {$block['slots']} across" . ($block_drags ? ' - drag to move it with what is in it' : '');
|
||||
// The tab opens the holder's editor - its asset, if it is one, is in the list below
|
||||
if ($elevation_can_edit) {
|
||||
$tab_open = '<button type="button" class="itflow-rack-holder-tab ajax-modal" data-modal-url="modals/rack/rack_device_edit.php?id=' . $block['id'] . '" title="' . $holder_title . '">';
|
||||
$tab_close = '</button>';
|
||||
} elseif ($block['asset_id']) {
|
||||
$tab_open = '<a class="itflow-rack-holder-tab" href="asset.php?client_id=' . $client_id . '&asset_id=' . $block['asset_id'] . '" title="' . $holder_title . '" draggable="false">';
|
||||
$tab_close = '</a>';
|
||||
} else {
|
||||
$tab_open = '<span class="itflow-rack-holder-tab" title="' . $holder_title . '">';
|
||||
$tab_close = '</span>';
|
||||
}
|
||||
?>
|
||||
<?= $tab_open ?><i class="fas fa-fw <?= $block['icon'] ?>"></i><span class="visually-hidden"><?= $block['name'] ?></span><?= $tab_close ?>
|
||||
<div class="itflow-rack-holder-slots" style="grid-template-columns: repeat(<?= $holder['columns'] ?>, minmax(0, 1fr)); grid-template-rows: repeat(<?= $holder['rows'] ?>, minmax(0, 1fr))">
|
||||
<?php foreach ($holder['cells'] as $cell) {
|
||||
$cell_place = "grid-column: {$cell['column']}; grid-row: {$cell['row']}";
|
||||
$child = $cell['item'];
|
||||
if (!$child) {
|
||||
if ($elevation_can_edit) { ?>
|
||||
<button type="button" class="itflow-rack-cell is-empty ajax-modal" style="<?= $cell_place ?>" data-rack-cell data-rack-holder="<?= $block['id'] ?>" data-rack-slot="<?= $cell['slot'] ?>"
|
||||
data-modal-url="modals/rack/rack_device_add.php?id=<?= $rack_id ?>&holder=<?= $block['id'] ?>&slot=<?= $cell['slot'] ?>"
|
||||
title="Add something to slot <?= $cell['slot'] ?> of <?= $block['name'] ?>">
|
||||
<i class="fas fa-plus"></i>
|
||||
</button>
|
||||
<?php } else { ?>
|
||||
<span class="itflow-rack-cell is-empty" style="<?= $cell_place ?>"></span>
|
||||
<?php }
|
||||
continue;
|
||||
}
|
||||
$child_title = $child['name'] . " - slot {$cell['slot']} of {$block['name']}" . ($child['meta'] ? " - {$child['meta']}" : '') . ($elevation_can_edit ? ' - drag to another slot' : '');
|
||||
if ($child['asset_id']) {
|
||||
$child_open = '<a class="itflow-rack-cell-body" href="asset.php?client_id=' . $client_id . '&asset_id=' . $child['asset_id'] . '" title="' . $child_title . '" draggable="false">';
|
||||
$child_close = '</a>';
|
||||
} elseif ($elevation_can_edit) {
|
||||
$child_open = '<button type="button" class="itflow-rack-cell-body ajax-modal" data-modal-url="modals/rack/rack_device_edit.php?id=' . $child['id'] . '" title="' . $child_title . '">';
|
||||
$child_close = '</button>';
|
||||
} else {
|
||||
$child_open = '<div class="itflow-rack-cell-body" title="' . $child_title . '">';
|
||||
$child_close = '</div>';
|
||||
}
|
||||
?>
|
||||
<div class="itflow-rack-cell itflow-rack-tone-<?= $child['tone'] ?><?= $child['asset_archived'] ? ' is-archived' : '' ?>" style="<?= $cell_place ?>"
|
||||
<?php if ($elevation_can_edit) { ?>draggable="true" data-rack-drag="unit" data-rack-child="1" data-rack-id="<?= $child['id'] ?>" data-rack-holder="<?= $block['id'] ?>" data-rack-slot="<?= $cell['slot'] ?>" data-rack-height="<?= $block['height'] ?>" data-rack-full="<?= $block['full_depth'] ? 1 : 0 ?>" data-rack-from="<?= $block['face'] ?>" data-rack-start="<?= $block['start'] ?>"<?php } ?>>
|
||||
<?= $child_open ?>
|
||||
<span class="itflow-rack-cell-name"><?= $child['name'] ?></span>
|
||||
<?php if ($child['meta'] && $block['height'] / $holder['rows'] >= 2) { ?>
|
||||
<span class="itflow-rack-cell-meta"><?= $child['meta'] ?></span>
|
||||
<?php } ?>
|
||||
<?= $child_close ?>
|
||||
<?php if ($elevation_can_edit && $child['asset_id']) { ?>
|
||||
<button type="button" class="itflow-rack-cell-edit ajax-modal" title="Move or edit"
|
||||
data-modal-url="modals/rack/rack_device_edit.php?id=<?= $child['id'] ?>">
|
||||
<i class="fas fa-pen"></i>
|
||||
</button>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } elseif ($block['ghost']) { ?>
|
||||
<div class="itflow-rack-item-body" title="<?= $block_title ?> - mounted on the <?= $elevation_other_face ?>, full depth">
|
||||
<span class="itflow-rack-item-text">
|
||||
<span class="itflow-rack-item-name"><?= $block['name'] ?></span>
|
||||
|
||||
@@ -12,6 +12,11 @@
|
||||
* The data-rack-* attributes come from agent/includes/rack_elevation.php:
|
||||
* each bay knows its face, height and numbering; each item its unit, units
|
||||
* and depth. Click still does what it did - an empty U adds, an item opens.
|
||||
*
|
||||
* Holders: an empty slot in one (data-rack-cell) takes what is dropped on it -
|
||||
* an item from the rack, a device from another slot, or an asset not racked
|
||||
* yet (which opens Add for that slot). A holder doesn't go in a holder, and a
|
||||
* device in one only drags to another slot - Edit takes it out.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
@@ -67,22 +72,39 @@
|
||||
return el;
|
||||
}
|
||||
|
||||
function clearTargets(keep) {
|
||||
document.querySelectorAll('.itflow-rack-cell.is-target').forEach(function (el) {
|
||||
if (el !== keep) {
|
||||
el.classList.remove('is-target');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function clearMarkers() {
|
||||
document.querySelectorAll('.itflow-rack-drop').forEach(function (el) {
|
||||
el.remove();
|
||||
});
|
||||
clearTargets(null);
|
||||
}
|
||||
|
||||
// The empty slot under the pointer that this can go in, or null
|
||||
function cellAt(bay, target) {
|
||||
var cell = target && target.closest ? target.closest('[data-rack-cell]') : null;
|
||||
return cell && bay.contains(cell) && !drag.holds ? cell : null;
|
||||
}
|
||||
|
||||
function label(place) {
|
||||
return place.start === place.end ? 'U' + place.start : 'U' + place.start + '–U' + place.end;
|
||||
}
|
||||
|
||||
function openAdd(place) {
|
||||
function openAdd(place, cell) {
|
||||
var open = document.createElement('a');
|
||||
open.href = '#';
|
||||
open.className = 'ajax-modal d-none';
|
||||
open.setAttribute('data-modal-url', 'modals/rack/rack_device_add.php?id=' + encodeURIComponent(rackId)
|
||||
+ '&asset_id=' + encodeURIComponent(drag.id) + '&u=' + place.start + '&face=' + place.face);
|
||||
+ '&asset_id=' + encodeURIComponent(drag.id) + (cell
|
||||
? '&holder=' + encodeURIComponent(cell.dataset.rackHolder) + '&slot=' + encodeURIComponent(cell.dataset.rackSlot)
|
||||
: '&u=' + place.start + '&face=' + place.face));
|
||||
document.body.appendChild(open);
|
||||
open.click();
|
||||
open.remove();
|
||||
@@ -94,8 +116,23 @@
|
||||
return;
|
||||
}
|
||||
form.elements.unit_id.value = drag.id;
|
||||
form.elements.unit_start.value = place.start;
|
||||
form.elements.face.value = place.face;
|
||||
form.elements.unit_start.value = place ? place.start : '';
|
||||
form.elements.face.value = place ? place.face : '';
|
||||
form.elements.holder.value = '';
|
||||
form.elements.slot.value = '';
|
||||
form.submit();
|
||||
}
|
||||
|
||||
function moveToSlot(cell) {
|
||||
var form = document.getElementById('rackMoveForm');
|
||||
if (!form) {
|
||||
return;
|
||||
}
|
||||
form.elements.unit_id.value = drag.id;
|
||||
form.elements.unit_start.value = '';
|
||||
form.elements.face.value = '';
|
||||
form.elements.holder.value = cell.dataset.rackHolder;
|
||||
form.elements.slot.value = cell.dataset.rackSlot;
|
||||
form.submit();
|
||||
}
|
||||
|
||||
@@ -117,6 +154,8 @@
|
||||
height: height,
|
||||
grab: grab,
|
||||
full: source.dataset.rackFull === '1',
|
||||
child: source.dataset.rackChild === '1',
|
||||
holds: source.dataset.rackHolds === '1',
|
||||
from: source.dataset.rackFrom || '',
|
||||
start: parseInt(source.dataset.rackStart, 10) || 0,
|
||||
source: source
|
||||
@@ -142,21 +181,28 @@
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
var place = placeAt(bay, e.clientY);
|
||||
var blocked = inTheWay(place);
|
||||
var cell = cellAt(bay, e.target);
|
||||
clearTargets(cell);
|
||||
bays.forEach(function (other) {
|
||||
if (other !== bay) {
|
||||
if (other !== bay || cell) {
|
||||
var old = other.querySelector('.itflow-rack-drop');
|
||||
if (old) {
|
||||
old.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
e.dataTransfer.dropEffect = 'move';
|
||||
// Over an empty slot in a holder: that is where it goes
|
||||
if (cell) {
|
||||
cell.classList.add('is-target');
|
||||
return;
|
||||
}
|
||||
var place = placeAt(bay, e.clientY);
|
||||
var blocked = drag.child ? 'slot' : inTheWay(place);
|
||||
var el = marker(bay);
|
||||
el.style.gridRow = place.top + ' / span ' + drag.height;
|
||||
el.classList.toggle('is-blocked', blocked !== '');
|
||||
el.textContent = blocked ? blocked + ' is here' : label(place);
|
||||
e.dataTransfer.dropEffect = 'move';
|
||||
el.textContent = drag.child ? 'Drop it on an empty slot' : (blocked ? blocked + ' is here' : label(place));
|
||||
});
|
||||
|
||||
bay.addEventListener('dragleave', function (e) {
|
||||
@@ -165,6 +211,9 @@
|
||||
if (el) {
|
||||
el.remove();
|
||||
}
|
||||
bay.querySelectorAll('.itflow-rack-cell.is-target').forEach(function (target) {
|
||||
target.classList.remove('is-target');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -173,9 +222,24 @@
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
var cell = cellAt(bay, e.target);
|
||||
clearMarkers();
|
||||
if (cell) {
|
||||
if (drag.kind === 'asset') {
|
||||
openAdd(null, cell);
|
||||
} else if (cell.dataset.rackHolder !== drag.source.dataset.rackHolder || cell.dataset.rackSlot !== drag.source.dataset.rackSlot) {
|
||||
moveToSlot(cell);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (drag.child) {
|
||||
if (typeof itflowToast === 'function') {
|
||||
itflowToast('Drop it on an empty slot - or take it out of the holder with Edit', 'error');
|
||||
}
|
||||
return;
|
||||
}
|
||||
var place = placeAt(bay, e.clientY);
|
||||
var blocked = inTheWay(place);
|
||||
clearMarkers();
|
||||
if (blocked) {
|
||||
if (typeof itflowToast === 'function') {
|
||||
itflowToast(label(place) + ' on the ' + place.face + ' is taken by ' + blocked, 'error');
|
||||
|
||||
@@ -299,7 +299,7 @@ ob_start();
|
||||
<?php if ($asset_rack) { ?>
|
||||
<div class="itflow-glance-item" title="Rack">
|
||||
<i class="fas fa-fw fa-server"></i>
|
||||
<span><a href="rack.php?client_id=<?= $client_id ?>&rack_id=<?= intval($asset_rack['rack_id']) ?>"><?= escapeHtml($asset_rack['rack_name']) ?></a> <span class="text-body-secondary">· <?= rackPositionLabel($asset_rack['unit_start_number'], $asset_rack['unit_end_number']) ?>, <?= $asset_rack['unit_face'] === 'rear' ? 'rear' : 'front' ?></span></span>
|
||||
<span><a href="rack.php?client_id=<?= $client_id ?>&rack_id=<?= intval($asset_rack['rack_id']) ?>"><?= escapeHtml($asset_rack['rack_name']) ?></a> <span class="text-body-secondary">· <?= rackPositionLabel($asset_rack['unit_start_number'], $asset_rack['unit_end_number']) ?>, <?= $asset_rack['unit_face'] === 'rear' ? 'rear' : 'front' ?><?= escapeHtml(rackSlotText($asset_rack['holder_name'], $asset_rack['unit_position'])) ?></span></span>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
@@ -6,7 +6,7 @@ enforceUserPermission('module_support', 2);
|
||||
|
||||
$rack_id = intval($_GET['id']);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT rack_client_id, rack_name, rack_units FROM racks WHERE rack_id = $rack_id LIMIT 1");
|
||||
$sql = mysqli_query($mysqli, "SELECT rack_client_id, rack_name, rack_units, rack_units_descending FROM racks WHERE rack_id = $rack_id LIMIT 1");
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
if (!$row) {
|
||||
@@ -15,11 +15,13 @@ if (!$row) {
|
||||
}
|
||||
$rack_name = escapeHtml($row['rack_name']);
|
||||
$rack_units = intval($row['rack_units']);
|
||||
$rack_units_descending = intval($row['rack_units_descending']);
|
||||
$client_id = intval($row['rack_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
// A new item. Clicking an empty U on the rack page passes where it was.
|
||||
// A new item. Clicking an empty U on the rack page passes where it was - an
|
||||
// empty slot in a holder passes the holder and the slot.
|
||||
$unit_id = 0;
|
||||
$unit_asset_id = 0;
|
||||
$unit_device = '';
|
||||
@@ -30,6 +32,9 @@ $unit_face = ($_GET['face'] ?? '') === 'rear' ? 'rear' : 'front';
|
||||
$unit_full_depth = 1;
|
||||
$unit_power_watts = 0;
|
||||
$unit_notes = '';
|
||||
$unit_holder_id = intval($_GET['holder'] ?? 0);
|
||||
$unit_slot = max(0, intval($_GET['slot'] ?? 0));
|
||||
$unit_slots = 0;
|
||||
|
||||
// "Rack it" on the rack page, or an asset dragged onto it, passes the asset - start from what that kind of kit usually is
|
||||
$unit_asset_id = intval($_GET['asset_id'] ?? 0);
|
||||
|
||||
@@ -7,7 +7,8 @@ enforceUserPermission('module_support', 2);
|
||||
$unit_id = intval($_GET['id']);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT unit_asset_id, unit_device, unit_end_number, unit_face, unit_full_depth, unit_notes,
|
||||
unit_power_watts, unit_rack_id, unit_start_number, unit_type, rack_client_id, rack_name, rack_units, asset_name
|
||||
unit_power_watts, unit_rack_id, unit_start_number, unit_type, unit_slots, unit_parent_id, unit_position,
|
||||
rack_client_id, rack_name, rack_units, rack_units_descending, asset_name
|
||||
FROM rack_units
|
||||
LEFT JOIN racks ON rack_id = unit_rack_id
|
||||
LEFT JOIN assets ON asset_id = unit_asset_id
|
||||
@@ -21,6 +22,7 @@ if (!$row) {
|
||||
$rack_id = intval($row['unit_rack_id']);
|
||||
$rack_name = escapeHtml($row['rack_name']);
|
||||
$rack_units = intval($row['rack_units']);
|
||||
$rack_units_descending = intval($row['rack_units_descending']);
|
||||
$client_id = intval($row['rack_client_id']);
|
||||
|
||||
$unit_asset_id = intval($row['unit_asset_id']);
|
||||
@@ -33,6 +35,11 @@ $unit_full_depth = intval($row['unit_full_depth']);
|
||||
$unit_power_watts = intval($row['unit_power_watts']);
|
||||
$unit_notes = escapeHtml($row['unit_notes']);
|
||||
$unit_name = escapeHtml(rackUnitName($row['asset_name'], $row['unit_device'], $row['unit_type']));
|
||||
$unit_holder_id = intval($row['unit_parent_id']);
|
||||
$unit_slot = $unit_holder_id ? intval($row['unit_position']) : 0;
|
||||
$unit_slots = $unit_holder_id ? 0 : intval($row['unit_slots']);
|
||||
// Removing a holder takes what is in it out of the rack too
|
||||
$unit_remove_children = rackChildCount($unit_id);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
@@ -53,7 +60,8 @@ ob_start();
|
||||
<?php require 'rack_device_form.php'; ?>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a class="btn btn-link text-danger me-auto confirm-link" href="post.php?remove_rack_unit=<?= $unit_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<a class="btn btn-link text-danger me-auto confirm-link" href="post.php?remove_rack_unit=<?= $unit_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>"
|
||||
<?php if ($unit_remove_children) { ?>data-confirm-text="<?= $unit_remove_children === 1 ? 'The device in it comes' : "The $unit_remove_children devices in it come" ?> out of the rack too. The assets themselves stay."<?php } ?>>
|
||||
<i class="fas fa-fw fa-minus-circle me-1"></i>Remove from rack
|
||||
</a>
|
||||
<button type="submit" name="edit_rack_unit" class="btn btn-primary fw-bold"><i class="fas fa-check me-2"></i>Save</button>
|
||||
|
||||
@@ -1,24 +1,43 @@
|
||||
<?php
|
||||
/*
|
||||
* Rack item form - shared by rack_device_add.php and rack_device_edit.php,
|
||||
* which load the rack ($rack_id, $rack_units, $client_id) and the item's
|
||||
* current values ($unit_*, empty for a new one) before including this.
|
||||
* Should not be accessed directly.
|
||||
* which load the rack ($rack_id, $rack_units, $rack_units_descending,
|
||||
* $client_id) and the item's current values ($unit_*, empty for a new one -
|
||||
* $unit_holder_id and $unit_slot for one in a holder, $unit_slots for one that
|
||||
* holds devices) before including this. Should not be accessed directly.
|
||||
*
|
||||
* The live position check below is advisory - agent/post/rack.php runs the
|
||||
* same bounds, overlap and asset checks again on submit.
|
||||
* The live position and slot checks below are advisory - agent/post/rack.php
|
||||
* runs the same bounds, overlap, slot and asset checks (rackPlacement()) again
|
||||
* on submit.
|
||||
*/
|
||||
|
||||
isset($mysqli) || die("Direct file access is not allowed");
|
||||
|
||||
// Everything else in the rack, for the live position check
|
||||
// Everything else in the rack, for the live position check - and the holders
|
||||
// it could go in, with what is in each, for the slot check
|
||||
$rack_other_units = [];
|
||||
$sql = mysqli_query($mysqli, "SELECT unit_id, unit_device, unit_type, unit_start_number, unit_end_number, unit_face, unit_full_depth, asset_name
|
||||
$rack_holders = [];
|
||||
$rack_holder_taken = [];
|
||||
$sql = mysqli_query($mysqli, "SELECT unit_id, unit_device, unit_type, unit_start_number, unit_end_number, unit_face, unit_full_depth,
|
||||
unit_slots, unit_parent_id, unit_position, asset_name, asset_type
|
||||
FROM rack_units
|
||||
LEFT JOIN assets ON asset_id = unit_asset_id
|
||||
WHERE unit_rack_id = $rack_id AND unit_id != $unit_id
|
||||
ORDER BY unit_start_number");
|
||||
ORDER BY unit_start_number DESC, unit_position");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
if (intval($row['unit_parent_id'])) {
|
||||
$rack_holder_taken[intval($row['unit_parent_id'])][intval($row['unit_position'])] = rackUnitName($row['asset_name'], $row['unit_device'], $row['unit_type']);
|
||||
continue;
|
||||
}
|
||||
if (intval($row['unit_slots']) > 0) {
|
||||
$rack_holders[intval($row['unit_id'])] = [
|
||||
'id' => intval($row['unit_id']),
|
||||
'name' => rackUnitName($row['asset_name'], $row['unit_device'], $row['unit_type']),
|
||||
'slots' => intval($row['unit_slots']),
|
||||
'where' => html_entity_decode(rackPositionLabel($row['unit_start_number'], $row['unit_end_number'])) . ', ' . ($row['unit_face'] === 'rear' ? 'rear' : 'front'),
|
||||
'icon' => rackItemStyle($row['asset_type'], $row['unit_type'], $row['asset_name'] !== null)['icon'],
|
||||
];
|
||||
}
|
||||
$rack_other_units[] = [
|
||||
'start' => intval($row['unit_start_number']),
|
||||
'end' => intval($row['unit_end_number']),
|
||||
@@ -46,6 +65,18 @@ while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$unit_is_asset = $unit_asset_id > 0 || ($unit_id === 0 && $unit_device === '');
|
||||
$item_types = rackItemTypes();
|
||||
|
||||
// Each holder's slots: what is in them, and how far they go (one row past what is used)
|
||||
foreach ($rack_holders as $holder_id => $holder) {
|
||||
$taken = $rack_holder_taken[$holder_id] ?? [];
|
||||
$rack_holders[$holder_id]['taken'] = (object) $taken;
|
||||
$rack_holders[$holder_id]['limit'] = rackSlotLimit($holder['slots'], $taken ? max(array_keys($taken)) : 0);
|
||||
}
|
||||
// A holder that holds something can't go in one, and one this item is in has to stay listed
|
||||
$unit_children = $unit_id ? rackChildCount($unit_id) : 0;
|
||||
$unit_holder_id = isset($rack_holders[$unit_holder_id]) && !$unit_children ? $unit_holder_id : 0;
|
||||
$unit_in_holder = $unit_holder_id > 0;
|
||||
$rack_slot_order = $rack_units_descending ? 'Slot 1 is at the top left, counting across and then down a row' : 'Slot 1 is at the bottom left, counting across and then up a row';
|
||||
|
||||
?>
|
||||
|
||||
<div class="mb-3">
|
||||
@@ -98,7 +129,32 @@ $item_types = rackItemTypes();
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row g-3 mb-1">
|
||||
<?php if ($rack_holders && !$unit_children) { ?>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Goes in</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-layer-group"></i></span>
|
||||
<select class="form-select select2" name="holder" id="rackItemHolder">
|
||||
<option value="0"<?= selectOptionData(['icon' => 'fas fa-server']) ?>>The rack</option>
|
||||
<?php foreach ($rack_holders as $holder) { ?>
|
||||
<option value="<?= $holder['id'] ?>" <?php if ($holder['id'] === $unit_holder_id) { echo "selected"; } ?><?= selectOptionData(['icon' => 'fas ' . $holder['icon'], 'description' => $holder['where'] . ' - ' . $holder['slots'] . ' across']) ?>><?= escapeHtml($holder['name']) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3" data-rack-in="holder">
|
||||
<label class="form-label" for="rackItemSlot">Slot <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-th"></i></span>
|
||||
<input type="number" class="form-control" name="slot" id="rackItemSlot" min="1" value="<?= $unit_slot ?: '' ?>">
|
||||
</div>
|
||||
<div class="form-text"><?= $rack_slot_order ?>.</div>
|
||||
<div class="itflow-rack-fit small mt-2" id="rackItemSlotFit" aria-live="polite"></div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="row g-3 mb-1" data-rack-in="rack">
|
||||
<div class="col-sm-4">
|
||||
<label class="form-label" for="rackItemStart">Lowest U <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
@@ -125,12 +181,35 @@ $item_types = rackItemTypes();
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-check form-switch mt-2">
|
||||
<input class="form-check-input" type="checkbox" name="full_depth" value="1" id="rackItemFullDepth" <?= $unit_full_depth ? 'checked' : '' ?>>
|
||||
<label class="form-check-label" for="rackItemFullDepth">Full depth <span class="text-secondary">- fills the front and the rear</span></label>
|
||||
</div>
|
||||
<div data-rack-in="rack">
|
||||
<div class="form-check form-switch mt-2">
|
||||
<input class="form-check-input" type="checkbox" name="full_depth" value="1" id="rackItemFullDepth" <?= $unit_full_depth ? 'checked' : '' ?>>
|
||||
<label class="form-check-label" for="rackItemFullDepth">Full depth <span class="text-secondary">- fills the front and the rear</span></label>
|
||||
</div>
|
||||
|
||||
<div class="itflow-rack-fit small mt-2 mb-3" id="rackItemFit" aria-live="polite"></div>
|
||||
<div class="itflow-rack-fit small mt-2 mb-3" id="rackItemFit" aria-live="polite"></div>
|
||||
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" name="holds" value="1" id="rackItemHolds" <?= $unit_slots ? 'checked' : '' ?><?= $unit_children ? ' disabled' : '' ?>>
|
||||
<label class="form-check-label" for="rackItemHolds">Holds devices side by side <span class="text-secondary">- a bracket, shelf or chassis</span></label>
|
||||
<?php if ($unit_children) { ?>
|
||||
<input type="hidden" name="holds" value="1">
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="mt-2 mb-3" id="rackItemSlotsRow">
|
||||
<div class="input-group itflow-rack-slots-input">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-th"></i></span>
|
||||
<input type="number" class="form-control" name="slots" id="rackItemSlots" min="1" max="<?= RACK_SLOTS_MAX ?>" value="<?= $unit_slots ?: 2 ?>">
|
||||
<span class="input-group-text">across</span>
|
||||
</div>
|
||||
<div class="form-text">
|
||||
How many fit side by side - more than that wrap onto another row, for stacks.
|
||||
<?php if ($unit_children) { ?>
|
||||
It holds <?= rackDeviceCount($unit_children) ?> now.
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row g-3">
|
||||
<div class="col-sm-5">
|
||||
@@ -153,6 +232,7 @@ $item_types = rackItemTypes();
|
||||
<script>
|
||||
(function () {
|
||||
var others = <?= json_encode($rack_other_units, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT) ?>;
|
||||
var holders = <?= json_encode((object) $rack_holders, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT) ?>;
|
||||
var rackUnits = <?= intval($rack_units) ?>;
|
||||
|
||||
var form = document.getElementById('rackItemFit').closest('form');
|
||||
@@ -163,6 +243,11 @@ $item_types = rackItemTypes();
|
||||
var nameInput = form.querySelector('#rackItemName');
|
||||
var assetSelect = form.querySelector('#rackItemAsset');
|
||||
var typeSelect = form.querySelector('#rackItemType');
|
||||
var holderSelect = form.querySelector('#rackItemHolder');
|
||||
var slot = form.querySelector('#rackItemSlot');
|
||||
var slotFit = form.querySelector('#rackItemSlotFit');
|
||||
var holds = form.querySelector('#rackItemHolds');
|
||||
var slotsRow = form.querySelector('#rackItemSlotsRow');
|
||||
|
||||
// Things that sit at the front and leave the back free, as a starting point
|
||||
var halfDepthTypes = ['Patch Panel', 'Cable Management', 'Blanking Panel'];
|
||||
@@ -181,7 +266,7 @@ $item_types = rackItemTypes();
|
||||
}
|
||||
|
||||
function setText(el, icon, cls, text) {
|
||||
el.className = 'itflow-rack-fit small mt-2 mb-3 ' + cls;
|
||||
el.className = 'itflow-rack-fit small mt-2' + (el === fit ? ' mb-3 ' : ' ') + cls;
|
||||
el.textContent = '';
|
||||
var i = document.createElement('i');
|
||||
i.className = 'fas fa-fw me-1 ' + icon;
|
||||
@@ -214,6 +299,62 @@ $item_types = rackItemTypes();
|
||||
}
|
||||
}
|
||||
|
||||
// The holder it goes in, or null for the rack itself
|
||||
function holder() {
|
||||
return holderSelect && holders[holderSelect.value] ? holders[holderSelect.value] : null;
|
||||
}
|
||||
|
||||
// The first slot nothing is in
|
||||
function firstFree(h) {
|
||||
for (var n = 1; n <= h.limit; n++) {
|
||||
if (!h.taken[n]) {
|
||||
return n;
|
||||
}
|
||||
}
|
||||
return h.limit;
|
||||
}
|
||||
|
||||
function checkSlot() {
|
||||
var h = holder();
|
||||
if (!h) {
|
||||
return;
|
||||
}
|
||||
var n = parseInt(slot.value, 10);
|
||||
if (!n) {
|
||||
slotFit.textContent = '';
|
||||
slotFit.className = 'itflow-rack-fit small mt-2';
|
||||
return;
|
||||
}
|
||||
if (n < 1 || n > h.limit) {
|
||||
setText(slotFit, 'fa-times-circle', 'text-danger', h.name + ' has slots 1 to ' + h.limit);
|
||||
} else if (h.taken[n]) {
|
||||
setText(slotFit, 'fa-times-circle', 'text-danger', 'Slot ' + n + ' has ' + h.taken[n] + ' in it');
|
||||
} else {
|
||||
setText(slotFit, 'fa-check-circle', 'text-success', 'Slot ' + n + ' in ' + h.name + ' is free');
|
||||
}
|
||||
}
|
||||
|
||||
// In a holder the units, face and depth are the holder's, and it can't hold devices of its own
|
||||
function applyPlace() {
|
||||
var h = holder();
|
||||
form.querySelectorAll('[data-rack-in]').forEach(function (el) {
|
||||
el.classList.toggle('d-none', el.getAttribute('data-rack-in') !== (h ? 'holder' : 'rack'));
|
||||
});
|
||||
start.required = !h;
|
||||
height.required = !h;
|
||||
if (slot) {
|
||||
slot.required = !!h;
|
||||
if (h) {
|
||||
slot.max = h.limit;
|
||||
if (!slot.value || (h.taken[parseInt(slot.value, 10)] && slot.dataset.picked !== '1')) {
|
||||
slot.value = firstFree(h);
|
||||
}
|
||||
}
|
||||
}
|
||||
slotsRow.classList.toggle('d-none', !holds.checked || !!h);
|
||||
checkSlot();
|
||||
}
|
||||
|
||||
function applyKind() {
|
||||
var k = kind();
|
||||
form.querySelectorAll('[data-rack-kind]').forEach(function (el) {
|
||||
@@ -235,6 +376,19 @@ $item_types = rackItemTypes();
|
||||
form.querySelectorAll('input[name="face"]').forEach(function (r) {
|
||||
r.addEventListener('change', check);
|
||||
});
|
||||
holds.addEventListener('change', applyPlace);
|
||||
if (holderSelect) {
|
||||
holderSelect.addEventListener('change', function () {
|
||||
slot.value = '';
|
||||
applyPlace();
|
||||
});
|
||||
['input', 'change'].forEach(function (type) {
|
||||
slot.addEventListener(type, function () {
|
||||
slot.dataset.picked = '1';
|
||||
checkSlot();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
<?php if ($unit_id === 0) { ?>
|
||||
// A new item: suggest the depth from what it is. Editing keeps what was saved.
|
||||
@@ -264,6 +418,7 @@ $item_types = rackItemTypes();
|
||||
});
|
||||
|
||||
applyKind();
|
||||
applyPlace();
|
||||
check();
|
||||
})();
|
||||
</script>
|
||||
|
||||
@@ -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 <strong>" . strip_tags($conflict['name']) . "</strong> (" . 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 <strong>" . strip_tags($place['holder_name']) . "</strong>";
|
||||
} 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("<strong>$item_name_display</strong> 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("<strong>$item_name_display</strong> 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("<strong>$item_name_display</strong> added at $position");
|
||||
logAudit("Rack", "Edit", "$session_name added $item_name_sql $where_log ($face) to rack $rack_name", $client_id, $rack_id);
|
||||
flashAlert("<strong>$item_name_display</strong> 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("<strong>" . strip_tags($item_name) . "</strong> moved to slot {$place['position']} of <strong>" . strip_tags($place['holder_name']) . "</strong>");
|
||||
$was = $parent_id
|
||||
? "in slot " . intval($row['unit_position']) . " of <strong>" . escapeHtml(strip_tags(rackHolderName($parent_id))) . "</strong>"
|
||||
: "at " . rackPositionLabel($row['unit_start_number'], $row['unit_end_number']) . " on the {$row['unit_face']}";
|
||||
undoOffer("<strong>" . escapeHtml(strip_tags($item_name)) . "</strong> 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("<strong>" . strip_tags(rackUnitName($row['asset_name'], $row['unit_device'], $row['unit_type'])) . "</strong> is in <strong>" . strip_tags(rackHolderName($parent_id)) . "</strong> - 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("<strong>" . strip_tags($item_name) . "</strong> removed from the rack", 'error');
|
||||
flashAlert("<strong>" . strip_tags($item_name) . "</strong>$with removed from the rack", 'error');
|
||||
|
||||
redirect();
|
||||
|
||||
|
||||
@@ -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) {
|
||||
<div class="card-body">
|
||||
<div class="itflow-rack-pair">
|
||||
<?php
|
||||
$elevation_items = $rack_items;
|
||||
$elevation_items = rackNestItems($rack_items);
|
||||
$elevation_rack_units = $rack_units;
|
||||
$elevation_descending = $rack_units_descending;
|
||||
$elevation_can_edit = $can_edit && !$rack_archived_at;
|
||||
@@ -228,15 +230,26 @@ if (mysqli_num_rows($sql) == 0) {
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
// Top of the rack first, the way you read it standing in front of it
|
||||
$table_items = $rack_items;
|
||||
usort($table_items, function ($a, $b) use ($rack_units_descending) {
|
||||
// Top of the rack first, the way you read it standing in front of it - what is in a holder right under it
|
||||
$table_tops = rackNestItems($rack_items);
|
||||
usort($table_tops, function ($a, $b) use ($rack_units_descending) {
|
||||
return $rack_units_descending ? $a['start'] <=> $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) { ?>
|
||||
<tr>
|
||||
<td class="ps-3 text-nowrap font-monospace small"><?= $item['position'] ?></td>
|
||||
<td>
|
||||
<?php if ($item['parent_id']) { ?>
|
||||
<td class="ps-3 text-nowrap small text-body-secondary"><i class="fas fa-fw fa-level-up-alt fa-rotate-90 me-1 opacity-50"></i>Slot <?= $item['slot'] ?></td>
|
||||
<?php } else { ?>
|
||||
<td class="ps-3 text-nowrap font-monospace small"><?= $item['position'] ?></td>
|
||||
<?php } ?>
|
||||
<td<?= $item['parent_id'] ? ' class="ps-4"' : '' ?>>
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<span class="itflow-rack-chip itflow-rack-tone-<?= $item['tone'] ?>"><i class="fas fa-fw <?= $item['icon'] ?>"></i></span>
|
||||
<div class="min-w-0">
|
||||
@@ -247,6 +260,7 @@ if (mysqli_num_rows($sql) == 0) {
|
||||
<?php } ?>
|
||||
<div class="small text-body-secondary">
|
||||
<?= $item['type_label'] ?>
|
||||
<?php if ($item['slots']) { ?>· holds <?= $item['slots'] ?> across<?php } ?>
|
||||
<?php if ($item['asset_id'] && $item['label']) { ?>· <?= $item['label'] ?><?php } ?>
|
||||
<?php if ($item['notes']) { ?>· <?= $item['notes'] ?><?php } ?>
|
||||
</div>
|
||||
@@ -465,6 +479,8 @@ if (mysqli_num_rows($sql) == 0) {
|
||||
<input type="hidden" name="unit_id">
|
||||
<input type="hidden" name="unit_start">
|
||||
<input type="hidden" name="face">
|
||||
<input type="hidden" name="holder">
|
||||
<input type="hidden" name="slot">
|
||||
</form>
|
||||
<script src="<?= staticFileUrl('/agent/js/rack_drag.js') ?>" data-rack-id="<?= $rack_id ?>"></script>
|
||||
<?php } ?>
|
||||
|
||||
@@ -230,7 +230,8 @@ foreach ($racks as $rack_id => $row) {
|
||||
<?php /* The front, to scale: a full-depth item from the rear fills it too */ ?>
|
||||
<div class="itflow-rack-mini" style="--rack-rows: <?= $rack_units ?>" aria-hidden="true">
|
||||
<?php foreach ($rack_items as $item) {
|
||||
if (!rackUnitOnFace($item['face'], $item['full_depth'], 'front')) {
|
||||
// A device in a holder is drawn by its holder
|
||||
if ($item['parent_id'] || !rackUnitOnFace($item['face'], $item['full_depth'], 'front')) {
|
||||
continue;
|
||||
} ?>
|
||||
<span class="itflow-rack-tone-<?= $item['tone'] ?><?= $item['face'] !== 'front' ? ' is-ghost' : '' ?>" style="grid-row: <?= rackGridRow($item['start'], $item['end'], $rack_units, $rack_units_descending) ?> / span <?= $item['height'] ?>"></span>
|
||||
|
||||
@@ -14,10 +14,13 @@
|
||||
* asset_id The client's asset - or unit_device for an item that isn't one
|
||||
* unit_device A name for the item
|
||||
* unit_type optional - Without an asset: Device (the default), Patch Panel, Cable Management, Shelf, PDU, UPS, KVM / Console or Blanking Panel
|
||||
* unit_start_number required - The lowest unit it takes
|
||||
* unit_start_number required - The lowest unit it takes (not in a holder)
|
||||
* unit_height optional - How many units, 1 if left out
|
||||
* unit_face optional - front (the default) or rear
|
||||
* unit_full_depth optional - 1: it takes the front and the rear
|
||||
* unit_slots optional - It holds devices side by side, this many across (a bracket, shelf or chassis)
|
||||
* unit_parent_id optional - The holder it goes in instead - it takes the holder's units, face and depth
|
||||
* unit_position optional - Its slot in the holder, 1 the first; the first free one if left out
|
||||
* unit_power_watts, unit_notes optional
|
||||
*/
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
* API - Rack Units - Delete
|
||||
* POST /api/v1/rack_units/delete.php
|
||||
*
|
||||
* Take an item out of its rack, as Remove does - the asset stays.
|
||||
* Take an item out of its rack, as Remove does - the asset stays. A holder takes
|
||||
* what is in it out with it.
|
||||
*
|
||||
* Parameters (POST, JSON body): api_key, unit_id, client_id (the rack's client -
|
||||
* needed when the key's user is limited to certain clients)
|
||||
@@ -18,11 +19,12 @@ require_once 'unit_find.php';
|
||||
|
||||
if ($unit) {
|
||||
|
||||
$children = rackChildCount($unit_id);
|
||||
mysqli_query($mysqli, "DELETE FROM rack_units WHERE unit_id = $unit_id");
|
||||
$delete_count = mysqli_affected_rows($mysqli);
|
||||
|
||||
if ($delete_count > 0) {
|
||||
$what = escapeSql(rackUnitName($unit['asset_name'], $unit['unit_device'], $unit['unit_type']) . ' from rack ' . $rack['rack_name']);
|
||||
$what = escapeSql(rackUnitName($unit['asset_name'], $unit['unit_device'], $unit['unit_type']) . ($children ? ' and the ' . rackDeviceCount($children) . ' in it' : '') . ' from rack ' . $rack['rack_name']);
|
||||
logAudit("Rack", "Edit", "Removed $what via API ($api_key_name)", $client_id, $rack_id);
|
||||
logAudit("API", "Success", "Removed $what via API ($api_key_name)", $client_id);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
// An item in a rack from POST, checked as the rack item form checks it - with what
|
||||
// the item has now ($unit) for those not sent, on an update. $rack is its rack and
|
||||
// $client_id the rack's client. Sets $unit_set (the SET clause) and $unit_label, or
|
||||
// turns the request down with 400 and why.
|
||||
// $client_id the rack's client. Sets $unit_set (the SET clause), $unit_label and
|
||||
// $unit_place (rackPlacement()), or turns the request down with 400 and why.
|
||||
|
||||
if (!function_exists('apiDeny')) {
|
||||
http_response_code(404);
|
||||
@@ -26,7 +26,10 @@ $face = (string) $sent('unit_face', $unit['unit_face'] ?? 'front');
|
||||
$full_depth = intval($sent('unit_full_depth', $unit['unit_full_depth'] ?? 0)) === 1 ? 1 : 0;
|
||||
$power_watts = intval($sent('unit_power_watts', $unit['unit_power_watts'] ?? 0));
|
||||
$notes = mb_substr(trim((string) $sent('unit_notes', $unit['unit_notes'] ?? '')), 0, 255);
|
||||
$rack_units = intval($rack['rack_units']);
|
||||
// In a holder at a slot, or in the rack - and holding devices side by side, or not
|
||||
$holder_id = intval($sent('unit_parent_id', $unit['unit_parent_id'] ?? 0));
|
||||
$position = intval($sent('unit_position', $unit['unit_position'] ?? 0));
|
||||
$slots = intval($sent('unit_slots', $unit['unit_slots'] ?? 0));
|
||||
|
||||
if ($unit_type === '' || !array_key_exists($unit_type, rackItemTypes())) {
|
||||
if (array_key_exists('unit_type', $_POST)) {
|
||||
@@ -37,8 +40,11 @@ if ($unit_type === '' || !array_key_exists($unit_type, rackItemTypes())) {
|
||||
if (!in_array($face, ['front', 'rear'], true)) {
|
||||
$rack_refuse('unit_face is front or rear.');
|
||||
}
|
||||
if ($start < 1 || $end > $rack_units) {
|
||||
$rack_refuse("That doesn't fit - this rack runs from U1 to U$rack_units.");
|
||||
if ($slots < 0 || $slots > RACK_SLOTS_MAX) {
|
||||
$rack_refuse('unit_slots is how many it holds side by side - 0 to ' . RACK_SLOTS_MAX . '.');
|
||||
}
|
||||
if ($holder_id && $slots) {
|
||||
$rack_refuse("An item in a holder (unit_parent_id) can't hold devices of its own (unit_slots).");
|
||||
}
|
||||
|
||||
// The asset has to be the client's, and in one place at a time
|
||||
@@ -58,13 +64,16 @@ if ($asset_id) {
|
||||
$rack_refuse('Send asset_id, or a name for the item in unit_device.');
|
||||
}
|
||||
|
||||
$conflict = rackUnitConflict($rack['rack_id'], $start, $end, $face, $full_depth, $unit_id);
|
||||
if ($conflict) {
|
||||
$rack_refuse(html_entity_decode(rackPositionLabel($start, $end)) . " on the $face is taken by {$conflict['name']} (" . html_entity_decode(rackPositionLabel($conflict['start'], $conflict['end'])) . ").");
|
||||
// Units, overlaps and slots - functions/rack.php
|
||||
$unit_place = rackPlacement($rack['rack_id'], $unit_id, ['holder' => $holder_id, 'position' => $position,
|
||||
'start' => $start, 'end' => $end, 'face' => $face, 'full_depth' => $full_depth, 'slots' => $slots]);
|
||||
if (isset($unit_place['error'])) {
|
||||
$rack_refuse(strip_tags($unit_place['error']) . '.');
|
||||
}
|
||||
|
||||
// A linked asset is drawn by its own asset type, so only unlinked items keep one
|
||||
$unit_set = "unit_device = '" . escapeSql(mb_substr($label, 0, 200)) . "', unit_asset_id = " . ($asset_id ?: 'NULL') . ", unit_type = " . ($asset_id ? 'NULL' : "'" . escapeSql($unit_type) . "'") . ",
|
||||
unit_start_number = $start, unit_end_number = $end, unit_face = '$face', unit_full_depth = $full_depth,
|
||||
" . rackPlacementSet($unit_place) . ", unit_slots = " . intval($unit_place['slots']) . ",
|
||||
unit_power_watts = " . ($power_watts > 0 ? $power_watts : 'NULL') . ", unit_notes = '" . escapeSql($notes) . "'";
|
||||
$unit_label = rackUnitName($asset_name, $label, $unit_type) . ' at ' . html_entity_decode(rackPositionLabel($start, $end)) . " ($face)";
|
||||
$unit_label = rackUnitName($asset_name, $label, $unit_type) . ($unit_place['holder'] ? " in slot {$unit_place['position']} of {$unit_place['holder_name']}" : '')
|
||||
. ' at ' . html_entity_decode(rackPositionLabel($unit_place['start'], $unit_place['end'])) . " ({$unit_place['face']})";
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* POST /api/v1/rack_units/update.php
|
||||
*
|
||||
* Move or change an item in its rack, as Edit does on it - only what is sent,
|
||||
* with the same checks as mounting it.
|
||||
* with the same checks as mounting it. A holder takes what is in it along.
|
||||
*
|
||||
* Parameters (POST, JSON body):
|
||||
* api_key required - Your API key
|
||||
@@ -26,6 +26,9 @@ if ($unit) {
|
||||
|
||||
if (mysqli_query($mysqli, "UPDATE rack_units SET $unit_set WHERE unit_id = $unit_id")) {
|
||||
$update_count = 1;
|
||||
if ($unit_place['slots']) {
|
||||
rackSyncChildren($unit_id);
|
||||
}
|
||||
$what = escapeSql("$unit_label in rack " . $rack['rack_name']);
|
||||
logAudit("Rack", "Edit", "Updated $what via API ($api_key_name)", $client_id, $rack_id);
|
||||
logAudit("API", "Success", "Updated $what via API ($api_key_name)", $client_id);
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
*
|
||||
* A client's racks - archived ones too. One, by rack_id, also has what is mounted
|
||||
* in it (units): each item's position (unit_start_number to unit_end_number), face,
|
||||
* whether it is full depth, and the asset it is, or its own name and type.
|
||||
* whether it is full depth, and the asset it is, or its own name and type. A holder
|
||||
* says how many it holds side by side (unit_slots); a device in one, which holder
|
||||
* (unit_parent_id) and its slot there (unit_position).
|
||||
*
|
||||
* rack_id optional - Just this rack, with its units
|
||||
* client_id optional - Just this client's
|
||||
@@ -19,6 +21,12 @@ if (isset($_GET['rack_id'])) {
|
||||
$id = intval($_GET['rack_id']);
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM racks WHERE rack_id = $id " . apiClientScopeSql('rack_client_id'));
|
||||
if ($sql && ($row = mysqli_fetch_assoc($sql))) {
|
||||
// From U1 up - a holder, then what is in it by slot
|
||||
$units = rackLoadUnits([$id])[$id];
|
||||
usort($units, function ($a, $b) {
|
||||
return [intval($a['unit_start_number']), intval($a['unit_parent_id'] ?: $a['unit_id']), intval($a['unit_position'])]
|
||||
<=> [intval($b['unit_start_number']), intval($b['unit_parent_id'] ?: $b['unit_id']), intval($b['unit_position'])];
|
||||
});
|
||||
$row['units'] = array_map(function ($unit) {
|
||||
return [
|
||||
'unit_id' => intval($unit['unit_id']),
|
||||
@@ -30,11 +38,14 @@ if (isset($_GET['rack_id'])) {
|
||||
'unit_type' => $unit['unit_type'],
|
||||
'unit_power_watts' => $unit['unit_power_watts'] !== null ? intval($unit['unit_power_watts']) : null,
|
||||
'unit_notes' => $unit['unit_notes'],
|
||||
'unit_slots' => intval($unit['unit_slots']),
|
||||
'unit_parent_id' => $unit['unit_parent_id'] !== null ? intval($unit['unit_parent_id']) : null,
|
||||
'unit_position' => $unit['unit_parent_id'] !== null ? intval($unit['unit_position']) : null,
|
||||
'asset_id' => $unit['asset_id'] !== null ? intval($unit['asset_id']) : null,
|
||||
'asset_name' => $unit['asset_name'],
|
||||
'asset_type' => $unit['asset_type'],
|
||||
];
|
||||
}, array_reverse(rackLoadUnits([$id])[$id]));
|
||||
}, $units);
|
||||
echo json_encode(['success' => 'True', 'count' => 1, 'data' => [$row]]);
|
||||
exit();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ if ($rack) {
|
||||
$units = intval($rack_set['rack_units']);
|
||||
$row = mysqli_fetch_assoc(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 ORDER BY unit_end_number DESC LIMIT 1"));
|
||||
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) {
|
||||
$rack_refuse("Can't shrink the rack to {$units}U - " . rackUnitName($row['asset_name'], $row['unit_device'], $row['unit_type']) . " is mounted up to U" . intval($row['unit_end_number']) . ". Move or remove it first.");
|
||||
}
|
||||
|
||||
@@ -4013,15 +4013,166 @@ button.itflow-rack-item-body:hover {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
/* A holder - a bracket, shelf or chassis - with the devices in it side by side,
|
||||
in rows when it wraps. Its tab at the left is the holder itself; each slot is
|
||||
a device, or an empty "add here". */
|
||||
.itflow-rack-item.is-holder {
|
||||
display: flex;
|
||||
}
|
||||
.itflow-rack-holder-tab {
|
||||
display: flex;
|
||||
flex: 0 0 1.4rem;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-right: 1px solid rgba(0, 0, 0, .25);
|
||||
background: transparent;
|
||||
font-size: .7rem;
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
a.itflow-rack-holder-tab:hover,
|
||||
button.itflow-rack-holder-tab:hover {
|
||||
color: inherit;
|
||||
background-color: rgba(255, 255, 255, .1);
|
||||
}
|
||||
.itflow-rack-holder-tab:focus-visible {
|
||||
outline: 2px solid #fff;
|
||||
outline-offset: -2px;
|
||||
}
|
||||
.itflow-rack-holder-slots {
|
||||
display: grid;
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
gap: 2px;
|
||||
padding: 2px;
|
||||
}
|
||||
.itflow-rack-cell {
|
||||
position: relative;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
border-radius: .2rem;
|
||||
color: #fff;
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .14), 0 1px 1px rgba(0, 0, 0, .35);
|
||||
container-type: inline-size;
|
||||
}
|
||||
.itflow-rack-cell.is-empty {
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0;
|
||||
border: 1px dashed rgba(255, 255, 255, .22);
|
||||
background-color: rgba(0, 0, 0, .25);
|
||||
box-shadow: none;
|
||||
font-size: .6rem;
|
||||
color: rgba(255, 255, 255, .8);
|
||||
}
|
||||
.itflow-rack-cell.is-empty i {
|
||||
opacity: 0;
|
||||
transition: opacity .12s ease-in-out;
|
||||
}
|
||||
button.itflow-rack-cell.is-empty:hover,
|
||||
button.itflow-rack-cell.is-empty:focus-visible {
|
||||
border-color: rgba(255, 255, 255, .5);
|
||||
background-color: rgba(255, 255, 255, .1);
|
||||
outline: 0;
|
||||
}
|
||||
button.itflow-rack-cell.is-empty:hover i,
|
||||
button.itflow-rack-cell.is-empty:focus-visible i,
|
||||
.itflow-rack-dragging .itflow-rack-cell.is-empty i {
|
||||
opacity: 1;
|
||||
}
|
||||
.itflow-rack-cell.is-target {
|
||||
border: 2px dashed rgba(117, 214, 157, .9);
|
||||
background-color: rgba(117, 214, 157, .25);
|
||||
}
|
||||
.itflow-rack-cell-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 0 .3rem;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
font: inherit;
|
||||
line-height: 1.1;
|
||||
text-align: left;
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
a.itflow-rack-cell-body:hover,
|
||||
button.itflow-rack-cell-body:hover {
|
||||
color: inherit;
|
||||
background-color: rgba(255, 255, 255, .1);
|
||||
}
|
||||
.itflow-rack-cell-body:focus-visible {
|
||||
outline: 2px solid #fff;
|
||||
outline-offset: -2px;
|
||||
}
|
||||
.itflow-rack-cell-name,
|
||||
.itflow-rack-cell-meta {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.itflow-rack-cell-name {
|
||||
font-size: .66rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
.itflow-rack-cell-meta {
|
||||
font-size: .6rem;
|
||||
opacity: .78;
|
||||
}
|
||||
.itflow-rack-cell-edit {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
right: .15rem;
|
||||
display: none;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 1.15rem;
|
||||
height: 1.05rem;
|
||||
margin-top: -.525rem;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: .2rem;
|
||||
background-color: rgba(0, 0, 0, .4);
|
||||
font-size: .55rem;
|
||||
color: #fff;
|
||||
}
|
||||
.itflow-rack-cell-edit:hover {
|
||||
background-color: rgba(0, 0, 0, .6);
|
||||
}
|
||||
/* The pen only where the slot is wide enough for it and the name */
|
||||
@container (min-width: 4.5rem) {
|
||||
.itflow-rack-cell:hover .itflow-rack-cell-edit,
|
||||
.itflow-rack-cell:focus-within .itflow-rack-cell-edit {
|
||||
display: flex;
|
||||
}
|
||||
}
|
||||
.itflow-rack-cell.is-archived {
|
||||
opacity: .55;
|
||||
}
|
||||
.itflow-rack-cell.is-archived .itflow-rack-cell-name {
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
/* Dragging kit into place (agent/js/rack_drag.js): where it would go, red
|
||||
where something is in the way, and the item being moved faded */
|
||||
.itflow-rack-item[draggable="true"] {
|
||||
cursor: grab;
|
||||
}
|
||||
.itflow-rack-item.is-dragging,
|
||||
.itflow-rack-cell.is-dragging,
|
||||
.itflow-rack-unracked.is-dragging {
|
||||
opacity: .45;
|
||||
}
|
||||
.itflow-rack-cell[draggable="true"] {
|
||||
cursor: grab;
|
||||
}
|
||||
.itflow-rack-unracked[draggable="true"] {
|
||||
cursor: grab;
|
||||
}
|
||||
@@ -4158,6 +4309,9 @@ button.itflow-rack-item-body:hover {
|
||||
.itflow-rack-fit:empty {
|
||||
display: none;
|
||||
}
|
||||
.itflow-rack-slots-input {
|
||||
max-width: 14rem;
|
||||
}
|
||||
|
||||
/* Listing cards: the whole card opens the rack, the menu sits above that link */
|
||||
.itflow-rack-card {
|
||||
@@ -4196,6 +4350,7 @@ button.itflow-rack-item-body:hover {
|
||||
.itflow-rack-frame,
|
||||
.itflow-rack-bay,
|
||||
.itflow-rack-item,
|
||||
.itflow-rack-cell,
|
||||
.itflow-rack-chip,
|
||||
.itflow-rack-swatch,
|
||||
.itflow-rack-head-icon {
|
||||
@@ -4203,7 +4358,9 @@ button.itflow-rack-item-body:hover {
|
||||
print-color-adjust: exact;
|
||||
}
|
||||
.itflow-rack-slot span,
|
||||
.itflow-rack-item-edit {
|
||||
.itflow-rack-item-edit,
|
||||
.itflow-rack-cell-edit,
|
||||
.itflow-rack-cell.is-empty i {
|
||||
display: none;
|
||||
}
|
||||
.itflow-rack {
|
||||
|
||||
7
db.sql
7
db.sql
@@ -3027,15 +3027,20 @@ CREATE TABLE `rack_units` (
|
||||
`unit_type` varchar(50) DEFAULT NULL,
|
||||
`unit_power_watts` int(11) DEFAULT NULL,
|
||||
`unit_notes` varchar(255) DEFAULT NULL,
|
||||
`unit_slots` int(11) NOT NULL DEFAULT 0,
|
||||
`unit_position` int(11) NOT NULL DEFAULT 0,
|
||||
`unit_created_at` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
`unit_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(),
|
||||
`unit_archived_at` datetime DEFAULT NULL,
|
||||
`unit_asset_id` int(11) DEFAULT NULL,
|
||||
`unit_rack_id` int(11) NOT NULL,
|
||||
`unit_parent_id` int(11) DEFAULT NULL,
|
||||
PRIMARY KEY (`unit_id`),
|
||||
KEY `unit_rack_id` (`unit_rack_id`),
|
||||
KEY `unit_asset_id` (`unit_asset_id`),
|
||||
CONSTRAINT `rack_units_ibfk_1` FOREIGN KEY (`unit_rack_id`) REFERENCES `racks` (`rack_id`) ON DELETE CASCADE
|
||||
KEY `unit_parent_id` (`unit_parent_id`),
|
||||
CONSTRAINT `rack_units_ibfk_1` FOREIGN KEY (`unit_rack_id`) REFERENCES `racks` (`rack_id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `rack_units_ibfk_2` FOREIGN KEY (`unit_parent_id`) REFERENCES `rack_units` (`unit_id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
|
||||
@@ -527,7 +527,7 @@ function assetDetailsText($asset_id) {
|
||||
$add('In the building', $row['asset_physical_location']);
|
||||
$rack = rackPositionForAsset($asset_id);
|
||||
if ($rack) {
|
||||
$add('Rack', $rack['rack_name'] . ', ' . html_entity_decode(rackPositionLabel($rack['unit_start_number'], $rack['unit_end_number'])) . ' (' . $rack['unit_face'] . ')');
|
||||
$add('Rack', $rack['rack_name'] . ', ' . html_entity_decode(rackPositionLabel($rack['unit_start_number'], $rack['unit_end_number'])) . ' (' . $rack['unit_face'] . ')' . rackSlotText($rack['holder_name'], $rack['unit_position']));
|
||||
}
|
||||
$add('Used by', $row['contact_name']);
|
||||
|
||||
|
||||
@@ -309,7 +309,7 @@ function clientExportDatasets() {
|
||||
] + $archived],
|
||||
'rack_units' => ['section' => 'racks', 'label' => 'Rack contents', 'columns' => [
|
||||
'rack' => 'Rack', 'from_unit' => 'From unit', 'to_unit' => 'To unit', 'face' => 'Face', 'device' => 'Device', 'asset' => 'Asset', 'type' => 'Type',
|
||||
'power_watts' => 'Power (W)', 'full_depth' => 'Full depth', 'notes' => 'Notes',
|
||||
'power_watts' => 'Power (W)', 'full_depth' => 'Full depth', 'notes' => 'Notes', 'holder' => 'In holder', 'slot' => 'Slot',
|
||||
]],
|
||||
'licenses' => ['section' => 'software', 'label' => 'Licenses', 'columns' => [
|
||||
'id' => 'ID', 'name' => 'Name', 'version' => 'Version', 'type' => 'Type', 'license_type' => 'License type', 'key' => 'License key', 'seats' => 'Seats',
|
||||
@@ -616,12 +616,16 @@ function clientExportRows($dataset, $client_id, $options) {
|
||||
break;
|
||||
|
||||
case 'rack_units':
|
||||
foreach ($fetch("SELECT rack_units.*, rack_name FROM rack_units JOIN racks ON rack_id = unit_rack_id
|
||||
WHERE rack_client_id = $client_id" . $live('rack_archived_at') . $live('unit_archived_at') . " ORDER BY rack_name, unit_face, unit_start_number") as $row) {
|
||||
foreach ($fetch("SELECT rack_units.*, rack_name, holder.unit_device AS holder_device, holder.unit_type AS holder_type, holder.unit_asset_id AS holder_asset_id
|
||||
FROM rack_units JOIN racks ON rack_id = rack_units.unit_rack_id
|
||||
LEFT JOIN rack_units holder ON holder.unit_id = rack_units.unit_parent_id
|
||||
WHERE rack_client_id = $client_id" . $live('rack_archived_at') . $live('rack_units.unit_archived_at') . " ORDER BY rack_name, rack_units.unit_face, rack_units.unit_start_number, rack_units.unit_position") as $row) {
|
||||
$asset = $name('asset', $row['unit_asset_id']);
|
||||
$holder = $row['unit_parent_id'] ? rackUnitName($name('asset', $row['holder_asset_id']), $row['holder_device'], $row['holder_type']) : '';
|
||||
$rows[] = ['rack' => $row['rack_name'], 'from_unit' => $row['unit_start_number'], 'to_unit' => $row['unit_end_number'], 'face' => ucfirst((string) $row['unit_face']),
|
||||
'device' => $row['unit_device'] ?: $asset, 'asset' => $asset, 'type' => $row['unit_type'], 'power_watts' => $row['unit_power_watts'] ?: '',
|
||||
'full_depth' => clientExportYes($row['unit_full_depth']), 'notes' => $row['unit_notes'], '_rack_id' => intval($row['unit_rack_id'])];
|
||||
'full_depth' => clientExportYes($row['unit_full_depth']), 'notes' => $row['unit_notes'], 'holder' => $holder, 'slot' => $holder !== '' ? intval($row['unit_position']) : '',
|
||||
'_rack_id' => intval($row['unit_rack_id'])];
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1356,7 +1360,7 @@ function clientExportPdf($client_id, $options) {
|
||||
$list = $units[$rack['name']] ?? [];
|
||||
usort($list, function ($a, $b) { return intval($b['from_unit']) <=> intval($a['from_unit']); });
|
||||
$write($list ? clientExportPdfTable(['Units' => 12, 'Face' => 10, 'Device' => 38, 'Type' => 16, 'Power' => 10, 'Notes' => 14], array_map(function ($u) use ($e) {
|
||||
$span = intval($u['from_unit']) === intval($u['to_unit']) ? 'U' . $u['from_unit'] : 'U' . $u['from_unit'] . '-' . $u['to_unit'];
|
||||
$span = (intval($u['from_unit']) === intval($u['to_unit']) ? 'U' . $u['from_unit'] : 'U' . $u['from_unit'] . '-' . $u['to_unit']) . ($u['holder'] !== '' ? ', slot ' . $u['slot'] : '');
|
||||
return [$e($span), $e($u['face']), '<b>' . $e($u['device']) . '</b>', $e($u['type']), $e($u['power_watts'] ? $u['power_watts'] . ' W' : ''), $e($u['notes'])];
|
||||
}, $list)) : '<span style="color:#6c757d;">Nothing documented in this rack.</span>');
|
||||
}
|
||||
|
||||
@@ -12,8 +12,23 @@
|
||||
* Faces: an item is mounted on the front or the rear. A full-depth item (most
|
||||
* servers, a UPS) fills both faces at its units; a half-depth one (a patch
|
||||
* panel, a small switch) leaves the other face free for something else.
|
||||
*
|
||||
* Holders: an item with unit_slots holds devices side by side - two Tiny PCs in
|
||||
* a 1U bracket, eight PLCs on a shelf. Each device is an item of its own with
|
||||
* unit_parent_id set to the holder and unit_position its slot: 1 is the first,
|
||||
* counting across and then a row on, so devices past unit_slots wrap onto
|
||||
* another row (stacks). Rows count the way the rack's units do - the first at
|
||||
* the bottom, or at the top when U1 is. A device keeps its holder's units, face
|
||||
* and depth in its own columns (rackSyncChildren() after the holder moves), so
|
||||
* whatever reads where an asset is racked reads it the same way - but only the
|
||||
* holder takes space in the rack: occupancy and clashes skip what is in one.
|
||||
* Holders don't go in holders. Removing a holder removes what is in it (the
|
||||
* foreign key cascades); the assets themselves stay.
|
||||
*/
|
||||
|
||||
/** The most devices a holder takes side by side */
|
||||
const RACK_SLOTS_MAX = 24;
|
||||
|
||||
/** Unlinked rack items - things worth documenting that are not assets. */
|
||||
function rackItemTypes() {
|
||||
return [
|
||||
@@ -92,6 +107,10 @@ function rackOccupancy(array $units, $rack_units) {
|
||||
$rear = $front;
|
||||
|
||||
foreach ($units as $unit) {
|
||||
// A device in a holder is in the holder's units already
|
||||
if (intval($unit['unit_parent_id'] ?? 0)) {
|
||||
continue;
|
||||
}
|
||||
$start = max(1, intval($unit['unit_start_number']));
|
||||
$end = min($rack_units, intval($unit['unit_end_number']));
|
||||
$face = ($unit['unit_face'] ?? 'front') === 'rear' ? 'rear' : 'front';
|
||||
@@ -152,7 +171,7 @@ function rackGridRow($start, $end, $rack_units, $descending) {
|
||||
* The first item that would clash with an item at $start..$end on $face, or
|
||||
* null if the space is free. Two items clash when their units overlap and they
|
||||
* share a face - which a full-depth item always does. $exclude_unit_id skips
|
||||
* the item being moved.
|
||||
* the item being moved. Devices in a holder never clash - their holder does.
|
||||
*
|
||||
* Returns the clashing item's display name and position, raw (escape it).
|
||||
*/
|
||||
@@ -171,6 +190,7 @@ function rackUnitConflict($rack_id, $start, $end, $face, $full_depth, $exclude_u
|
||||
LEFT JOIN assets ON asset_id = unit_asset_id
|
||||
WHERE unit_rack_id = $rack_id
|
||||
AND unit_id != $exclude_unit_id
|
||||
AND unit_parent_id IS NULL
|
||||
AND unit_start_number <= $end AND unit_end_number >= $start
|
||||
AND (unit_full_depth = 1 OR $full_depth = 1 OR unit_face = '$face')
|
||||
ORDER BY unit_start_number
|
||||
@@ -253,7 +273,7 @@ function rackLoadUnits(array $rack_ids) {
|
||||
}
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT unit_id, unit_rack_id, unit_start_number, unit_end_number, unit_device,
|
||||
unit_face, unit_full_depth, unit_type, unit_power_watts, unit_notes,
|
||||
unit_face, unit_full_depth, unit_type, unit_power_watts, unit_notes, unit_slots, unit_parent_id, unit_position,
|
||||
asset_id, asset_name, asset_type, asset_make, asset_model, asset_serial, asset_status, asset_archived_at,
|
||||
(SELECT interface_ip FROM asset_interfaces
|
||||
WHERE interface_asset_id = asset_id AND interface_primary = 1 AND interface_ip IS NOT NULL AND interface_ip != ''
|
||||
@@ -261,7 +281,7 @@ function rackLoadUnits(array $rack_ids) {
|
||||
FROM rack_units
|
||||
LEFT JOIN assets ON asset_id = unit_asset_id
|
||||
WHERE unit_rack_id IN (" . implode(',', $rack_ids) . ")
|
||||
ORDER BY unit_start_number DESC");
|
||||
ORDER BY unit_start_number DESC, unit_position");
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$units[intval($row['unit_rack_id'])][] = $row;
|
||||
@@ -323,9 +343,234 @@ function rackUnitView(array $row) {
|
||||
'tone' => $style['tone'],
|
||||
'type_label' => escapeHtml($style['label']),
|
||||
'position' => rackPositionLabel($start, $end),
|
||||
'slots' => intval($row['unit_parent_id'] ?? 0) ? 0 : max(0, intval($row['unit_slots'] ?? 0)),
|
||||
'parent_id' => intval($row['unit_parent_id'] ?? 0),
|
||||
'slot' => intval($row['unit_parent_id'] ?? 0) ? max(1, intval($row['unit_position'] ?? 0)) : 0,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* rackUnitView() items as they are drawn: the items in the rack itself, each
|
||||
* holder with what is in it as 'children', in slot order. A device whose holder
|
||||
* isn't among them (it can't be - the key cascades) is left out rather than
|
||||
* drawn loose.
|
||||
*/
|
||||
function rackNestItems(array $items) {
|
||||
$children = [];
|
||||
foreach ($items as $item) {
|
||||
if ($item['parent_id']) {
|
||||
$children[$item['parent_id']][] = $item;
|
||||
}
|
||||
}
|
||||
$nested = [];
|
||||
foreach ($items as $item) {
|
||||
if ($item['parent_id']) {
|
||||
continue;
|
||||
}
|
||||
$kids = $children[$item['id']] ?? [];
|
||||
usort($kids, function ($a, $b) {
|
||||
return $a['slot'] <=> $b['slot'];
|
||||
});
|
||||
$nested[] = $item + ['children' => $kids];
|
||||
}
|
||||
return $nested;
|
||||
}
|
||||
|
||||
/** How many rows a holder with $slots across draws, its highest slot in use being $highest */
|
||||
function rackHolderRows($slots, $highest) {
|
||||
$slots = max(1, intval($slots));
|
||||
return max(1, intval(ceil(max(0, intval($highest)) / $slots)));
|
||||
}
|
||||
|
||||
/** The highest slot a device can go in: the holder's rows so far, and one row more */
|
||||
function rackSlotLimit($slots, $highest) {
|
||||
$slots = max(1, intval($slots));
|
||||
return (rackHolderRows($slots, $highest) + 1) * $slots;
|
||||
}
|
||||
|
||||
/**
|
||||
* A holder's slots as they are drawn: each ['slot', 'column', 'row' (the CSS
|
||||
* grid row), 'item' (the device there, or null)], in slot order. Rows count
|
||||
* the way the rack's units do - slot 1 is at the bottom left unless U1 is at
|
||||
* the top.
|
||||
*/
|
||||
function rackHolderCells(array $holder, $descending) {
|
||||
$slots = max(1, intval($holder['slots']));
|
||||
$by_slot = [];
|
||||
foreach ($holder['children'] ?? [] as $child) {
|
||||
$by_slot[$child['slot']] = $child;
|
||||
}
|
||||
$rows = rackHolderRows($slots, $by_slot ? max(array_keys($by_slot)) : 0);
|
||||
$cells = [];
|
||||
for ($slot = 1; $slot <= $rows * $slots; $slot++) {
|
||||
$row = intdiv($slot - 1, $slots);
|
||||
$cells[] = [
|
||||
'slot' => $slot,
|
||||
'column' => ($slot - 1) % $slots + 1,
|
||||
'row' => $descending ? $row + 1 : $rows - $row,
|
||||
'item' => $by_slot[$slot] ?? null,
|
||||
];
|
||||
}
|
||||
return ['rows' => $rows, 'columns' => $slots, 'cells' => $cells];
|
||||
}
|
||||
|
||||
/** How many devices are in a holder */
|
||||
function rackChildCount($unit_id) {
|
||||
global $mysqli;
|
||||
return intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM rack_units WHERE unit_parent_id = " . intval($unit_id)))[0]);
|
||||
}
|
||||
|
||||
/** What a holder is called (rackUnitName()), raw - '' when it is gone */
|
||||
function rackHolderName($unit_id) {
|
||||
global $mysqli;
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT unit_device, unit_type, asset_name FROM rack_units
|
||||
LEFT JOIN assets ON asset_id = unit_asset_id WHERE unit_id = " . intval($unit_id)));
|
||||
return $row ? rackUnitName($row['asset_name'], $row['unit_device'], $row['unit_type']) : '';
|
||||
}
|
||||
|
||||
/** "1 device" / "3 devices" */
|
||||
function rackDeviceCount($count) {
|
||||
$count = intval($count);
|
||||
return $count === 1 ? '1 device' : "$count devices";
|
||||
}
|
||||
|
||||
/**
|
||||
* Where an item would go, checked the way Add and Edit check it - the rack item
|
||||
* form, a drag, Undo and the API all come through here, so they can't drift
|
||||
* apart. $want:
|
||||
*
|
||||
* holder the holder (unit id) to put it in, 0 for the rack itself
|
||||
* position its slot in the holder - 0 for the first free one
|
||||
* start, end, face, full_depth where in the rack, when it isn't in a holder
|
||||
* slots how many it holds side by side, 0 when it holds nothing
|
||||
*
|
||||
* Returns ['error' => why] (HTML - names are in <strong>, tags stripped) or
|
||||
* where it goes: holder, position, start, end, face, full_depth, slots and
|
||||
* holder_name (raw). rackPlacementSet() turns that into the SET.
|
||||
*/
|
||||
function rackPlacement($rack_id, $unit_id, array $want) {
|
||||
global $mysqli;
|
||||
|
||||
$rack_id = intval($rack_id);
|
||||
$unit_id = intval($unit_id);
|
||||
$holder_id = intval($want['holder'] ?? 0);
|
||||
$slots = max(0, min(RACK_SLOTS_MAX, intval($want['slots'] ?? 0)));
|
||||
$children = $unit_id ? rackChildCount($unit_id) : 0;
|
||||
$strong = function ($name) {
|
||||
return '<strong>' . strip_tags((string) $name) . '</strong>';
|
||||
};
|
||||
|
||||
if ($holder_id) {
|
||||
if ($holder_id === $unit_id) {
|
||||
return ['error' => "An item can't go in itself"];
|
||||
}
|
||||
$holder = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT unit_id, unit_rack_id, unit_slots, unit_parent_id, unit_start_number, unit_end_number,
|
||||
unit_face, unit_full_depth, unit_device, unit_type, asset_name
|
||||
FROM rack_units
|
||||
LEFT JOIN assets ON asset_id = unit_asset_id
|
||||
WHERE unit_id = $holder_id AND unit_rack_id = $rack_id"));
|
||||
if (!$holder) {
|
||||
return ['error' => "That holder isn't in this rack any more"];
|
||||
}
|
||||
$holder_name = rackUnitName($holder['asset_name'], $holder['unit_device'], $holder['unit_type']);
|
||||
$holder_slots = intval($holder['unit_slots']);
|
||||
if ($holder_slots < 1 || intval($holder['unit_parent_id'])) {
|
||||
return ['error' => $strong($holder_name) . " doesn't hold devices"];
|
||||
}
|
||||
if ($children) {
|
||||
return ['error' => 'It holds ' . rackDeviceCount($children) . " of its own - a holder can't go in another holder"];
|
||||
}
|
||||
|
||||
$taken = [];
|
||||
$sql = mysqli_query($mysqli, "SELECT unit_position, unit_device, unit_type, asset_name FROM rack_units
|
||||
LEFT JOIN assets ON asset_id = unit_asset_id
|
||||
WHERE unit_parent_id = $holder_id AND unit_id != $unit_id");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$taken[intval($row['unit_position'])] = rackUnitName($row['asset_name'], $row['unit_device'], $row['unit_type']);
|
||||
}
|
||||
$limit = rackSlotLimit($holder_slots, $taken ? max(array_keys($taken)) : 0);
|
||||
|
||||
$position = intval($want['position'] ?? 0);
|
||||
if ($position < 1) {
|
||||
$position = 1;
|
||||
while (isset($taken[$position])) {
|
||||
$position++;
|
||||
}
|
||||
}
|
||||
if ($position > $limit) {
|
||||
return ['error' => $strong($holder_name) . " has slots 1 to $limit - pick one of those"];
|
||||
}
|
||||
if (isset($taken[$position])) {
|
||||
return ['error' => "Slot $position in " . $strong($holder_name) . ' is taken by ' . $strong($taken[$position])];
|
||||
}
|
||||
|
||||
return [
|
||||
'holder' => $holder_id,
|
||||
'position' => $position,
|
||||
'start' => intval($holder['unit_start_number']),
|
||||
'end' => intval($holder['unit_end_number']),
|
||||
'face' => $holder['unit_face'] === 'rear' ? 'rear' : 'front',
|
||||
'full_depth' => intval($holder['unit_full_depth']) === 1 ? 1 : 0,
|
||||
'slots' => 0,
|
||||
'holder_name' => $holder_name,
|
||||
];
|
||||
}
|
||||
|
||||
$rack_units = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT rack_units FROM racks WHERE rack_id = $rack_id"))[0] ?? 0);
|
||||
$start = intval($want['start'] ?? 0);
|
||||
$end = max($start, intval($want['end'] ?? $start));
|
||||
$face = ($want['face'] ?? 'front') === 'rear' ? 'rear' : 'front';
|
||||
$full_depth = intval($want['full_depth'] ?? 0) === 1 ? 1 : 0;
|
||||
|
||||
if ($start < 1 || $end > $rack_units) {
|
||||
return ['error' => "That doesn't fit - this rack runs from U1 to U$rack_units"];
|
||||
}
|
||||
|
||||
$conflict = rackUnitConflict($rack_id, $start, $end, $face, $full_depth, $unit_id);
|
||||
if ($conflict) {
|
||||
return ['error' => html_entity_decode(rackPositionLabel($start, $end)) . " on the $face is taken by " . $strong($conflict['name']) . ' (' . html_entity_decode(rackPositionLabel($conflict['start'], $conflict['end'])) . ')'];
|
||||
}
|
||||
|
||||
if ($children && $slots < 1) {
|
||||
return ['error' => 'It holds ' . rackDeviceCount($children) . ' - take ' . ($children === 1 ? 'it' : 'them') . ' out before it stops holding devices'];
|
||||
}
|
||||
|
||||
return [
|
||||
'holder' => 0,
|
||||
'position' => 0,
|
||||
'start' => $start,
|
||||
'end' => $end,
|
||||
'face' => $face,
|
||||
'full_depth' => $full_depth,
|
||||
'slots' => $slots,
|
||||
'holder_name' => '',
|
||||
];
|
||||
}
|
||||
|
||||
/** The SET for where rackPlacement() says an item goes - not its slots, which only Add and Edit change */
|
||||
function rackPlacementSet(array $place) {
|
||||
return "unit_parent_id = " . (intval($place['holder']) ?: 'NULL') . ", unit_position = " . intval($place['position']) . ",
|
||||
unit_start_number = " . intval($place['start']) . ", unit_end_number = " . intval($place['end']) . ",
|
||||
unit_face = '" . ($place['face'] === 'rear' ? 'rear' : 'front') . "', unit_full_depth = " . (intval($place['full_depth']) ? 1 : 0);
|
||||
}
|
||||
|
||||
/** What is in a holder takes its units, face and depth again - after the holder moves or changes */
|
||||
function rackSyncChildren($holder_id) {
|
||||
global $mysqli;
|
||||
$holder_id = intval($holder_id);
|
||||
mysqli_query($mysqli, "UPDATE rack_units child
|
||||
JOIN rack_units holder ON holder.unit_id = child.unit_parent_id
|
||||
SET child.unit_start_number = holder.unit_start_number, child.unit_end_number = holder.unit_end_number,
|
||||
child.unit_face = holder.unit_face, child.unit_full_depth = holder.unit_full_depth, child.unit_rack_id = holder.unit_rack_id
|
||||
WHERE holder.unit_id = $holder_id");
|
||||
}
|
||||
|
||||
/** " - slot 2 in Tiny bracket", raw, for where an asset is racked - '' for one in the rack itself */
|
||||
function rackSlotText($holder_name, $position) {
|
||||
$holder_name = trim((string) $holder_name);
|
||||
return $holder_name !== '' ? ' - slot ' . intval($position) . " in $holder_name" : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* How an asset of this type usually goes in a rack, to start the Add window
|
||||
* from: ['height' => U, 'full_depth' => 0|1]. A server, NAS or UPS takes 2U;
|
||||
@@ -339,16 +584,28 @@ function rackAssetDefaults($asset_type) {
|
||||
];
|
||||
}
|
||||
|
||||
/** Where an asset is racked: the rack and its position, or null. Raw values. */
|
||||
/**
|
||||
* Where an asset is racked: the rack and its position, or null. Raw values. In
|
||||
* a holder, holder_name is the holder and unit_position its slot there.
|
||||
*/
|
||||
function rackPositionForAsset($asset_id) {
|
||||
global $mysqli;
|
||||
|
||||
$asset_id = intval($asset_id);
|
||||
$sql = mysqli_query($mysqli, "SELECT rack_id, rack_name, rack_archived_at, unit_start_number, unit_end_number, unit_face
|
||||
$sql = mysqli_query($mysqli, "SELECT rack_id, rack_name, rack_archived_at, rack_units.unit_start_number, rack_units.unit_end_number,
|
||||
rack_units.unit_face, rack_units.unit_position, holder.unit_id AS holder_id, holder.unit_device AS holder_device,
|
||||
holder.unit_type AS holder_type, holder_asset.asset_name AS holder_asset_name
|
||||
FROM rack_units
|
||||
JOIN racks ON rack_id = unit_rack_id
|
||||
WHERE unit_asset_id = $asset_id
|
||||
JOIN racks ON rack_id = rack_units.unit_rack_id
|
||||
LEFT JOIN rack_units holder ON holder.unit_id = rack_units.unit_parent_id
|
||||
LEFT JOIN assets holder_asset ON holder_asset.asset_id = holder.unit_asset_id
|
||||
WHERE rack_units.unit_asset_id = $asset_id
|
||||
LIMIT 1");
|
||||
|
||||
return mysqli_fetch_assoc($sql) ?: null;
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
$row['holder_name'] = $row['holder_id'] ? rackUnitName($row['holder_asset_name'], $row['holder_device'], $row['holder_type']) : '';
|
||||
return $row;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
* ['recurring_on', recurring invoice id] a recurring invoice the change stopped, running again
|
||||
* ['folder', folder id, parent before, parent after, client id] a folder back under its parent
|
||||
* ['rack', unit id, start, end, face, start after, face after] a rack item back where it was, if that's free
|
||||
* ['rack_place', unit id, [holder, slot, start, end, face, full depth] before, [holder, slot] after]
|
||||
* a rack item back in the slot - or the units - it came from
|
||||
* ['ticket_priority', ticket id, before, after] through ticketChangePriority(), as the picker
|
||||
* ['ticket_category', ticket id, before, after] with the ticket's history line, as the bulk change
|
||||
* ['ticket_project', ticket id, before, after] the same
|
||||
@@ -386,9 +388,30 @@ function undoStep(array $step) {
|
||||
return false;
|
||||
}
|
||||
mysqli_query($mysqli, "UPDATE rack_units SET unit_start_number = " . intval($start) . ", unit_end_number = " . intval($end) . ", unit_face = " . undoSqlValue($face) . " WHERE unit_id = " . intval($unit_id));
|
||||
rackSyncChildren($unit_id);
|
||||
logAudit("Rack", "Edit", "$session_name moved an item back to " . html_entity_decode(rackPositionLabel($start, $end)) . " ($face)", intval($row['rack_client_id']), intval($row['unit_rack_id']));
|
||||
return true;
|
||||
|
||||
case 'rack_place':
|
||||
[, $unit_id, $before, $after] = $step;
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT unit_rack_id, unit_parent_id, unit_position, rack_client_id, rack_archived_at FROM rack_units
|
||||
JOIN racks ON rack_id = unit_rack_id WHERE unit_id = " . intval($unit_id)));
|
||||
if (!$row || $row['rack_archived_at'] || !hasClientAccess($row['rack_client_id'])
|
||||
|| intval($row['unit_parent_id']) !== intval($after[0]) || intval($row['unit_position']) !== intval($after[1])) {
|
||||
return false;
|
||||
}
|
||||
[$holder, $slot, $start, $end, $face, $full_depth] = $before;
|
||||
$place = rackPlacement(intval($row['unit_rack_id']), $unit_id, ['holder' => $holder, 'position' => max(1, intval($slot)),
|
||||
'start' => $start, 'end' => $end, 'face' => $face, 'full_depth' => $full_depth]);
|
||||
if (isset($place['error'])) {
|
||||
return false;
|
||||
}
|
||||
mysqli_query($mysqli, "UPDATE rack_units SET " . rackPlacementSet($place) . " WHERE unit_id = " . intval($unit_id));
|
||||
logAudit("Rack", "Edit", "$session_name moved an item back " . escapeSql($place['holder']
|
||||
? "to slot {$place['position']} of {$place['holder_name']}"
|
||||
: 'to ' . html_entity_decode(rackPositionLabel($place['start'], $place['end'])) . " ({$place['face']})"), intval($row['rack_client_id']), intval($row['unit_rack_id']));
|
||||
return true;
|
||||
|
||||
case 'ticket_priority':
|
||||
[, $ticket_id, $before, $after] = $step;
|
||||
$row = ticketFieldsRow($ticket_id);
|
||||
|
||||
Reference in New Issue
Block a user