Difference between revisions of "Dev/Results"

(tweaked child row)
(New data source. One row per team*award. everything's different now)
Line 18: Line 18:
 
<script>
 
<script>
  
 +
//Request the awards data
 +
var resultsRequest = jQuery.ajax({
 +
url: 'https://igem.org/awards/json_dump.cgi',
 +
type: 'GET',
 +
timeout: 30000,
 +
dataType: "json",
 +
error: function(jqxhr, textStatus, errorThrown) {
 +
alert("AJAX error; look at var resultsRequest");
 +
},
 +
success: function(data, textStatus, jqxhr) {
 +
console.log("successfully got team award data, now parsing");
 +
var arrayOfTeamAwards = parseTeamsToAwards(data);
 +
}
 +
});
 +
 +
 +
//Helper function
 
String.prototype.capitalize = function() {
 
String.prototype.capitalize = function() {
 
     return this.charAt(0).toUpperCase() + this.slice(1);
 
     return this.charAt(0).toUpperCase() + this.slice(1);
Line 38: Line 55:
 
}
 
}
  
 +
//Accepts an array of team objects and reorganizes it into an array of team*awards (incl no-awards)
 +
function parseTeamsToAwards(arrayOfTeams) {
 +
var arrayOfTeamAwards = [];
 +
arrayOfTeams.forEach(function(teamObj, index, array) {
 +
//Take care of any teams that didn't win any awards
 +
if (teamObj.awards.length == 0) {
 +
teamObj.awards.push(null);
 +
}
 +
awards.forEach(function(award) {
 +
var teamAwardObj = jQuery.extend({}, teamObj); //copy the team object
 +
delete teamAwardObj.awards; //delete the array of awards
 +
teamAwardObj.award = award; //add the one award back
 +
arrayOfTeamAwards.push(teamAwardObj); //and put the team*award on the list to return
 +
});
 +
});
 +
}
 +
 +
 +
//Initialize dataTable and set up event bindings. **Move this to after the data request comes back and document is ready.
 
jQuery(document).ready(function() {
 
jQuery(document).ready(function() {
var t = jQuery('#table_team').DataTable( {
+
// var t = jQuery('#table_team').DataTable( {
'lengthMenu': [[10, 25, 50, 100, -1],[10, 25, 50, 100, 'All']],
+
// 'lengthMenu': [[10, 25, 50, 100, -1],[10, 25, 50, 100, 'All']],
'pageLength': -1,
+
// 'pageLength': -1,
'deferRender': true, //improves performance
+
// 'deferRender': true, //improves performance
'ajax': {
+
// // 'ajax': {
'url': 'https://igem.org/awards/json_dump.cgi',
+
// // 'url': 'https://igem.org/awards/json_dump.cgi',
'dataSrc': ''
+
// // 'dataSrc': ''
},
+
// // },
'columns': [
+
// //CHANGE DATA SOURCE
{ //Child-table control element
+
// 'columns': [
'className': 'details-control',
+
// { //Child-table control element
'orderable': false,
+
// 'className': 'details-control',
'data': null,
+
// 'orderable': false,
'defaultContent': ''
+
// 'data': null,
},
+
// 'defaultContent': ''
{'data': 'team_name'},
+
// },
{'data': 'region'},
+
// {'data': 'team_name'},
{'data': 'medal',}
+
// {'data': 'region'},
],
+
// {'data': 'medal',}
'order': [[1, 'asc']] //This came in with the child-table control element but I don't know why
+
// ],
} );
+
// 'order': [[1, 'asc']] //I think this sorts by team-name by default
 +
// } );
 
 
// Add event listener for opening and closing details
+
// // Add event listener for opening and closing details
$('#table_team tbody').on('click', 'td.details-control', function () {
+
// $('#table_team tbody').on('click', 'td.details-control', function () {
var tr = $(this).closest('tr');
+
// var tr = $(this).closest('tr');
var row = t.row( tr );
+
// var row = t.row( tr );
 
   
 
   
if ( row.child.isShown() ) {
+
// if ( row.child.isShown() ) {
// This row is already open - close it
+
// // This row is already open - close it
row.child.hide();
+
// row.child.hide();
tr.removeClass('shown');
+
// tr.removeClass('shown');
}
+
// }
else {
+
// else {
// Open this row
+
// // Open this row
row.child( childRowFormat(row.data()) ).show();
+
// row.child( childRowFormat(row.data()) ).show();
tr.addClass('shown');
+
// tr.addClass('shown');
}
+
// }
} );
+
// } );
  
jQuery('#table_team').addClass('hover');
+
// jQuery('#table_team').addClass('hover');
  
 
});
 
});

Revision as of 18:28, 23 September 2015

Comprehensive Results from iGEM 2015

View: [All Teams] [Award Winners] [other?]

Team Region Medal