Repository navigation
Expand file tree
/
Copy pathadmin-tests.php
More file actions
391 lines (372 loc) · 23.7 KB
/
Copy pathadmin-tests.php
File metadata and controls
391 lines (372 loc) · 23.7 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
<?php
/**
* Admin Tests Management Page
*
* Global admins, resource admins, and users whose role reads the test types
* (test_editor, developer) view liturgical test definitions via the /tests API;
* holders of the matching editor/admin scopes also create, edit and delete them. Per-row edit/delete are
* gated against the caller's scopes from GET /auth/test-scopes; the API is
* the hard backstop.
*/
include_once 'includes/common.php';
include_once 'includes/messages.php';
// Require authentication - redirect to home if not logged in
if (!$authHelper->isAuthenticated) {
header('Location: index.php');
exit;
}
// This is an admin page. Reading comes from the role (LiturgicalCalendarAPI #1049):
// global admins and every role whose scope includes a test type (test_editor,
// developer) may enter — the same rule that gates the dashboard's Tests card. So may an
// admin of a test scope, whatever their role. Being admin of some other resource (a
// calendar) is not a path to the tests. Per-row gating (below, in JS) governs what each
// user may change.
$isGlobalAdmin = $authHelper->hasRole('admin');
$hasTestEditor = $authHelper->hasRole('test_editor');
$testTypes = ['national_calendar_test', 'diocesan_calendar_test', 'rite_calendar_test'];
$canViewTests = $authHelper->canViewAnyResourceOfType(...$testTypes);
$adminsTestScope = array_filter(
$authHelper->adminScopes(),
fn (array $scope): bool => in_array($scope['object_type'], $testTypes, true)
) !== [];
if (!$canViewTests && !$adminsTestScope) {
header('Location: admin-dashboard.php');
exit;
}
?>
<!doctype html>
<html lang="<?php echo htmlspecialchars($i18n->LOCALE, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>">
<head>
<title><?php
$testsTitle = _('Test Definitions');
$calendarTitle = _('Catholic Liturgical Calendar');
echo htmlspecialchars($testsTitle, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
echo ' - ';
echo htmlspecialchars($calendarTitle, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
?></title>
<?php include_once('./layout/head.php'); ?>
</head>
<body class="sb-nav-fixed">
<?php include_once('./layout/header.php'); ?>
<h1 class="h3 mb-4 text-black" style="--bs-text-opacity: .6;">
<i class="fas fa-vial me-2 text-info"></i><?php echo htmlspecialchars(_('Test Definitions'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</h1>
<p class="text-muted mb-4"><?php
echo htmlspecialchars(
_('Create, edit, and delete liturgical accuracy test definitions.'),
ENT_QUOTES | ENT_SUBSTITUTE,
'UTF-8'
);
?></p>
<!-- Filters -->
<div class="card shadow mb-4">
<div class="card-body">
<div class="row g-2 align-items-end">
<div class="col-md-4">
<label class="form-label" for="filterTestName">
<?php echo htmlspecialchars(_('Filter by name'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</label>
<input type="text" class="form-control" id="filterTestName" />
</div>
<div class="col-md-4">
<label class="form-label" for="filterTestScope">
<?php echo htmlspecialchars(_('Filter by scope'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</label>
<input type="text" class="form-control" id="filterTestScope"
placeholder="<?php echo htmlspecialchars(_('USA, diocese id, ...'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>" />
</div>
<div class="col-md-4 text-end">
<button type="button" class="btn btn-outline-secondary" id="refreshTestsBtn">
<i class="fas fa-rotate"></i> <?php echo htmlspecialchars(_('Refresh'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</button>
<button type="button" class="btn btn-primary" id="createTestBtn" data-requires-auth>
<i class="fas fa-plus"></i> <?php
/* translators: "test" here is an accuracy-test definition checking the calendar produces the expected
result, not a scientific experiment or an examination */
echo htmlspecialchars(_('New Test'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
?>
</button>
</div>
</div>
</div>
</div>
<!-- Tests table -->
<div class="card shadow mb-4">
<div class="card-header d-flex justify-content-between align-items-center">
<span><?php
/* translators: accuracy-test definitions checking the calendar produces the expected results, not scientific experiments
or examinations */
echo htmlspecialchars(_('Tests'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
?></span>
<span class="badge bg-secondary" id="testsCount">0</span>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-sm table-hover align-middle">
<thead>
<tr>
<th><?php echo htmlspecialchars(_('Name'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?></th>
<th><?php echo htmlspecialchars(_('Event'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?></th>
<th><?php echo htmlspecialchars(_('Scope'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?></th>
<th><?php echo htmlspecialchars(_('Type'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?></th>
<th><?php echo htmlspecialchars(_('Years'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?></th>
<th class="text-end"><?php echo htmlspecialchars(_('Actions'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?></th>
</tr>
</thead>
<tbody id="testsTableBody"></tbody>
</table>
</div>
</div>
</div>
<!-- Editor modal -->
<div class="modal fade" id="testEditorModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-xl modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="testEditorModalLabel">
<?php echo htmlspecialchars(_('Test Definition'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="<?php echo htmlspecialchars(_('Close'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>"></button>
</div>
<div class="modal-body">
<div id="testEditorAlerts"></div>
<form id="testEditorForm" novalidate>
<!-- Step 1: scope, liturgical event, base date -->
<div class="row g-3">
<div class="col-md-6">
<label class="form-label" for="testScopeType">
<?php echo htmlspecialchars(_('Scope'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</label>
<select class="form-select" id="testScopeType">
<option value="general_roman_calendar">
<?php echo htmlspecialchars(_('General Roman Calendar'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</option>
<option value="national_calendar">
<?php echo htmlspecialchars(_('National Calendar'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</option>
<option value="diocesan_calendar">
<?php echo htmlspecialchars(_('Diocesan Calendar'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</option>
</select>
<!-- Static scope display for users whose scope is fixed (single-scope
editor/admin, or when editing an existing test). -->
<div id="testScopeStatic" class="form-text fw-semibold d-none"></div>
<div id="testScopeIdMount" class="mt-2"></div>
</div>
<div class="col-md-6">
<label class="form-label" for="testEventKey">
<?php echo htmlspecialchars(_('Liturgical event'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</label>
<input type="text" class="form-control" id="testEventKey"
list="testEventKeyList" required />
<datalist id="testEventKeyList"></datalist>
<!-- Derived, read-only test name (name = event_key + 'Test'). -->
<small id="derivedTestName" class="form-text text-muted"></small>
</div>
<div class="col-md-4">
<label class="form-label" for="baseDate">
<?php echo htmlspecialchars(_('Base date'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</label>
<input type="date" class="form-control" id="baseDate"
min="1970-01-01" max="2050-12-31" />
</div>
</div>
<!-- Step 2: test type -->
<div class="mb-3 mt-3">
<label class="form-label fw-bold">
<?php echo htmlspecialchars(_('Test type'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</label>
<div class="btn-group d-flex flex-wrap" role="group" id="testTypeGroup">
<input type="radio" class="btn-check" name="testType" id="tt-exact"
value="exactCorrespondence" autocomplete="off">
<label class="btn btn-outline-primary" for="tt-exact">
<i class="fas fa-vial me-1"></i><?php echo htmlspecialchars(_('Exact date'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</label>
<input type="radio" class="btn-check" name="testType" id="tt-since"
value="exactCorrespondenceSince" autocomplete="off">
<label class="btn btn-outline-primary" for="tt-since">
<i class="fas fa-right-from-bracket me-1"></i><?php echo htmlspecialchars(_('Exact since year'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</label>
<input type="radio" class="btn-check" name="testType" id="tt-until"
value="exactCorrespondenceUntil" autocomplete="off">
<label class="btn btn-outline-primary" for="tt-until">
<i class="fas fa-right-to-bracket me-1"></i><?php echo htmlspecialchars(_('Exact until year'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</label>
</div>
</div>
<!-- Step 3: description -->
<div class="mb-3">
<label class="form-label" for="testDescription">
<?php echo htmlspecialchars(_('Description'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</label>
<textarea class="form-control" id="testDescription" rows="2" required></textarea>
</div>
<!-- Step 4: year range -->
<div class="mt-3">
<label class="form-label fw-bold">
<?php echo htmlspecialchars(_('Year range'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</label>
<div class="range-slider flat" id="yearsRangeSlider"
style="--min:1970; --max:2050; --value-a:1999; --value-b:2030; --text-value-a:'1999'; --text-value-b:'2030';">
<input type="range" id="lowerRange" min="1970" max="2050" value="1999" />
<output></output>
<input type="range" id="upperRange" min="1970" max="2050" value="2030" />
<output></output>
<div class="range-slider__progress"></div>
</div>
<div class="year-grid mt-2" id="yearGrid"></div>
<div class="d-flex flex-wrap align-items-center gap-3 small text-muted mt-2" id="yearGridLegend">
<span><span class="legend-chip me-1"></span><?php
/* translators: year-grid legend: the test asserts the liturgical event DOES occur in that year */
echo htmlspecialchars(_('event expected'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
?></span>
<span><span class="legend-chip sunday me-1"></span><?php echo htmlspecialchars(_('falls on a Sunday'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?></span>
<span><span class="legend-chip bg-info me-1"></span><?php
/* translators: the boundary year of an accuracy test: for a "since" test the first year the event is
expected to exist, for an "until" test the last. Years beyond it are asserted NOT to
occur. A domain term - not a hinge, turning point or midpoint. Use ONE term for it
throughout */
echo htmlspecialchars(_('pivot year'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
?></span>
<span><span class="legend-chip bg-warning me-1"></span><?php
/* translators: year-grid legend: the test asserts the liturgical event does NOT occur in that year */
echo htmlspecialchars(_('event not expected'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
?></span>
<span><span class="legend-chip deleted me-1"></span><?php
/* translators: year-grid legend for years left out of the test. "click" is the mouse action - it
needs translating too */
echo htmlspecialchars(_('excluded — click to restore'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
?></span>
</div>
</div>
<!-- Step 5: per-year assertions -->
<div class="mt-3">
<label class="form-label fw-bold">
<?php echo htmlspecialchars(_('Per-year assertions'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</label>
<div id="assertionsContainer"></div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
<?php echo htmlspecialchars(_('Cancel'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</button>
<button type="button" class="btn btn-primary" id="saveTestBtn" data-requires-auth>
<?php echo htmlspecialchars(_('Save'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</button>
</div>
</div>
</div>
</div>
<!-- Comment modal -->
<div class="modal fade" id="testCommentModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
<?php echo htmlspecialchars(_('Assertion comment'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="<?php echo htmlspecialchars(_('Close'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>"></button>
</div>
<div class="modal-body">
<input type="hidden" id="commentYear" />
<textarea class="form-control" id="commentText" rows="3"></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
<?php echo htmlspecialchars(_('Cancel'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</button>
<button type="button" class="btn btn-primary" id="saveCommentBtn">
<?php echo htmlspecialchars(_('Save comment'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</button>
</div>
</div>
</div>
</div>
<!-- Delete modal -->
<div class="modal fade" id="deleteTestModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
<?php echo htmlspecialchars(_('Delete Test'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="<?php echo htmlspecialchars(_('Close'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>"></button>
</div>
<div class="modal-body">
<div id="deleteTestAlerts"></div>
<p id="deleteTestConfirmText"></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
<?php echo htmlspecialchars(_('Cancel'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</button>
<button type="button" class="btn btn-danger" id="confirmDeleteTestBtn" data-requires-auth>
<?php echo htmlspecialchars(_('Delete'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</button>
</div>
</div>
</div>
</div>
<!-- Config for JavaScript -->
<script>
window.AdminTestsConfig = {
apiUrl: <?php echo json_encode($apiBaseUrl); ?>,
isGlobalAdmin: <?php echo json_encode($isGlobalAdmin); ?>,
hasTestEditor: <?php echo json_encode($hasTestEditor); ?>,
<?php // BCP-47 (en-US), not gettext/ICU (en_US): Intl.DateTimeFormat rejects underscore tags. ?>
locale: <?php echo json_encode(str_replace('_', '-', $i18n->LOCALE)); ?>,
i18n: {
loading: <?php echo json_encode(_('Loading...')); ?>,
noTests: <?php echo json_encode(_('No tests found.')); ?>,
failedToLoad: <?php echo json_encode(_('Failed to load tests. Please try again later.')); ?>,
createSuccess: <?php echo json_encode(_('Test created successfully.')); ?>,
updateSuccess: <?php echo json_encode(_('Test updated successfully.')); ?>,
deleteSuccess: <?php echo json_encode(_('Test deleted successfully.')); ?>,
<?php // A write may be recorded as a change request awaiting review instead of
// being applied; the API says which in the response `disposition` field.
// Shared with includes/messages.php — same msgids, one translation each. ?>
writeSubmitted: <?php echo json_encode(_('Your changes were submitted for review as batch %s. Nothing has been saved yet.')); ?>,
writeApproved: <?php echo json_encode(_('Your changes were approved as batch %s and are queued for publication. They are not live yet.')); ?>,
writeSuperseded: <?php echo json_encode(_('Earlier pending submissions were folded into this one and no longer appear in your queue: %s')); ?>,
writeUnknown: <?php echo json_encode(_('The server reported an unrecognized outcome (\'%s\') for these changes. Reload the page to check whether they were saved.')); ?>,
saving: <?php echo json_encode(_('Saving...')); ?>,
deleting: <?php echo json_encode(_('Deleting...')); ?>,
edit: <?php echo json_encode(_('Edit')); ?>,
delete: <?php echo json_encode(_('Delete')); ?>,
confirmDelete: <?php echo json_encode(_('Are you sure you want to delete the test "%s"?')); ?>,
generalRomanCalendar: <?php echo json_encode(_('General Roman Calendar')); ?>,
nationalCalendar: <?php echo json_encode(_('National Calendar')); ?>,
diocesanCalendar: <?php echo json_encode(_('Diocesan Calendar')); ?>,
requiredFields: <?php echo json_encode(_('Please fill in all required fields.')); ?>,
denied403: <?php echo json_encode(_('You do not have permission to perform this action.')); ?>,
conflict409: <?php echo json_encode(_('A test with that name already exists.')); ?>,
setYear: <?php
/* translators: action label for the same boundary year; use the same term as the "pivot year" legend chip */
echo json_encode(_('set pivot year'));
?>,
toggleAssertion: <?php
/* translators: an assertion is one expected-result check for a single year of the test */
echo json_encode(_('toggle assertion'));
?>,
removeYear: <?php echo json_encode(_('remove')); ?>,
sundayInYear: <?php
/* translators: %1$s is a year, %2$s is the name of a liturgical event. Keep both placeholders and their order */
echo json_encode(_('In the year %1$s, %2$s falls on a Sunday'));
?>,
excludedRestore: <?php
/* translators: %s is a year, e.g. 2015. "click" is the mouse action - it needs translating too */
echo json_encode(_('%s excluded — click to restore'));
?>,
testNameLabel: <?php echo json_encode(_('Test name:')); ?>,
invalidName: <?php echo json_encode(_('Select a valid liturgical event from the list.')); ?>
}
};
</script>
<?php include_once('./layout/footer.php'); ?>
</body>
</html>