more renaming. also moved apps and datasource menus

This commit is contained in:
woodsaj 2015-12-18 13:46:40 +08:00
parent 42db1378e0
commit 48cf56b69a
16 changed files with 162 additions and 188 deletions

View File

@ -41,8 +41,8 @@ func Register(r *macaron.Macaron) {
r.Get("/admin/orgs", reqGrafanaAdmin, Index)
r.Get("/admin/orgs/edit/:id", reqGrafanaAdmin, Index)
r.Get("/plugins", reqSignedIn, Index)
r.Get("/plugins/edit/*", reqSignedIn, Index)
r.Get("/org/apps", reqSignedIn, Index)
r.Get("/org/apps/edit/*", reqSignedIn, Index)
r.Get("/dashboard/*", reqSignedIn, Index)
r.Get("/dashboard-solo/*", reqSignedIn, Index)
@ -116,6 +116,10 @@ func Register(r *macaron.Macaron) {
r.Get("/invites", wrap(GetPendingOrgInvites))
r.Post("/invites", quota("user"), bind(dtos.AddInviteForm{}), wrap(AddOrgInvite))
r.Patch("/invites/:code/revoke", wrap(RevokeInvite))
// apps
r.Get("/apps", wrap(GetAppPlugins))
r.Post("/apps", bind(m.UpdateAppPluginCmd{}), wrap(UpdateAppPlugin))
}, reqOrgAdmin)
// create new org
@ -155,12 +159,6 @@ func Register(r *macaron.Macaron) {
r.Get("/plugins", GetDataSourcePlugins)
}, reqOrgAdmin)
// PluginBundles
r.Group("/plugins", func() {
r.Get("/", wrap(GetAppPlugins))
r.Post("/", bind(m.UpdateAppPluginCmd{}), wrap(UpdateAppPlugin))
}, reqOrgAdmin)
r.Get("/frontend/settings/", GetFrontendSettings)
r.Any("/datasources/proxy/:id/*", reqSignedIn, ProxyDataSourceRequest)
r.Any("/datasources/proxy/:id", reqSignedIn, ProxyDataSourceRequest)

View File

@ -55,18 +55,6 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) {
Href: "/",
})
if c.OrgRole == m.ROLE_ADMIN {
data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{
Text: "Data Sources",
Icon: "fa fa-fw fa-database",
Href: "/datasources",
}, &dtos.NavLink{
Text: "Plugins",
Icon: "fa fa-fw fa-cubes",
Href: "/plugins",
})
}
orgApps := m.GetAppPluginsQuery{OrgId: c.OrgId}
err = bus.Dispatch(&orgApps)
if err != nil {

View File

@ -40,6 +40,14 @@ function (angular, _, $, coreModule, config) {
text: "API Keys",
href: $scope.getUrl("/org/apikeys"),
});
$scope.orgMenu.push({
text: "Datasources",
href: $scope.getUrl("/datasources"),
});
$scope.orgMenu.push({
text: "Apps",
href: $scope.getUrl("/org/apps"),
});
}
if ($scope.orgMenu.length > 0) {

View File

@ -131,14 +131,14 @@ define([
templateUrl: 'app/partials/reset_password.html',
controller : 'ResetPasswordCtrl',
})
.when('/plugins', {
templateUrl: 'app/features/org/partials/plugins.html',
controller: 'PluginsCtrl',
.when('/org/apps', {
templateUrl: 'app/features/org/partials/apps.html',
controller: 'AppsCtrl',
resolve: loadOrgBundle,
})
.when('/plugins/edit/:type', {
templateUrl: 'app/features/org/partials/pluginEdit.html',
controller: 'PluginEditCtrl',
.when('/org/apps/edit/:type', {
templateUrl: 'app/features/org/partials/appEdit.html',
controller: 'AppEditCtrl',
resolve: loadOrgBundle,
})
.otherwise({

View File

@ -6,8 +6,8 @@ define([
'./userInviteCtrl',
'./orgApiKeysCtrl',
'./orgDetailsCtrl',
'./pluginsCtrl',
'./pluginEditCtrl',
'./plugin_srv',
'./plugin_directive',
'./appsCtrl',
'./appEditCtrl',
'./app_srv',
'./app_directive',
], function () {});

View File

@ -8,14 +8,14 @@ function (angular, _, config) {
var module = angular.module('grafana.controllers');
module.controller('PluginEditCtrl', function($scope, pluginSrv, $routeParams) {
module.controller('AppEditCtrl', function($scope, appSrv, $routeParams) {
$scope.init = function() {
$scope.current = {};
$scope.getPlugins();
$scope.getApps();
};
$scope.getPlugins = function() {
pluginSrv.get($routeParams.type).then(function(result) {
$scope.getApps = function() {
appSrv.get($routeParams.type).then(function(result) {
$scope.current = _.clone(result);
});
};
@ -25,7 +25,7 @@ function (angular, _, config) {
};
$scope._update = function() {
pluginSrv.update($scope.current).then(function() {
appSrv.update($scope.current).then(function() {
window.location.href = config.appSubUrl + "plugins";
});
};

View File

@ -0,0 +1,32 @@
define([
'angular',
],
function (angular) {
'use strict';
var module = angular.module('grafana.directives');
module.directive('appConfigLoader', function($compile) {
return {
restrict: 'E',
link: function(scope, elem) {
var directive = 'grafana-app-default';
//wait for the parent scope to be applied.
scope.panelAdded = false;
scope.$watch("current", function(newVal) {
if (newVal && !scope.panelAdded) {
if (newVal.module) {
scope.panelAdded = true;
directive = 'grafana-app-'+newVal.type;
scope.require([newVal.module], function () {
var panelEl = angular.element(document.createElement(directive));
elem.append(panelEl);
$compile(panelEl)(scope);
});
}
}
});
}
};
});
});

View File

@ -0,0 +1,58 @@
define([
'angular',
'lodash',
],
function (angular, _) {
'use strict';
var module = angular.module('grafana.services');
module.service('appSrv', function($rootScope, $timeout, $q, backendSrv) {
var self = this;
this.init = function() {
console.log("appSrv init");
this.apps = {};
};
this.get = function(type) {
return $q(function(resolve) {
if (type in self.apps) {
return resolve(self.apps[type]);
}
backendSrv.get('api/org/apps').then(function(results) {
_.forEach(results, function(p) {
self.apps[p.type] = p;
});
return resolve(self.apps[type]);
});
});
};
this.getAll = function() {
return $q(function(resolve) {
if (!_.isEmpty(self.apps)) {
return resolve(self.apps);
}
backendSrv.get('api/org/apps').then(function(results) {
_.forEach(results, function(p) {
self.apps[p.type] = p;
});
return resolve(self.apps);
});
});
};
this.update = function(app) {
return $q(function(resolve, reject) {
backendSrv.post('api/org/apps', app).then(function(resp) {
self.apps[app.type] = app;
resolve(resp);
}, function(resp) {
reject(resp);
});
});
};
this.init();
});
});

View File

@ -0,0 +1,32 @@
define([
'angular',
'app/core/config',
],
function (angular, config) {
'use strict';
var module = angular.module('grafana.controllers');
module.controller('AppsCtrl', function($scope, $location, appSrv) {
$scope.init = function() {
$scope.apps = {};
$scope.getApps();
};
$scope.getApps = function() {
appSrv.getAll().then(function(result) {
$scope.apps = result;
});
};
$scope.update = function(app) {
appSrv.update(app).then(function() {
window.location.href = config.appSubUrl + $location.path();
});
};
$scope.init();
});
});

View File

@ -1,3 +0,0 @@
<div>
{{current.type}} app does not have any additional config.
</div>

View File

@ -1,13 +1,13 @@
<topnav title="Plugins" icon="fa fa-fw fa-cubes" subnav="true">
<ul class="nav">
<li ><a href="plugins">Overview</a></li>
<li class="active" ><a href="plugins/edit/{{current.type}}">Edit</a></li>
<li ><a href="org/apps">Overview</a></li>
<li class="active" ><a href="org/apps/edit/{{current.type}}">Edit</a></li>
</ul>
</topnav>
<div class="page-container">
<div class="page">
<h2>Edit Plugin</h2>
<h2>Edit App</h2>
<form name="editForm">
@ -30,10 +30,10 @@
<div class="clearfix"></div>
</div>
<br>
<plugin-config-loader plugin="current"></plugin-config-loader>
<app-config-loader></app-config-loader>
<div class="pull-right" style="margin-top: 35px">
<button type="submit" class="btn btn-success" ng-click="update()">Save</button>
<a class="btn btn-inverse" href="plugins">Cancel</a>
<a class="btn btn-inverse" href="org/apps">Cancel</a>
</div>
<br>
</form>

View File

@ -1,6 +1,6 @@
<topnav title="Plugins" icon="fa fa-fw fa-cubes" subnav="true">
<ul class="nav">
<li class="active" ><a href="plugins">Overview</a></li>
<li class="active" ><a href="org/apps">Overview</a></li>
</ul>
</topnav>
@ -8,23 +8,23 @@
<div class="page">
<h2>Plugins</h2>
<div ng-if="!plugins">
<em>No plugins defined</em>
<div ng-if="!apps">
<em>No apps defined</em>
</div>
<table class="grafana-options-table" ng-if="plugins">
<table class="grafana-options-table" ng-if="apps">
<tr>
<td><strong>Type</strong></td>
<td></td>
<td></td>
</tr>
<tr ng-repeat="(type, p) in plugins">
<tr ng-repeat="(type, p) in apps">
<td style="width:1%">
<i class="fa fa-cubes"></i> &nbsp;
{{p.type}}
</td>
<td style="width: 1%">
<a href="plugins/edit/{{p.type}}" class="btn btn-inverse btn-mini">
<a href="org/apps/edit/{{p.type}}" class="btn btn-inverse btn-mini">
<i class="fa fa-edit"></i>
Edit
</a>

View File

@ -1,47 +0,0 @@
define([
'angular',
],
function (angular) {
'use strict';
var module = angular.module('grafana.directives');
module.directive('pluginConfigLoader', function($compile) {
return {
restrict: 'E',
link: function(scope, elem) {
var directive = 'grafana-app-core';
//wait for the parent scope to be applied.
scope.$watch("current", function(newVal) {
if (newVal) {
if (newVal.module) {
directive = 'grafana-app-'+newVal.type;
}
scope.require([newVal.module], function () {
var panelEl = angular.element(document.createElement(directive));
elem.append(panelEl);
$compile(panelEl)(scope);
});
}
});
}
};
});
module.directive('grafanaAppCore', function() {
return {
restrict: 'E',
templateUrl: 'app/features/org/partials/appConfigCore.html',
transclude: true,
link: function(scope) {
scope.update = function() {
//Perform custom save events to the plugins own backend if needed.
// call parent update to commit the change to the plugin object.
// this will cause the page to reload.
scope._update();
};
}
};
});
});

View File

@ -1,58 +0,0 @@
define([
'angular',
'lodash',
],
function (angular, _) {
'use strict';
var module = angular.module('grafana.services');
module.service('pluginSrv', function($rootScope, $timeout, $q, backendSrv) {
var self = this;
this.init = function() {
console.log("pluginSrv init");
this.plugins = {};
};
this.get = function(type) {
return $q(function(resolve) {
if (type in self.plugins) {
return resolve(self.plugins[type]);
}
backendSrv.get('/api/plugins').then(function(results) {
_.forEach(results, function(p) {
self.plugins[p.type] = p;
});
return resolve(self.plugins[type]);
});
});
};
this.getAll = function() {
return $q(function(resolve) {
if (!_.isEmpty(self.plugins)) {
return resolve(self.plugins);
}
backendSrv.get('api/plugins').then(function(results) {
_.forEach(results, function(p) {
self.plugins[p.type] = p;
});
return resolve(self.plugins);
});
});
};
this.update = function(plugin) {
return $q(function(resolve, reject) {
backendSrv.post('/api/plugins', plugin).then(function(resp) {
self.plugins[plugin.type] = plugin;
resolve(resp);
}, function(resp) {
reject(resp);
});
});
};
this.init();
});
});

View File

@ -1,33 +0,0 @@
define([
'angular',
'app/core/config',
],
function (angular, config) {
'use strict';
var module = angular.module('grafana.controllers');
module.controller('PluginsCtrl', function($scope, $location, pluginSrv) {
$scope.init = function() {
$scope.plugins = {};
$scope.getPlugins();
};
$scope.getPlugins = function() {
pluginSrv.getAll().then(function(result) {
console.log(result);
$scope.plugins = result;
});
};
$scope.update = function(plugin) {
pluginSrv.update(plugin).then(function() {
window.location.href = config.appSubUrl + $location.path();
});
};
$scope.init();
});
});

View File

@ -98,7 +98,6 @@ function (angular, app, _, require, PanelMeta) {
console.log('Text panel error: ', e);
$scope.content = $sce.trustAsHtml(html);
}
if(!$scope.$$phase) {
$scope.$digest();
}