Commit a036f87a by Иван Кубота

human readable generator

parent 298d9d71
Pipeline #545 failed with stage
...@@ -91,6 +91,7 @@ module.exports = { ...@@ -91,6 +91,7 @@ module.exports = {
type: {required: false, description: '1 - products, 2 - standards', type: Number}, type: {required: false, description: '1 - products, 2 - standards', type: Number},
nolog: {required: false, description: 'remove human readable log', type: Boolean}, nolog: {required: false, description: 'remove human readable log', type: Boolean},
stats: {required: false, description: 'aggregate stats and explain questions', type: Boolean}, stats: {required: false, description: 'aggregate stats and explain questions', type: Boolean},
human: {required: false, description: 'aggregate stats and explain questions', type: Boolean}
}, },
fn: async function(args, req, res) { fn: async function(args, req, res) {
let seed = args.seed || Math.random().toString(36).substr(2); let seed = args.seed || Math.random().toString(36).substr(2);
...@@ -187,7 +188,39 @@ module.exports = { ...@@ -187,7 +188,39 @@ module.exports = {
'<h2>Type</h2><div>'+Object.keys(statsType).map(k=>`<b>${k}</b>: <span>${statsType[k]}</span>`).join('<br/>')+'</div>'+ '<h2>Type</h2><div>'+Object.keys(statsType).map(k=>`<b>${k}</b>: <span>${statsType[k]}</span>`).join('<br/>')+'</div>'+
'</body></HTML>' '</body></HTML>'
} }
if(args.human){
res.header("Content-Type", "text/html; charset=utf-8");
return '<HTML><head>'+`<style>
.hidden {
display: none
}
.how-block {
white-space: pre-wrap;
padding: 0 16px;
border-left: 4px solid #ff0060;
}
.seed {color: #999}
.title {font-size:26px}
*{font-family: Verdana;}
pre {font-family: monospace;}
.how {color: #ff0060;border-bottom: 1px dotted;font-size:14px;cursor: pointer}
</style><script>var toggle=function(a){a.parentNode.parentNode.querySelector('.how-block').classList.toggle('hidden')}</script>`+'</head><body><div class="seed">seed: '+seed+'</div> ' +
list.map((result, i)=>
`<div class="quest"><div class="title">${i+1}) ${result.question} <span class="how" onclick="toggle(this)">Как так получилось?</span></div>
<pre>
${ result.answers.map(a=>
( (result.type==='checkbox'?(a.correct?'[v]':'[ ]'):(a.correct?'(o)':'( )'))+ ' '+a.text)
).join('\n')}
</pre>
<pre class="how-block hidden">${result.log.join('\n')}</pre>
</div>
`
).join('<br/><br/>')+
'</body></HTML>'
}
return list; return list;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment