2017-12-20 05:33:33 -06:00
|
|
|
import angular from 'angular';
|
|
|
|
import _ from 'lodash';
|
2016-02-09 04:17:49 -06:00
|
|
|
|
2019-04-15 09:54:00 -05:00
|
|
|
import { getPluginSettings } from './PluginSettingsCache';
|
|
|
|
import { PluginMeta } from '@grafana/ui';
|
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-04-15 09:54:00 -05:00
|
|
|
constructor(private $routeParams: any, private $rootScope, private navModelSrv) {
|
2016-02-29 01:50:02 -06:00
|
|
|
this.pluginId = $routeParams.pluginId;
|
2016-03-21 13:07:08 -05:00
|
|
|
|
2019-04-15 09:54:00 -05:00
|
|
|
getPluginSettings(this.pluginId)
|
|
|
|
.then(settings => {
|
|
|
|
this.initPage(settings);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
this.$rootScope.appEvent('alert-error', ['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) {
|
2017-12-20 05:33:33 -06:00
|
|
|
this.$rootScope.appEvent('alert-error', ['App Page Not Found', '']);
|
2019-04-15 09:54:00 -05:00
|
|
|
this.navModel = this.navModelSrv.getNotFoundNav();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (app.type !== 'app' || !app.enabled) {
|
|
|
|
this.$rootScope.appEvent('alert-error', ['Applicaiton 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);
|