module.ts 1.9 KB

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