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

System.register(["angular","lodash"],function(a){var b,c,d,e,f;return{setters:[function(a){b=a},function(a){c=a}],execute:function(){d=b["default"].module("grafana.directives"),e='\n<div class="gf-form-group">\n  <div class="gf-form-inline">\n    <div class="gf-form">\n      <label class="gf-form-label">\n        <i class="icon-gf icon-gf-datasources"></i>\n      </label>\n      <label class="gf-form-label">\n        Panel data source\n      </label>\n\n      <metric-segment segment="ctrl.dsSegment" style-mode="select"\n                      get-options="ctrl.getOptions()"\n                      on-change="ctrl.datasourceChanged()"></metric-segment>\n    </div>\n\n    <div class="gf-form gf-form--offset-1">\n      <button class="btn btn-inverse gf-form-btn" ng-click="ctrl.addDataQuery()" ng-hide="ctrl.current.meta.mixed">\n        <i class="fa fa-plus"></i>&nbsp;\n        Add query\n      </button>\n\n      <div class="dropdown" ng-if="ctrl.current.meta.mixed">\n        <button class="btn btn-inverse dropdown-toggle gf-form-btn" data-toggle="dropdown">\n          Add Query&nbsp;<span class="fa fa-caret-down"></span>\n        </button>\n\n        <ul class="dropdown-menu" role="menu">\n          <li ng-repeat="datasource in ctrl.datasources" role="menuitem" ng-hide="datasource.meta.builtIn">\n            <a ng-click="ctrl.addDataQuery(datasource);">{{datasource.name}}</a>\n          </li>\n        </ul>\n      </div>\n    </div>\n  </div>\n</div>\n',f=function(){function a(a,b){this.uiSegmentSrv=a,this.datasources=b.getMetricSources();for(var c=this.panelCtrl.panel.datasource||null,d=0,e=this.datasources;d<e.length;d++){var f=e[d];f.value===c&&(this.current=f)}this.current||(this.current={name:c+" not found",value:null}),this.dsSegment=a.newSegment(this.current.name)}return a.$inject=["uiSegmentSrv","datasourceSrv"],a.prototype.getOptions=function(){var a=this;return Promise.resolve(this.datasources.map(function(b){return a.uiSegmentSrv.newSegment(b.name)}))},a.prototype.datasourceChanged=function(){var a=c["default"].findWhere(this.datasources,{name:this.dsSegment.value});a&&(this.current=a,this.panelCtrl.setDatasource(a))},a.prototype.addDataQuery=function(a){var b={isNew:!0};a&&(b.datasource=a.name),this.panelCtrl.panel.targets.push(b)},a}(),a("MetricsDsSelectorCtrl",f),d.directive("metricsDsSelector",function(){return{restrict:"E",template:e,controller:f,bindToController:!0,controllerAs:"ctrl",transclude:!0,scope:{panelCtrl:"="}}})}}});