var triggerError = attachErrorHandler('runtimeViewer', true); var decoder = decodeURIComponent || unescape; $(document).ready(function() { var runtimes = null; var loading = true; var viewingDetails = false; var occurrences = {}; var $wrap = $('#runtime-wrap'); var $header = $('#runtime-header'); var $list = $('#runtime-list'); var $details = $('#runtime-details'); /*********************** * METHODS ***********************/ //At some point the json is gonna be fucked up ok function parseRuntimes(json) { try { runtimes = $.parseJSON(json); } catch(e) { triggerError('JSON parse error: ' + e + '. For runtime data: ' + json); return } } //Actually builds the main list of runtimes, while building secondary datasets at the same time function buildView() { var count = 0; occurrences = {}; $list.empty(); $.each(runtimes, function(key, run) { var row = null; if (run.invalid) { row = $('
  • ', {'class': 'runtime runtime-invalid well'}).append( $('', {'class': 'seen', text: '[' + run.seen + ']'}), ' Invalid exception in error handler: ', $('', {'class': 'name', text: run.name}) ); } else { row = $('
  • ', {'class': 'runtime well'}).append( $('', {'class': 'seen', text: '[' + run.seen + ']'}), ' In ', $('', {'class': 'file', text: run.file}), ', line ', $('', {'class': 'line', text: run.line}), ': ', $('', {'class': 'name', text: run.name}) ); if (run.desc) { row.append( $('', {'class': 'desc', html: run.desc}) ); } var uid = run.file + run.line + run.name; if (typeof occurrences[uid] !== 'undefined') { occurrences[uid]++; } else { occurrences[uid] = 1; } } $list.prepend(row); count++; }); $header.find('.total-runtimes').text(count); $('#content').nanoScroller(); //refreshes scrollbar for new height loading = false; } //Byond hits this via error_handling.dm window.refreshRuntimes = function(json) { if (!json) { triggerError('Got no json in refreshRuntimes'); return; } loading = true; parseRuntimes(decoder(json)); buildView(); }; /*********************** * EVENTS ***********************/ //Trigger refresh $header.on('click', '.refresh', function() { if (loading) { return; } if (viewingDetails) { $details.hide(); $list.show(); viewingDetails = false; } $list.html( $('
  • ', {'class': 'loading well', text: 'Loading...'}) ); window.location = '?action=getRuntimeData'; }); //Show details view $list.on('click', '.runtime:not(.runtime-invalid)', function() { if (loading || viewingDetails) { return; } viewingDetails = true; var $this = $(this); var file = $this.find('.file').text(); var line = $this.find('.line').text(); var name = $this.find('.name').text(); var uid = file + line + name; var details = '

    Summary

    '; details += 'This runtime has occurred ' + occurrences[uid] + ' times.

    '; details += ''; details += ''; details += ''; details += ''; details += '
    File' + file + '
    Line' + line + '
    Error' + name + '
    '; details += '

    Description

    '; details += '
    ' + $this.find('.desc').html() + '
    '; $details.find('.details').html(details); $list.hide(); $details.show(); $('#content').nanoScroller(); //refreshes scrollbar for new height }); //Hide details view $details.on('click', '.back', function() { $details.hide(); $list.show(); $('#content').nanoScroller(); //refreshes scrollbar for new height viewingDetails = false; }); /*********************** * INIT ***********************/ window.location = '?action=getRuntimeData'; });