-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhstp_fsp.html
More file actions
450 lines (376 loc) · 16.3 KB
/
hstp_fsp.html
File metadata and controls
450 lines (376 loc) · 16.3 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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>HSTP → FSP Export</title>
<style>
body { margin:0; font-family: Arial, sans-serif; background:#fafafa; }
.app { display:flex; min-height:100vh; }
.sidebar { width:360px; background:#111827; color:#fff; padding:20px 18px; box-sizing:border-box; position:sticky; top:0; height:100vh; }
.sidebar h1 { font-size:16px; margin:0 0 8px 0; }
.sidebar .sub { color:#cbd5e1; font-size:13px; line-height:1.5; }
.box { background: rgba(255,255,255,0.06); border:1px solid rgba(255,255,255,0.12); border-radius:12px; padding:12px; margin:12px 0; }
.box h3 { margin:0 0 8px 0; font-size:13px; color:#e5e7eb; text-transform:uppercase; letter-spacing:0.5px; }
.sidebar ul { margin:0; padding-left:18px; color:#e5e7eb; font-size:13px; }
.sidebar li { margin:6px 0; }
.small { font-size:12px; color:#9ca3af; margin-top:10px; }
.main { flex:1; padding:26px; box-sizing:border-box; }
.card { background:#fff; border:1px solid #e5e7eb; border-radius:14px; padding:16px; margin-bottom:14px; box-shadow:0 1px 2px rgba(0,0,0,0.04); }
.row { display:flex; gap:14px; flex-wrap:wrap; align-items:end; }
label { font-size:13px; color:#111827; font-weight:bold; }
input[type="text"], input[type="password"], input[type="number"], select {
padding:8px 10px; border:1px solid #d1d5db; border-radius:10px; outline:none; min-height:36px; background:#fff;
}
button { padding:9px 12px; border-radius:10px; border:1px solid #d1d5db; background:#111827; color:#fff; cursor:pointer; }
button.secondary { background:#fff; color:#111827; }
button.danger { background:#fff; color:#b91c1c; border:1px solid #fecaca; }
.msg { margin-top:10px; color:#374151; font-size:13px; white-space: pre-wrap; }
table { width:100%; border-collapse:collapse; }
thead th { background:#f3f4f6; border-bottom:1px solid #e5e7eb; padding:10px; text-align:left; font-size:13px; }
tbody td { border-bottom:1px solid #eef2f7; padding:10px; vertical-align:top; }
</style>
</head>
<body>
<div class="app">
<aside class="sidebar">
<h1>HSTP → FSP export</h1>
<div class="sub">Upload ZIP (contains Excel), build CSV mapping (supports constants), then download an AES passworded ZIP.</div>
<div class="box">
<h3>Steps</h3>
<ul>
<li>Upload ZIP</li>
<li>Load Excel list</li>
<li>Select Excel + load headers</li>
<li>Map output columns</li>
<li>Set output name + password</li>
<li>Generate ZIP</li>
</ul>
</div>
<div class="small">
<button class="secondary" onclick="window.location.href='index.html'">← Back</button>
</div>
</aside>
<main class="main">
<div class="card">
<div class="row">
<div style="min-width:320px;">
<label>Upload ZIP (contains Excel)</label><br/>
<input type="file" id="zipfile" accept=".zip"/>
</div>
<div>
<label>Header row</label><br/>
<input type="number" id="headerRow" value="2" min="1" style="width:120px;"/>
</div>
<div>
<button id="btnLoadZip">Load Excel list</button>
</div>
<div style="min-width:280px;">
<label>Excel inside ZIP</label><br/>
<select id="excelSelect" style="width:280px;"></select>
</div>
<div>
<button id="btnLoadHeaders">Load headers</button>
</div>
</div>
<div id="msg" class="msg"></div>
</div>
<div class="card">
<div class="row">
<div>
<label>FSP</label><br/>
<select id="fsp" style="width:220px;">
<option value="">(Select FSP)</option>
<option value="EquityBank">Equity Bank</option>
<option value="MTN">MTN</option>
<option value="Zain">Zain</option>
<option value="Other">Other</option>
</select>
</div>
<div>
<label>Output base name</label><br/>
<input type="text" id="outputName" placeholder="e.g. HSTP_Dec_2025" style="width:260px;"/>
</div>
<div>
<label>ZIP password</label><br/>
<input type="password" id="zipPassword" placeholder="Min 4 characters" style="width:260px;"/>
</div>
<div style="margin-left:auto; display:flex; gap:10px;">
<button class="secondary" id="btnAddRow">+ Add output column</button>
<button id="btnGenerate">Generate ZIP</button>
</div>
</div>
</div>
<div class="card">
<h3 style="margin:0 0 8px 0;">Output mapping</h3>
<div style="color:#6b7280; font-size:13px; margin-bottom: 10px;">
Rules: copy / conditional_copy / constant
</div>
<div style="overflow:auto; border:1px solid #e5e7eb; border-radius:12px;">
<table>
<thead>
<tr>
<th style="min-width:220px;">Target</th>
<th style="min-width:160px;">Rule</th>
<th style="min-width:220px;">Source</th>
<th style="min-width:220px;">Condition column</th>
<th style="min-width:260px;">Equals any of</th>
<th style="min-width:220px;">Constant value</th>
<th style="width:80px; text-align:center;">Remove</th>
</tr>
</thead>
<tbody id="mapBody"></tbody>
</table>
</div>
</div>
</main>
</div>
<script>
const API = (window.location.port === "8000") ? window.location.origin : "http://127.0.0.1:8000";
const msg = document.getElementById("msg");
const zipInput = document.getElementById("zipfile");
const headerRowInput = document.getElementById("headerRow");
const excelSelect = document.getElementById("excelSelect");
const btnLoadZip = document.getElementById("btnLoadZip");
const btnLoadHeaders = document.getElementById("btnLoadHeaders");
const fspSel = document.getElementById("fsp");
const outputName = document.getElementById("outputName");
const zipPassword = document.getElementById("zipPassword");
const btnAddRow = document.getElementById("btnAddRow");
const btnGenerate = document.getElementById("btnGenerate");
const mapBody = document.getElementById("mapBody");
let headers = [];
function clearExcelSelect() {
excelSelect.innerHTML = "";
const opt = document.createElement("option");
opt.value = "";
opt.textContent = "(Load ZIP first)";
excelSelect.appendChild(opt);
}
clearExcelSelect();
function makeSelect(options, placeholder) {
const sel = document.createElement("select");
const opt0 = document.createElement("option");
opt0.value = "";
opt0.textContent = placeholder || "(select)";
sel.appendChild(opt0);
options.forEach(o => {
const opt = document.createElement("option");
opt.value = o;
opt.textContent = o;
sel.appendChild(opt);
});
sel.style.width = "100%";
return sel;
}
function addRow() {
const tr = document.createElement("tr");
const tdTarget = document.createElement("td");
const target = document.createElement("input");
target.type = "text";
target.placeholder = "e.g. phone_number";
target.style.width = "100%";
tdTarget.appendChild(target);
const tdRule = document.createElement("td");
const rule = document.createElement("select");
rule.innerHTML = `
<option value="copy">copy</option>
<option value="conditional_copy">conditional_copy</option>
<option value="constant">constant</option>
`;
rule.style.width = "100%";
tdRule.appendChild(rule);
const tdSource = document.createElement("td");
const source = makeSelect(headers, "(choose source)");
tdSource.appendChild(source);
const tdCondCol = document.createElement("td");
const condCol = makeSelect(headers, "(choose condition col)");
tdCondCol.appendChild(condCol);
const tdCondVals = document.createElement("td");
const condVals = document.createElement("input");
condVals.type = "text";
condVals.placeholder = "e.g. SUCCESSFUL, PAID";
condVals.style.width = "100%";
tdCondVals.appendChild(condVals);
const tdConst = document.createElement("td");
const constVal = document.createElement("input");
constVal.type = "text";
constVal.placeholder = "value for constant columns";
constVal.style.width = "100%";
tdConst.appendChild(constVal);
const tdRemove = document.createElement("td");
tdRemove.style.textAlign = "center";
const rm = document.createElement("button");
rm.textContent = "X";
rm.className = "danger";
rm.onclick = () => tr.remove();
tdRemove.appendChild(rm);
[tdTarget, tdRule, tdSource, tdCondCol, tdCondVals, tdConst, tdRemove].forEach(td => td.style.padding = "10px");
function toggleUI() {
const t = rule.value;
const isCopy = t === "copy";
const isCond = t === "conditional_copy";
const isConst = t === "constant";
source.disabled = !(isCopy || isCond);
condCol.disabled = !isCond;
condVals.disabled = !isCond;
constVal.disabled = !isConst;
source.style.opacity = (isCopy || isCond) ? "1" : "0.5";
condCol.style.opacity = isCond ? "1" : "0.5";
condVals.style.opacity = isCond ? "1" : "0.5";
constVal.style.opacity = isConst ? "1" : "0.5";
}
rule.onchange = toggleUI;
toggleUI();
tr.appendChild(tdTarget);
tr.appendChild(tdRule);
tr.appendChild(tdSource);
tr.appendChild(tdCondCol);
tr.appendChild(tdCondVals);
tr.appendChild(tdConst);
tr.appendChild(tdRemove);
mapBody.appendChild(tr);
}
function refreshSelects() {
const rows = Array.from(mapBody.querySelectorAll("tr"));
rows.forEach(r => {
const selects = r.querySelectorAll("select");
const ruleSel = selects[0];
const sourceOld = selects[1];
const condOld = selects[2];
const oldSourceVal = sourceOld.value;
const oldCondVal = condOld.value;
const newSource = makeSelect(headers, "(choose source)");
newSource.value = headers.includes(oldSourceVal) ? oldSourceVal : "";
const newCond = makeSelect(headers, "(choose condition col)");
newCond.value = headers.includes(oldCondVal) ? oldCondVal : "";
sourceOld.replaceWith(newSource);
condOld.replaceWith(newCond);
const inputs = r.querySelectorAll("input");
const condVals = inputs[1];
const constVal = inputs[2];
function toggleUI() {
const t = ruleSel.value;
const isCopy = t === "copy";
const isCond = t === "conditional_copy";
const isConst = t === "constant";
newSource.disabled = !(isCopy || isCond);
newCond.disabled = !isCond;
condVals.disabled = !isCond;
constVal.disabled = !isConst;
newSource.style.opacity = (isCopy || isCond) ? "1" : "0.5";
newCond.style.opacity = isCond ? "1" : "0.5";
condVals.style.opacity = isCond ? "1" : "0.5";
constVal.style.opacity = isConst ? "1" : "0.5";
}
ruleSel.onchange = toggleUI;
toggleUI();
});
}
btnAddRow.onclick = () => addRow();
btnLoadZip.onclick = async () => {
if (!zipInput.files.length) { msg.textContent = "Select a ZIP file first."; return; }
msg.textContent = "Inspecting ZIP...";
try {
const form = new FormData();
form.append("zipfile_upload", zipInput.files[0]);
form.append("header_row", headerRowInput.value || "2");
form.append("excel_name", "");
const res = await fetch(`${API}/hstp/inspect`, { method:"POST", body: form });
const data = await res.json();
if (!res.ok) { msg.textContent = data.detail || "Failed to inspect ZIP."; return; }
excelSelect.innerHTML = "";
(data.excel_files || []).forEach(name => {
const opt = document.createElement("option");
opt.value = name;
opt.textContent = name;
excelSelect.appendChild(opt);
});
msg.textContent = "ZIP loaded. Select an Excel file and click 'Load headers'.";
} catch (e) {
console.error(e);
msg.textContent = "Request failed: " + (e?.message || e);
}
};
btnLoadHeaders.onclick = async () => {
if (!zipInput.files.length) { msg.textContent = "Select a ZIP file first."; return; }
if (!excelSelect.value) { msg.textContent = "Select an Excel file inside the ZIP."; return; }
msg.textContent = "Loading headers...";
try {
const form = new FormData();
form.append("zipfile_upload", zipInput.files[0]);
form.append("header_row", headerRowInput.value || "2");
form.append("excel_name", excelSelect.value);
const res = await fetch(`${API}/hstp/inspect`, { method:"POST", body: form });
const data = await res.json();
if (!res.ok) { msg.textContent = data.detail || "Failed to load headers."; return; }
headers = data.columns || [];
msg.textContent = `Loaded ${headers.length} headers.`;
refreshSelects();
if (mapBody.querySelectorAll("tr").length === 0) addRow();
} catch (e) {
console.error(e);
msg.textContent = "Request failed: " + (e?.message || e);
}
};
btnGenerate.onclick = async () => {
if (!zipInput.files.length) { msg.textContent = "Select a ZIP file first."; return; }
if (!excelSelect.value) { msg.textContent = "Select an Excel file inside the ZIP."; return; }
if (!zipPassword.value || zipPassword.value.trim().length < 4) { msg.textContent = "Enter ZIP password (min 4 chars)."; return; }
msg.textContent = "Generating password-protected ZIP...";
try {
const rows = Array.from(mapBody.querySelectorAll("tr"));
const output_columns = [];
rows.forEach(r => {
const inputs = r.querySelectorAll("input");
const selects = r.querySelectorAll("select");
const target = (inputs[0].value || "").trim();
const ruleType = selects[0].value;
const source = (selects[1].value || "").trim();
const condCol = (selects[2].value || "").trim();
const condValsRaw = (inputs[1].value || "").trim();
const constVal = (inputs[2].value || "");
if (!target) return;
if (ruleType === "constant") {
output_columns.push({ target, type: "constant", value: constVal });
} else if (ruleType === "copy") {
output_columns.push({ target, type: "copy", source });
} else {
const equals_any = condValsRaw.split(",").map(x => x.trim()).filter(x => x.length > 0);
output_columns.push({ target, type: "conditional_copy", source, condition: { column: condCol, equals_any } });
}
});
const mapping_config = JSON.stringify({ output_columns });
const form = new FormData();
form.append("zipfile_upload", zipInput.files[0]);
form.append("excel_name", excelSelect.value);
form.append("header_row", headerRowInput.value || "2");
form.append("fsp", fspSel.value || "");
form.append("output_name", outputName.value || "hstp_export");
form.append("zip_password", zipPassword.value);
form.append("mapping_config", mapping_config);
const res = await fetch(`${API}/hstp/generate`, { method:"POST", body: form });
const ct = res.headers.get("content-type") || "";
if (ct.includes("application/json")) {
const data = await res.json();
msg.textContent = data.detail || "Generate failed.";
return;
}
if (!res.ok) { msg.textContent = "Generate failed."; return; }
const blob = await res.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = (outputName.value || "hstp_export") + ".zip";
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(url);
msg.textContent = "Done. Download started.";
} catch (e) {
console.error(e);
msg.textContent = "Request failed: " + (e?.message || e);
}
};
</script>
</body>
</html>