module.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. ///<reference path="../../../headers/common.d.ts" />
  2. import _ from 'lodash';
  3. import {PanelCtrl} from '../../../features/panel/panel_ctrl';
  4. class PluginListCtrl extends PanelCtrl {
  5. static templateUrl = 'module.html';
  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) { evt.stopPropagation(); }
  29. this.$location.url(`plugins/${plugin.id}/edit`);
  30. }
  31. updateAvailable(plugin, $event) {
  32. $event.stopPropagation();
  33. $event.preventDefault();
  34. var modalScope = this.$scope.$new(true);
  35. modalScope.plugin = plugin;
  36. this.publishAppEvent('show-modal', {
  37. src: 'public/app/features/plugins/partials/update_instructions.html',
  38. scope: modalScope
  39. });
  40. }
  41. update() {
  42. this.backendSrv.get('api/plugins', {embedded: 0, core: 0}).then(plugins => {
  43. this.pluginList = plugins;
  44. this.viewModel[0].list = _.filter(plugins, {type: 'app'});
  45. this.viewModel[1].list = _.filter(plugins, {type: 'panel'});
  46. this.viewModel[2].list = _.filter(plugins, {type: 'datasource'});
  47. for (let plugin of this.pluginList) {
  48. if (plugin.hasUpdate) {
  49. plugin.state = 'has-update';
  50. } else if (!plugin.enabled) {
  51. plugin.state = 'not-enabled';
  52. }
  53. }
  54. });
  55. }
  56. }
  57. export {PluginListCtrl, PluginListCtrl as PanelCtrl};