Skip to content

Commit 615eaac

Browse files
no error logs so far
1 parent 7b2bd43 commit 615eaac

1 file changed

Lines changed: 102 additions & 1 deletion

File tree

src/export/xapi.ts

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,111 @@ export async function exporter(
130130
debug: argument['xapi-debug'] || false,
131131
}
132132

133+
// Add config UI if endpoint wasn't provided
134+
if (!argument['xapi-endpoint']) {
135+
index = helper.inject(
136+
`<script>
137+
// Store xAPI config in localStorage
138+
function saveXAPIConfig() {
139+
const endpoint = document.getElementById('xapi-endpoint').value;
140+
const auth = document.getElementById('xapi-auth').value;
141+
const actor = document.getElementById('xapi-actor').value;
142+
143+
try {
144+
// Validate actor as JSON
145+
JSON.parse(actor);
146+
147+
// Save to localStorage
148+
localStorage.setItem('xapi-config', JSON.stringify({
149+
endpoint,
150+
auth,
151+
actor: JSON.parse(actor)
152+
}));
153+
154+
// Reload to apply settings
155+
window.location.reload();
156+
} catch (e) {
157+
alert('Invalid Actor JSON format. Please check your input.');
158+
}
159+
}
160+
161+
// Load xAPI config from localStorage on page load
162+
document.addEventListener('DOMContentLoaded', function() {
163+
const storedConfig = localStorage.getItem('xapi-config');
164+
if (storedConfig) {
165+
const config = JSON.parse(storedConfig);
166+
window.xAPIConfig = config;
167+
}
168+
169+
// Show/hide config panel
170+
const configPanel = document.getElementById('xapi-config-panel');
171+
if (configPanel) {
172+
document.getElementById('toggle-xapi-config').addEventListener('click', function() {
173+
configPanel.style.display = configPanel.style.display === 'none' ? 'block' : 'none';
174+
});
175+
176+
// Populate fields if stored config exists
177+
if (storedConfig) {
178+
const config = JSON.parse(storedConfig);
179+
document.getElementById('xapi-endpoint').value = config.endpoint || '';
180+
document.getElementById('xapi-auth').value = config.auth || '';
181+
document.getElementById('xapi-actor').value = JSON.stringify(config.actor || {}, null, 2);
182+
}
183+
}
184+
});
185+
</script>
186+
<style>
187+
#xapi-config-panel {
188+
position: fixed;
189+
top: 0;
190+
right: 0;
191+
width: 400px;
192+
background: white;
193+
border: 1px solid #ccc;
194+
padding: 15px;
195+
box-shadow: 0 0 10px rgba(0,0,0,0.2);
196+
z-index: 9999;
197+
display: none;
198+
}
199+
#toggle-xapi-config {
200+
position: fixed;
201+
top: 10px;
202+
right: 10px;
203+
z-index: 9998;
204+
background: #f5f5f5;
205+
border: 1px solid #ccc;
206+
padding: 5px 10px;
207+
cursor: pointer;
208+
}
209+
</style>
210+
<div id="toggle-xapi-config">xAPI Settings</div>
211+
<div id="xapi-config-panel">
212+
<h3>xAPI LRS Configuration</h3>
213+
<div>
214+
<label for="xapi-endpoint">LRS Endpoint URL</label><br>
215+
<input type="text" id="xapi-endpoint" style="width: 100%" placeholder="https://your-lrs.com/data/xAPI/" value="">
216+
</div>
217+
<div style="margin-top: 10px">
218+
<label for="xapi-auth">Authentication (e.g., Basic dXNlcm5hbWU6cGFzc3dvcmQ=)</label><br>
219+
<input type="text" id="xapi-auth" style="width: 100%" placeholder="Basic dXNlcm5hbWU6cGFzc3dvcmQ=" value="">
220+
</div>
221+
<div style="margin-top: 10px">
222+
<label for="xapi-actor">Actor (JSON format)</label><br>
223+
<textarea id="xapi-actor" style="width: 100%; height: 100px">{"objectType":"Agent","name":"Anonymous","mbox":"mailto:anonymous@example.com"}</textarea>
224+
</div>
225+
<div style="margin-top: 10px">
226+
<button onclick="saveXAPIConfig()">Save Configuration</button>
227+
</div>
228+
</div>`,
229+
index
230+
)
231+
}
232+
233+
// Set the window.xAPIConfig object with the base configuration
133234
index = helper.inject(
134235
`<script>
135236
window.xAPIConfig = ${JSON.stringify(xapiConfig, null, 2)};
136-
</script>`,
237+
</script>`,
137238
index
138239
)
139240

0 commit comments

Comments
 (0)