function create_requests_table(requests) { var overdue_requests = []; var pending_requests = []; var resolved_requests = []; $.each(requests, function (i, request) { if (request.overdue()) overdue_requests.push(request); else if (request.pending()) pending_requests.push(request); else if (request.resolved()) resolved_requests.push(request); }); function sort_asc(r1, r2) { var date1 = Date.parse(r1.deadline); var date2 = Date.parse(r2.deadline); if (date1 > date2) return 1; if (date1 < date2) return -1; return 0; } function sort_desc(r1, r2) { var date1 = Date.parse(r1.deadline); var date2 = Date.parse(r2.deadline); if (date1 > date2) return -1; if (date1 < date2) return 1; return 0; } overdue_requests.sort(sort_asc); pending_requests.sort(sort_asc); resolved_requests.sort(sort_desc); requests = overdue_requests.concat(pending_requests, resolved_requests); var table = $('
'); table.append('IDTitleStatusAssigned to'); $.each(requests, function (i, request) { var row = create_request_row(request); row.appendTo(table); }); table.appendTo('#container'); } function create_request_row(request) { var resolved_on = request.resolved() ? moment(request.resolved_on) : null; var deadline = moment(request.deadline); var status_description = request.resolved() ? 'Resolved ' + resolved_on.fromNow() : 'Due ' + deadline.fromNow(); var more_info = '
Submitted by ' + request.submitted_by + ' on ' + moment(request.submitted_on).format('D MMM YYYY') + '. ' + status_description + '.
'; var title = request.title + more_info; var row = $(''); var rowClass = request.resolved() ? 'resolved' : (request.overdue() ? 'overdue' : 'pending'); row.addClass(rowClass); function add_cell(text, className) { var cell = $(''); if (className) cell.addClass(className); var data = $('
' + text + '
'); data.appendTo(cell); cell.appendTo(row); return cell; } add_cell(request.id); add_cell(title, 'title'); add_cell(request.status, 'status'); add_cell(request.assigned_to); return row; } function add_methods_to_request(request) { request.resolved = function () { return this.status == 'resolved' || this.status == 'closed'; }; request.overdue = function () { return !this.resolved() && moment(this.deadline).isBefore(moment()); }; request.pending = function () { return !this.resolved() && !this.overdue(); }; } function getParameterByName(name) { name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search); return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); } $(document).ready(function () { var team = getParameterByName('team'); if(team == null) return; var data_file = 'data/' + team + '.json'; $.getJSON(data_file, function (data) { $('div.title').text(data.title); $.each(data.requests, function (i, request) { add_methods_to_request(request); }); create_requests_table(data.requests); }); var font_size = getParameterByName('font-size'); $('body').css('font-size', font_size); });