2017-12-21 15:39:31 +08:00
|
|
|
import { PanelCtrl } from 'app/plugins/sdk';
|
2016-11-03 05:21:11 +08:00
|
|
|
|
2017-12-21 15:39:31 +08:00
|
|
|
import { contextSrv } from 'app/core/core';
|
2016-11-09 17:41:39 +08:00
|
|
|
|
|
|
|
|
class GettingStartedPanelCtrl extends PanelCtrl {
|
2017-12-21 15:39:31 +08:00
|
|
|
static templateUrl = 'public/app/plugins/panel/gettingstarted/module.html';
|
2016-11-09 17:41:39 +08:00
|
|
|
checksDone: boolean;
|
2016-11-19 00:42:14 +08:00
|
|
|
stepIndex: number;
|
|
|
|
|
steps: any;
|
2016-11-03 05:21:11 +08:00
|
|
|
|
2018-08-31 22:40:43 +08:00
|
|
|
/** @ngInject */
|
2017-12-21 15:39:31 +08:00
|
|
|
constructor($scope, $injector, private backendSrv, datasourceSrv, private $q) {
|
2016-11-03 05:21:11 +08:00
|
|
|
super($scope, $injector);
|
2016-11-09 17:41:39 +08:00
|
|
|
|
2016-11-19 00:42:14 +08:00
|
|
|
this.stepIndex = 0;
|
|
|
|
|
this.steps = [];
|
|
|
|
|
|
|
|
|
|
this.steps.push({
|
2017-12-21 15:39:31 +08:00
|
|
|
title: 'Install Grafana',
|
|
|
|
|
icon: 'icon-gf icon-gf-check',
|
|
|
|
|
href: 'http://docs.grafana.org/',
|
|
|
|
|
target: '_blank',
|
|
|
|
|
note: 'Review the installation docs',
|
|
|
|
|
check: () => $q.when(true),
|
2016-11-19 00:42:14 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.steps.push({
|
2017-12-21 15:39:31 +08:00
|
|
|
title: 'Create your first data source',
|
|
|
|
|
cta: 'Add data source',
|
2019-04-17 21:18:32 +08:00
|
|
|
icon: 'gicon gicon-datasources',
|
2017-12-21 15:39:31 +08:00
|
|
|
href: 'datasources/new?gettingstarted',
|
2016-11-19 00:42:14 +08:00
|
|
|
check: () => {
|
|
|
|
|
return $q.when(
|
|
|
|
|
datasourceSrv.getMetricSources().filter(item => {
|
2017-10-18 18:02:57 +08:00
|
|
|
return item.meta.builtIn !== true;
|
2016-11-19 00:42:14 +08:00
|
|
|
}).length > 0
|
|
|
|
|
);
|
2017-12-21 15:39:31 +08:00
|
|
|
},
|
2016-11-19 00:42:14 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.steps.push({
|
2017-12-21 15:39:31 +08:00
|
|
|
title: 'Create your first dashboard',
|
|
|
|
|
cta: 'New dashboard',
|
2019-04-17 21:18:32 +08:00
|
|
|
icon: 'gicon gicon-dashboard',
|
2017-12-21 15:39:31 +08:00
|
|
|
href: 'dashboard/new?gettingstarted',
|
2016-11-19 00:42:14 +08:00
|
|
|
check: () => {
|
2017-12-19 23:06:54 +08:00
|
|
|
return this.backendSrv.search({ limit: 1 }).then(result => {
|
2016-11-19 00:42:14 +08:00
|
|
|
return result.length > 0;
|
|
|
|
|
});
|
2017-12-21 15:39:31 +08:00
|
|
|
},
|
2016-11-19 00:42:14 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.steps.push({
|
2017-12-21 15:39:31 +08:00
|
|
|
title: 'Invite your team',
|
|
|
|
|
cta: 'Add Users',
|
2019-04-17 21:18:32 +08:00
|
|
|
icon: 'gicon gicon-team',
|
2017-12-21 15:39:31 +08:00
|
|
|
href: 'org/users?gettingstarted',
|
2016-11-19 00:42:14 +08:00
|
|
|
check: () => {
|
2017-12-21 15:39:31 +08:00
|
|
|
return this.backendSrv.get('/api/org/users').then(res => {
|
2016-11-19 00:42:14 +08:00
|
|
|
return res.length > 1;
|
|
|
|
|
});
|
2017-12-21 15:39:31 +08:00
|
|
|
},
|
2016-11-09 17:41:39 +08:00
|
|
|
});
|
|
|
|
|
|
2016-11-19 00:42:14 +08:00
|
|
|
this.steps.push({
|
2017-12-21 15:39:31 +08:00
|
|
|
title: 'Install apps & plugins',
|
|
|
|
|
cta: 'Explore plugin repository',
|
2019-04-17 21:18:32 +08:00
|
|
|
icon: 'gicon gicon-plugins',
|
2017-12-21 15:39:31 +08:00
|
|
|
href: 'https://grafana.com/plugins?utm_source=grafana_getting_started',
|
2016-11-19 00:42:14 +08:00
|
|
|
check: () => {
|
2017-12-21 15:39:31 +08:00
|
|
|
return this.backendSrv.get('/api/plugins', { embedded: 0, core: 0 }).then(plugins => {
|
|
|
|
|
return plugins.length > 0;
|
|
|
|
|
});
|
|
|
|
|
},
|
2016-11-19 00:42:14 +08:00
|
|
|
});
|
|
|
|
|
}
|
2016-11-18 23:31:19 +08:00
|
|
|
|
2016-11-19 00:42:14 +08:00
|
|
|
$onInit() {
|
|
|
|
|
this.stepIndex = -1;
|
|
|
|
|
return this.nextStep().then(res => {
|
2016-11-18 23:31:19 +08:00
|
|
|
this.checksDone = true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-19 00:42:14 +08:00
|
|
|
nextStep() {
|
|
|
|
|
if (this.stepIndex === this.steps.length - 1) {
|
|
|
|
|
return this.$q.when();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.stepIndex += 1;
|
2018-08-29 20:27:29 +08:00
|
|
|
const currentStep = this.steps[this.stepIndex];
|
2016-11-19 00:42:14 +08:00
|
|
|
return currentStep.check().then(passed => {
|
|
|
|
|
if (passed) {
|
2017-12-21 15:39:31 +08:00
|
|
|
currentStep.cssClass = 'completed';
|
2016-11-19 00:42:14 +08:00
|
|
|
return this.nextStep();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 15:39:31 +08:00
|
|
|
currentStep.cssClass = 'active';
|
2016-11-19 00:42:14 +08:00
|
|
|
return this.$q.when();
|
|
|
|
|
});
|
2016-11-03 05:21:11 +08:00
|
|
|
}
|
|
|
|
|
|
2016-11-09 17:41:39 +08:00
|
|
|
dismiss() {
|
2017-08-25 16:41:24 +08:00
|
|
|
this.dashboard.removePanel(this.panel, false);
|
2016-11-09 17:41:39 +08:00
|
|
|
|
2017-12-19 23:06:54 +08:00
|
|
|
this.backendSrv
|
|
|
|
|
.request({
|
2017-12-21 15:39:31 +08:00
|
|
|
method: 'PUT',
|
|
|
|
|
url: '/api/user/helpflags/1',
|
|
|
|
|
showSuccessAlert: false,
|
2017-12-19 23:06:54 +08:00
|
|
|
})
|
|
|
|
|
.then(res => {
|
|
|
|
|
contextSrv.user.helpFlags1 = res.helpFlags1;
|
|
|
|
|
});
|
2016-11-09 17:41:39 +08:00
|
|
|
}
|
2016-11-03 05:21:11 +08:00
|
|
|
}
|
|
|
|
|
|
2017-12-19 23:06:54 +08:00
|
|
|
export { GettingStartedPanelCtrl, GettingStartedPanelCtrl as PanelCtrl };
|