/*! grafana - v3.1.0 - 2016-07-18
 * Copyright (c) 2016 Torkel Ödegaard; Licensed Apache-2.0 */

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