From f862dbbb936c003e0f6ce28ae0062428db30b8e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Pu=C5=A1nik?= Date: Mon, 12 Oct 2015 18:23:33 +0200 Subject: show basic user statistics on profile page --- js/codeq/profile.js | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'js/codeq/profile.js') diff --git a/js/codeq/profile.js b/js/codeq/profile.js index 2759be3..4723b4a 100644 --- a/js/codeq/profile.js +++ b/js/codeq/profile.js @@ -73,9 +73,45 @@ codeq.globalStateMachine.register('profile',{ 'enter': function(){ - $("#screen_profile").css('display', ''); $('#disabled').css('display', 'none'); + codeq.comms.getUserStat() + .then(function (data) { + if (data.code !== 0) throw new Error('GetUserStat failed, code: ' + data.code + ', message: ' + data.message); + console.log(data); + var data = data.stat; + + var columns = ['language', 'problem_group', 'problems_count', 'done', 'in_progress'], + labels = ['Language', 'Problem group', 'All', 'Done', 'In progress']; + + var items=''; + $.each(labels, function( key, val ) { + items+=''+val+''; + }); + items+=''; + $.each( data, function( object, row ) { + items+=''; + if(row['problem_group']) { + $.each( columns, function( key, val ) { + items+=''+row[val]||""+''; + }); + } + else { + $.each( columns, function( key, val ) { + items+=''+(row[val]==null?'(all)':row[val])+''; + }); + } + items+=''; + }); + + $('#table1').html(items) + + }) + .fail(function (reason) { + codeq.log.error('GetUserStat failed: ' + reason, reason); + alert('GetUserStat failed: ' + reason); + }) + .done(); }, 'exit' : function(){ $("#screen_profile").css('display', 'none'); -- cgit v1.2.1