module.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. href: 'http://docs.grafana.org/',
  18. target: '_blank',
  19. note: 'Review the installation docs',
  20. check: () => $q.when(true),
  21. });
  22. this.steps.push({
  23. title: 'Create your first data source',
  24. cta: 'Add data source',
  25. icon: 'icon-gf icon-gf-datasources',
  26. href: 'datasources/new?gettingstarted',
  27. check: () => {
  28. return $q.when(
  29. datasourceSrv.getMetricSources().filter(item => {
  30. return item.meta.builtIn === false;
  31. }).length > 0
  32. );
  33. }
  34. });
  35. this.steps.push({
  36. title: 'Create your first dashboard',
  37. cta: 'New dashboard',
  38. icon: 'icon-gf icon-gf-dashboard',
  39. href: 'dashboard/new?gettingstarted',
  40. check: () => {
  41. return this.backendSrv.search({limit: 1}).then(result => {
  42. return result.length > 0;
  43. });
  44. }
  45. });
  46. this.steps.push({
  47. title: 'Invite your team',
  48. cta: 'Add Users',
  49. icon: 'icon-gf icon-gf-users',
  50. href: 'org/users?gettingstarted',
  51. check: () => {
  52. return this.backendSrv.get('/api/org/users').then(res => {
  53. return res.length > 1;
  54. });
  55. }
  56. });
  57. this.steps.push({
  58. title: 'Install apps & plugins',
  59. cta: 'Explore plugin repository',
  60. icon: 'icon-gf icon-gf-apps',
  61. href: 'https://grafana.com/plugins?utm_source=grafana_getting_started',
  62. check: () => {
  63. return this.backendSrv.get('/api/plugins', {embedded: 0, core: 0}).then(plugins => {
  64. return plugins.length > 0;
  65. });
  66. }
  67. });
  68. }
  69. $onInit() {
  70. this.stepIndex = -1;
  71. return this.nextStep().then(res => {
  72. this.checksDone = true;
  73. });
  74. }
  75. nextStep() {
  76. if (this.stepIndex === this.steps.length - 1) {
  77. return this.$q.when();
  78. }
  79. this.stepIndex += 1;
  80. var currentStep = this.steps[this.stepIndex];
  81. return currentStep.check().then(passed => {
  82. if (passed) {
  83. currentStep.cssClass = 'completed';
  84. return this.nextStep();
  85. }
  86. currentStep.cssClass = 'active';
  87. return this.$q.when();
  88. });
  89. }
  90. dismiss() {
  91. this.row.removePanel(this.panel, false);
  92. this.backendSrv.request({
  93. method: 'PUT',
  94. url: '/api/user/helpflags/1',
  95. showSuccessAlert: false,
  96. }).then(res => {
  97. contextSrv.user.helpFlags1 = res.helpFlags1;
  98. });
  99. }
  100. }
  101. export {GettingStartedPanelCtrl, GettingStartedPanelCtrl as PanelCtrl};