diff options
author | Aleš Smodiš <aless@guru.si> | 2015-09-29 17:14:49 +0200 |
---|---|---|
committer | Aleš Smodiš <aless@guru.si> | 2015-09-29 17:14:49 +0200 |
commit | 85e530fc7d2cf091734f0d126968d8c50defb65c (patch) | |
tree | 8457266b046e23344bcf4819a959952c3520b372 /js | |
parent | d657145124a601a9375b04a488ff2950f645f26d (diff) |
Temporary hint fix: hints are shown in slovene only.
Diffstat (limited to 'js')
-rw-r--r-- | js/codeq/hint.js | 69 |
1 files changed, 30 insertions, 39 deletions
diff --git a/js/codeq/hint.js b/js/codeq/hint.js index 0cb047a..d30f934 100644 --- a/js/codeq/hint.js +++ b/js/codeq/hint.js @@ -133,28 +133,15 @@ codeq.tr.registerDictionary(trNamespace, dictionary); - // TODO: below is a temporary code to bridge the old implementation with the new data format - var hintDefsA = problemDef.hint, - commonHintDefsA = commonDef.hint, - planDef = problemDef.plan; - if (planDef.sl) planDef = planDef.sl; - else planDef = planDef.en || []; - var hintDefs = {}, t1, t2, k; - if (hintDefsA.sl) t1 = hintDefsA.sl; - else t1 = hintDefsA.en || {}; - if (commonHintDefsA.sl) t2 = commonHintDefsA.sl; - else t2 = commonHintDefsA.en || {}; - for (k in t2) { - if (!t2.hasOwnProperty(k)) continue; - hintDefs[k] = t2[k]; - } - for (k in t1) { - if (!t1.hasOwnProperty(k)) continue; - hintDefs[k] = t1[k]; - } + var hintProblemDefs = problemDef.hint_type, + hintCommonDefs = commonDef.hint_type, + hintProblemTr = problemDef.hint, + hintCommonTr = commonDef.hint, + planDef = problemDef.plan.sl; return { - /** Display the next "planning" hint and return whether there are + /** + * Display the next "planning" hint and return whether there are * any more available. */ 'planNext': function () { @@ -173,46 +160,50 @@ */ 'handle': function (serverHints) { var n = serverHints.length, - /** number */ i, - /** ServerHint */ serverHint, - /** HintDefinition */ hintDef, - hintType, hintTemplate, t, fn, indices; + i, serverHint, hintId, hintDef, hintContent, hintType, hintTemplate, t, fn, indices; clearHints(); mainLoop: for (i = 0; i < n; i++) { serverHint = serverHints[i]; - hintDef = hintDefs[serverHint.id]; + hintId = serverHint.id; + hintDef = hintProblemDefs[hintId]; + if (hintDef) { + hintContent = hintProblemTr[hintId]; + } + else { + hintDef = hintCommonDefs[hintId]; + hintContent = hintCommonTr[hintId]; + } if (!hintDef) { - codeq.log.error('Undefined hint ' + serverHint.id); + codeq.log.error('Undefined hint: ' + hintId); + continue; + } + if (!hintContent) { + codeq.log.error('Hint without content: ' + hintId); continue; } if (serverHint.indices) { indices = serverHint.indices; for (i = 0; i < indices.length; i++) { - hintDef = hintDef[indices[i]]; - if (!hintDef) { - codeq.log.error('Undefined hint ' + serverHint.id + ' with indices ' + serverHint.indices); + hintContent = hintContent[indices[i]]; + if (!hintContent) { + codeq.log.error('Cannot reference hint ' + hintId + ' with indices ' + serverHint.indices); continue mainLoop; } } } + t = typeof hintDef; - if ((t === 'string') || (hintDef instanceof Array)) { - hintType = 'static'; - hintTemplate = hintDef; - } - else if (t === 'object') { - hintType = hintDef.type; - hintTemplate = hintDef.message; - } + if (t === 'string') hintType = hintDef; + else if ((t === 'object') && (hintDef !== null)) hintType = hintDef.type; else { - codeq.log.error('Unsupported hint definition: ' + t); + codeq.log.error('Cannot determine type of hint ' + hintId + ' from: ' + hintDef); continue; } fn = typeHandlers[hintType]; if (!fn) codeq.log.error('Unsupported hint type: ' + hintType); - else fn(hintType, hintTemplate, serverHint); + else fn(hintType, hintContent.sl, serverHint); } }, |