diff options
6 files changed, 193 insertions, 60 deletions
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 @@ <div class="row"> + <div class="col-md-4 text-left"> + <select multiple name="roles[]" id="select-role"> + <option value></option> + {{#roles}} + <option value="{{roleId}}">{{roleName}}</option> + {{/roles}} + </select> + </div> +</div> + +<div class="row"> <div class="col-md-12"> <table id="locationsTable" class="table table-condensed table-hover"> <thead> - <tr> - <th data-sort="string">{{lang_Locations}}</th> - <th>{{lang_Roles}}</th> - </tr> + <tr> + <th data-sort="string">{{lang_Locations}}</th> + <th>{{lang_Roles}}</th> + </tr> </thead> <tbody> - {{#location}} - <tr> - <td>{{name}}</td> - <td> - {{#role}} - <span class="label label-default customSpanMargin">{{.}}</span> - {{/role}} - </td> - </tr> + {{#location}} + <tr data-selectizeCount='0'> + <td>{{locname}}</td> + <td> + {{#roles}} + <span class="label label-default customSpanMargin roleId-{{roleId}}">{{roleName}}</span> + {{/roles}} + </td> + </tr> {{/location}} </tbody> </table> </div> -</div>
\ No newline at end of file +</div> + +<script> + document.addEventListener("DOMContentLoaded", function() { + 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(); + }); + }); +</script>
\ 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 @@ -<form method="post" action="?do=permissionmanager"> +<form method="post" action="?do=permissionmanager&show=users"> <input type="hidden" name="token" value="{{token}}"> - <button class="btn btn-success" type="button" data-toggle="modal" data-target="#addRoleToUserModal"><span class="glyphicon glyphicon-share-alt"></span> {{lang_addRole}}</button> - <button class="btn btn-danger" type="button" data-toggle="modal" data-target="#removeRoleFromUserModal"><span class="glyphicon glyphicon-trash"></span> {{lang_removeRole}}</button> + + <div class="row"> + <div class="col-md-4"> + <button class="btn btn-success" type="button" data-toggle="modal" data-target="#addRoleToUserModal"><span class="glyphicon glyphicon-share-alt"></span> {{lang_addRole}}</button> + <button class="btn btn-danger" type="button" data-toggle="modal" data-target="#removeRoleFromUserModal"><span class="glyphicon glyphicon-trash"></span> {{lang_removeRole}}</button> + </div> + <div class="col-md-4 text-left"> + <select multiple name="roles[]" id="select-role"> + <option value></option> + {{#roles}} + <option value="{{roleId}}">{{roleName}}</option> + {{/roles}} + </select> + </div> + </div> <div class="row"> <div class="col-md-12"> <table id="usersTable" class="table table-condensed table-hover"> <thead> - <tr> - <th data-sort="string">{{lang_Users}}</th> - <th>{{lang_Roles}}</th> - <th data-sort="int" data-sort-default="desc">{{lang_Selected}}</th> - </tr> + <tr> + <th data-sort="string">{{lang_Users}}</th> + <th>{{lang_Roles}}</th> + <th data-sort="int" data-sort-default="desc">{{lang_Selected}}</th> + </tr> </thead> <tbody> {{#user}} - <tr> - <td>{{name}}</td> + <tr data-selectizeCount='0'> + <td>{{username}}</td> <td> - {{#role}} - <span class="label label-default customSpanMargin">{{.}}</span> - {{/role}} + {{#roles}} + <span class="label label-default customSpanMargin roleId-{{roleId}}">{{roleName}}</span> + {{/roles}} </td> <td data-sort-value="0"> <div class="checkbox"> @@ -49,25 +62,25 @@ <div class="col-md-12 scrollingTable"> <table id="addRoleToUserTable" class="table table-condensed table-hover"> <thead> - <tr> - <th data-sort="string">{{lang_Roles}}</th> - <th data-sort="int" data-sort-default="desc">{{lang_Selected}}</th> - </tr> + <tr> + <th data-sort="string">{{lang_Roles}}</th> + <th data-sort="int" data-sort-default="desc">{{lang_Selected}}</th> + </tr> </thead> - <tbody> - {{#roles}} - <tr> - <td>{{roleName}}</td> - <td data-sort-value="0"> - <div class="checkbox"> - <input id="add{{roleId}}" type="checkbox" name="roles[]" value='{{roleId}}'> - <label for="add{{roleId}}"></label> - </div> - </td> - </tr> - {{/roles}} - </tbody> + <tbody> + {{#roles}} + <tr> + <td>{{roleName}}</td> + <td data-sort-value="0"> + <div class="checkbox"> + <input id="add{{roleId}}" type="checkbox" name="roles[]" value='{{roleId}}'> + <label for="add{{roleId}}"></label> + </div> + </td> + </tr> + {{/roles}} + </tbody> </table> </div> </div> @@ -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(); } - </script>
\ No newline at end of file |