Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure empty question and answer IDs have values. #41

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion assets/css/mwdk-creator.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@
width: 100%;
height: 600px;
}

24 changes: 14 additions & 10 deletions express.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const yaml = require('yamljs');
const { execSync } = require('child_process');
const waitUntil = require('wait-until-promise').default
const hoganExpress = require('hogan-express')
const uuid = require('uuid')

var webPackMiddleware = false;
var hasCompiled = false;
Expand Down Expand Up @@ -89,16 +90,16 @@ var getDemoQset = () => {
throw "Couldn't find demo.json file for qset data"
}

return performQSetSubsitutions(qset.toString())
}

var performQSetSubsitutions = (qset) => {
console.log('media and ids inserted into qset..')
// convert media urls into usable ones
qset = qset.toString()
qset = qset.replace(/"<%MEDIA='(.+?)'%>"/g, '"__$1__"')

// look for "id": null or "id": 0 and build a mock id
let id = 0
qset = qset.replace(/("id"\s?:\s?)(null|0)/g, function(match, offset, string){
id++
return `"id": "mwdk-mock-id-${id}"`
})
// look for "id": null or "id": 0 or "id": "" and build a mock id
qset = qset.replace(/("id"\s?:\s?)(null|0|"")/g, () => `"id": "mwdk-mock-id-${uuid()}"`)

return JSON.parse(qset)
}
Expand Down Expand Up @@ -280,7 +281,7 @@ module.exports = (app) => {


// insert the port into the res.locals
app.use(function (req, res, next) {
app.use( (req, res, next) => {
// console.log(`request to ${req.url}`)
res.locals.port = process.env.PORT || 8118
next()
Expand Down Expand Up @@ -363,7 +364,7 @@ module.exports = (app) => {
});

// Play Score page
app.get('/mwdk/scores/demo', (req, res) => {
app.get(['/mwdk/scores/demo', '/mwdk/scores/preview/:id'], (req, res) => {
res.locals = Object.assign(res.locals, { template: 'score_mwdk'})
res.render(res.locals.template)
})
Expand Down Expand Up @@ -492,7 +493,10 @@ module.exports = (app) => {
// load instance, fallback to demo
try {
const id = JSON.parse(req.body.data)[0];
res.send(fs.readFileSync(path.join(qsets, id+'.json')).toString());
let qset = fs.readFileSync(path.join(qsets, id+'.json')).toString()
qset = performQSetSubsitutions(qset)
qset = JSON.stringify(qset)
res.send(qset.toString());
} catch (e) {
res.json(getDemoQset().qset);
}
Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"test": "echo 'No tests yet'",
"start": "env TEST_MDK=true webpack-dev-server --open --config webpack.config.widget.js",
"postinstall": "yarn build",
"prettier:run": "prettier --write 'src/*.js' --write 'assets/**/*.{js,css}' --write '*.js",
"clientAssets:link": "cd ../materia-server-client-assets && yarn link && cd - && yarn link materia-server-client-assets"
},
"materia": {
Expand Down Expand Up @@ -50,5 +51,11 @@
"whatwg-fetch": "^3.0.0",
"yamljs": "^0.2.8",
"zip-webpack-plugin": "^2.0.0"
},
"prettier": {
"printWidth": 100,
"semi": false,
"useTabs": true,
"singleQuote": true
}
}