module.ts 3.1 KB

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