module.ts 2.2 KB

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