Skip to content

Commit 604039f

Browse files
replace custom tables with datatables.net (#456)
Co-authored-by: Copilot <[email protected]>
1 parent b32fa84 commit 604039f

File tree

19 files changed

+416
-564
lines changed

19 files changed

+416
-564
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ node_modules
2828
# copied from node_modules using the copy-files-from-to NPM package
2929
webroot/js/jquery.min.js
3030
webroot/js/ckeditor5.umd.js
31+
webroot/js/*dataTables*.js
32+
webroot/js/buttons.colVis.min.js
33+
webroot/js/buttons.html5.min.js
34+
webroot/js/buttons.print.min.js
3135
webroot/css/ckeditor5.css
36+
webroot/css/*dataTables*.css

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Admin Features:
2525
- Cluster notices
2626
- Added to front page, mailed, and exposed via REST API
2727
- WYSIWYG HTML editor ([ckeditor5](https://github.com/ckeditor/ckeditor5)) for webpage contents, cluster notices
28+
- Responsive Tables ([datatables.net](https://datatables.net)) for filtering, sorting, pagination, etc.
2829
- Branding customization for multiple domains simultaneously
2930
- Custom UIDNumber / GIDNumber mappings for specific users
3031
- Login as another user

package-lock.json

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
"dependencies": {
77
"ckeditor5": "^47.3.0",
88
"copy-files-from-to": "^3.13.0",
9+
"datatables.net-buttons-dt": "^3.2.6",
10+
"datatables.net-columncontrol-dt": "^1.2.0",
11+
"datatables.net-dt": "^2.3.6",
12+
"datatables.net-responsive-dt": "^3.0.7",
913
"jquery": "^3.7.1"
1014
},
1115
"copyFiles": [
@@ -20,6 +24,50 @@
2024
{
2125
"from": "node_modules/ckeditor5/dist/browser/ckeditor5.css",
2226
"to": "webroot/css/ckeditor5.css"
27+
},
28+
{
29+
"from": "node_modules/datatables.net-responsive/js/dataTables.responsive.min.js",
30+
"to": "webroot/js/dataTables.responsive.min.js"
31+
},
32+
{
33+
"from": "node_modules/datatables.net-columncontrol/js/dataTables.columnControl.min.js",
34+
"to": "webroot/js/dataTables.columnControl.min.js"
35+
},
36+
{
37+
"from": "node_modules/datatables.net-buttons/js/buttons.print.min.js",
38+
"to": "webroot/js/buttons.print.min.js"
39+
},
40+
{
41+
"from": "node_modules/datatables.net-buttons/js/buttons.colVis.min.js",
42+
"to": "webroot/js/buttons.colVis.min.js"
43+
},
44+
{
45+
"from": "node_modules/datatables.net-buttons/js/dataTables.buttons.min.js",
46+
"to": "webroot/js/dataTables.buttons.min.js"
47+
},
48+
{
49+
"from": "node_modules/datatables.net-buttons/js/buttons.html5.min.js",
50+
"to": "webroot/js/buttons.html5.min.js"
51+
},
52+
{
53+
"from": "node_modules/datatables.net/js/dataTables.min.js",
54+
"to": "webroot/js/dataTables.min.js"
55+
},
56+
{
57+
"from": "node_modules/datatables.net-responsive-dt/css/responsive.dataTables.min.css",
58+
"to": "webroot/css/responsive.dataTables.min.css"
59+
},
60+
{
61+
"from": "node_modules/datatables.net-dt/css/dataTables.dataTables.min.css",
62+
"to": "webroot/css/dataTables.dataTables.min.css"
63+
},
64+
{
65+
"from": "node_modules/datatables.net-columncontrol-dt/css/columnControl.dataTables.min.css",
66+
"to": "webroot/css/columnControl.dataTables.min.css"
67+
},
68+
{
69+
"from": "node_modules/datatables.net-buttons-dt/css/buttons.dataTables.min.css",
70+
"to": "webroot/css/buttons.dataTables.min.css"
2371
}
2472
]
2573
}

resources/lib/UnityLDAP.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,19 @@ public function getAllPIGroupOwnerUIDs(): array
231231
);
232232
}
233233

234+
public function getPIGroupAttributesWithMemberUID(
235+
string $uid,
236+
array $attributes,
237+
array $default_values = [],
238+
) {
239+
return $this->pi_groupOU->getChildrenArrayStrict(
240+
$attributes,
241+
recursive: false,
242+
filter: sprintf("(memberuid=%s)", ldap_escape($uid, "", LDAP_ESCAPE_FILTER)),
243+
default_values: $default_values,
244+
);
245+
}
246+
234247
/**
235248
* Returns an associative array where keys are UIDs and values are arrays of PI GIDs
236249
*/

resources/templates/footer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
</body>
3232
<?php
33-
foreach (["filter", "sort", "global-late", "tables", "messages"] as $x) {
33+
foreach (["global-late", "messages"] as $x) {
3434
$url = getURL("js/$x.js?cache_bust_increment_me=" . CONFIG["upstream"]["version"]);
3535
echo "<script src='$url'></script>";
3636
}

resources/templates/header.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@
3737

3838
<head>
3939
<?php
40-
foreach (["jquery.min", "global-early", "ckeditor5.umd"] as $x) {
40+
$scripts = [
41+
"jquery.min", "global-early", "ckeditor5.umd", "dataTables.min", "dataTables.responsive.min",
42+
"dataTables.buttons.min", "dataTables.columnControl.min", "buttons.print.min",
43+
"buttons.colVis.min", "buttons.html5.min",
44+
];
45+
foreach ($scripts as $x) {
4146
$url = getURL("js/$x.js?cache_bust_increment_me=" . CONFIG["upstream"]["version"]);
4247
echo "<script src='$url'></script>";
4348
}
@@ -54,7 +59,11 @@
5459
</style>
5560

5661
<?php
57-
foreach (["global", "navbar", "modal", "tables", "filters", "messages", "ckeditor5"] as $x) {
62+
$stylesheets = [
63+
"global", "navbar", "modal", "messages", "ckeditor5", "responsive.dataTables.min",
64+
"dataTables.dataTables.min", "columnControl.dataTables.min", "buttons.dataTables.min",
65+
];
66+
foreach ($stylesheets as $x) {
5867
$url = getURL("css/$x.css?cache_bust_increment_me=" . CONFIG["upstream"]["version"]);
5968
echo "<link rel='stylesheet' type='text/css' href='$url' />";
6069
}

webroot/admin/ajax/get_group_members.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
/* pi-mgmt.php uses ajax to get this output and then uses it to insert new rows to the PI table */
4+
35
require_once __DIR__ . "/../../../resources/autoload.php";
46

57
use UnityWebPortal\lib\UnityGroup;
@@ -15,25 +17,19 @@
1517
$members = $group->getGroupMembersAttributes(["gecos", "mail"]);
1618
$requests = $group->getRequests();
1719

18-
$CSRFTokenHiddenFormInput = UnityHTTPD::getCSRFTokenHiddenFormInput();
19-
20-
$i = 0;
2120
$count = count($members) + count($requests);
2221
foreach ($members as $uid => $attributes) {
2322
if ($uid == $group->getOwner()->uid) {
2423
continue;
2524
}
26-
if ($i >= $count - 1) {
27-
echo "<tr class='expanded $i last'>";
28-
} else {
29-
echo "<tr class='expanded $i'>";
30-
}
25+
echo "<tr style='background: var(--light_panel_background);'>";
3126
$fullname = $attributes["gecos"][0];
3227
$mail = $attributes["mail"][0];
3328
echo "<td>$fullname</td>";
3429
echo "<td>$uid</td>";
35-
echo "<td><a href='mailto:$mail'>$mail</a></td>";
30+
echo "<td>$mail</td>";
3631
echo "<td>";
32+
$CSRFTokenHiddenFormInput = UnityHTTPD::getCSRFTokenHiddenFormInput();
3733
echo "
3834
<form
3935
action=''
@@ -51,21 +47,17 @@
5147
";
5248
echo "</td>";
5349
echo "</tr>";
54-
$i++;
5550
}
5651

57-
foreach ($requests as $i => [$user, $timestamp]) {
58-
if ($i >= $count - 1) {
59-
echo "<tr class='expanded $i last'>";
60-
} else {
61-
echo "<tr class='expanded $i'>";
62-
}
52+
foreach ($requests as [$user, $timestamp]) {
53+
echo "<tr style='background: var(--light_panel_background);'>";
6354
$name = $user->getFullName();
6455
$email = $user->getMail();
6556
echo "<td>$name</td>";
6657
echo "<td>$user->uid</td>";
67-
echo "<td><a href='mailto:$email'>$email</a></td>";
58+
echo "<td>$email</td>";
6859
echo "<td>";
60+
$CSRFTokenHiddenFormInput = UnityHTTPD::getCSRFTokenHiddenFormInput();
6961
echo
7062
"<form action='' method='POST'
7163
onsubmit='return confirm(\"Are you sure you want to approve $user->uid ?\");'>
@@ -77,5 +69,4 @@
7769
<input type='submit' name='action' value='Deny'></form>";
7870
echo "</td>";
7971
echo "</tr>";
80-
$i++;
8172
}

0 commit comments

Comments
 (0)