/*! grafana - v4.2.0 - 2017-03-24
 * Copyright (c) 2017 Torkel Ödegaard; Licensed Apache-2.0 */

System.register(["./bucket_agg","./metric_agg","angular","lodash","./query_def","app/plugins/sdk"],function(a,b){"use strict";var c,d,e,f,g,h=this&&this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);a.prototype=null===b?Object.create(b):(c.prototype=b.prototype,new c)};b&&b.id;return{setters:[function(a){},function(a){},function(a){c=a},function(a){d=a},function(a){e=a},function(a){f=a}],execute:function(){g=function(a){function b(b,c,d,e,f){var g=a.call(this,b,c)||this;return g.$rootScope=d,g.$timeout=e,g.uiSegmentSrv=f,g.esVersion=g.datasource.esVersion,g.queryUpdated(),g}return h(b,a),b.$inject=["$scope","$injector","$rootScope","$timeout","uiSegmentSrv"],b.prototype.getFields=function(a){var b=c.default.toJson({find:"fields",type:a});return this.datasource.metricFindQuery(b).then(this.uiSegmentSrv.transformToSegments(!1)).catch(this.handleQueryError.bind(this))},b.prototype.queryUpdated=function(){var a=c.default.toJson(this.datasource.queryBuilder.build(this.target),!0);a!==this.rawQueryOld&&(this.rawQueryOld=a,this.refresh()),this.$rootScope.appEvent("elastic-query-updated")},b.prototype.getCollapsedText=function(){var a=this.target.metrics,b=this.target.bucketAggs,c=e.default.getMetricAggTypes(this.esVersion),f=e.default.bucketAggTypes,g="";return this.target.query&&(g+="Query: "+this.target.query+", "),g+="Metrics: ",d.default.each(a,function(a,b){var e=d.default.find(c,{value:a.type});g+=e.text+"(",e.requiresField&&(g+=a.field),g+="), "}),d.default.each(b,function(a,b){0===b&&(g+=" Group by: ");var c=d.default.find(f,{value:a.type});g+=c.text+"(",c.requiresField&&(g+=a.field),g+="), "}),this.target.alias&&(g+="Alias: "+this.target.alias),g},b.prototype.handleQueryError=function(a){return this.error=a.message||"Failed to issue metric query",[]},b}(f.QueryCtrl),g.templateUrl="partials/query.editor.html",a("ElasticQueryCtrl",g)}}});