module.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. /* tslint:disable */
  13. if (contextSrv.user.helpFlags1 & 1) {
  14. this.row.removePanel(this.panel, false);
  15. return;
  16. }
  17. /* tslint:enable */
  18. this.stepIndex = 0;
  19. this.steps = [];
  20. if (!contextSrv.hasRole('Admin')) {
  21. this.steps.push({
  22. cta: 'Basic Concepts Guide',
  23. icon: 'fa fa-file-text-o',
  24. href: 'http://docs.grafana.org/guides/basic_concepts/',
  25. check: () => $q.when(false),
  26. cssClass: 'active',
  27. });
  28. this.steps.push({
  29. cta: 'Getting Started Guide',
  30. icon: 'fa fa-file-text-o',
  31. href: 'http://docs.grafana.org/guides/getting_started/',
  32. check: () => $q.when(false),
  33. cssClass: 'active',
  34. });
  35. this.steps.push({
  36. cta: 'Building a dashboard',
  37. icon: 'fa fa-film',
  38. href: 'http://docs.grafana.org/tutorials/screencasts/',
  39. check: () => $q.when(false),
  40. cssClass: 'active',
  41. });
  42. return;
  43. }
  44. this.steps.push({
  45. title: 'Install Grafana',
  46. icon: 'icon-gf icon-gf-check',
  47. check: () => $q.when(true),
  48. });
  49. this.steps.push({
  50. title: 'Create your first data source',
  51. cta: 'Add data source',
  52. icon: 'icon-gf icon-gf-datasources',
  53. href: 'datasources/new?gettingstarted',
  54. check: () => {
  55. return $q.when(
  56. datasourceSrv.getMetricSources().filter(item => {
  57. return item.meta.builtIn === false;
  58. }).length > 0
  59. );
  60. }
  61. });
  62. this.steps.push({
  63. title: 'Create your first dashboard',
  64. cta: 'New dashboard',
  65. icon: 'icon-gf icon-gf-dashboard',
  66. href: 'dashboard/new?gettingstarted',
  67. check: () => {
  68. return this.backendSrv.search({limit: 1}).then(result => {
  69. return result.length > 0;
  70. });
  71. }
  72. });
  73. this.steps.push({
  74. title: 'Invite your team',
  75. cta: 'Add Users',
  76. icon: 'icon-gf icon-gf-users',
  77. href: 'org/users?gettingstarted',
  78. check: () => {
  79. return this.backendSrv.get('api/org/users').then(res => {
  80. return res.length > 1;
  81. });
  82. }
  83. });
  84. this.steps.push({
  85. title: 'Install apps & plugins',
  86. cta: 'Explore plugin repository',
  87. icon: 'icon-gf icon-gf-apps',
  88. href: 'https://grafana.net/plugins?utm_source=grafana_getting_started',
  89. check: () => {
  90. return this.backendSrv.get('api/plugins', {embedded: 0, core: 0}).then(plugins => {
  91. return plugins.length > 0;
  92. });
  93. }
  94. });
  95. }
  96. $onInit() {
  97. this.stepIndex = -1;
  98. return this.nextStep().then(res => {
  99. this.checksDone = true;
  100. console.log(this.steps);
  101. });
  102. }
  103. nextStep() {
  104. if (this.stepIndex === this.steps.length - 1) {
  105. return this.$q.when();
  106. }
  107. this.stepIndex += 1;
  108. var currentStep = this.steps[this.stepIndex];
  109. return currentStep.check().then(passed => {
  110. if (passed) {
  111. currentStep.cssClass = 'completed';
  112. return this.nextStep();
  113. }
  114. currentStep.cssClass = 'active';
  115. return this.$q.when();
  116. });
  117. }
  118. dismiss() {
  119. this.row.removePanel(this.panel, false);
  120. this.backendSrv.request({
  121. method: 'PUT',
  122. url: '/api/user/helpflags/1',
  123. showSuccessAlert: false,
  124. }).then(res => {
  125. contextSrv.user.helpFlags1 = res.helpFlags1;
  126. });
  127. }
  128. }
  129. export {GettingStartedPanelCtrl, GettingStartedPanelCtrl as PanelCtrl}