generated from NHSDigital/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
362 lines (313 loc) · 10.1 KB
/
index.html
File metadata and controls
362 lines (313 loc) · 10.1 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Campaign Config Validator - NHS Digital</title>
<script src="https://cdn.jsdelivr.net/pyodide/v0.26.4/full/pyodide.js"></script>
<style>
body {
margin: 0;
font-family: "Frutiger W01", Arial, sans-serif; /* NHS standard font stack */
background-color: #f0f4f5; /* NHS Light Grey */
color: #212b32; /* NHS Black */
display: flex;
flex-direction: column;
min-height: 100vh;
}
.nhs-header {
background-color: #005eb8; /* NHS Blue */
padding: 12px 16px;
border-bottom: 4px solid white; /* NHS Standard header spacing */
}
.nhs-header-content {
max-width: 960px;
margin: 0 auto;
display: flex;
align-items: center;
}
.nhs-logo {
width: 80px;
height: 32px;
}
.nhs-container {
max-width: 960px;
margin: 2rem auto;
padding: 0 16px;
width: 100%;
box-sizing: border-box;
flex: 1;
}
h1 {
font-size: 2.5rem;
font-weight: 700;
margin-bottom: 1.5rem;
}
.nhs-card {
background: white;
border: 1px solid #d8dde0;
padding: 2rem;
margin-bottom: 2rem;
}
.status-bar {
background: #e8edee;
color: #212b32;
padding: 12px;
border-left: 10px solid #005eb8;
margin-bottom: 24px;
font-weight: 600;
display: flex;
justify-content: space-between;
align-items: center;
}
.nhs-button {
background-color: #007f3b; /* NHS Green */
color: white;
font-size: 19px;
line-height: 19px;
font-weight: 600;
padding: 12px 24px;
border: none;
cursor: pointer;
box-shadow: 0 4px 0 #00401e; /* The distinct NHS button shadow */
margin-top: 1rem;
width: 100%;
text-align: center;
text-decoration: none;
display: inline-block;
}
.nhs-button:hover:not(:disabled) {
background-color: #00642e; /* Darker Green hover */
}
.nhs-button:active:not(:disabled) {
transform: translateY(4px); /* Button press effect */
box-shadow: none;
}
.nhs-button:disabled {
background-color: #d8dde0;
color: #768692;
box-shadow: none;
cursor: not-allowed;
}
label {
display: block;
margin-bottom: 8px;
font-weight: 600;
font-size: 1.1rem;
}
input[type="file"] {
font-size: 1.1rem;
padding: 10px;
background: #f0f4f5;
border: 2px solid #212b32;
width: 100%;
box-sizing: border-box;
cursor: pointer;
}
.log {
background: #212b32;
color: white;
font-family: monospace;
padding: 20px;
min-height: 250px;
white-space: pre-wrap;
margin-top: 30px;
font-size: 0.95rem;
border-left: 10px solid #768692;
}
.ansi-green {
color: #007f3b;
font-weight: bold;
background: #ccffdd;
padding: 2px 5px;
}
.ansi-red {
color: #d81e05;
font-weight: bold;
background: #ffd1d1;
padding: 2px 5px;
}
.ansi-yellow {
color: #ffb81c;
font-weight: bold;
}
footer {
background: #d8dde0;
padding: 2rem 0;
margin-top: auto;
font-size: 0.9rem;
text-align: center;
}
</style>
</head>
<body>
<header class="nhs-header">
<div class="nhs-header-content">
<svg class="nhs-logo" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 16" aria-hidden="true">
<path fill="#fff" d="M0 0h40v16H0z"></path>
<path fill="#005eb8"
d="M3.9 1.5h4.4l2.6 9h.1l1.8-9h3.3l-2.8 13H9l-2.7-9h-.1l-1.8 9H1.1M17.3 1.5h3.6l-1 4.9h4L25 1.5h3.5l-2.7 13h-3.5l1.1-5.6h-4.1l-1.2 5.6h-3.4M37.7 4.4c-.7-.3-1.6-.6-2.9-.6-1.4 0-2.5.2-2.5 1.3 0 1.8 5.1 1.2 5.1 5.1 0 3.6-3.3 4.5-6.4 4.5-1.3 0-2.9-.3-4-.7l.8-2.7c.7.4 2.1.7 3.2.7 1.3 0 2.3-.2 2.3-1.4 0-2-5.1-1.2-5.1-5.1 0-4 3.7-4.5 6.4-4.5 1.2 0 2.7.3 3.5.6"></path>
</svg>
</div>
</header>
<div class="nhs-container">
<h1>Campaign Config Validator</h1>
<div class="status-bar">
<span id="statusText">⏳ Booting Python Environment...</span>
<span id="versionInfo" style="font-size: 0.8em; opacity: 0.7"></span>
</div>
<div class="nhs-card">
<label for="jsonfile">Upload Configuration File (JSON)</label>
<span style="display:block; margin-bottom:10px; color:#4c6272; font-size:0.9rem;">Select the campaign configuration file you wish to validate against the rules API.</span>
<input type="file" id="jsonfile" accept=".json" disabled/>
<button id="run" class="nhs-button" disabled>
Run Validation
</button>
</div>
<h3>Validation Output</h3>
<div id="result" class="log">System initializing...
</div>
</div>
<div class="nhs-card" style="margin-top:2rem;">
<h3>Visualiser Output</h3>
<iframe
id="visualiserFrame"
src="https://elidvisualiser.hadfieldjohn.com/index.html"
style="width:100%; height:600px; border:1px solid #d8dde0;"
title="ELiD Visualiser"
></iframe>
</div>
<footer>
<div class="nhs-header-content" style="justify-content: center;">
© NHS England. Intended for internal use only.
</div>
</footer>
<script>
let pyodide;
const output = document.getElementById("result");
const statusText = document.getElementById("statusText");
const jsonInput = document.getElementById("jsonfile");
const runBtn = document.getElementById("run");
function log(text) {
let cleanText = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
// ANSI color replacements
cleanText = cleanText
.replace(/\x1b\[92m/g, '<span class="ansi-grey">') // validator/method green
.replace(/\x1b\[93m/g, '<span class="ansi-yellow">') // general yellow
.replace(/\x1b\[34m/g, '<span style="color:#005eb8;font-weight:bold">') // blue
.replace(/\x1b\[33m/g, '<span class="ansi-yellow">') // colon yellow
.replace(/\x1b\[0m/g, '</span>'); // reset
if (cleanText.includes("Valid Config")) {
cleanText = cleanText.replace(/Valid Config/g, '<span style="font-size:2em;font-weight:bold;color:#007f3b">Valid Config</span>');
}
output.innerHTML += cleanText + "\n";
output.scrollTop = output.scrollHeight;
}
function clearLog() {
output.innerHTML = "";
} // Changed to innerHTML for spans
function setStatus(msg, ready = false) {
statusText.innerHTML = ready ? `✅ ${msg}` : `⏳ ${msg}`;
if (ready) {
jsonInput.disabled = false;
statusText.style.borderLeftColor = "#007f3b"; // Switch the status bar to green
}
}
const filesToFetch = [
"src/rules_validation_api/app.py",
"src/eligibility_signposting_api/__init__.py",
"src/eligibility_signposting_api/model/__init__.py",
"src/eligibility_signposting_api/model/campaign_config.py",
"src/eligibility_signposting_api/config/__init__.py",
"src/eligibility_signposting_api/config/constants.py",
"src/eligibility_signposting_api/common/__init__.py",
"src/eligibility_signposting_api/common/date_util.py",
"src/rules_validation_api/decorators/__init__.py",
"src/rules_validation_api/decorators/tracker.py",
"src/rules_validation_api/__init__.py",
"src/rules_validation_api/validators/__init__.py",
"src/rules_validation_api/validators/rules_validator.py",
"src/rules_validation_api/validators/campaign_config_validator.py",
"src/rules_validation_api/validators/actions_mapper_validator.py",
"src/rules_validation_api/validators/available_action_validator.py",
"src/rules_validation_api/validators/iteration_cohort_validator.py",
"src/rules_validation_api/validators/iteration_rules_validator.py",
"src/rules_validation_api/validators/iteration_validator.py"
];
async function main() {
try {
pyodide = await loadPyodide();
pyodide.setStdout({batched: (msg) => log(msg)});
pyodide.setStderr({batched: (msg) => log("ERR: " + msg)});
setStatus("Installing Python Libraries...");
await pyodide.loadPackage("micropip");
await pyodide.loadPackage("tzdata");
await pyodide.pyimport("micropip").install("pydantic");
await pyodide.pyimport("micropip").install("markdown");
setStatus("Downloading Source Code...");
for (const path of filesToFetch) {
const response = await fetch(path);
if (!response.ok) throw new Error(`404 Not Found: ${path}`);
const content = await response.text();
const dir = path.substring(0, path.lastIndexOf('/'));
if (dir) {
const parts = dir.split('/');
let current = "";
for (const part of parts) {
current += part + "/";
if (!pyodide.FS.analyzePath(current.slice(0, -1)).exists) {
pyodide.FS.mkdir(current.slice(0, -1));
}
}
}
pyodide.FS.writeFile(path, content);
}
setStatus("System Ready", true);
log("✅ Environment loaded. Please upload a JSON file.");
} catch (err) {
setStatus("Error", false);
statusText.style.color = "#d81e05";
log(`❌ FATAL ERROR: ${err.message}`);
}
}
main();
let configContent = null;
jsonInput.addEventListener("change", (e) => {
const reader = new FileReader();
reader.onload = () => {
configContent = reader.result;
runBtn.disabled = false;
log(`\n📄 Loaded: ${e.target.files[0].name}`);
};
reader.readAsText(e.target.files[0]);
});
runBtn.addEventListener("click", async () => {
clearLog();
log("🚀 Validating Configuration...\n");
try {
JSON.parse(configContent);
} catch (err) {
log("❌ JSON Error: " + err.message);
return;
}
pyodide.globals.set("raw_json", configContent);
try {
await pyodide.runPythonAsync(`
import sys
import json
import importlib
import os
if "src" not in sys.path: sys.path.insert(0, "src")
from rules_validation_api import app
importlib.reload(app)
with open("config.json", "w") as f:
f.write(raw_json)
sys.argv = ["app.py", "--config_path", "config.json"]
app.main()
`);
} catch (e) {
log(`\n❌ EXECUTION ERROR:\n${e}`);
}
});
</script>
</body>
</html>