module.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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, private $location) {
  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.editorTabIndex = 1;
  25. this.addEditorTab('Options', 'public/app/plugins/panel/pluginlist/editor.html');
  26. }
  27. gotoPlugin(plugin, evt) {
  28. if (evt) {
  29. evt.stopPropagation();
  30. }
  31. this.$location.url(`plugins/${plugin.id}/edit`);
  32. }
  33. updateAvailable(plugin, $event) {
  34. $event.stopPropagation();
  35. $event.preventDefault();
  36. var modalScope = this.$scope.$new(true);
  37. modalScope.plugin = plugin;
  38. this.publishAppEvent('show-modal', {
  39. src: 'public/app/features/plugins/partials/update_instructions.html',
  40. scope: modalScope,
  41. });
  42. }
  43. update() {
  44. this.backendSrv.get('api/plugins', { embedded: 0, core: 0 }).then(plugins => {
  45. this.pluginList = plugins;
  46. this.viewModel[0].list = _.filter(plugins, { type: 'app' });
  47. this.viewModel[1].list = _.filter(plugins, { type: 'panel' });
  48. this.viewModel[2].list = _.filter(plugins, { type: 'datasource' });
  49. for (let plugin of this.pluginList) {
  50. if (plugin.hasUpdate) {
  51. plugin.state = 'has-update';
  52. } else if (!plugin.enabled) {
  53. plugin.state = 'not-enabled';
  54. }
  55. }
  56. });
  57. }
  58. }
  59. export { PluginListCtrl, PluginListCtrl as PanelCtrl };