{"size": 7834, "ext": "js", "max_stars_repo_path": "public/app/plugins/datasource/influxdb/query_ctrl.js", "max_stars_repo_name": "Inspur-ocata/grafana-source", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "public/app/plugins/datasource/influxdb/query_ctrl.js", "max_issues_repo_name": "Inspur-ocata/grafana-source", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "public/app/plugins/datasource/influxdb/query_ctrl.js", "max_forks_repo_name": "Inspur-ocata/grafana-source", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 1958.5, "max_line_length": 7737, "alphanum_fraction": 0.7561909625}
/*! grafana - v4.2.0 - 2017-03-22
 * Copyright (c) 2017 Torkel Ödegaard; Licensed Apache-2.0 */

System.register(["angular","lodash","./query_builder","./influx_query","./query_part","app/plugins/sdk"],function(a,b){"use strict";var c,d,e,f,g,h,i,j=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){c=a},function(a){d=a},function(a){e=a},function(a){f=a},function(a){g=a},function(a){h=a}],execute:function(){i=function(a){function b(b,c,d,g,h){var i=a.call(this,b,c)||this;i.templateSrv=d,i.$q=g,i.uiSegmentSrv=h,i.target=i.target,i.queryModel=new f.default(i.target,d,i.panel.scopedVars),i.queryBuilder=new e.default(i.target,i.datasource.database),i.groupBySegment=i.uiSegmentSrv.newPlusButton(),i.resultFormats=[{text:"Time series",value:"time_series"},{text:"Table",value:"table"}],i.policySegment=h.newSegment(i.target.policy),i.target.measurement?i.measurementSegment=h.newSegment(i.target.measurement):i.measurementSegment=h.newSelectMeasurement(),i.tagSegments=[];for(var j=0,k=i.target.tags;j<k.length;j++){var l=k[j];l.operator||(/^\/.*\/$/.test(l.value)?l.operator="=~":l.operator="="),l.condition&&i.tagSegments.push(h.newCondition(l.condition)),i.tagSegments.push(h.newKey(l.key)),i.tagSegments.push(h.newOperator(l.operator)),i.tagSegments.push(h.newKeyValue(l.value))}return i.fixTagSegments(),i.buildSelectMenu(),i.removeTagFilterSegment=h.newSegment({fake:!0,value:"-- remove tag filter --"}),i}return j(b,a),b.$inject=["$scope","$injector","templateSrv","$q","uiSegmentSrv"],b.prototype.buildSelectMenu=function(){var a=g.default.getCategories();this.selectMenu=d.default.reduce(a,function(a,b,c){var d={text:c,submenu:b.map(function(a){return{text:a.type,value:a.type}})};return a.push(d),a},[])},b.prototype.getGroupByOptions=function(){var a=this,b=this.queryBuilder.buildExploreQuery("TAG_KEYS");return this.datasource.metricFindQuery(b).then(function(b){var c=[];a.queryModel.hasFill()||c.push(a.uiSegmentSrv.newSegment({value:"fill(null)"})),a.queryModel.hasGroupByTime()||c.push(a.uiSegmentSrv.newSegment({value:"time($interval)"}));for(var d=0,e=b;d<e.length;d++){var f=e[d];c.push(a.uiSegmentSrv.newSegment({value:"tag("+f.text+")"}))}return c}).catch(this.handleQueryError.bind(this))},b.prototype.groupByAction=function(){this.queryModel.addGroupBy(this.groupBySegment.value);var a=this.uiSegmentSrv.newPlusButton();this.groupBySegment.value=a.value,this.groupBySegment.html=a.html,this.panelCtrl.refresh()},b.prototype.addSelectPart=function(a,b,c){this.queryModel.addSelectPart(a,c.value),this.panelCtrl.refresh()},b.prototype.handleSelectPartEvent=function(a,b,c){switch(c.name){case"get-param-options":var d=this.queryBuilder.buildExploreQuery("FIELDS");return this.datasource.metricFindQuery(d).then(this.transformToSegments(!0)).catch(this.handleQueryError.bind(this));case"part-param-changed":this.panelCtrl.refresh();break;case"action":this.queryModel.removeSelectPart(a,b),this.panelCtrl.refresh();break;case"get-part-actions":return this.$q.when([{text:"Remove",value:"remove-part"}])}},b.prototype.handleGroupByPartEvent=function(a,b,c){switch(c.name){case"get-param-options":var d=this.queryBuilder.buildExploreQuery("TAG_KEYS");return this.datasource.metricFindQuery(d).then(this.transformToSegments(!0)).catch(this.handleQueryError.bind(this));case"part-param-changed":this.panelCtrl.refresh();break;case"action":this.queryModel.removeGroupByPart(a,b),this.panelCtrl.refresh();break;case"get-part-actions":return this.$q.when([{text:"Remove",value:"remove-part"}])}},b.prototype.fixTagSegments=function(){var a=this.tagSegments.length,b=this.tagSegments[Math.max(a-1,0)];b&&"plus-button"===b.type||this.tagSegments.push(this.uiSegmentSrv.newPlusButton())},b.prototype.measurementChanged=function(){this.target.measurement=this.measurementSegment.value,this.panelCtrl.refresh()},b.prototype.getPolicySegments=function(){var a=this.queryBuilder.buildExploreQuery("RETENTION POLICIES");return this.datasource.metricFindQuery(a).then(this.transformToSegments(!1)).catch(this.handleQueryError.bind(this))},b.prototype.policyChanged=function(){this.target.policy=this.policySegment.value,this.panelCtrl.refresh()},b.prototype.toggleEditorMode=function(){try{this.target.query=this.queryModel.render(!1)}catch(a){console.log("query render error")}this.target.rawQuery=!this.target.rawQuery},b.prototype.getMeasurements=function(a){var b=this.queryBuilder.buildExploreQuery("MEASUREMENTS",void 0,a);return this.datasource.metricFindQuery(b).then(this.transformToSegments(!0)).catch(this.handleQueryError.bind(this))},b.prototype.handleQueryError=function(a){return this.error=a.message||"Failed to issue metric query",[]},b.prototype.transformToSegments=function(a){var b=this;return function(c){var e=d.default.map(c,function(a){return b.uiSegmentSrv.newSegment({value:a.text,expandable:a.expandable})});if(a)for(var f=0,g=b.templateSrv.variables;f<g.length;f++){var h=g[f];e.unshift(b.uiSegmentSrv.newSegment({type:"template",value:"/^$"+h.name+"$/",expandable:!0}))}return e}},b.prototype.getTagsOrValues=function(a,b){var d=this;if("condition"===a.type)return this.$q.when([this.uiSegmentSrv.newSegment("AND"),this.uiSegmentSrv.newSegment("OR")]);if("operator"===a.type){var e=this.tagSegments[b+1].value;return/^\/.*\/$/.test(e)?this.$q.when(this.uiSegmentSrv.newOperators(["=~","!~"])):this.$q.when(this.uiSegmentSrv.newOperators(["=","!=","<>","<",">"]))}var f,g;return"key"===a.type||"plus-button"===a.type?(f=this.queryBuilder.buildExploreQuery("TAG_KEYS"),g=!1):"value"===a.type&&(f=this.queryBuilder.buildExploreQuery("TAG_VALUES",this.tagSegments[b-2].value),g=!0),this.datasource.metricFindQuery(f).then(this.transformToSegments(g)).then(function(b){return"key"===a.type&&b.splice(0,0,c.default.copy(d.removeTagFilterSegment)),b}).catch(this.handleQueryError.bind(this))},b.prototype.getFieldSegments=function(){var a=this.queryBuilder.buildExploreQuery("FIELDS");return this.datasource.metricFindQuery(a).then(this.transformToSegments(!1)).catch(this.handleQueryError)},b.prototype.tagSegmentUpdated=function(a,b){this.tagSegments[b]=a,a.value===this.removeTagFilterSegment.value?(this.tagSegments.splice(b,3),0===this.tagSegments.length?this.tagSegments.push(this.uiSegmentSrv.newPlusButton()):this.tagSegments.length>2&&(this.tagSegments.splice(Math.max(b-1,0),1),"plus-button"!==this.tagSegments[this.tagSegments.length-1].type&&this.tagSegments.push(this.uiSegmentSrv.newPlusButton()))):("plus-button"===a.type&&(b>2&&this.tagSegments.splice(b,0,this.uiSegmentSrv.newCondition("AND")),this.tagSegments.push(this.uiSegmentSrv.newOperator("=")),this.tagSegments.push(this.uiSegmentSrv.newFake("select tag value","value","query-segment-value")),a.type="key",a.cssClass="query-segment-key"),b+1===this.tagSegments.length&&this.tagSegments.push(this.uiSegmentSrv.newPlusButton())),this.rebuildTargetTagConditions()},b.prototype.rebuildTargetTagConditions=function(){var a=this,b=[],c=0,e="";d.default.each(this.tagSegments,function(d,f){"key"===d.type?(0===b.length&&b.push({}),b[c].key=d.value):"value"===d.type?(e=a.getTagValueOperator(d.value,b[c].operator),e&&(a.tagSegments[f-1]=a.uiSegmentSrv.newOperator(e),b[c].operator=e),b[c].value=d.value):"condition"===d.type?(b.push({condition:d.value}),c+=1):"operator"===d.type&&(b[c].operator=d.value)}),this.target.tags=b,this.panelCtrl.refresh()},b.prototype.getTagValueOperator=function(a,b){return"=~"!==b&&"!~"!==b&&/^\/.*\/$/.test(a)?"=~":"=~"!==b&&"!~"!==b||!/^(?!\/.*\/$)/.test(a)?void 0:"="},b.prototype.getCollapsedText=function(){return this.queryModel.render(!1)},b}(h.QueryCtrl),i.templateUrl="partials/query.editor.html",a("InfluxQueryCtrl",i)}}});