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

System.register(["angular","lodash","app/plugins/sdk","./completer"],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){c=a},function(a){d=a},function(a){e=a},function(a){f=a}],execute:function(){g=function(a){function b(b,c,e){var f=a.call(this,b,c)||this;f.templateSrv=e;var g=f.target;return g.expr=g.expr||"",g.intervalFactor=g.intervalFactor||2,g.format=g.format||f.getDefaultFormat(),f.metric="",f.resolutions=d.default.map([1,2,3,4,5,10],function(a){return{factor:a,label:"1/"+a}}),f.formats=[{text:"Time series",value:"time_series"},{text:"Table",value:"table"}],f.updateLink(),f}return h(b,a),b.$inject=["$scope","$injector","templateSrv"],b.prototype.getCompleter=function(a){return new f.PromCompleter(this.datasource)},b.prototype.getDefaultFormat=function(){return"table"===this.panelCtrl.panel.type?"table":"time_series"},b.prototype.refreshMetricData=function(){d.default.isEqual(this.oldTarget,this.target)||(this.oldTarget=c.default.copy(this.target),this.panelCtrl.refresh(),this.updateLink())},b.prototype.updateLink=function(){var a=this.panelCtrl.range;if(a){var b=Math.ceil((a.to.valueOf()-a.from.valueOf())/1e3),c=a.to.utc().format("YYYY-MM-DD HH:mm"),e={"g0.expr":this.templateSrv.replace(this.target.expr,this.panelCtrl.panel.scopedVars,this.datasource.interpolateQueryExpr),"g0.range_input":b+"s","g0.end_input":c,"g0.step_input":this.target.step,"g0.stacked":this.panelCtrl.panel.stack?1:0,"g0.tab":0},f=d.default.map(e,function(a,b){return b+"="+encodeURIComponent(a)}).join("&");this.linkToPrometheus=this.datasource.directUrl+"/graph?"+f}},b.prototype.getCollapsedText=function(){return this.target.expr},b.templateUrl="partials/query.editor.html",b}(e.QueryCtrl),a("PrometheusQueryCtrl",g)}}});