module.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 DashListCtrl extends PanelCtrl {
  9. static templateUrl = 'module.html';
  10. pluginList: any[];
  11. /** @ngInject */
  12. constructor($scope, $injector, private backendSrv) {
  13. super($scope, $injector);
  14. _.defaults(this.panel, panelDefaults);
  15. this.events.on('init-edit-mode', this.onInitEditMode.bind(this));
  16. this.pluginList = [];
  17. this.update();
  18. }
  19. onInitEditMode() {
  20. this.editorTabIndex = 1;
  21. this.addEditorTab('Options', 'public/app/plugins/panel/pluginlist/editor.html');
  22. }
  23. update() {
  24. this.backendSrv.get('api/plugins', {embedded: 0, core: 0}).then(plugins => {
  25. this.pluginList = plugins;
  26. for (let plugin of this.pluginList) {
  27. if (!plugin.enabled) {
  28. plugin.state = 'not-enabled';
  29. }
  30. }
  31. }).then(this.checkForUpdates.bind(this));
  32. }
  33. checkForUpdates() {
  34. return this.backendSrv.get('api/gnet/plugins/repo').then(data => {
  35. var gNetPlugins = _.reduce(data.plugins, (memo, val) => {
  36. memo[val.id] = val;
  37. return memo;
  38. }, {});
  39. for (let plugin of this.pluginList) {
  40. var source = gNetPlugins[plugin.id];
  41. if (!source) {
  42. continue;
  43. }
  44. if (plugin.info.version !== source.versions[0].version) {
  45. plugin.hasUpdate = true;
  46. plugin.state = 'has-update';
  47. }
  48. }
  49. });
  50. }
  51. }
  52. export {DashListCtrl, DashListCtrl as PanelCtrl}