Skip to content

Instantly share code, notes, and snippets.

@jezhalford
Last active March 11, 2018 21:49
Show Gist options
  • Select an option

  • Save jezhalford/f689eb5b5cca129b3875e9cfe7c734cf to your computer and use it in GitHub Desktop.

Select an option

Save jezhalford/f689eb5b5cca129b3875e9cfe7c734cf to your computer and use it in GitHub Desktop.

Revisions

  1. jezhalford revised this gist Dec 15, 2016. No changes.
  2. jezhalford created this gist Dec 15, 2016.
    46 changes: 46 additions & 0 deletions grafana-text-panel-api.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    <!--
    Heavily based on https://github.com/grafana/grafana/issues/1816#issuecomment-137827966,
    with some simplification and modifications for newer version of Grafana
    -->
    <div>
    <script type="text/javascript">

    (function() {
    // get a reference to the result container (this is a div at the bottom of this script)
    var elem = $('#myPanel')

    function refreshMyPanel() {
    $.ajax({
    // api url and options...
    url: "http://example.com/api/query",
    jsonp: "callback",
    dataType: "jsonp",

    success: function( response ) {
    // show loading spinner...
    elem.parent().closest(".panel-container").find('.panel-loading').removeClass("ng-hide");

    // handle the response...
    elem.text(response);

    // hide loading spinner...
    setTimeout(function() { elem.parent().closest(".panel-container").find('.panel-loading').addClass("ng-hide"); }, 1000);
    }

    })
    }

    $(document).ready(function() {

    // initial load
    refreshMyPanel()

    // hook into the dashboard refresh event
    angular.element(elem).injector().get('$rootScope').$on('refresh', function() {
    refreshMyPanel()
    })
    });
    })();
    </script>
    <div id="myPanel" />
    </div>