/*! grafana - v4.5.1 - 2017-09-19
 * Copyright (c) 2017 Torkel Ödegaard; Licensed Apache-2.0 */

System.register(["remarkable"],function(a,b){"use strict";function c(){return{restrict:"E",scope:!0,templateUrl:"public/app/features/panel/partials/metrics_tab.html",controller:e}}b&&b.id;a("metricsTabDirective",c);var d,e;return{setters:[function(a){d=a}],execute:function(){e=function(){function a(a,b,c,d,e){this.$sce=b,this.datasourceSrv=c,this.backendSrv=d,this.$timeout=e,this.panelCtrl=a.ctrl,a.ctrl=this,this.panel=this.panelCtrl.panel,this.dashboard=this.panelCtrl.dashboard,this.datasources=c.getMetricSources(),this.panelDsValue=this.panelCtrl.panel.datasource;for(var f=0,g=this.datasources;f<g.length;f++){var h=g[f];h.value===this.panelDsValue&&(this.datasourceInstance=h)}this.addQueryDropdown={text:"Add Query",value:null,fake:!0},this.panelCtrl.nextRefId=this.dashboard.getNextQueryLetter(this.panel),this.updateDatasourceOptions()}return a.$inject=["$scope","$sce","datasourceSrv","backendSrv","$timeout"],a.prototype.updateDatasourceOptions=function(){this.datasourceInstance&&(this.hasQueryHelp=this.datasourceInstance.meta.hasQueryHelp,this.queryOptions=this.datasourceInstance.meta.queryOptions)},a.prototype.getOptions=function(a){return Promise.resolve(this.datasources.filter(function(b){return a||!b.meta.builtIn}).map(function(a){return{value:a.value,text:a.name,datasource:a}}))},a.prototype.datasourceChanged=function(a){a&&(this.datasourceInstance=a.datasource,this.panelCtrl.setDatasource(a.datasource),this.updateDatasourceOptions())},a.prototype.addMixedQuery=function(a){if(a){this.panelCtrl.addQuery({isNew:!0,datasource:a.datasource.name}),this.addQueryDropdown={text:"Add Query",value:null,fake:!0}}},a.prototype.addQuery=function(){this.panelCtrl.addQuery({isNew:!0})},a.prototype.toggleHelp=function(){var a=this;this.optionsOpen=!1,this.queryTroubleshooterOpen=!1,this.helpOpen=!this.helpOpen,this.backendSrv.get("/api/plugins/"+this.datasourceInstance.meta.id+"/markdown/query_help").then(function(b){var c=new d.default;a.helpHtml=a.$sce.trustAsHtml(c.render(b))})},a.prototype.toggleOptions=function(){this.helpOpen=!1,this.queryTroubleshooterOpen=!1,this.optionsOpen=!this.optionsOpen},a.prototype.toggleQueryTroubleshooter=function(){this.helpOpen=!1,this.optionsOpen=!1,this.queryTroubleshooterOpen=!this.queryTroubleshooterOpen},a}(),a("MetricsTabCtrl",e)}}});