module.ts 2.9 KB

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