module.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ///<reference path="../../../headers/common.d.ts" />
  2. import _ from 'lodash';
  3. import config from 'app/core/config';
  4. import {PanelCtrl} from '../../../features/panel/panel_ctrl';
  5. class PluginListCtrl extends PanelCtrl {
  6. static templateUrl = 'module.html';
  7. pluginList: any[];
  8. viewModel: any;
  9. // Set and populate defaults
  10. panelDefaults = {};
  11. /** @ngInject */
  12. constructor($scope, $injector, private backendSrv, private $location) {
  13. super($scope, $injector);
  14. _.defaults(this.panel, this.panelDefaults);
  15. this.events.on('init-edit-mode', this.onInitEditMode.bind(this));
  16. this.pluginList = [];
  17. this.viewModel = [
  18. {header: "Installed Apps", list: [], type: 'app'},
  19. {header: "Installed Panels", list: [], type: 'panel'},
  20. {header: "Installed Datasources", list: [], type: 'datasource'},
  21. ];
  22. this.update();
  23. }
  24. onInitEditMode() {
  25. this.editorTabIndex = 1;
  26. this.addEditorTab('Options', 'public/app/plugins/panel/pluginlist/editor.html');
  27. }
  28. gotoPlugin(plugin, evt) {
  29. if (evt) { evt.stopPropagation(); }
  30. this.$location.url(`plugins/${plugin.id}/edit`);
  31. }
  32. updateAvailable(plugin, $event) {
  33. $event.stopPropagation();
  34. $event.preventDefault();
  35. var 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 (let 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};