module.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import _ from 'lodash';
  2. import { PanelCtrl } from '../../../features/panel/panel_ctrl';
  3. import { auto } from 'angular';
  4. import { BackendSrv } from '@grafana/runtime';
  5. class PluginListCtrl extends PanelCtrl {
  6. static templateUrl = 'module.html';
  7. static scrollable = true;
  8. pluginList: any[];
  9. viewModel: any;
  10. // Set and populate defaults
  11. panelDefaults = {};
  12. /** @ngInject */
  13. constructor($scope: any, $injector: auto.IInjectorService, private backendSrv: BackendSrv) {
  14. super($scope, $injector);
  15. _.defaults(this.panel, this.panelDefaults);
  16. this.events.on('init-edit-mode', this.onInitEditMode.bind(this));
  17. this.pluginList = [];
  18. this.viewModel = [
  19. { header: 'Installed Apps', list: [], type: 'app' },
  20. { header: 'Installed Panels', list: [], type: 'panel' },
  21. { header: 'Installed Datasources', list: [], type: 'datasource' },
  22. ];
  23. this.update();
  24. }
  25. onInitEditMode() {
  26. this.addEditorTab('Options', 'public/app/plugins/panel/pluginlist/editor.html');
  27. }
  28. gotoPlugin(plugin: { id: any }, evt: any) {
  29. if (evt) {
  30. evt.stopPropagation();
  31. }
  32. this.$location.url(`plugins/${plugin.id}/edit`);
  33. }
  34. updateAvailable(plugin: any, $event: any) {
  35. $event.stopPropagation();
  36. $event.preventDefault();
  37. const modalScope = this.$scope.$new(true);
  38. modalScope.plugin = plugin;
  39. this.publishAppEvent('show-modal', {
  40. src: 'public/app/features/plugins/partials/update_instructions.html',
  41. scope: modalScope,
  42. });
  43. }
  44. update() {
  45. this.backendSrv.get('api/plugins', { embedded: 0, core: 0 }).then(plugins => {
  46. this.pluginList = plugins;
  47. this.viewModel[0].list = _.filter(plugins, { type: 'app' });
  48. this.viewModel[1].list = _.filter(plugins, { type: 'panel' });
  49. this.viewModel[2].list = _.filter(plugins, { type: 'datasource' });
  50. for (const plugin of this.pluginList) {
  51. if (plugin.hasUpdate) {
  52. plugin.state = 'has-update';
  53. } else if (!plugin.enabled) {
  54. plugin.state = 'not-enabled';
  55. }
  56. }
  57. });
  58. }
  59. }
  60. export { PluginListCtrl, PluginListCtrl as PanelCtrl };