dashboard_selector.ts 856 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import coreModule from 'app/core/core_module';
  2. const template = `
  3. <select class="gf-form-input" ng-model="ctrl.model" ng-options="f.value as f.text for f in ctrl.options"></select>
  4. `;
  5. export class DashboardSelectorCtrl {
  6. model: any;
  7. options: any;
  8. /** @ngInject */
  9. constructor(private backendSrv) {}
  10. $onInit() {
  11. this.options = [{ value: 0, text: 'Default' }];
  12. return this.backendSrv.search({ starred: true }).then(res => {
  13. res.forEach(dash => {
  14. this.options.push({ value: dash.id, text: dash.title });
  15. });
  16. });
  17. }
  18. }
  19. export function dashboardSelector() {
  20. return {
  21. restrict: 'E',
  22. controller: DashboardSelectorCtrl,
  23. bindToController: true,
  24. controllerAs: 'ctrl',
  25. template: template,
  26. scope: {
  27. model: '=',
  28. },
  29. };
  30. }
  31. coreModule.directive('dashboardSelector', dashboardSelector);