diff options
author | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2015-10-19 13:36:50 +0200 |
---|---|---|
committer | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2015-10-19 14:42:56 +0200 |
commit | cb84c6558b66e1441ddfc9701d91c9c994335198 (patch) | |
tree | cfe415fccb0e0b51d9d019bd70896c387cf8285e | |
parent | bea986b587a8e61234430bc1144609e1a5f117b4 (diff) |
Show attempted/solved status in problem list
-rw-r--r-- | css/codeq.css | 12 | ||||
-rw-r--r-- | js/codeq/comms.js | 7 | ||||
-rw-r--r-- | js/codeq/problem_list.js | 44 |
3 files changed, 48 insertions, 15 deletions
diff --git a/css/codeq.css b/css/codeq.css index 77d1d9c..ba10bcd 100644 --- a/css/codeq.css +++ b/css/codeq.css @@ -520,10 +520,20 @@ ul.dropdown-menu a { padding-left: 1em; } -#screen_problem_list .group-problems li { +#screen_problem_list ul.group-problems li { list-style-type: none; } #screen_problem_list a { cursor: pointer; } + +#screen_problem_list .group-problems a.attempted::after { + color: orange; + content: ' ●'; +} + +#screen_problem_list .group-problems a.solved::after { + color: green; + content: ' ✔'; +} diff --git a/js/codeq/comms.js b/js/codeq/comms.js index 5908e0d..fe609c9 100644 --- a/js/codeq/comms.js +++ b/js/codeq/comms.js @@ -436,6 +436,13 @@ }); }, + getAttempts: function commsGetAttempts (language) { + return this.send({ + 'action': 'get_attempts', + 'language': language + }); + }, + loadProblem: function commsLoadProblem (problem_id) { return this.send({ 'action': 'load_problem', diff --git a/js/codeq/problem_list.js b/js/codeq/problem_list.js index 4a3d24d..853c8cb 100644 --- a/js/codeq/problem_list.js +++ b/js/codeq/problem_list.js @@ -275,6 +275,21 @@ }); }, + /** + * Show attempted/solved status in the link for every problem. + */ + showAttempts = function (languageData, attempts) { + var i; + for (i = 0; i < languageData.refs.length; i++) { + ref = languageData.refs[i]; + if (ref.id in attempts) { + jqScreen.find('a.problem-'+i) + .removeClass('solved attempted') + .addClass(attempts[ref.id] ? 'solved' : 'attempted'); + } + } + }, + // ================================================================================ // Problem definition processing // ================================================================================ @@ -349,27 +364,28 @@ codeq.globalStateMachine.register('problem_list', { 'enter': function(language){ - var data = null; // language data + var data = languageCache[language]; // language data $("#navigation-problem_list").addClass("active").css('display', ''); if (!language) language = currentLanguage; // This happens when we hit this with the back button - - if (currentLanguage !== language) { + if (language !== currentLanguage) { jqScreen.empty(); - currentLanguage = language; - data = languageCache[language]; - if (data) { - createDom(data); + } + codeq.wait(Q.all([ + data || codeq.comms.getLanguageDef(language), + codeq.comms.getAttempts(language) + ]).spread(function (langData, attemptData) { + if (!data) { + data = createLanguageData(langData, language); + languageCache[language] = data; } - else { - codeq.wait(codeq.comms.getLanguageDef(language).then(function (rawData) { - var data = createLanguageData(rawData, language); - languageCache[language] = data; - createDom(data); - })).done(); + if (language !== currentLanguage) { + createDom(data); } - } + currentLanguage = language; + showAttempts(data, attemptData.data); + })).done(); jqScreen.css('display', ''); }, |