/*! grafana - v4.5.1 - 2017-09-19
 * 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(){var a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,b){a.__proto__=b}||function(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c])};return function(b,c){function d(){this.constructor=b}a(b,c),b.prototype=null===c?Object.create(c):(d.prototype=c.prototype,new d)}}();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);this.rawQueryOld&&a!==this.rawQueryOld&&this.refresh(),this.rawQueryOld=a,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.templateUrl="partials/query.editor.html",b}(f.QueryCtrl),a("ElasticQueryCtrl",g)}}});