Skip to content

Commit

Permalink
grossly making progress
Browse files Browse the repository at this point in the history
  • Loading branch information
TomWoodward committed May 17, 2024
1 parent e101495 commit 0fa1198
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 16 deletions.
10 changes: 7 additions & 3 deletions src/helpers/ItemFactory.js

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

4 changes: 2 additions & 2 deletions src/helpers/TestControllerUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export class TestControllerUtilities {
navigateItemData = null

constructor () {
this.testFactory = new TestFactory()
this.itemFactory = new ItemFactory()
this.testFactory = TestFactory.instance()
this.itemFactory = ItemFactory.instance()
return this
}

Expand Down
12 changes: 9 additions & 3 deletions src/helpers/TestFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,12 @@ const tests = [

/* eslint-enable */
export class TestFactory {
static _instance;

static instance () {
return TestFactory._instance ??= new TestFactory();
}


constructor () {
this.tests = tests
Expand All @@ -1570,10 +1576,10 @@ export class TestFactory {
return this.tests.find(test => test.id === id)
}

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

tests.push({
this.tests.push({
id,
title,
description,
Expand All @@ -1582,7 +1588,7 @@ export class TestFactory {
"sessionControl": item.sessionControl || {
"showFeedback": true,
"validateResponses": false,
"submissionMode": "individual"
"submissionMode": "simultaneous"
}
})),
count: items.length.toString()
Expand Down
63 changes: 55 additions & 8 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@
Upload an .xml file containing a qti-assessment-item
<input
type="file"
webkitdirectory directory
name="upload"
accept="*.xml"
@change="onFileChanged($event)"
/>
</label>
Expand All @@ -116,6 +116,7 @@
<script>
import TopBarApp from '@/components/TopBarApp'
import SkipNav from '@/components/SkipNav'
import { ItemFactory } from '@/helpers/ItemFactory'
import { TestFactory } from '@/helpers/TestFactory'
export default {
Expand All @@ -138,7 +139,8 @@ export default {
initialize () {
// Load tests
this.tests = new TestFactory().load()
this.testFactory = TestFactory.instance();
this.tests = this.testFactory.load()
this.tests.forEach((test) => {
switch (test.id) {
Expand All @@ -159,12 +161,57 @@ export default {
onFileChanged($event) {
const target = $event.target;
if (target && target.files && target.files[0]) {
const file = target.files[0];
const reader = new FileReader();
reader.onload = (e) => {
console.log(e.target.result);
};
reader.readAsText(file);
const files = {};
for (const file of target.files) {
files[file.webkitRelativePath.split('/').slice(1).join('/')] = file;
}
const manifest = files['imsmanifest.xml'];
console.log(files);
const loadText = (file) => new Promise(resolve => {
const reader = new FileReader();
reader.onload = e => resolve(e.target.result);
reader.readAsText(file);
})
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 parser = new DOMParser();
loadText(manifest).then(manifestXML => {
const manifestDoc = parser.parseFromString(manifestXML, "application/xml");
const items = [];
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 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));
})).then(() => {
itemFactory.pushItem(identifier, itemXML);
});
});
})).then(() => {
that.testFactory.pushTest(`Test Upload ${new Date().toISOString()}`, '', items);
that.tests = this.testFactory.load();
console.log('done');
});
});
}
}
Expand Down

0 comments on commit 0fa1198

Please sign in to comment.