Skip to content

Commit

Permalink
refine import a little
Browse files Browse the repository at this point in the history
  • Loading branch information
TomWoodward committed May 17, 2024
1 parent 0fa1198 commit 0402557
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 33 deletions.
11 changes: 7 additions & 4 deletions src/helpers/ItemFactory.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 13 additions & 10 deletions src/helpers/TestFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -1576,24 +1576,27 @@ export class TestFactory {
return this.tests.find(test => test.id === id)
}

pushTest (title, description, items) {
const id = Math.random().toString(16).slice(2);
pushTest (title, description, submissionMode, items) {
const id = Math.random().toString(16).slice(2)

this.tests.push({
const test = {
id,
category: 'uploads',
title,
description,
items: items.map(item => ({
"identifier": item.identifier,
"sessionControl": item.sessionControl || {
"showFeedback": true,
"validateResponses": false,
"submissionMode": "simultaneous"
identifier: item.identifier,
sessionControl: item.sessionControl || {
showFeedback: true,
validateResponses: submissionMode === 'individual',
submissionMode
}
})),
count: items.length.toString()
})
}

this.tests.push(test)

return id;
return test;
}
}
61 changes: 43 additions & 18 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@
</div>

<div class="tab-pane" id="tab3" role="tabpanel">
<table class="table table-sm w-100">
<thead>
<tr>
<th scope="col" class="th-no-top text-muted">Title</th>
<th scope="col" class="th-no-top text-muted">Items</th>
</tr>
</thead>
<tbody>
<tr v-for="test in uploadsTab" v-bind:key="test.id">
<td class="table-cell router-link">
<router-link :to="{ name: 'Start', params: { id: test.id } }">
{{ test.title }}
</router-link>
</td>
<td>
{{ test.count }}
</td>
</tr>
</tbody>
</table>
<label>
Upload an .xml file containing a qti-assessment-item
<input
Expand Down Expand Up @@ -131,7 +151,8 @@ export default {
return {
tests: null,
examplesTab: [],
conformanceTab: []
conformanceTab: [],
uploadsTab: [],
}
},
Expand All @@ -143,6 +164,10 @@ export default {
this.tests = this.testFactory.load()
this.tests.forEach((test) => {
if ('category' in test && `${test.category}Tab` in this) {
this[`${test.category}Tab`].push(test)
return;
}
switch (test.id) {
case "1":
case "2":
Expand All @@ -168,53 +193,53 @@ export default {
}
const manifest = files['imsmanifest.xml'];
console.log(files);
const assessment = files['assessment.xml'];
const loadText = (file) => new Promise(resolve => {
const reader = new FileReader();
reader.onload = e => resolve(e.target.result);
reader.readAsText(file);
})
const loadXML = (file) => loadText(file).then(
text => parser.parseFromString(text, "application/xml")
)
const loadDataURL = (file) => new Promise(resolve => {
const reader = new FileReader();
reader.onload = e => resolve(e.target.result);
reader.readAsDataURL(file);
})
const itemFactory = ItemFactory.instance();
const that = this;
const vm = this;
const parser = new DOMParser();
loadText(manifest).then(manifestXML => {
const manifestDoc = parser.parseFromString(manifestXML, "application/xml");
const items = [];
const serializer = new XMLSerializer();
Promise.all([loadXML(manifest), assessment ? loadXML(assessment) : undefined]).then(([manifestDoc, assessmentDoc]) => {
const submissionMode = assessmentDoc?.querySelector('[submission-mode]')?.getAttribute('submission-mode') || 'individual'
Promise.all(Array.from(manifestDoc.querySelectorAll('resource[type="imsqti_item_xmlv3p0"]')).map(resourceNode => {
const identifier = resourceNode.getAttribute('identifier');
const resourceHref = resourceNode.getAttribute('href');
items.push({identifier});
return loadText(files[resourceHref]).then(itemXML => {
return loadXML(files[resourceHref]).then(itemDOC => {
return Promise.all(Array.from(resourceNode.querySelectorAll(`file:not([href="${resourceHref}"])`)).map(fileNode => {
const fileHref = fileNode.getAttribute('href');
console.log(fileHref);
return loadDataURL(files[fileHref]).then(fileData => itemXML = itemXML.replace(fileHref, fileData));
loadDataURL(files[fileHref]).then(fileData => {
itemDOC.querySelectorAll(`[src="${fileHref}"]`).forEach(thing => thing.setAttribute('src', fileData));
});
})).then(() => {
itemFactory.pushItem(identifier, itemXML);
return itemFactory.pushItem(identifier, submissionMode, serializer.serializeToString(itemDOC));
});
});
})).then(() => {
that.testFactory.pushTest(`Test Upload ${new Date().toISOString()}`, '', items);
that.tests = this.testFactory.load();
console.log('done');
})).then(items => {
const test = vm.testFactory.pushTest(`Test Upload ${new Date().toISOString()}`, '', submissionMode, items);
vm.tests = vm.testFactory.load();
this.uploadsTab.push(test);
});
});
}
}
},
created () {
Expand Down
2 changes: 1 addition & 1 deletion src/views/TestRunner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ export default {
// Inject report into End Panel
this.$refs.endpanel.setUnanswered(report.unanswered)
this.$refs.endpanel.setItemSummary(report.summary)
// Show the End page
this.currentPanel = 'end'
Expand Down

0 comments on commit 0402557

Please sign in to comment.