/*! grafana - v4.2.0 - 2017-03-24
 * Copyright (c) 2017 Torkel Ödegaard; Licensed Apache-2.0 */

System.register(["angular","lodash"],function(a,b){"use strict";var c,d,e,f,g;b&&b.id;return{setters:[function(a){c=a},function(a){d=a}],execute:function(){e=c.default.module("grafana.directives"),f='\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"\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',g=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({value:this.current.name,selectMode:!0})}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=d.default.find(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",g),e.directive("metricsDsSelector",function(){return{restrict:"E",template:f,controller:g,bindToController:!0,controllerAs:"ctrl",transclude:!0,scope:{panelCtrl:"="}}})}}});