Commit c504abb8 by Torkel Ödegaard

feat(plugins): added dashboards tab to plugin edit page, #4275

parent 2527289e
<navbar title="Plugins" title-url="plugins" icon="icon-gf icon-gf-apps"> <navbar title="Plugins" title-url="plugins" icon="icon-gf icon-gf-apps">
<a href="plugins/{{ctrl.model.pluginId}}/edit" class="navbar-page-btn">
{{ctrl.model.name}}
</a>
</navbar> </navbar>
<div class="page-container" ng-init="ctrl.init()"> <div class="page-container" ng-init="ctrl.init()">
...@@ -23,7 +20,7 @@ ...@@ -23,7 +20,7 @@
</div> </div>
<ul class="gf-tabs"> <ul class="gf-tabs">
<li class="gf-tabs-item" ng-repeat="tab in ::['Overview', 'Config']"> <li class="gf-tabs-item" ng-repeat="tab in ctrl.tabs">
<a class="gf-tabs-link" ng-click="ctrl.tabIndex = $index" ng-class="{active: ctrl.tabIndex === $index}"> <a class="gf-tabs-link" ng-click="ctrl.tabIndex = $index" ng-class="{active: ctrl.tabIndex === $index}">
{{::tab}} {{::tab}}
</a> </a>
...@@ -39,21 +36,18 @@ ...@@ -39,21 +36,18 @@
</div> </div>
<div class="tab-content page-content-with-sidebar" ng-if="ctrl.tabIndex === 1"> <div class="tab-content page-content-with-sidebar" ng-if="ctrl.tabIndex === 1">
<div class="gf-form-inline">
<div class="gf-form">
<editor-checkbox text="Enabled" model="ctrl.model.enabled" change="ctrl.toggleEnabled()"></editor-checkbox>
</div>
<div class="gf-form">
<editor-checkbox text="Pinned" model="ctrl.model.pinned" change="ctrl.togglePinned()"></editor-checkbox>
</div>
</div>
<div ng-if="ctrl.model.id"> <div ng-if="ctrl.model.id">
<plugin-component type="app-config-ctrl"></plugin-component> <plugin-component type="app-config-ctrl"></plugin-component>
<div class="clearfix"></div>
<button type="submit" class="btn btn-success" ng-click="ctrl.update()">Save</button> <div class="gf-form-button-row">
<button type="submit" class="btn btn-success" ng-click="ctrl.enable()" ng-show="!ctrl.model.enabled">Enable</button>
<button type="submit" class="btn btn-success" ng-click="ctrl.update()" ng-show="ctrl.model.enabled">Update</button>
</div>
</div>
</div> </div>
<div class="tab-content page-content-with-sidebar" ng-if="ctrl.tabIndex === 2">
<dashboard-import-list plugin="ctrl.model"></dashboard-import-list>
</div> </div>
<aside class="page-sidebar"> <aside class="page-sidebar">
......
...@@ -11,6 +11,8 @@ export class PluginEditCtrl { ...@@ -11,6 +11,8 @@ export class PluginEditCtrl {
readmeHtml: any; readmeHtml: any;
includedDatasources: any; includedDatasources: any;
tabIndex: number; tabIndex: number;
tabs: any;
hasDashboards: any;
preUpdateHook: () => any; preUpdateHook: () => any;
postUpdateHook: () => any; postUpdateHook: () => any;
...@@ -19,6 +21,7 @@ export class PluginEditCtrl { ...@@ -19,6 +21,7 @@ export class PluginEditCtrl {
this.model = {}; this.model = {};
this.pluginId = $routeParams.pluginId; this.pluginId = $routeParams.pluginId;
this.tabIndex = 0; this.tabIndex = 0;
this.tabs = ['Overview'];
} }
init() { init() {
...@@ -35,6 +38,15 @@ export class PluginEditCtrl { ...@@ -35,6 +38,15 @@ export class PluginEditCtrl {
return plug; return plug;
}); });
if (this.model.type === 'app') {
this.tabs.push('Config');
this.hasDashboards = _.findWhere(result.includes, {type: 'dashboard'});
if (this.hasDashboards) {
this.tabs.push('Dashboards');
}
}
return this.initReadme(); return this.initReadme();
}); });
} }
...@@ -54,6 +66,7 @@ export class PluginEditCtrl { ...@@ -54,6 +66,7 @@ export class PluginEditCtrl {
case 'panel': return 'icon-gf icon-gf-panel'; case 'panel': return 'icon-gf icon-gf-panel';
case 'app': return 'icon-gf icon-gf-apps'; case 'app': return 'icon-gf icon-gf-apps';
case 'page': return 'icon-gf icon-gf-share'; case 'page': return 'icon-gf icon-gf-share';
case 'dashboard': return 'icon-gf icon-gf-dashboard';
} }
} }
...@@ -64,9 +77,7 @@ export class PluginEditCtrl { ...@@ -64,9 +77,7 @@ export class PluginEditCtrl {
// the next step of execution will block until the promise resolves. // the next step of execution will block until the promise resolves.
// if the promise is rejected, this update will be aborted. // if the promise is rejected, this update will be aborted.
if (this.preUpdateHook != null) { if (this.preUpdateHook != null) {
chain = chain.then(function() { chain = self.preUpdateHook();
return Promise.resolve(self.preUpdateHook());
});
} }
// Perform the core update procedure // Perform the core update procedure
...@@ -86,7 +97,7 @@ export class PluginEditCtrl { ...@@ -86,7 +97,7 @@ export class PluginEditCtrl {
// resolves. If the promise is rejected the page will not be reloaded. // resolves. If the promise is rejected the page will not be reloaded.
if (this.postUpdateHook != null) { if (this.postUpdateHook != null) {
chain = chain.then(function() { chain = chain.then(function() {
return Promise.resolve(this.postUpdateHook()); return this.postUpdateHook();
}); });
} }
...@@ -101,17 +112,16 @@ export class PluginEditCtrl { ...@@ -101,17 +112,16 @@ export class PluginEditCtrl {
this.preUpdateHook = callback; this.preUpdateHook = callback;
} }
setPOstUpdateHook(callback: () => any) { setPostUpdateHook(callback: () => any) {
this.postUpdateHook = callback; this.postUpdateHook = callback;
} }
toggleEnabled() { enable() {
this.model.enabled = true;
this.model.pinned = true;
this.update(); this.update();
} }
togglePinned() {
this.update();
}
} }
angular.module('grafana.controllers').controller('PluginEditCtrl', PluginEditCtrl); angular.module('grafana.controllers').controller('PluginEditCtrl', PluginEditCtrl);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment