2019-12-05 03:04:03 -06:00
|
|
|
import angular from 'angular';
|
2017-12-20 05:33:33 -06:00
|
|
|
import _ from 'lodash';
|
2016-02-09 04:17:49 -06:00
|
|
|
|
2019-04-15 09:54:00 -05:00
|
|
|
import { getPluginSettings } from './PluginSettingsCache';
|
2019-10-31 04:48:05 -05:00
|
|
|
import { PluginMeta } from '@grafana/data';
|
2019-07-18 01:03:04 -05:00
|
|
|
import { NavModelSrv } from 'app/core/core';
|
2019-10-14 03:27:47 -05:00
|
|
|
import { GrafanaRootScope } from 'app/routes/GrafanaCtrl';
|
|
|
|
import { AppEvents } from '@grafana/data';
|
2020-01-30 06:47:11 -06:00
|
|
|
import { promiseToDigest } from '../../core/utils/promiseToDigest';
|
2016-03-23 10:37:58 -05:00
|
|
|
|
2016-02-09 04:17:49 -06:00
|
|
|
export class AppPageCtrl {
|
|
|
|
page: any;
|
2016-02-29 01:50:02 -06:00
|
|
|
pluginId: any;
|
2016-02-09 04:17:49 -06:00
|
|
|
appModel: any;
|
2017-08-15 13:24:16 -05:00
|
|
|
navModel: any;
|
2016-02-09 04:17:49 -06:00
|
|
|
|
|
|
|
/** @ngInject */
|
2019-12-05 03:04:03 -06:00
|
|
|
constructor(private $routeParams: any, private $rootScope: GrafanaRootScope, private navModelSrv: NavModelSrv) {
|
2016-02-29 01:50:02 -06:00
|
|
|
this.pluginId = $routeParams.pluginId;
|
2016-03-21 13:07:08 -05:00
|
|
|
|
2020-01-30 06:47:11 -06:00
|
|
|
promiseToDigest($rootScope)(
|
|
|
|
Promise.resolve(getPluginSettings(this.pluginId))
|
|
|
|
.then(settings => {
|
|
|
|
this.initPage(settings);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
this.$rootScope.appEvent(AppEvents.alertError, ['Unknown Plugin']);
|
|
|
|
this.navModel = this.navModelSrv.getNotFoundNav();
|
|
|
|
})
|
|
|
|
);
|
2016-03-23 10:37:58 -05:00
|
|
|
}
|
|
|
|
|
2019-04-15 09:54:00 -05:00
|
|
|
initPage(app: PluginMeta) {
|
2016-03-23 10:43:32 -05:00
|
|
|
this.appModel = app;
|
2017-12-19 09:06:54 -06:00
|
|
|
this.page = _.find(app.includes, { slug: this.$routeParams.slug });
|
2016-03-23 10:37:58 -05:00
|
|
|
|
2016-03-23 10:43:32 -05:00
|
|
|
if (!this.page) {
|
2019-10-14 03:27:47 -05:00
|
|
|
this.$rootScope.appEvent(AppEvents.alertError, ['App Page Not Found']);
|
2019-04-15 09:54:00 -05:00
|
|
|
this.navModel = this.navModelSrv.getNotFoundNav();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (app.type !== 'app' || !app.enabled) {
|
2019-10-14 03:27:47 -05:00
|
|
|
this.$rootScope.appEvent(AppEvents.alertError, ['Application Not Enabled']);
|
2017-08-15 13:24:16 -05:00
|
|
|
this.navModel = this.navModelSrv.getNotFoundNav();
|
2017-06-02 07:00:42 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-26 10:14:40 -05:00
|
|
|
const pluginNav = this.navModelSrv.getNav('plugin-page-' + app.id);
|
2017-12-13 04:12:09 -06:00
|
|
|
|
|
|
|
this.navModel = {
|
|
|
|
main: {
|
|
|
|
img: app.info.logos.large,
|
|
|
|
subTitle: app.name,
|
2017-12-20 05:33:33 -06:00
|
|
|
url: '',
|
2018-01-11 10:53:06 -06:00
|
|
|
text: this.page.name,
|
|
|
|
breadcrumbs: [{ title: app.name, url: pluginNav.main.url }],
|
2017-12-20 05:33:33 -06:00
|
|
|
},
|
2017-12-13 04:12:09 -06:00
|
|
|
};
|
2016-03-23 10:43:32 -05:00
|
|
|
}
|
2016-02-09 04:17:49 -06:00
|
|
|
}
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
angular.module('grafana.controllers').controller('AppPageCtrl', AppPageCtrl);
|