-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin-user-permissions.php
More file actions
194 lines (165 loc) · 5.43 KB
/
admin-user-permissions.php
File metadata and controls
194 lines (165 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
</head>
<body>
<div class="content-block">
<h1>User Permissions</h1>
</div>
<table id="permissions-table">
<thead></thead>
<tbody></tbody>
</table>
<div class="content-block">
<h1>Organizers you can create Events for</h1>
</div>
<table id="organizers-table">
<thead></thead>
<tbody></tbody>
</table>
<script>
init();
async function init() {
fetchPermissions()
.then(jsonData => renderPermissionsTable(jsonData["permissions"] || []))
.catch(err => console.error(err));
fetchUserOrganizers()
.then(jsonData => renderOrganizersTable(jsonData["event-organizers"] || []))
.catch(err => console.error(err));
}
async function fetchPermissions() {
try {
const resp = await fetch('http://localhost:9090/api/admin/user/permissions/all', {
method: 'GET',
headers: { 'Accept': 'application/json' },
credentials: 'include' // Keep if cookies/session needed
});
if (!resp.ok) {
throw new Error(`HTTP ${resp.status} ${resp.statusText}`);
}
const jsonData = await resp.json();
console.log(jsonData);
return jsonData;
} catch (err) {
console.error('Fetch error:', err);
throw err;
}
}
async function fetchUserOrganizers() {
try {
const resp = await fetch('http://localhost:9090/api/admin/user/event-organizers', {
method: 'GET',
headers: { 'Accept': 'application/json' },
credentials: 'include'
});
if (!resp.ok) {
throw new Error(`HTTP ${resp.status} ${resp.statusText}`);
}
const jsonData = await resp.json();
console.log(jsonData);
return jsonData;
} catch (err) {
console.error('Fetch error:', err);
throw err;
}
}
function renderPermissionsTable(jsonData) {
const desiredOrder = [
"entity_type", "entity_name", "name",
"edit_organizer", "delete_organizer",
"add_venue", "edit_venue", "delete_venue",
"add_space", "edit_space", "delete_space",
"add_event", "edit_event", "delete_event",
"release_event", "view_event_insights"
];
const table = document.getElementById('permissions-table');
const thead = table.querySelector('thead');
const tbody = table.querySelector('tbody');
if (jsonData.length === 0) {
thead.innerHTML = '<tr><th>No data</th></tr>';
tbody.innerHTML = '';
return;
}
// Use desiredOrder directly
const columns = desiredOrder;
// Build table header
// Manual header with groups and subcolumns
thead.innerHTML = `
<tr>
<th>type</th>
<th>name</th>
<th>role</th>
<th colspan="2">org</th>
<th colspan="3">venue</th>
<th colspan="3">space</th>
<th colspan="5">event</th>
</tr>
<tr>
<th></th>
<th></th>
<th></th>
<th>e</th>
<th>d</th>
<th>a</th>
<th>e</th>
<th>d</th>
<th>a</th>
<th>e</th>
<th>d</th>
<th>a</th>
<th>e</th>
<th>d</th>
<th>r</th>
<th>i</th>
</tr>
`;
// Build table body
tbody.innerHTML = '';
jsonData.forEach(row => {
const tr = document.createElement('tr');
columns.forEach(col => {
const td = document.createElement('td');
let value = row[col];
if (value === null || value === undefined) {
value = '';
} else if (typeof value === 'boolean') {
value = value ? '✓' : '';
}
td.textContent = value;
tr.appendChild(td);
});
tbody.appendChild(tr);
});
}
function renderOrganizersTable(jsonData) {
const table = document.getElementById('organizers-table');
const thead = table.querySelector('thead');
const tbody = table.querySelector('tbody');
if (!jsonData || jsonData.length === 0) {
thead.innerHTML = '<tr><th>No data</th></tr>';
tbody.innerHTML = '';
return;
}
// Define columns for organizers table (adjust as needed)
const columns = [
"user_id", "organizer_id", "organizer_name", "organizer_city", "organizer_country"
];
// Build header row
thead.innerHTML = `<tr>${columns.map(c => `<th>${c.replace(/_/g, ' ')}</th>`).join('')}</tr>`;
tbody.innerHTML = '';
jsonData.forEach(row => {
const tr = document.createElement('tr');
columns.forEach(col => {
const td = document.createElement('td');
let value = row[col];
if (value === null || value === undefined) value = '';
td.textContent = value;
tr.appendChild(td);
});
tbody.appendChild(tr);
});
}
</script>
</body>
</html>