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