diff --git a/pkg/api/api.go b/pkg/api/api.go index 4092ff8a826..f4946a19cb6 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -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) diff --git a/pkg/api/index.go b/pkg/api/index.go index bf79059281e..8caa709b0be 100644 --- a/pkg/api/index.go +++ b/pkg/api/index.go @@ -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 { diff --git a/public/app/core/controllers/sidemenu_ctrl.js b/public/app/core/controllers/sidemenu_ctrl.js index a2885674d34..93e1afd151b 100644 --- a/public/app/core/controllers/sidemenu_ctrl.js +++ b/public/app/core/controllers/sidemenu_ctrl.js @@ -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) { diff --git a/public/app/core/routes/all.js b/public/app/core/routes/all.js index fd029a27939..5b0939d133b 100644 --- a/public/app/core/routes/all.js +++ b/public/app/core/routes/all.js @@ -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({ diff --git a/public/app/features/org/all.js b/public/app/features/org/all.js index be9668e33de..3c9e0a4453c 100644 --- a/public/app/features/org/all.js +++ b/public/app/features/org/all.js @@ -6,8 +6,8 @@ define([ './userInviteCtrl', './orgApiKeysCtrl', './orgDetailsCtrl', - './pluginsCtrl', - './pluginEditCtrl', - './plugin_srv', - './plugin_directive', + './appsCtrl', + './appEditCtrl', + './app_srv', + './app_directive', ], function () {}); diff --git a/public/app/features/org/pluginEditCtrl.js b/public/app/features/org/appEditCtrl.js similarity index 65% rename from public/app/features/org/pluginEditCtrl.js rename to public/app/features/org/appEditCtrl.js index b4ba2c05653..8d4bb80dea9 100644 --- a/public/app/features/org/pluginEditCtrl.js +++ b/public/app/features/org/appEditCtrl.js @@ -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"; }); }; diff --git a/public/app/features/org/app_directive.js b/public/app/features/org/app_directive.js new file mode 100644 index 00000000000..c58464f8075 --- /dev/null +++ b/public/app/features/org/app_directive.js @@ -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); + }); + } + } + }); + } + }; + }); +}); \ No newline at end of file diff --git a/public/app/features/org/app_srv.js b/public/app/features/org/app_srv.js new file mode 100644 index 00000000000..f88f17eaff8 --- /dev/null +++ b/public/app/features/org/app_srv.js @@ -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(); + }); +}); diff --git a/public/app/features/org/appsCtrl.js b/public/app/features/org/appsCtrl.js new file mode 100644 index 00000000000..47e6dfcc5d4 --- /dev/null +++ b/public/app/features/org/appsCtrl.js @@ -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(); + + }); +}); \ No newline at end of file diff --git a/public/app/features/org/partials/appConfigCore.html b/public/app/features/org/partials/appConfigCore.html deleted file mode 100644 index 8435f39d07b..00000000000 --- a/public/app/features/org/partials/appConfigCore.html +++ /dev/null @@ -1,3 +0,0 @@ -
| Type | ||
| {{p.type}} | - + Edit diff --git a/public/app/features/org/plugin_directive.js b/public/app/features/org/plugin_directive.js deleted file mode 100644 index 845a60aaa3a..00000000000 --- a/public/app/features/org/plugin_directive.js +++ /dev/null @@ -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(); - }; - } - }; - }); -}); \ No newline at end of file diff --git a/public/app/features/org/plugin_srv.js b/public/app/features/org/plugin_srv.js deleted file mode 100644 index 863828c7659..00000000000 --- a/public/app/features/org/plugin_srv.js +++ /dev/null @@ -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(); - }); -}); diff --git a/public/app/features/org/pluginsCtrl.js b/public/app/features/org/pluginsCtrl.js deleted file mode 100644 index 49dc104a840..00000000000 --- a/public/app/features/org/pluginsCtrl.js +++ /dev/null @@ -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(); - - }); -}); \ No newline at end of file diff --git a/public/app/plugins/panels/text/module.js b/public/app/plugins/panels/text/module.js index 145b3be9b0c..bb3c5faae03 100644 --- a/public/app/plugins/panels/text/module.js +++ b/public/app/plugins/panels/text/module.js @@ -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(); } |