From df5fd48da3a0163375e4567485b882f14baf6ead Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 12 May 2023 14:21:28 +0200 Subject: [locations] cleanup: Hide/disable move button if action not available Hide the button entirely if there are no movable machines in the displayed list. Disable the button as long as the user selected at least one unmovable machine. --- .../locations/inc/locationutil.inc.php | 5 +---- modules-available/locations/pages/cleanup.inc.php | 3 +++ .../locations/templates/mismatch-cleanup.html | 24 +++++++++++++++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) (limited to 'modules-available/locations') diff --git a/modules-available/locations/inc/locationutil.inc.php b/modules-available/locations/inc/locationutil.inc.php index 960eefa8..acdaed2f 100644 --- a/modules-available/locations/inc/locationutil.inc.php +++ b/modules-available/locations/inc/locationutil.inc.php @@ -70,12 +70,9 @@ class LocationUtil * grouped by the location the client was assigned to via roomplanner. * Otherwise, just return an assoc array with the requested locationid, name * and a list of all clients that are wrongfully assigned to that room. - * @param int $locationId - * @return array */ - public static function getMachinesWithLocationMismatch($locationId = 0, $checkPerms = false) + public static function getMachinesWithLocationMismatch(int $locationId = 0, bool $checkPerms = false): array { - $locationId = (int)$locationId; if ($checkPerms) { if ($locationId !== 0) { // Query details for specific location -- use assert and fake array diff --git a/modules-available/locations/pages/cleanup.inc.php b/modules-available/locations/pages/cleanup.inc.php index d10dbac0..a7562c50 100644 --- a/modules-available/locations/pages/cleanup.inc.php +++ b/modules-available/locations/pages/cleanup.inc.php @@ -21,6 +21,9 @@ class SubPage $list = self::loadForLocation(); if ($list === false) return true; + $list['canmove'] = array_reduce($list['clients'], function (bool $carry, array $item): bool { + return $carry || ($item['canmove'] ?? false); + }, false); Permission::addGlobalTags($list['perms'], NULL, ['subnets.edit', 'location.view']); Render::addTemplate('mismatch-cleanup', $list); return true; diff --git a/modules-available/locations/templates/mismatch-cleanup.html b/modules-available/locations/templates/mismatch-cleanup.html index a6f45d27..53a956df 100644 --- a/modules-available/locations/templates/mismatch-cleanup.html +++ b/modules-available/locations/templates/mismatch-cleanup.html @@ -32,7 +32,7 @@
- +
@@ -60,10 +60,28 @@ {{lang_resetMachines}} - + {{/canmove}} -
\ No newline at end of file +
+ + \ No newline at end of file -- cgit v1.2.3-55-g7522