From 4cb1aa005616821312c099b8a92e2444509178bb Mon Sep 17 00:00:00 2001 From: Varakh Date: Fri, 6 Apr 2018 10:56:04 +0200 Subject: [PATCH] Add groups rename --- config/ACL.php | 11 ++-- config/routes.php | 35 +++++++----- data/locale/en.yml | 34 ++++++------ .../Actions/ChannelGroupRenameAction.php | 25 +++++++++ ...AddAction.php => ServerGroupAddAction.php} | 4 +- ...Action.php => ServerGroupDeleteAction.php} | 2 +- ...foAction.php => ServerGroupInfoAction.php} | 6 +-- ...Action.php => ServerGroupRemoveAction.php} | 4 +- .../Actions/ServerGroupRenameAction.php | 25 +++++++++ src/View/material/form_inline.twig | 47 ++++++++++++++++ src/View/material/groups.twig | 26 ++++++++- src/View/material/keyvalue.twig | 44 ++------------- ...{group_info.twig => servergroup_info.twig} | 16 +++--- src/View/material/table.twig | 53 +++++++++++++------ 14 files changed, 224 insertions(+), 108 deletions(-) create mode 100644 src/Control/Actions/ChannelGroupRenameAction.php rename src/Control/Actions/{GroupAddAction.php => ServerGroupAddAction.php} (82%) rename src/Control/Actions/{GroupDeleteAction.php => ServerGroupDeleteAction.php} (91%) rename src/Control/Actions/{GroupInfoAction.php => ServerGroupInfoAction.php} (79%) rename src/Control/Actions/{GroupRemoveAction.php => ServerGroupRemoveAction.php} (81%) create mode 100644 src/Control/Actions/ServerGroupRenameAction.php create mode 100644 src/View/material/form_inline.twig rename src/View/material/{group_info.twig => servergroup_info.twig} (63%) diff --git a/config/ACL.php b/config/ACL.php index 3c0b0a4..287d8fe 100644 --- a/config/ACL.php +++ b/config/ACL.php @@ -65,13 +65,16 @@ class ACL extends \Zend\Permissions\Acl\Acl '/channels/send/{sid}/{cid}', '/groups/{sid}', - '/groups/{sid}/{sgid}', - '/groups/delete/{sid}/{sgid}', - '/groups/remove/{sid}/{sgid}/{cldbid}', - '/groups/add/{sid}/{sgid}', + + '/servergroups/{sid}/{sgid}', + '/servergroups/delete/{sid}/{sgid}', + '/servergroups/rename/{sid}/{sgid}', + '/servergroups/remove/{sid}/{sgid}/{cldbid}', + '/servergroups/add/{sid}/{sgid}', '/channelgroups/{sid}/{cgid}', '/channelgroups/delete/{sid}/{cgid}', + '/channelgroups/rename/{sid}/{cgid}', '/bans/{sid}', '/bans/delete/{sid}/{banId}', diff --git a/config/routes.php b/config/routes.php index 1154be8..5e0fb06 100644 --- a/config/routes.php +++ b/config/routes.php @@ -184,25 +184,31 @@ $container[GroupsAction::class] = function ($container) { }; $app->get('/groups/{sid}', GroupsAction::class); -$container[GroupInfoAction::class] = function ($container) { - return new GroupInfoAction($container); +// server group +$container[ServerGroupInfoAction::class] = function ($container) { + return new ServerGroupInfoAction($container); }; -$app->get('/groups/{sid}/{sgid}', GroupInfoAction::class); +$app->get('/servergroups/{sid}/{sgid}', ServerGroupInfoAction::class); -$container[GroupDeleteAction::class] = function ($container) { - return new GroupDeleteAction($container); +$container[ServerGroupDeleteAction::class] = function ($container) { + return new ServerGroupDeleteAction($container); }; -$app->get('/groups/delete/{sid}/{sgid}', GroupDeleteAction::class); +$app->get('/servergroups/delete/{sid}/{sgid}', ServerGroupDeleteAction::class); -$container[GroupRemoveAction::class] = function ($container) { - return new GroupRemoveAction($container); +$container[ServerGroupRemoveAction::class] = function ($container) { + return new ServerGroupRemoveAction($container); }; -$app->get('/groups/remove/{sid}/{sgid}/{cldbid}', GroupRemoveAction::class); +$app->get('/servergroups/remove/{sid}/{sgid}/{cldbid}', ServerGroupRemoveAction::class); -$container[GroupAddAction::class] = function ($container) { - return new GroupAddAction($container); +$container[ServerGroupAddAction::class] = function ($container) { + return new ServerGroupAddAction($container); }; -$app->post('/groups/add/{sid}/{sgid}', GroupAddAction::class); +$app->post('/servergroups/add/{sid}/{sgid}', ServerGroupAddAction::class); + +$container[ServerGroupRenameAction::class] = function ($container) { + return new ServerGroupRenameAction($container); +}; +$app->post('/servergroups/rename/{sid}/{sgid}', ServerGroupRenameAction::class); // channel group @@ -216,6 +222,11 @@ $container[ChannelGroupDeleteAction::class] = function ($container) { }; $app->get('/channelgroups/delete/{sid}/{cgid}', ChannelGroupDeleteAction::class); +$container[ChannelGroupRenameAction::class] = function ($container) { + return new ChannelGroupRenameAction($container); +}; +$app->post('/channelgroups/rename/{sid}/{cgid}', ChannelGroupRenameAction::class); + // ban $container[BansAction::class] = function ($container) { return new BansAction($container); diff --git a/data/locale/en.yml b/data/locale/en.yml index 62c4e20..76e2c67 100644 --- a/data/locale/en.yml +++ b/data/locale/en.yml @@ -80,7 +80,8 @@ clients.title: "Clients" bans.title: "Bans" complains.title: "Complains" groups.title: "Groups" -group_info.title: "Group Info" +servergroup_info.title: "Server Group Info" +channelgroup_info.title: "Channelgroup" profile.title: "Profile" tokens.title: "Tokens" @@ -142,27 +143,26 @@ channel_info.h.clients: "Clients" channel_info.send: "Send a message" channel_info.send.message: "Message" -# channelgroups -channelgroups.delete: "Delete" - -# channelgroup info -channelgroup_info.title: "Channelgroup" -channelgroup_info.h.clients: "Clients" -channelgroup_info.h.permissions: "Permissions" -channelgroup_info.remove: "Remove" - # groups groups.delete: "Delete" groups.h.servergroups: "Server Groups" groups.h.channelgroups: "Channel Groups" -# group info -group_info.h.clients_add: "Add" -group_info.h.clients: "Clients" -group_info.h.permissions: "Permissions" -group_info.remove: "Remove" -group_info.add: "Add a client" -group_info.add.cldbid: "Client Database Id" +# channelgroups +channelgroups.delete: "Delete" + +# channelgroup info +channelgroup_info.h.clients: "Clients" +channelgroup_info.h.permissions: "Permissions" +channelgroup_info.remove: "Remove" + +# server group info +servergroup_info.h.clients_add: "Add" +servergroup_info.h.clients: "Clients" +servergroup_info.h.permissions: "Permissions" +servergroup_info.remove: "Remove" +servergroup_info.add: "Add a client" +servergroup_info.add.cldbid: "Client Database Id" # clients clients.delete: "Delete" diff --git a/src/Control/Actions/ChannelGroupRenameAction.php b/src/Control/Actions/ChannelGroupRenameAction.php new file mode 100644 index 0000000..362db54 --- /dev/null +++ b/src/Control/Actions/ChannelGroupRenameAction.php @@ -0,0 +1,25 @@ +getParsedBody(); + $name = $body['name']; + + $this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']); + $selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId'); + + $groupRenameResult = $this->ts->getInstance()->channelGroupRename($cgid, $name); + + $this->flash->addMessage('success', $this->translator->trans('done')); + + return $response->withRedirect('/groups/' . $sid); + } +} \ No newline at end of file diff --git a/src/Control/Actions/GroupAddAction.php b/src/Control/Actions/ServerGroupAddAction.php similarity index 82% rename from src/Control/Actions/GroupAddAction.php rename to src/Control/Actions/ServerGroupAddAction.php index d6c315b..f26891d 100644 --- a/src/Control/Actions/GroupAddAction.php +++ b/src/Control/Actions/ServerGroupAddAction.php @@ -3,7 +3,7 @@ use Slim\Http\Request; use Slim\Http\Response; -final class GroupAddAction extends AbstractAction +final class ServerGroupAddAction extends AbstractAction { public function __invoke(Request $request, Response $response, $args) { @@ -20,6 +20,6 @@ final class GroupAddAction extends AbstractAction $this->flash->addMessage('success', $this->translator->trans('added')); - return $response->withRedirect('/groups/' . $sid . '/' . $sgid); + return $response->withRedirect('/servergroups/' . $sid . '/' . $sgid); } } \ No newline at end of file diff --git a/src/Control/Actions/GroupDeleteAction.php b/src/Control/Actions/ServerGroupDeleteAction.php similarity index 91% rename from src/Control/Actions/GroupDeleteAction.php rename to src/Control/Actions/ServerGroupDeleteAction.php index 32d10b8..9a1938d 100644 --- a/src/Control/Actions/GroupDeleteAction.php +++ b/src/Control/Actions/ServerGroupDeleteAction.php @@ -3,7 +3,7 @@ use Slim\Http\Request; use Slim\Http\Response; -final class GroupDeleteAction extends AbstractAction +final class ServerGroupDeleteAction extends AbstractAction { public function __invoke(Request $request, Response $response, $args) { diff --git a/src/Control/Actions/GroupInfoAction.php b/src/Control/Actions/ServerGroupInfoAction.php similarity index 79% rename from src/Control/Actions/GroupInfoAction.php rename to src/Control/Actions/ServerGroupInfoAction.php index 522bdc4..e563e27 100644 --- a/src/Control/Actions/GroupInfoAction.php +++ b/src/Control/Actions/ServerGroupInfoAction.php @@ -3,7 +3,7 @@ use Slim\Http\Request; use Slim\Http\Response; -final class GroupInfoAction extends AbstractAction +final class ServerGroupInfoAction extends AbstractAction { public function __invoke(Request $request, Response $response, $args) { @@ -18,8 +18,8 @@ final class GroupInfoAction extends AbstractAction $permissionsResult = $this->ts->getInstance()->serverGroupPermList($sgid, true); // render GET - $this->view->render($response, 'group_info.twig', [ - 'title' => $this->translator->trans('group_info.title') . ' ' . $sgid, + $this->view->render($response, 'servergroup_info.twig', [ + 'title' => $this->translator->trans('servergroup_info.title') . ' ' . $sgid, 'clients' => $this->ts->getInstance()->getElement('data', $clientsResult), 'permissions' => $this->ts->getInstance()->getElement('data', $permissionsResult), 'sid' => $sid, diff --git a/src/Control/Actions/GroupRemoveAction.php b/src/Control/Actions/ServerGroupRemoveAction.php similarity index 81% rename from src/Control/Actions/GroupRemoveAction.php rename to src/Control/Actions/ServerGroupRemoveAction.php index 107abd2..a61f6eb 100644 --- a/src/Control/Actions/GroupRemoveAction.php +++ b/src/Control/Actions/ServerGroupRemoveAction.php @@ -3,7 +3,7 @@ use Slim\Http\Request; use Slim\Http\Response; -final class GroupRemoveAction extends AbstractAction +final class ServerGroupRemoveAction extends AbstractAction { public function __invoke(Request $request, Response $response, $args) { @@ -18,6 +18,6 @@ final class GroupRemoveAction extends AbstractAction $this->flash->addMessage('success', $this->translator->trans('removed')); - return $response->withRedirect('/groups/' . $sid . '/' . $sgid); + return $response->withRedirect('/servergroups/' . $sid . '/' . $sgid); } } \ No newline at end of file diff --git a/src/Control/Actions/ServerGroupRenameAction.php b/src/Control/Actions/ServerGroupRenameAction.php new file mode 100644 index 0000000..40be718 --- /dev/null +++ b/src/Control/Actions/ServerGroupRenameAction.php @@ -0,0 +1,25 @@ +getParsedBody(); + $name = $body['name']; + + $this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']); + $selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId'); + + $groupRenameResult = $this->ts->getInstance()->serverGroupRename($sgid, $name); + + $this->flash->addMessage('success', $this->translator->trans('done')); + + return $response->withRedirect('/groups/' . $sid); + } +} \ No newline at end of file diff --git a/src/View/material/form_inline.twig b/src/View/material/form_inline.twig new file mode 100644 index 0000000..1446bd9 --- /dev/null +++ b/src/View/material/form_inline.twig @@ -0,0 +1,47 @@ +{% set uri = editable.uri %} + +{% if editable.uri_param is not empty %} + {% for searchingKey, searchingValue in arr %} + {% if searchingKey == editable.uri_param %} + {% set uri = uri ~ '/' ~ searchingValue %} + {% endif %} + {% endfor %} +{% endif %} + + +
+ {% if editable.type == 'checkbox' %} + + {% if item %} + + + {% else %} + + + {% endif %} + {% elseif editable.type == 'select' %} + + {% else %} + + {% endif %} + + +
\ No newline at end of file diff --git a/src/View/material/groups.twig b/src/View/material/groups.twig index f90fdba..52084e4 100644 --- a/src/View/material/groups.twig +++ b/src/View/material/groups.twig @@ -6,14 +6,25 @@

{% trans %}groups.h.servergroups{% endtrans %}

{% if serverGroups|length > 0 %} {% include 'table.twig' with {'data': serverGroups, - 'links': [{'key': 'sgid', 'uri': '/groups/' ~ sid}], + 'links': [{'key': 'sgid', 'uri': '/servergroups/' ~ sid}], + 'hiddenColumns': ['savedb', 'sortid', 'namemode', 'n_modifyp', 'n_member_addp', 'n_member_removep'], 'additional_links': [ { 'header_label': 'groups.delete'|trans, 'label': 'delete', - 'uri': '/groups/delete/' ~ sid, + 'uri': '/servergroups/delete/' ~ sid, 'uri_param': 'sgid' } + ], + 'attributesEditable': [ + { + 'key': 'name', + 'type': 'text', + 'uri': '/servergroups/rename/' ~ sid, + 'uri_param': 'sgid', + 'uri_method': 'post', + 'submit_label': 'check_circle' + } ] } %} {% else %} @@ -25,6 +36,7 @@ {% if channelGroups|length > 0 %} {% include 'table.twig' with {'data': channelGroups, 'links': [{'key': 'cgid', 'uri': '/channelgroups/' ~ sid}], + 'hiddenColumns': ['savedb', 'sortid', 'namemode', 'n_modifyp', 'n_member_addp', 'n_member_removep'], 'additional_links': [ { 'header_label': 'channelgroups.delete'|trans, @@ -32,6 +44,16 @@ 'uri': '/channelgroups/delete/' ~ sid, 'uri_param': 'cgid' } + ], + 'attributesEditable': [ + { + 'key': 'name', + 'type': 'text', + 'uri': '/channelgroups/rename/' ~ sid, + 'uri_param': 'cgid', + 'uri_method': 'post', + 'submit_label': 'check_circle' + } ] } %} {% else %} diff --git a/src/View/material/keyvalue.twig b/src/View/material/keyvalue.twig index 96358e5..308cae5 100644 --- a/src/View/material/keyvalue.twig +++ b/src/View/material/keyvalue.twig @@ -13,63 +13,27 @@ {{ key|replace({'_' : ' '})|title }} + {% set editable = null %} - {% for attr in attributesEditable %} {% if attr.key == key %} {% set editable = attr %} {% endif %} {% endfor %} - {% set item = value %} - {% for filter in filters %} {% if filter.key == key %} {% set item = value|apply_filter(filter.apply)|raw %} {% endif %} {% endfor %} - + {% if editable is not empty %} + {% include 'form_inline.twig' with {'editable': editable} %} -
- {% if editable.type == 'checkbox' %} - - {% if item %} - - - {% else %} - - - {% endif %} - {% elseif editable.type == 'select' %} - - {% else %} - - {% endif %} - - -
+ {% else %} {{ item }} {% endif %} diff --git a/src/View/material/group_info.twig b/src/View/material/servergroup_info.twig similarity index 63% rename from src/View/material/group_info.twig rename to src/View/material/servergroup_info.twig index 69b35ee..5387e4b 100644 --- a/src/View/material/group_info.twig +++ b/src/View/material/servergroup_info.twig @@ -3,32 +3,32 @@ {% block content %}

{{ title }}

-

{% trans %}group_info.h.clients_add{% endtrans %}

+

{% trans %}servergroup_info.h.clients_add{% endtrans %}

{% include 'form.twig' with { 'fields': [ { - 'header_label': 'group_info.add'|trans, + 'header_label': 'servergroup_info.add'|trans, 'label': 'check_circle', - 'uri': '/groups/add/' ~ sid ~ '/' ~ sgid, + 'uri': '/servergroups/add/' ~ sid ~ '/' ~ sgid, 'uri_method': 'post', 'fields': [ - {'type': 'text', 'key': 'cldbid', 'label': 'group_info.add.cldbid'|trans}, + {'type': 'text', 'key': 'cldbid', 'label': 'servergroup_info.add.cldbid'|trans}, ] } ] } %} {% if clients|length > 0 %} -

{% trans %}group_info.h.clients{% endtrans %}

+

{% trans %}servergroup_info.h.clients{% endtrans %}

{% include 'table.twig' with {'data': clients, 'links': [ {'key': 'cldbid', 'uri': '/clients/' ~ sid, 'uri_param': 'cldbid'} ], 'additional_links': [ { - 'header_label': 'group_info.remove'|trans, + 'header_label': 'servergroup_info.remove'|trans, 'label': 'delete', - 'uri': '/groups/remove/' ~ sid ~ '/' ~ sgid, + 'uri': '/servergroups/remove/' ~ sid ~ '/' ~ sgid, 'uri_param': 'cldbid' } ] @@ -36,7 +36,7 @@ {% endif %} {% if permissions|length > 0 %} -

{% trans %}group_info.h.permissions{% endtrans %}

+

{% trans %}servergroup_info.h.permissions{% endtrans %}

{% include 'table.twig' with {'data': permissions} %} {% endif %} diff --git a/src/View/material/table.twig b/src/View/material/table.twig index 3304e48..77bb630 100644 --- a/src/View/material/table.twig +++ b/src/View/material/table.twig @@ -2,11 +2,13 @@ + {% set added = [] %} {% for arr in data %} {% set added = arr|keys %} {% endfor %} + {% for key in added %} {% if key not in hiddenColumns %} @@ -22,8 +24,8 @@ {% for arr in data %} + {% set show = true %} - {% for hidden in hiddenDependingOnAttribute %} {% if hidden.key in arr|keys and attribute(arr, hidden.key) in hidden.values %} {% set show = false %} @@ -35,41 +37,58 @@ {% for key, value in arr %} {% set value = value %} + {% for filter in filters %} {% if filter.key == key %} {% set value = value|apply_filter(filter.apply)|raw %} {% endif %} {% endfor %} + {% set showColumn = true %} - {% if key in hiddenColumns %} {% set showColumn = false %} {% endif %} {% if showColumn %} - {% set item = '' %} + " %} - {% endif %} - {% endfor %} - {% else %} - {% set item = "" %} + + {% set editable = null %} + {% for attr in attributesEditable %} + {% if attr.key == key %} + {% set editable = attr %} {% endif %} - {% endif %} - {% endfor %} + {% endfor %} - {{ item|raw }} + + {% if editable is not empty %} + {% include 'form_inline.twig' with {'editable': editable} %} + + {% else %} + {% for link in links %} + {% if link.key == key %} + {% if link.uri_param is not empty %} + {% for searchingKey, searchingValue in arr %} + {% if searchingKey == link.uri_param %} + {% set item = "#{value}" %} + {% endif %} + {% endfor %} + {% else %} + {% set item = "#{value}" %} + {% endif %} + {% endif %} + {% endfor %} + + {{ item|raw }} + {% endif %} + {% endif %} {% endfor %} + {% for link in additional_links %} -
{{ key|replace({'_' : ' '})|title }}' ~ value ~ ' + {% set item = value %} - {% for link in links %} - {% if link.key == key %} - {% if link.uri_param is not empty %} - {% for searchingKey, searchingValue in arr %} - {% if searchingKey == link.uri_param %} - {% set item = "#{value}#{value} {% set item = "#{link.label}" %}