From 1a2d98607ace5f31a4ac2146c08a7cfb14fadf16 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 12 Apr 2024 14:58:48 +0200 Subject: [PATCH] Introduce RolesTable widget --- library/Icinga/Web/Widget/RolesTable.php | 101 +++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 library/Icinga/Web/Widget/RolesTable.php diff --git a/library/Icinga/Web/Widget/RolesTable.php b/library/Icinga/Web/Widget/RolesTable.php new file mode 100644 index 000000000..e18c136d0 --- /dev/null +++ b/library/Icinga/Web/Widget/RolesTable.php @@ -0,0 +1,101 @@ +setAttributes([ + 'class' => 'table-row-selectable common-table', + 'data-base-target' => '_next' + ]); + + $this->addHtml(Html::tag('thead', [], [ + Html::tag('tr', [], [ + Html::tag('th', [], [$this->translate('Name')]), + Html::tag('th', [], [$this->translate('Users')]), + Html::tag('th', [], [$this->translate('Groups')]), + Html::tag('th', [], [$this->translate('Inherits From')]), + Html::tag('th') + ]) + ])); + + $tbody = Html::tag('tbody'); + + $this->addHtml($tbody); + + foreach ($this->roles as $role) { + $users = []; + $groups = []; + + foreach ($role->users as $user) { + $users[] = $user->user_name; + } + + foreach ($role->groups as $group) { + $groups[] = $group->group_name; + } + + sort($users); + sort($groups); + + $tbody->addHtml(Html::tag('tr', [], [ + Html::tag('td', [], [Html::tag( + 'a', + [ + 'href' => Url::fromPath('role/edit', ['role' => $role->name]), + 'title' => sprintf($this->translate('Edit role %s'), $role->name) + ], + $role->name + )]), + Html::tag('td', [], [implode(',', $users)]), + Html::tag('td', [], [implode(',', $groups)]), + Html::tag('td', [], $role->parent ? [$role->parent->name] : null), + Html::tag('td', ['class' => 'icon-col'], [Html::tag( + 'a', + [ + 'href' => Url::fromPath('role/remove', ['role' => $role->name]), + 'class' => 'action-link icon-cancel', + 'title' => sprintf($this->translate('Remove role %s'), $role->name) + ] + )]) + ])); + } + } + + /** + * Set the roles to display + * + * @param iterable $roles + * + * @return $this + */ + public function setRoles(iterable $roles): self + { + $this->roles = $roles; + + return $this; + } +}