dashboard_selector.ts 1.0 KB

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