diff options
author | Marko Pušnik <marko.pusnik@guru.si> | 2015-10-12 18:23:33 +0200 |
---|---|---|
committer | Marko Pušnik <marko.pusnik@guru.si> | 2015-10-12 18:23:33 +0200 |
commit | f862dbbb936c003e0f6ce28ae0062428db30b8e5 (patch) | |
tree | 8ae8cf49ee279cc552d25b1ec8f9ff3f7af1e421 | |
parent | 05fc111e65c93cc8f33051f0c0a8084a5c5debf1 (diff) |
show basic user statistics on profile page
-rw-r--r-- | index.html | 4 | ||||
-rw-r--r-- | js/codeq/comms.js | 4 | ||||
-rw-r--r-- | js/codeq/profile.js | 38 |
3 files changed, 45 insertions, 1 deletions
@@ -289,6 +289,10 @@ <li class="list-group-item text-right"><span class="pull-left"><strong>Last seen</strong></span><span id="profileLastLogin">1 hour ago</span></li> </ul> </div> + <div class="panel panel-default"> + <div class="panel-heading">Statistics</div> + <table id="table1" class="table table-bordered table-striped small"></table> + </div> </div><!--/col-12--> </div><!--row--> </div><!--container--> diff --git a/js/codeq/comms.js b/js/codeq/comms.js index ab168ff..89813ee 100644 --- a/js/codeq/comms.js +++ b/js/codeq/comms.js @@ -382,6 +382,10 @@ return this.send({'action': 'change_password', 'password': newpassword}); }, + 'getUserStat': function () { + return this.send({'action': 'user_stat'}); + }, + 'updateSettings': function (new_settings){ return this.send({'action': 'update_settings', 'settings': new_settings}); }, 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='<thead><tr>';
+ $.each(labels, function( key, val ) {
+ items+='<th>'+val+'</th>';
+ });
+ items+='</tr></thead>';
+ $.each( data, function( object, row ) {
+ items+='<tr>';
+ if(row['problem_group']) {
+ $.each( columns, function( key, val ) {
+ items+='<td style="white-space: nowrap">'+row[val]||""+'</td>';
+ });
+ }
+ else {
+ $.each( columns, function( key, val ) {
+ items+='<td style="white-space: nowrap"><strong>'+(row[val]==null?'(all)':row[val])+'</strong></td>';
+ });
+ }
+ items+='</td>';
+ });
+
+ $('#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');
|