dashboard_selector.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. ///<reference path="../../headers/common.d.ts" />
  2. import config from 'app/core/config';
  3. import _ from 'lodash';
  4. import $ from 'jquery';
  5. import coreModule from 'app/core/core_module';
  6. var template = `
  7. <select class="gf-form-input" ng-model="ctrl.model" ng-options="f.value as f.text for f in ctrl.options"></select>
  8. <info-popover mode="right-absolute">
  9. Not finding dashboard you want? Star it first, then it should appear in this select box.
  10. </info-popover>
  11. `;
  12. export class DashboardSelectorCtrl {
  13. model: any;
  14. options: any;
  15. /** @ngInject */
  16. constructor(private backendSrv) {
  17. }
  18. $onInit() {
  19. this.options = [{value: 0, text: 'Default'}];
  20. return this.backendSrv.search({starred: true}).then(res => {
  21. res.forEach(dash => {
  22. this.options.push({value: dash.id, text: dash.title});
  23. });
  24. });
  25. }
  26. }
  27. export function dashboardSelector() {
  28. return {
  29. restrict: 'E',
  30. controller: DashboardSelectorCtrl,
  31. bindToController: true,
  32. controllerAs: 'ctrl',
  33. template: template,
  34. scope: {
  35. model: '='
  36. }
  37. };
  38. }
  39. coreModule.directive('dashboardSelector', dashboardSelector);