|
@@ -1,7 +1,8 @@
|
|
|
import angular from 'angular';
|
|
import angular from 'angular';
|
|
|
import _ from 'lodash';
|
|
import _ from 'lodash';
|
|
|
|
|
|
|
|
-const pluginInfoCache = {};
|
|
|
|
|
|
|
+import { getPluginSettings } from './PluginSettingsCache';
|
|
|
|
|
+import { PluginMeta } from '@grafana/ui';
|
|
|
|
|
|
|
|
export class AppPageCtrl {
|
|
export class AppPageCtrl {
|
|
|
page: any;
|
|
page: any;
|
|
@@ -10,25 +11,30 @@ export class AppPageCtrl {
|
|
|
navModel: any;
|
|
navModel: any;
|
|
|
|
|
|
|
|
/** @ngInject */
|
|
/** @ngInject */
|
|
|
- constructor(private backendSrv, private $routeParams: any, private $rootScope, private navModelSrv) {
|
|
|
|
|
|
|
+ constructor(private $routeParams: any, private $rootScope, private navModelSrv) {
|
|
|
this.pluginId = $routeParams.pluginId;
|
|
this.pluginId = $routeParams.pluginId;
|
|
|
|
|
|
|
|
- if (pluginInfoCache[this.pluginId]) {
|
|
|
|
|
- this.initPage(pluginInfoCache[this.pluginId]);
|
|
|
|
|
- } else {
|
|
|
|
|
- this.loadPluginInfo();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ getPluginSettings(this.pluginId)
|
|
|
|
|
+ .then(settings => {
|
|
|
|
|
+ this.initPage(settings);
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch(err => {
|
|
|
|
|
+ this.$rootScope.appEvent('alert-error', ['Unknown Plugin', '']);
|
|
|
|
|
+ this.navModel = this.navModelSrv.getNotFoundNav();
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- initPage(app) {
|
|
|
|
|
|
|
+ initPage(app: PluginMeta) {
|
|
|
this.appModel = app;
|
|
this.appModel = app;
|
|
|
this.page = _.find(app.includes, { slug: this.$routeParams.slug });
|
|
this.page = _.find(app.includes, { slug: this.$routeParams.slug });
|
|
|
|
|
|
|
|
- pluginInfoCache[this.pluginId] = app;
|
|
|
|
|
-
|
|
|
|
|
if (!this.page) {
|
|
if (!this.page) {
|
|
|
this.$rootScope.appEvent('alert-error', ['App Page Not Found', '']);
|
|
this.$rootScope.appEvent('alert-error', ['App Page Not Found', '']);
|
|
|
-
|
|
|
|
|
|
|
+ this.navModel = this.navModelSrv.getNotFoundNav();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (app.type !== 'app' || !app.enabled) {
|
|
|
|
|
+ this.$rootScope.appEvent('alert-error', ['Applicaiton Not Enabled', '']);
|
|
|
this.navModel = this.navModelSrv.getNotFoundNav();
|
|
this.navModel = this.navModelSrv.getNotFoundNav();
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -45,12 +51,6 @@ export class AppPageCtrl {
|
|
|
},
|
|
},
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- loadPluginInfo() {
|
|
|
|
|
- this.backendSrv.get(`/api/plugins/${this.pluginId}/settings`).then(app => {
|
|
|
|
|
- this.initPage(app);
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
angular.module('grafana.controllers').controller('AppPageCtrl', AppPageCtrl);
|
|
angular.module('grafana.controllers').controller('AppPageCtrl', AppPageCtrl);
|