From 094fbb64a8a373a723d5497746616a080d981e7c Mon Sep 17 00:00:00 2001 From: Christian Hofmaier Date: Fri, 7 Apr 2017 16:00:50 +0200 Subject: [permission-manager] filter for roles in user and location table, changed structure of role-spans in both tables --- .../inc/getpermissiondata.inc.php | 38 ++++--- .../permissionmanager/lang/de/template-tags.json | 3 +- .../permissionmanager/lang/en/template-tags.json | 3 +- modules-available/permissionmanager/page.inc.php | 2 +- .../templates/locationstable.html | 88 ++++++++++++--- .../permissionmanager/templates/userstable.html | 119 +++++++++++++++------ 6 files changed, 193 insertions(+), 60 deletions(-) (limited to 'modules-available/permissionmanager') diff --git a/modules-available/permissionmanager/inc/getpermissiondata.inc.php b/modules-available/permissionmanager/inc/getpermissiondata.inc.php index be7ddb1c..5114f4ef 100644 --- a/modules-available/permissionmanager/inc/getpermissiondata.inc.php +++ b/modules-available/permissionmanager/inc/getpermissiondata.inc.php @@ -5,12 +5,20 @@ class GetPermissionData { // get UserIDs, User Login Names, User Roles public static function getUserData() { $res = self::queryUserData(); - $data = array(); + $userdata= array(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $userdata[$row['userid'].' '.$row['login']][] = array( + 'roleId' => $row['roleId'], + 'roleName' => $row['roleName'] + ); + } + $data = array(); + foreach($userdata AS $user => $roles) { + $user = explode(" ", $user, 2); $data[] = array( - 'userid' => $row['userid'], - 'name' => $row['login'], - 'role' => explode(",",$row['role']) + 'userid' => $user[0], + 'username' => $user[1], + 'roles' => $roles ); } return $data; @@ -19,12 +27,20 @@ class GetPermissionData { // get LocationIDs, Location Names, Roles of each Location public static function getLocationData() { $res = self::queryLocationData(); - $data = array(); + $locdata = array(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $locdata[$row['locid'].' '.$row['locname']][] = array( + 'roleId' => $row['roleId'], + 'roleName' => $row['roleName'] + ); + } + $data = array(); + foreach($locdata AS $loc => $roles) { + $loc = explode(" ", $loc, 2); $data[] = array( - 'locid' => $row['locid'], - 'name' => $row['locname'], - 'role' => explode(",",$row['role']) + 'locid' => $loc[0], + 'locname' => $loc[1], + 'roles' => $roles ); } return $data; @@ -73,22 +89,20 @@ class GetPermissionData { // UserID, User Login Name, Roles of each User private static function queryUserData() { - $res = Database::simpleQuery("SELECT user.userid AS userid, user.login AS login, GROUP_CONCAT(role.name ORDER BY role.name ASC) AS role + $res = Database::simpleQuery("SELECT user.userid AS userid, user.login AS login, role.name AS roleName, role.id AS roleId FROM user LEFT JOIN user_x_role ON user.userid = user_x_role.userid LEFT JOIN role ON user_x_role.roleid = role.id - GROUP BY user.userid "); return $res; } // LocationID, Location Name, Roles of each Location private static function queryLocationData() { - $res = Database::simpleQuery("SELECT location.locationid AS locid, location.locationname AS locname, GROUP_CONCAT(role.name ORDER BY role.name ASC) AS role + $res = Database::simpleQuery("SELECT location.locationid AS locid, location.locationname AS locname, role.name AS roleName, role.id AS roleId FROM location LEFT JOIN role_x_location ON location.locationid = role_x_location.locid LEFT JOIN role ON role_x_location.roleid = role.id - GROUP BY location.locationid ORDER BY location.locationname "); return $res; diff --git a/modules-available/permissionmanager/lang/de/template-tags.json b/modules-available/permissionmanager/lang/de/template-tags.json index d67bde65..86c03871 100644 --- a/modules-available/permissionmanager/lang/de/template-tags.json +++ b/modules-available/permissionmanager/lang/de/template-tags.json @@ -17,5 +17,6 @@ "lang_Save": "Speichern", "lang_all": "alle", "lang_selected": "ausgewählte", - "lang_Permissions": "Rechte" + "lang_Permissions": "Rechte", + "lang_selectizePlaceholder": "Nach Rollen filtern..." } \ No newline at end of file diff --git a/modules-available/permissionmanager/lang/en/template-tags.json b/modules-available/permissionmanager/lang/en/template-tags.json index e6227b90..82cbc933 100644 --- a/modules-available/permissionmanager/lang/en/template-tags.json +++ b/modules-available/permissionmanager/lang/en/template-tags.json @@ -17,5 +17,6 @@ "lang_Save": "Save", "lang_all": "all", "lang_selected": "selected", - "lang_Permissions": "Permissions" + "lang_Permissions": "Permissions", + "lang_selectizePlaceholder": "Filter for roles..." } \ No newline at end of file diff --git a/modules-available/permissionmanager/page.inc.php b/modules-available/permissionmanager/page.inc.php index 3c72cfe4..94a5469f 100644 --- a/modules-available/permissionmanager/page.inc.php +++ b/modules-available/permissionmanager/page.inc.php @@ -61,7 +61,7 @@ class Page_PermissionManager extends Page $data = array("user" => GetPermissionData::getUserData(), "roles" => GetPermissionData::getRoles()); Render::addTemplate('userstable', $data); } elseif ($show === "locations") { - $data = array("location" => GetPermissionData::getLocationData()); + $data = array("location" => GetPermissionData::getLocationData(), "roles" => GetPermissionData::getRoles()); Render::addTemplate('locationstable', $data); } } elseif ($show === "roleEditor") { diff --git a/modules-available/permissionmanager/templates/locationstable.html b/modules-available/permissionmanager/templates/locationstable.html index e170cd02..3f15ee7b 100644 --- a/modules-available/permissionmanager/templates/locationstable.html +++ b/modules-available/permissionmanager/templates/locationstable.html @@ -1,25 +1,85 @@ +
+
+ +
+
+
- - - - + + + + - {{#location}} - - - - + {{#location}} + + + + {{/location}}
{{lang_Locations}}{{lang_Roles}}
{{lang_Locations}}{{lang_Roles}}
{{name}} - {{#role}} - {{.}} - {{/role}} -
{{locname}} + {{#roles}} + {{roleName}} + {{/roles}} +
-
\ No newline at end of file + + + \ No newline at end of file diff --git a/modules-available/permissionmanager/templates/userstable.html b/modules-available/permissionmanager/templates/userstable.html index 3db1ebdb..e15228d5 100644 --- a/modules-available/permissionmanager/templates/userstable.html +++ b/modules-available/permissionmanager/templates/userstable.html @@ -1,27 +1,40 @@ -
+ - - + +
+
+ + +
+
+ +
+
- - - - - + + + + + {{#user}} - - + +
{{lang_Users}}{{lang_Roles}}{{lang_Selected}}
{{lang_Users}}{{lang_Roles}}{{lang_Selected}}
{{name}}
{{username}} - {{#role}} - {{.}} - {{/role}} + {{#roles}} + {{roleName}} + {{/roles}}
@@ -49,25 +62,25 @@
- - - - + + + + - - {{#roles}} - - - - - {{/roles}} - + + {{#roles}} + + + + + {{/roles}} +
{{lang_Roles}}{{lang_Selected}}
{{lang_Roles}}{{lang_Selected}}
{{roleName}} -
- - -
-
{{roleName}} +
+ + +
+
@@ -138,6 +151,51 @@ }); + var selectize = $('#select-role').selectize({ + allowEmptyOption: false, + maxItems: null, + highlight: false, + hideSelected: true, + create: false, + placeholder: "{{lang_selectizePlaceholder}}", + plugins: [ "remove_button" ] + })[0].selectize; + + // If Site gets refreshed, all data-selectizeCounts will be reset to 0, so delete the filters from the selectize + selectize.clear(); + + selectize.on('item_add', function(value, $item) { + // When first item gets added the filter isn't empty anymore, so hide all rows + if (selectize.items.length === 1) { + $('#locationsTable').find('tr').hide(); + } + // Find all rows which shall be shown and increase their counter by 1 + $(".roleId-"+value).closest("tr").each(function() { + $(this).data("selectizeCount", $(this).data("selectizeCount") + 1); + $(this).show(); + }); + }); + + selectize.on('item_remove', function(value, $item) { + // When no items in the filter, show all rows again + if (selectize.items.length === 0) { + $('#locationsTable').find('tr').show(); + } else { + // Find all rows which have the delete role, decrease their counter by 1 + $(".roleId-"+value).closest("tr").each(function() { + $(this).data("selectizeCount", $(this).data("selectizeCount") - 1); + // If counter is 0, hide the row (no filter given to show the row anymore) + if ($(this).data("selectizeCount") === 0) { + $(this).closest("tr").hide(); + } + }); + } + }); + + $("form input").keydown(function(e) { + if (e.keyCode === 13) e.preventDefault(); + }); + }); @@ -156,5 +214,4 @@ .prop("checked", "") .end(); } - \ No newline at end of file -- cgit v1.2.3-55-g7522