module.ts 1.9 KB

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