2016-02-09 04:17:49 -06:00
|
|
|
import angular from 'angular';
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
2016-03-23 10:37:58 -05:00
|
|
|
var pluginInfoCache = {};
|
|
|
|
|
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 */
|
2017-08-15 13:24:16 -05:00
|
|
|
constructor(private backendSrv, 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
|
|
|
|
2016-03-23 10:37:58 -05:00
|
|
|
if (pluginInfoCache[this.pluginId]) {
|
2016-03-23 10:43:32 -05:00
|
|
|
this.initPage(pluginInfoCache[this.pluginId]);
|
2016-03-23 10:37:58 -05:00
|
|
|
} else {
|
|
|
|
this.loadPluginInfo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-23 10:43:32 -05:00
|
|
|
initPage(app) {
|
|
|
|
this.appModel = app;
|
2016-09-13 15:10:44 -05: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
|
|
|
pluginInfoCache[this.pluginId] = app;
|
2016-03-22 04:15:47 -05:00
|
|
|
|
2016-03-23 10:43:32 -05:00
|
|
|
if (!this.page) {
|
|
|
|
this.$rootScope.appEvent('alert-error', ['App Page Not Found', '']);
|
2017-06-02 07:00:42 -05:00
|
|
|
|
2017-08-15 13:24:16 -05:00
|
|
|
this.navModel = this.navModelSrv.getNotFoundNav();
|
2017-06-02 07:00:42 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-13 04:12:09 -06:00
|
|
|
let pluginNav = this.navModelSrv.getNav('plugin-page-' + app.id);
|
|
|
|
|
|
|
|
this.navModel = {
|
|
|
|
main: {
|
|
|
|
img: app.info.logos.large,
|
|
|
|
subTitle: app.name,
|
|
|
|
url: '',
|
|
|
|
text: '',
|
|
|
|
breadcrumbs: [
|
|
|
|
{ title: app.name, url: pluginNav.main.url },
|
|
|
|
{ title: this.page.name },
|
|
|
|
],
|
|
|
|
}
|
|
|
|
};
|
2016-03-23 10:43:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
loadPluginInfo() {
|
|
|
|
this.backendSrv.get(`/api/plugins/${this.pluginId}/settings`).then(app => {
|
|
|
|
this.initPage(app);
|
2016-02-09 04:17:49 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
angular.module('grafana.controllers').controller('AppPageCtrl', AppPageCtrl);
|
|
|
|
|