module.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { PanelCtrl } from 'app/plugins/sdk';
  2. import { contextSrv } from 'app/core/core';
  3. class GettingStartedPanelCtrl extends PanelCtrl {
  4. static templateUrl = 'public/app/plugins/panel/gettingstarted/module.html';
  5. checksDone: boolean;
  6. stepIndex: number;
  7. steps: any;
  8. /** @ngInject */
  9. constructor($scope, $injector, private backendSrv, datasourceSrv, private $q) {
  10. super($scope, $injector);
  11. this.stepIndex = 0;
  12. this.steps = [];
  13. this.steps.push({
  14. title: 'Install Grafana',
  15. icon: 'icon-gf icon-gf-check',
  16. href: 'http://docs.grafana.org/',
  17. target: '_blank',
  18. note: 'Review the installation docs',
  19. check: () => $q.when(true),
  20. });
  21. this.steps.push({
  22. title: 'Create your first data source',
  23. cta: 'Add data source',
  24. icon: 'icon-gf icon-gf-datasources',
  25. href: 'datasources/new?gettingstarted',
  26. check: () => {
  27. return $q.when(
  28. datasourceSrv.getMetricSources().filter(item => {
  29. return item.meta.builtIn !== true;
  30. }).length > 0
  31. );
  32. },
  33. });
  34. this.steps.push({
  35. title: 'Create your first dashboard',
  36. cta: 'New dashboard',
  37. icon: 'icon-gf icon-gf-dashboard',
  38. href: 'dashboard/new?gettingstarted',
  39. check: () => {
  40. return this.backendSrv.search({ limit: 1 }).then(result => {
  41. return result.length > 0;
  42. });
  43. },
  44. });
  45. this.steps.push({
  46. title: 'Invite your team',
  47. cta: 'Add Users',
  48. icon: 'icon-gf icon-gf-users',
  49. href: 'org/users?gettingstarted',
  50. check: () => {
  51. return this.backendSrv.get('/api/org/users').then(res => {
  52. return res.length > 1;
  53. });
  54. },
  55. });
  56. this.steps.push({
  57. title: 'Install apps & plugins',
  58. cta: 'Explore plugin repository',
  59. icon: 'icon-gf icon-gf-apps',
  60. href: 'https://grafana.com/plugins?utm_source=grafana_getting_started',
  61. check: () => {
  62. return this.backendSrv.get('/api/plugins', { embedded: 0, core: 0 }).then(plugins => {
  63. return plugins.length > 0;
  64. });
  65. },
  66. });
  67. }
  68. $onInit() {
  69. this.stepIndex = -1;
  70. return this.nextStep().then(res => {
  71. this.checksDone = true;
  72. });
  73. }
  74. nextStep() {
  75. if (this.stepIndex === this.steps.length - 1) {
  76. return this.$q.when();
  77. }
  78. this.stepIndex += 1;
  79. const currentStep = this.steps[this.stepIndex];
  80. return currentStep.check().then(passed => {
  81. if (passed) {
  82. currentStep.cssClass = 'completed';
  83. return this.nextStep();
  84. }
  85. currentStep.cssClass = 'active';
  86. return this.$q.when();
  87. });
  88. }
  89. dismiss() {
  90. this.dashboard.removePanel(this.panel, false);
  91. this.backendSrv
  92. .request({
  93. method: 'PUT',
  94. url: '/api/user/helpflags/1',
  95. showSuccessAlert: false,
  96. })
  97. .then(res => {
  98. contextSrv.user.helpFlags1 = res.helpFlags1;
  99. });
  100. }
  101. }
  102. export { GettingStartedPanelCtrl, GettingStartedPanelCtrl as PanelCtrl };