From 095336bf0d29aeb83761b1f8983bf5f4294278ca Mon Sep 17 00:00:00 2001 From: Brandon Stull Date: Mon, 28 Jan 2019 11:10:09 -0500 Subject: [PATCH 1/5] #17 Any time a qset is being loaded, all blank IDs will be given values. --- express.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/express.js b/express.js index 7e90018..701193c 100644 --- a/express.js +++ b/express.js @@ -89,13 +89,16 @@ var getDemoQset = () => { throw "Couldn't find demo.json file for qset data" } + return performQSetSubsitutions(qset.toString()) +} + +var performQSetSubsitutions = (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 + // look for "id": null or "id": 0 or "id": "" and build a mock id let id = 0 - qset = qset.replace(/("id"\s?:\s?)(null|0)/g, function(match, offset, string){ + qset = qset.replace(/("id"\s?:\s?)(null|0|"")/g, function(match, offset, string){ id++ return `"id": "mwdk-mock-id-${id}"` }) @@ -488,7 +491,14 @@ 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() + console.log('before') + console.log(qset) + qset = performQSetSubsitutions(qset) + qset = JSON.stringify(qset) + console.log('after') + console.log(qset) + res.send(qset.toString()); } catch (e) { res.json(getDemoQset().qset); } @@ -506,6 +516,8 @@ module.exports = (app) => { // creates files in our qset directory (probably should use a better thing)session app.use(['/api/json/widget_instance_new', '/api/json/widget_instance_update'], (req, res) => { const data = JSON.parse(req.body.data); + console.log('what even is') + console.log(data) // sweep through the qset items and make sure there aren't any nonstandard question properties const standard_props = [ From 20f64bec5855edc390b44af2e5f753b105f845c9 Mon Sep 17 00:00:00 2001 From: Brandon Stull Date: Mon, 28 Jan 2019 11:12:46 -0500 Subject: [PATCH 2/5] #17 console.logs. --- express.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/express.js b/express.js index 701193c..844c53d 100644 --- a/express.js +++ b/express.js @@ -516,8 +516,6 @@ module.exports = (app) => { // creates files in our qset directory (probably should use a better thing)session app.use(['/api/json/widget_instance_new', '/api/json/widget_instance_update'], (req, res) => { const data = JSON.parse(req.body.data); - console.log('what even is') - console.log(data) // sweep through the qset items and make sure there aren't any nonstandard question properties const standard_props = [ From 7a61f7b474169193c397aaaf23e371bd59c14cbe Mon Sep 17 00:00:00 2001 From: Brandon Stull Date: Mon, 28 Jan 2019 11:59:32 -0500 Subject: [PATCH 3/5] #17 Use UUIDs instead of an incrementing number for new IDs. --- express.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/express.js b/express.js index 844c53d..bbd60e1 100644 --- a/express.js +++ b/express.js @@ -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; @@ -97,10 +98,8 @@ var performQSetSubsitutions = (qset) => { qset = qset.replace(/"<%MEDIA='(.+?)'%>"/g, '"__$1__"') // look for "id": null or "id": 0 or "id": "" 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}"` + return `"id": "mwdk-mock-id-${uuid()}"` }) return JSON.parse(qset) From faba3ffa2381243d73437b7914f8630dc45f64fa Mon Sep 17 00:00:00 2001 From: Ian Turgeon Date: Tue, 28 May 2019 21:39:01 -0400 Subject: [PATCH 4/5] adds prettier command --- assets/css/mwdk-creator.css | 1 - express.js | 13 ++++--------- package.json | 7 +++++++ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/assets/css/mwdk-creator.css b/assets/css/mwdk-creator.css index ef3ba90..37ece4f 100644 --- a/assets/css/mwdk-creator.css +++ b/assets/css/mwdk-creator.css @@ -12,4 +12,3 @@ width: 100%; height: 600px; } - diff --git a/express.js b/express.js index 99da9f6..f4ecac8 100644 --- a/express.js +++ b/express.js @@ -94,13 +94,12 @@ var getDemoQset = () => { } var performQSetSubsitutions = (qset) => { + console.log('media and ids inserted into qset..') // convert media urls into usable ones qset = qset.replace(/"<%MEDIA='(.+?)'%>"/g, '"__$1__"') // look for "id": null or "id": 0 or "id": "" and build a mock id - qset = qset.replace(/("id"\s?:\s?)(null|0|"")/g, function(match, offset, string){ - return `"id": "mwdk-mock-id-${uuid()}"` - }) + qset = qset.replace(/("id"\s?:\s?)(null|0|"")/g, () => `"id": "mwdk-mock-id-${uuid()}"`) return JSON.parse(qset) } @@ -282,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() @@ -365,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) }) @@ -495,12 +494,8 @@ module.exports = (app) => { try { const id = JSON.parse(req.body.data)[0]; let qset = fs.readFileSync(path.join(qsets, id+'.json')).toString() - console.log('before') - console.log(qset) qset = performQSetSubsitutions(qset) qset = JSON.stringify(qset) - console.log('after') - console.log(qset) res.send(qset.toString()); } catch (e) { res.json(getDemoQset().qset); diff --git a/package.json b/package.json index 7257133..3e23e1a 100644 --- a/package.json +++ b/package.json @@ -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}'", "clientAssets:link": "cd ../materia-server-client-assets && yarn link && cd - && yarn link materia-server-client-assets" }, "materia": { @@ -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 } } From d1d654d62e5bccb34f47b258c195fe916035a754 Mon Sep 17 00:00:00 2001 From: Ian Turgeon Date: Tue, 28 May 2019 21:40:18 -0400 Subject: [PATCH 5/5] update prettier to run on js in top level dir --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3e23e1a..0bf1c07 100644 --- a/package.json +++ b/package.json @@ -10,7 +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}'", + "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": {