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> | Section: <b>' + data.section.capitalize() + '</b>' + | + | 'Track: <b>' + data.track + |
+ | '</b> | ' + | ||
+ | 'Region: <b>' + data.region + | ||
+ | '</b> | ' + | ||
+ | '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 | + | 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"); | ||
}, | }, | ||
− | + | }); | |
− | + | ||
− | + | //When both requests finish, parse the data and set up the table. | |
− | + | jQuery.when(teamsRequest, resultsRequest).done(function(teamsReqResult, awardsReqResult) { | |
− | + | var teamsData = teamsReqResult[0]; | |
− | + | var awardsData = awardsReqResult[0]; | |
− | + | var arrayOfTeamAwards = parseTeamsToAwards(awardsData, teamsData); | |
− | + | ||
− | + | //Initialize dataTable and set up event bindings. | |
− | + | var t = jQuery('#table_team').DataTable( { | |
− | + | 'lengthMenu': [[10, 25, 50, 100, -1],[10, 25, 50, 100, 'All']], | |
− | + | 'pageLength': -1, | |
− | + | //'deferRender': true, //improves performance | |
− | + | 'data': arrayOfTeamAwards, | |
− | + | 'columns': [ | |
− | + | // { //Child-table control element | |
− | + | // 'className': 'details-control', | |
− | + | // 'orderable': false, | |
− | + | // 'data': null, | |
− | + | // 'defaultContent': '' | |
− | + | // }, | |
− | + | { | |
− | + | 'data': function(row, type, val, meta) { | |
− | + | if (row.medal.toUpperCase() == "GOLD") { | |
− | + | return "<img title='Gold Medal' src='https://igem.org/images/medals/seal_gold.png'>"; | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
− | + | else if (row.medal.toUpperCase() == "SILVER") { | |
− | + | return "<img title='Silver Medal' src='https://igem.org/images/medals/seal_silver.png'>"; | |
− | + | ||
− | + | ||
− | return "< | + | |
} | } | ||
− | }, | + | else if (row.medal.toUpperCase() == "BRONZE") { |
− | {'data': 'award', 'defaultContent': ' '} | + | 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'>"; | |
− | + | } | |
− | + | } | |
− | + | }, | |
− | + | //{'data': 'team_name', 'className': 'details-control'}, | |
− | + | { | |
− | + | 'data': function(row, type, val, meta) { | |
− | + | return "<a class='team-info-control' style='cursor: pointer;'>" + row.team_name + "</a>"; | |
− | + | } | |
− | + | }, | |
− | + | {'data': 'award', 'defaultContent': ' '} | |
− | + | ], | |
− | + | 'order': [[1, 'asc']] //I think this sorts by team-name by default | |
− | + | } ); | |
− | + | ||
− | + | // 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? | |
− | + | ||
− | + | ||
}); | }); | ||
− | |||
− | |||
}); | }); |
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 |
---|