diff options
author | Simon Rettberg | 2021-12-07 16:14:19 +0100 |
---|---|---|
committer | Simon Rettberg | 2022-03-09 15:06:54 +0100 |
commit | 9399fab2c22582c2d9dc7127bc7bf85b0ed86210 (patch) | |
tree | 4bcd4f6ee4875ad9b52e6a467badbc50d038c0ea /modules-available | |
parent | [statistics/passthrough] Consider group<->location mapping for KCL (diff) | |
download | slx-admin-9399fab2c22582c2d9dc7127bc7bf85b0ed86210.tar.gz slx-admin-9399fab2c22582c2d9dc7127bc7bf85b0ed86210.tar.xz slx-admin-9399fab2c22582c2d9dc7127bc7bf85b0ed86210.zip |
[passthrough] Add location assignment page
Diffstat (limited to 'modules-available')
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..b36b45ac 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 = (string)$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&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 |