# Pony.fm - A community for pony fan music. # Copyright (C) 2015 Peter Deltchev # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . $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 queryText = query.query for binding in query.bindings queryText = queryText.replace '?', '"' + binding + '"' $liItem = $("
    • ") ($("").text query.time).appendTo $liItem $("

      ") .html(prettyPrintOne(queryText, '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