]> iEval git - plack-app-gruntmaster.git/commitdiff
Add user tracking
authorMarius Gavrilescu <marius@ieval.ro>
Fri, 12 Dec 2014 14:55:20 +0000 (16:55 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Fri, 12 Dec 2014 14:55:20 +0000 (16:55 +0200)
css/custom.css
js/80-sidebar.js [new file with mode: 0644]
js/90-tracker.js [new file with mode: 0644]
tmpl/skel.en

index 429955b32bbc6b1ec91189a8d79f5b02bb773a48..4239ab8421843a38ed6e3f5a12abda283c3c4497 100644 (file)
@@ -78,4 +78,12 @@ ul.inline li:after {
 
 ul.inline li:last-child:after {
        content: "";
+}
+
+.tracker-mark.tick {
+       color: green;
+}
+
+.tracker-mark.x{
+       color: red;
 }
\ No newline at end of file
diff --git a/js/80-sidebar.js b/js/80-sidebar.js
new file mode 100644 (file)
index 0000000..cf729ec
--- /dev/null
@@ -0,0 +1,10 @@
+(function(){
+       'use strict';
+
+       $( document ).ready(function() {
+               if(!$('#sidebar').size()) {
+            var content = $('#content');
+            content.wrapInner('<div class="col-md-9">').append('<div id="sidebar" class="col-md-3">').addClass('row');
+        }
+       });
+})();
diff --git a/js/90-tracker.js b/js/90-tracker.js
new file mode 100644 (file)
index 0000000..5c71e12
--- /dev/null
@@ -0,0 +1,94 @@
+(function(){
+       'use strict';
+
+       function tick()  { return $('<span class="tick tracker-mark">✔</span>') }
+       function xmark() { return $('<span class="x tracker-mark">✘</span>')    }
+
+       function update_tracker(){
+               var data = localStorage.getItem('tracker_data');
+               var user = localStorage.getItem('tracker_username');
+               if(!data)
+                       return;
+               data = JSON.parse(data);
+               var solved = {};
+               var attempted = {};
+               var solvednr = 0;
+               var attemptednr = 0;
+               data.problems.forEach(function(e){
+                       if(e.solved){
+                               solved[e.problem] = 1;
+                               solvednr++;
+                       } else {
+                               attempted[e.problem] = 1;
+                               attemptednr++;
+                       }
+               });
+
+               var contests = {};
+               data.contests.forEach(function(e){
+                       contests[e.contest] = 1;
+               });
+
+               $('#tracker_userlink').html(data.name);
+               $('#tracker_solved').html(solvednr);
+               $('#tracker_attempted').html(attemptednr);
+               $('#tracker_contests').html(data.contests.length);
+
+               $('.tracker-mark').detach();
+               if(location.pathname == '/pb/')
+                       $('table').find('.name').find('a').each(function() {
+                               var id = $(this).attr('href').split('?', 2)[0];
+                               if(solved[id])
+                                       $(this).parent().append(tick());
+                               else if(attempted[id])
+                                       $(this).parent().append(xmark());
+                       });
+
+               if(location.pathname == '/ct/')
+                       $('table').find('.name').find('a').each(function() {
+                               var id = $(this).attr('href').substr(4);
+                               if(contests[id])
+                                       $(this).parent().append(tick());
+                       });
+
+               if(location.pathname == '/log/')
+                       $('table').find('tbody').find('tr').each(function() {
+                               if($(this).find('.owner').find('a').attr('href') != "/us/" + user)
+                                       return;
+                               $(this).find('.id').append($(this).find('.r0').size() ? tick() : xmark());
+                       });
+       }
+
+       function start_tracking(user){
+               localStorage.setItem('tracker_username', user);
+               $('#tracker_userlink').attr('href', '/us/' + user).html(user);
+               $('#tracker_tracking').removeClass('hidden');
+               $('#tracker_form').addClass('hidden');
+               update_tracker();
+               var xhr = new XMLHttpRequest();
+               xhr.open('GET', '/us/' + user);
+               xhr.setRequestHeader('Accept', 'application/json');
+               xhr.onload = function () {
+                       localStorage.setItem('tracker_data', this.responseText);
+                       update_tracker();
+               };
+               xhr.send();
+       }
+
+       function stop_tracking(){
+               $('.tracker-mark').detach();
+               localStorage.removeItem('tracker_username');
+               localStorage.removeItem('tracker_data');
+               $('#tracker_tracking').addClass('hidden');
+               $('#tracker_form').removeClass('hidden');
+       }
+
+       $( document ).ready(function(){
+               $('#tracker').detach().prependTo($('#sidebar')).removeClass('hidden');
+               $('#tracker_button').on('click', function() { start_tracking($('#tracker_username').val()) });
+               $('#tracker_stop').on('click', stop_tracking);
+
+               if(localStorage.getItem('tracker_username'))
+                       start_tracking(localStorage.getItem('tracker_username'));
+       });
+})();
index 1e20c87e0269c819007b7d52d41282455a4e9cdb..4d1e73e847b9e0271018adb8f9818f867ce8e9c6 100644 (file)
 
 <div id="content">Content goes here</div>
 
+<div id="tracker">
+<h1>Track user</h1>
+<div id="tracker_form">
+<div class="form-group">
+<label for="tracker_username">Username</label>
+<input type="text" id="tracker_username" class="form-control">
+</div>
+<button id="tracker_button" class="btn">Start tracking</button>
+</div>
+
+<div id="tracker_tracking" class="hidden">
+Tracking <a href="#" id="tracker_userlink"></a>.<br>
+<a href="#" id="tracker_stop">Stop tracking</a>
+<dl class="dl-horizontal">
+<dt>Solved</dt>    <dd id="tracker_solved">?</dd>
+<dt>Attempted</dt> <dd id="tracker_attempted">?</dd>
+<dt>Contests</dt>  <dd id="tracker_contests">?</dd>
+</dl>
+</div>
+</div>
+
 <footer>
 Dilmom: Why don't you call your product the Gruntmaster 6000?<br>
 Dilbert: What kind of product do you see when you imagine a Gruntmaster 6000?<br>
This page took 0.037892 seconds and 4 git commands to generate.