summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/codeq/comms.js7
-rw-r--r--js/codeq/problem_list.js44
2 files changed, 37 insertions, 14 deletions
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', '');
},