summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2021-12-17 11:30:37 +0100
committerSimon Rettberg2021-12-17 11:30:37 +0100
commitfbb5e1594e15d16dbec6265cb006cdeca22ae978 (patch)
tree7aca2e403d23eea7cfaf9acb74156f32cee17f9d
parent[statistics] Fix query building (diff)
downloadslx-admin-fbb5e1594e15d16dbec6265cb006cdeca22ae978.tar.gz
slx-admin-fbb5e1594e15d16dbec6265cb006cdeca22ae978.tar.xz
slx-admin-fbb5e1594e15d16dbec6265cb006cdeca22ae978.zip
[locations/passthrough] Make location assignment recusive
Properly show inherited passthough groups in location list, disable inherited passthrough groups in selection dialog.
-rw-r--r--modules-available/locations/inc/abstractlocationcolumn.inc.php5
-rw-r--r--modules-available/locations/pages/locations.inc.php23
-rw-r--r--modules-available/passthrough/hooks/locations-column.inc.php10
-rw-r--r--modules-available/passthrough/page.inc.php22
-rw-r--r--modules-available/passthrough/templates/location-assign.html13
5 files changed, 55 insertions, 18 deletions
diff --git a/modules-available/locations/inc/abstractlocationcolumn.inc.php b/modules-available/locations/inc/abstractlocationcolumn.inc.php
index 9583429e..65224da9 100644
--- a/modules-available/locations/inc/abstractlocationcolumn.inc.php
+++ b/modules-available/locations/inc/abstractlocationcolumn.inc.php
@@ -16,6 +16,11 @@ abstract class AbstractLocationColumn
return false;
}
+ public function propagationOverride(string $parent, string $data): string
+ {
+ return $data;
+ }
+
public function propagateDefaultHtml(): string
{
return $this->getColumnHtml(0);
diff --git a/modules-available/locations/pages/locations.inc.php b/modules-available/locations/pages/locations.inc.php
index 0eb035c8..8ba4793e 100644
--- a/modules-available/locations/pages/locations.inc.php
+++ b/modules-available/locations/pages/locations.inc.php
@@ -123,7 +123,7 @@ class SubPage
unset($loc);
foreach ($plugins as $pk => $plugin) {
if ($plugin->propagateColumn()) {
- self::propagateFields($locationList, $plugin->propagateDefaultHtml(), $pk);
+ self::propagateFields($locationList, $plugin, $pk);
}
}
foreach ($locationList as &$loc) {
@@ -155,23 +155,22 @@ class SubPage
Module::isAvailable('js_ip'); // For CIDR magic
}
- private static function propagateFields(array &$locationList, string $defaultValue, string $plugin)
+ private static function propagateFields(array &$locationList, AbstractLocationColumn $plugin, string $pluginKey)
{
$depth = array();
foreach ($locationList as &$loc) {
$d = $loc['depth'];
- if (empty($loc['plugins'][$plugin]['html'])) {
+ if (empty($loc['plugins'][$pluginKey]['html'])) {
// Has no explicit config assignment
- if ($d === 0) {
- $loc['plugins'][$plugin]['html'] = $defaultValue;
- } else {
- $loc['plugins'][$plugin]['html'] = $depth[$d - 1];
- }
- $loc['plugins'][$plugin]['class'] = 'gray';
- } elseif (empty($loc['plugins'][$plugin]['class'])) {
- $loc['plugins'][$plugin]['class'] = 'slx-bold';
+ $loc['plugins'][$pluginKey]['html'] = $depth[$d - 1] ?? $plugin->propagateDefaultHtml();
+ $loc['plugins'][$pluginKey]['class'] = 'gray';
+ } elseif (empty($loc['plugins'][$pluginKey]['class'])) {
+ $loc['plugins'][$pluginKey]['class'] = 'slx-bold';
+ $loc['plugins'][$pluginKey]['html'] =
+ $plugin->propagationOverride($depth[$d - 1] ?? $plugin->propagateDefaultHtml(),
+ $loc['plugins'][$pluginKey]['html']);
}
- $depth[$d] = $loc['plugins'][$plugin]['html'];
+ $depth[$d] = $loc['plugins'][$pluginKey]['html'];
unset($depth[$d + 1]);
}
}
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 @@
+<h1>{{lang_assignPassthrough}}</h1>
+<h2>{{locationname}}</h2>
+
<form method="post" action="?do=passthrough">
<input type="hidden" name="token" value="{{token}}">
<input type="hidden" name="locationid" value="{{locationid}}">
@@ -13,14 +16,20 @@
</div>
<div class="col-sm-3">
<div class="checkbox">
- <input id="check-{{groupid}}" type="checkbox" name="enabled[]" value="{{groupid}}" {{#enabled}}checked="checked"{{/enabled}}>
+ {{#disabled}}
+ <input id="check-{{groupid}}" type="checkbox" disabled checked>
+ {{/disabled}}
+ {{^disabled}}
+ <input id="check-{{groupid}}" type="checkbox" name="enabled[]" value="{{groupid}}" {{checked}}>
+ {{/disabled}}
<label for="check-{{groupid}}"></label>
+ <span class="text-muted">{{parent_location}}</span>
</div>
</div>
</div>
{{/list}}
<div class="buttonbar text-right">
- <button type="submit" name="action" value="save-location">
+ <button class="btn btn-success" type="submit" name="action" value="save-location">
<span class="glyphicon glyphicon-floppy-disk"></span>
{{lang_save}}
</button>