injectorMonkeyPatch.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. export function monkeyPatchInjectorWithPreAssignedBindings(injector: any) {
  2. injector.oldInvoke = injector.invoke;
  3. injector.invoke = (fn: any, self: any, locals: any, serviceName: any) => {
  4. const parentScope = locals?.$scope?.$parent;
  5. if (parentScope) {
  6. // PanelCtrl
  7. if (parentScope.panel) {
  8. self.panel = parentScope.panel;
  9. }
  10. // Panels & dashboard SettingsCtrl
  11. if (parentScope.dashboard) {
  12. self.dashboard = parentScope.dashboard;
  13. }
  14. // Query editors
  15. if (parentScope.ctrl?.target) {
  16. self.panelCtrl = parentScope.ctrl;
  17. self.datasource = parentScope.ctrl.datasource;
  18. self.target = parentScope.ctrl.target;
  19. }
  20. // Data source ConfigCtrl
  21. if (parentScope.ctrl?.datasourceMeta) {
  22. self.meta = parentScope.ctrl.datasourceMeta;
  23. self.current = parentScope.ctrl.current;
  24. }
  25. // Data source AnnotationsQueryCtrl
  26. if (parentScope.ctrl?.currentAnnotation) {
  27. self.annotation = parentScope.ctrl.currentAnnotation;
  28. self.datasource = parentScope.ctrl.currentDatasource;
  29. }
  30. // App config ctrl
  31. if (parentScope.isAppConfigCtrl) {
  32. self.appEditCtrl = parentScope.ctrl;
  33. self.appModel = parentScope.ctrl.model;
  34. }
  35. // App page ctrl
  36. if (parentScope.$parent?.$parent?.ctrl?.appModel) {
  37. self.appModel = parentScope.$parent?.$parent?.ctrl?.appModel;
  38. }
  39. }
  40. return injector.oldInvoke(fn, self, locals, serviceName);
  41. };
  42. }