summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2021-12-07 16:14:19 +0100
committerSimon Rettberg2021-12-07 16:14:19 +0100
commit9e954a509f3e69fbe9d06ba26975e581af0dbd20 (patch)
treed135b13eb089cb8331e2278f05215cb57f18e87d
parent[eventlog] Fix deleting transport (diff)
downloadslx-admin-9e954a509f3e69fbe9d06ba26975e581af0dbd20.tar.gz
slx-admin-9e954a509f3e69fbe9d06ba26975e581af0dbd20.tar.xz
slx-admin-9e954a509f3e69fbe9d06ba26975e581af0dbd20.zip
[passthrough] Add location assignment page
-rw-r--r--modules-available/passthrough/page.inc.php49
-rw-r--r--modules-available/passthrough/permissions/permissions.json4
-rw-r--r--modules-available/passthrough/templates/hardware-list.html2
-rw-r--r--modules-available/passthrough/templates/location-assign.html28
4 files changed, 81 insertions, 2 deletions
diff --git a/modules-available/passthrough/page.inc.php b/modules-available/passthrough/page.inc.php
index 7dcc8215..b0c830ef 100644
--- a/modules-available/passthrough/page.inc.php
+++ b/modules-available/passthrough/page.inc.php
@@ -10,6 +10,8 @@ class Page_Passthrough extends Page
$action = Request::post('action');
if ($action === 'save-hwlist') {
$this->saveHwList();
+ } elseif ($action === 'save-location') {
+ $this->saveLocation();
}
if (Request::isPost()) {
Util::redirect('?do=passthrough');
@@ -18,6 +20,7 @@ class Page_Passthrough extends Page
private function saveHwList()
{
+ User::assertPermission('edit.group');
$newgroups = Request::post('newgroup', [], 'array');
foreach ($newgroups as $id => $title) {
$id = strtoupper(preg_replace('/[^a-z0-9_\-]/i', '', $id));
@@ -49,6 +52,30 @@ class Page_Passthrough extends Page
Util::redirect('?do=passthrough&show=hwlist');
}
+ private function saveLocation()
+ {
+ $locationId = Request::post('locationid', Request::REQUIRED, 'int');
+ User::assertPermission('edit.location', $locationId);
+ $list = [];
+ $groups = [];
+ foreach (Request::post('enabled', [], 'array') as $groupId) {
+ $groupId = (int)$groupId;
+ $list[] = [$groupId, $locationId];
+ $groups[] = $groupId;
+ }
+ if (!empty($list)) {
+ Database::exec("INSERT IGNORE INTO passthrough_group_x_location (groupid, locationid)
+ VALUES :list", ['list' => $list]);
+ Database::exec("DELETE FROM passthrough_group_x_location
+ WHERE locationid = :lid AND groupid NOT IN (:groups)", ['lid' => $locationId, 'groups' => $groups]);
+ } else {
+ Database::exec("DELETE FROM passthrough_group_x_location
+ WHERE locationid = :lid", ['lid' => $locationId]);
+ }
+ Message::addSuccess('location-updated', Location::getName($locationId));
+ Util::redirect('?do=passthrough&show=assignlocation&locationid=' . $locationId);
+ }
+
/*
*
*/
@@ -58,11 +85,16 @@ class Page_Passthrough extends Page
$show = Request::get('show');
if ($show === 'hwlist') {
$this->showHardwareList();
+ } elseif ($show === 'assignlocation') {
+ $this->showLocationMapping();
} else {
Util::redirect('?do=passthrough&show=hwlist');
}
}
+ /**
+ * Show all the hardware that is known. Start with video adapters.
+ */
private function showHardwareList()
{
$q = new HardwareQuery(HardwareInfo::PCI_DEVICE, null, false);
@@ -118,6 +150,23 @@ class Page_Passthrough extends Page
}
}
+ /**
+ * Show mapping between specific location and passthrough groups.
+ * @return void
+ */
+ 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]);
+ Render::addTemplate('location-assign', [
+ 'list' => array_reverse($res),
+ 'locationid' => $locationId,
+ ]);
+ }
+
/*
*
*/
diff --git a/modules-available/passthrough/permissions/permissions.json b/modules-available/passthrough/permissions/permissions.json
index d0932f1e..bf3095c4 100644
--- a/modules-available/passthrough/permissions/permissions.json
+++ b/modules-available/passthrough/permissions/permissions.json
@@ -1,3 +1,5 @@
{
- "view": false
+ "view": false,
+ "edit.group": false,
+ "edit.location": true
} \ No newline at end of file
diff --git a/modules-available/passthrough/templates/hardware-list.html b/modules-available/passthrough/templates/hardware-list.html
index d3424b7a..720427fd 100644
--- a/modules-available/passthrough/templates/hardware-list.html
+++ b/modules-available/passthrough/templates/hardware-list.html
@@ -1,4 +1,4 @@
-<form method="post" action="?do=passthrough&amp;show=hwlist">
+<form method="post" action="?do=passthrough">
<input type="hidden" name="token" value="{{token}}">
<table class="table">
<thead>
diff --git a/modules-available/passthrough/templates/location-assign.html b/modules-available/passthrough/templates/location-assign.html
new file mode 100644
index 00000000..c2a8f805
--- /dev/null
+++ b/modules-available/passthrough/templates/location-assign.html
@@ -0,0 +1,28 @@
+<form method="post" action="?do=passthrough">
+ <input type="hidden" name="token" value="{{token}}">
+ <input type="hidden" name="locationid" value="{{locationid}}">
+ <div class="row">
+ <div class="col-sm-9">{{lang_group}}</div>
+ <div class="col-sm-3">{{lang_enabled}}</div>
+ </div>
+ {{#list}}
+ <div class="row">
+ <div class="col-sm-9">
+ {{groupid}}
+ <span class="small text-muted">{{title}}</span>
+ </div>
+ <div class="col-sm-3">
+ <div class="checkbox">
+ <input id="check-{{groupid}}" type="checkbox" name="enabled[]" value="{{groupid}}" {{#enabled}}checked="checked"{{/enabled}}>
+ <label for="check-{{groupid}}"></label>
+ </div>
+ </div>
+ </div>
+ {{/list}}
+ <div class="buttonbar text-right">
+ <button type="submit" name="action" value="save-location">
+ <span class="glyphicon glyphicon-floppy-disk"></span>
+ {{lang_save}}
+ </button>
+ </div>
+</form> \ No newline at end of file