From ecb80fc2afed0407e9903023242a34e75fb7bde4 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 17 Dec 2021 11:30:37 +0100 Subject: [locations/passthrough] Make location assignment recusive Properly show inherited passthough groups in location list, disable inherited passthrough groups in selection dialog. --- .../passthrough/hooks/locations-column.inc.php | 10 ++++++++++ modules-available/passthrough/page.inc.php | 22 ++++++++++++++++++---- .../passthrough/templates/location-assign.html | 13 +++++++++++-- 3 files changed, 39 insertions(+), 6 deletions(-) (limited to 'modules-available/passthrough') diff --git a/modules-available/passthrough/hooks/locations-column.inc.php b/modules-available/passthrough/hooks/locations-column.inc.php index 9757ac50..3d12a0f8 100644 --- a/modules-available/passthrough/hooks/locations-column.inc.php +++ b/modules-available/passthrough/hooks/locations-column.inc.php @@ -43,6 +43,16 @@ class PassthroughLocationColumn extends AbstractLocationColumn return true; } + public function propagationOverride(string $parent, string $data): string + { + if (empty($parent)) + return $data; + $merge = array_unique(array_merge( + explode(', ', $parent), explode(', ', $data))); + sort($merge); + return implode(', ', $merge); + } + } return new PassthroughLocationColumn($allowedLocationIds); \ No newline at end of file diff --git a/modules-available/passthrough/page.inc.php b/modules-available/passthrough/page.inc.php index b36b45ac..2db2525e 100644 --- a/modules-available/passthrough/page.inc.php +++ b/modules-available/passthrough/page.inc.php @@ -94,6 +94,7 @@ class Page_Passthrough extends Page /** * Show all the hardware that is known. Start with video adapters. + * @return void */ private function showHardwareList() { @@ -157,13 +158,26 @@ class Page_Passthrough extends Page private function showLocationMapping() { $locationId = Request::get('locationid', Request::REQUIRED, 'int'); - $res = Database::queryAll("SELECT g.groupid, g.title, gxl.locationid AS enabled FROM passthrough_group g - LEFT JOIN passthrough_group_x_location gxl ON (g.groupid = gxl.groupid AND gxl.locationid = :locationid) - ORDER BY gxl.locationid ASC", - ['locationid' => $locationId]); + $locationIds = Location::getLocationRootChain($locationId); + $res = Database::queryAll("SELECT g.groupid, g.title, GROUP_CONCAT(gxl.locationid) AS lids FROM passthrough_group g + LEFT JOIN passthrough_group_x_location gxl ON (g.groupid = gxl.groupid AND gxl.locationid IN (:lids)) + GROUP BY groupid, title + ORDER BY lids ASC", + ['lids' => $locationIds]); + foreach ($res as &$item) { + if ($item['lids'] === null) + continue; + $item['checked'] = 'checked'; + $list = explode(',', $item['lids']); + if (!in_array($locationId, $list)) { + $item['disabled'] = true; + $item['parent_location'] = Location::getName($list[0]); + } + } Render::addTemplate('location-assign', [ 'list' => array_reverse($res), 'locationid' => $locationId, + 'locationname' => Location::getName($locationId), ]); } diff --git a/modules-available/passthrough/templates/location-assign.html b/modules-available/passthrough/templates/location-assign.html index c2a8f805..037ab79d 100644 --- a/modules-available/passthrough/templates/location-assign.html +++ b/modules-available/passthrough/templates/location-assign.html @@ -1,3 +1,6 @@ +

{{lang_assignPassthrough}}

+

{{locationname}}

+
@@ -13,14 +16,20 @@
- + {{#disabled}} + + {{/disabled}} + {{^disabled}} + + {{/disabled}} + {{parent_location}}
{{/list}}
- -- cgit v1.2.3-55-g7522