module.ts 3.1 KB

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