Difference between revisions of "Dev/Results"

(Improved "team info shows when you click team name")
(Integrate a call to https://igem.org/aj/team_list.cgi so I have track info as well)
Line 33: Line 33:
 
return '<div border="0" style="padding-left:50px;">'+
 
return '<div border="0" style="padding-left:50px;">'+
 
'<p>' +  
 
'<p>' +  
'Region: <b>' + data.region + '</b>&nbsp;&nbsp;|&nbsp;&nbsp;Section: <b>' + data.section.capitalize() + '</b>' +
+
'Track: <b>' + data.track +
 +
'</b>&nbsp;&nbsp;|&nbsp;&nbsp;' +
 +
'Region: <b>' + data.region +  
 +
'</b>&nbsp;&nbsp;|&nbsp;&nbsp;' +
 +
'Section: <b>' + data.section.capitalize() + '</b>' +
 
'</p>' +
 
'</p>' +
 
'<p>'+
 
'<p>'+
Line 47: Line 51:
  
 
//Accepts an array of team objects and reorganizes it into an array of team*awards (incl no-awards)
 
//Accepts an array of team objects and reorganizes it into an array of team*awards (incl no-awards)
function parseTeamsToAwards(arrayOfTeams) {
+
function parseTeamsToAwards(arrayOfTeams, extraTeamInfo) {
 
var arrayOfTeamAwards = [];
 
var arrayOfTeamAwards = [];
arrayOfTeams.forEach(function(teamObj, index, array) {
+
//arrayOfTeams.forEach(function(teamObj, index, array) {
 +
for (i = 0; i < arrayOfTeams.length; i++) {
 +
var teamObj = jQuery.extend(arrayOfTeams[i], extraTeamInfo[i]);
 
//Take care of any teams that didn't win any awards
 
//Take care of any teams that didn't win any awards
 
if (teamObj.awards.length == 0) {
 
if (teamObj.awards.length == 0) {
Line 66: Line 72:
  
 
jQuery(document).ready(function() {
 
jQuery(document).ready(function() {
 +
//Request team data
 +
var teamsRequest = jQuery.ajax({
 +
url: "https://igem.org/aj/team_list.cgi",
 +
type: "GET",
 +
timeout: 30000,
 +
dataType: "json",
 +
data: {command: "get_team_list", year: "2015"}, //**Make this auto-update itself
 +
error: function(jqxhr, textStatus, errorThrown) {
 +
alert("Failed to get list of teams");
 +
},
 +
});
 
//Request the awards data
 
//Request the awards data
var resultsRequest = jQuery.ajax({
+
var awardsRequest = jQuery.ajax({
 
url: 'https://igem.org/awards/json_dump.cgi',
 
url: 'https://igem.org/awards/json_dump.cgi',
 
type: 'GET',
 
type: 'GET',
Line 75: Line 92:
 
alert("AJAX error; look at var resultsRequest");
 
alert("AJAX error; look at var resultsRequest");
 
},
 
},
success: function(data, textStatus, jqxhr) {
+
});
console.log("successfully got team award data, now parsing");
+
arrayOfTeamAwards = parseTeamsToAwards(data);
+
//When both requests finish, parse the data and set up the table.
+
jQuery.when(teamsRequest, resultsRequest).done(function(teamsReqResult, awardsReqResult) {
//Initialize dataTable and set up event bindings.
+
var teamsData = teamsReqResult[0];
var t = jQuery('#table_team').DataTable( {
+
var awardsData = awardsReqResult[0];
'lengthMenu': [[10, 25, 50, 100, -1],[10, 25, 50, 100, 'All']],
+
var arrayOfTeamAwards = parseTeamsToAwards(awardsData, teamsData);
'pageLength': -1,
+
//'deferRender': true, //improves performance
+
//Initialize dataTable and set up event bindings.
'data': arrayOfTeamAwards,
+
var t = jQuery('#table_team').DataTable( {
'columns': [
+
'lengthMenu': [[10, 25, 50, 100, -1],[10, 25, 50, 100, 'All']],
// { //Child-table control element
+
'pageLength': -1,
// 'className': 'details-control',
+
//'deferRender': true, //improves performance
// 'orderable': false,
+
'data': arrayOfTeamAwards,
// 'data': null,
+
'columns': [
// 'defaultContent': ''
+
// { //Child-table control element
// },
+
// 'className': 'details-control',
{
+
// 'orderable': false,
'data': function(row, type, val, meta) {
+
// 'data': null,
if (row.medal.toUpperCase() == "GOLD") {
+
// 'defaultContent': ''
return "<img title='Gold Medal' src='https://igem.org/images/medals/seal_gold.png'>";
+
// },
}
+
{
else if (row.medal.toUpperCase() == "SILVER") {
+
'data': function(row, type, val, meta) {
return "<img title='Silver Medal' src='https://igem.org/images/medals/seal_silver.png'>";
+
if (row.medal.toUpperCase() == "GOLD") {
}
+
return "<img title='Gold Medal' src='https://igem.org/images/medals/seal_gold.png'>";
else if (row.medal.toUpperCase() == "BRONZE") {
+
return "<img title='Bronze Medal' src='https://igem.org/images/medals/seal_bronze.png'>";
+
}
+
else if (row.medal.toUpperCase() == "NO MEDAL") {
+
return "<img title='No Medal' src='http://web.mit.edu/kdrinkwa/Public/Pictures/seal_transparent.png'>";
+
}
+
else {
+
return "<img title='Medal Data Not Available' src='https://igem.org/images/medals/seal_blocked.png'>";
+
}
+
 
}
 
}
},
+
else if (row.medal.toUpperCase() == "SILVER") {
//{'data': 'team_name', 'className': 'details-control'},
+
return "<img title='Silver Medal' src='https://igem.org/images/medals/seal_silver.png'>";
{
+
'data': function(row, type, val, meta) {
+
return "<a class='team-info-control' style='cursor: pointer;'>" + row.team_name + "</a>";
+
 
}
 
}
},
+
else if (row.medal.toUpperCase() == "BRONZE") {
{'data': 'award', 'defaultContent': ' '}
+
return "<img title='Bronze Medal' src='https://igem.org/images/medals/seal_bronze.png'>";
],
+
}
'order': [[1, 'asc']] //I think this sorts by team-name by default
+
else if (row.medal.toUpperCase() == "NO MEDAL") {
} );
+
return "<img title='No Medal' src='http://web.mit.edu/kdrinkwa/Public/Pictures/seal_transparent.png'>";
+
}
// Add event listener for opening and closing details
+
else {
$('#table_team tbody').on('click', 'a.team-info-control', function () {
+
return "<img title='Medal Data Not Available' src='https://igem.org/images/medals/seal_blocked.png'>";
var tr = $(this).closest('tr');
+
}
var row = t.row( tr );
+
}
+
},
if ( row.child.isShown() ) {
+
//{'data': 'team_name', 'className': 'details-control'},
// This row is already open - close it
+
{
row.child.hide();
+
'data': function(row, type, val, meta) {
tr.removeClass('shown');
+
return "<a class='team-info-control' style='cursor: pointer;'>" + row.team_name + "</a>";
}
+
}
else {
+
},
// Close any others
+
{'data': 'award', 'defaultContent': ' '}
t.row($("#table_team tbody").children(".shown").removeClass("shown")).child.hide();
+
],
// Open this row
+
'order': [[1, 'asc']] //I think this sorts by team-name by default
row.child( childRowFormat(row.data()) ).show();
+
} );
tr.addClass('shown');
+
}
+
// Add event listener for opening and closing details
} );
+
$('#table_team tbody').on('click', 'a.team-info-control', function () {
 +
var tr = $(this).closest('tr');
 +
var row = t.row( tr );
 +
 +
if ( row.child.isShown() ) {
 +
// This row is already open - close it
 +
row.child.hide();
 +
tr.removeClass('shown');
 +
}
 +
else {
 +
// Close any others
 +
t.row($("#table_team tbody").children(".shown").removeClass("shown")).child.hide();
 +
// Open this row
 +
row.child( childRowFormat(row.data()) ).show();
 +
tr.addClass('shown');
 +
}
 +
} );
  
jQuery('#table_team').addClass('hover'); //What's this?
+
jQuery('#table_team').addClass('hover'); //What's this?
+
}
+
 
});
 
});
 
 
  
 
});
 
});

Revision as of 20:32, 23 September 2015

Comprehensive Results from iGEM 2015

View: [All Teams] [Award Winners] | [Africa] [Asia] [Europe] [Latin America][other?]

Team Award