From 85e530fc7d2cf091734f0d126968d8c50defb65c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Smodi=C5=A1?= Date: Tue, 29 Sep 2015 17:14:49 +0200 Subject: Temporary hint fix: hints are shown in slovene only. --- js/codeq/hint.js | 69 ++++++++++++++++++++++++-------------------------------- 1 file changed, 30 insertions(+), 39 deletions(-) (limited to 'js') 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); } }, -- cgit v1.2.1