module.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. };
  12. /** @ngInject */
  13. constructor($scope, $injector, private backendSrv, private $location) {
  14. super($scope, $injector);
  15. _.defaults(this.panel, this.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, evt) {
  30. if (evt) { evt.stopPropagation(); }
  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}