$profiler = $("
").appendTo document.body
$toolbar = $('').appendTo $profiler
$('')
.click (e) ->
e.preventDefault()
$(document.body).toggleClass 'profiler-open'
.appendTo $toolbar
$('Clear')
.click (e) ->
e.preventDefault()
$profiler.find('.requests').empty()
.appendTo $toolbar
$requestItems = $("").appendTo $profiler
appendRequest = (method, url, req) ->
$requestItem = $("")
$requestHeader = ($("")).appendTo $requestItem
($("").text method).appendTo $requestHeader
($("").text url).appendTo $requestHeader
$logItems = $("").appendTo $requestItem
for logItem in req.request.log
$liItem = $("- ")
$("")
.html(logItem.message)
.click () ->
$(this).toggleClass 'open'
.appendTo($liItem)
$("").appendTo $liItem
$liItem.appendTo $logItems
for query in req.request.queries
$liItem = $("
- ")
($("").text query.time).appendTo $liItem
$("")
.html(prettyPrintOne(query.query, 'lang-sql'))
.click () ->
$(this).toggleClass 'open'
.appendTo($liItem)
$("").appendTo $liItem
$liItem.appendTo $logItems
$requestItem.appendTo $requestItems
$requestItems.animate {scrollTop: $requestItems[0].scrollHeight}, 300
oldOpen = XMLHttpRequest.prototype.open
XMLHttpRequest.prototype.open = (method, url) ->
intercept = =>
return if this.readyState != 4
return if !this.getResponseHeader('X-Request-Id')
id = this.getResponseHeader('X-Request-Id')
$.getJSON('/api/web/profiler/' + id).done (res) -> appendRequest method, url, res
(this.addEventListener "readystatechange", intercept, false) if url.indexOf('/api/web/profiler/') == -1
oldOpen.apply this, arguments