diff --git a/pkg/api/app_plugin.go b/pkg/api/app_plugin.go index c39acb4dba4..6bc0e5a4933 100644 --- a/pkg/api/app_plugin.go +++ b/pkg/api/app_plugin.go @@ -18,11 +18,11 @@ func GetAppPlugins(c *middleware.Context) Response { installedAppsMap := make(map[string]*dtos.AppPlugin) for t, a := range plugins.Apps { installedAppsMap[t] = &dtos.AppPlugin{ - Type: a.Type, - Enabled: a.Enabled, - PinNavLinks: a.PinNavLinks, - Module: a.Module, - JsonData: make(map[string]interface{}), + Type: a.Type, + Enabled: a.Enabled, + Pinned: a.Pinned, + Module: a.Module, + JsonData: make(map[string]interface{}), } } @@ -32,11 +32,11 @@ func GetAppPlugins(c *middleware.Context) Response { for _, b := range query.Result { if def, ok := installedAppsMap[b.Type]; ok { result = append(result, &dtos.AppPlugin{ - Type: b.Type, - Enabled: b.Enabled, - PinNavLinks: b.PinNavLinks, - Module: def.Module, - JsonData: b.JsonData, + Type: b.Type, + Enabled: b.Enabled, + Pinned: b.Pinned, + Module: def.Module, + JsonData: b.JsonData, }) seenApps[b.Type] = true } diff --git a/pkg/api/datasources.go b/pkg/api/datasources.go index 8451a3e8c14..04fdca8242a 100644 --- a/pkg/api/datasources.go +++ b/pkg/api/datasources.go @@ -125,7 +125,7 @@ func GetDataSourcePlugins(c *middleware.Context) { } enabledPlugins := plugins.GetEnabledPlugins(orgApps.Result) - for key, value := range enabledPlugins.DataSourcePlugins { + for key, value := range enabledPlugins.DataSources { if !value.BuiltIn { dsList[key] = value } diff --git a/pkg/api/dtos/app_plugin.go b/pkg/api/dtos/app_plugin.go index d7eaf8f4140..741b17ab383 100644 --- a/pkg/api/dtos/app_plugin.go +++ b/pkg/api/dtos/app_plugin.go @@ -1,9 +1,9 @@ package dtos type AppPlugin struct { - Type string `json:"type"` - Enabled bool `json:"enabled"` - PinNavLinks bool `json:"pin_nav_links"` - Module string `json:"module"` - JsonData map[string]interface{} `json:"jsonData"` + Type string `json:"type"` + Enabled bool `json:"enabled"` + Pinned bool `json:"pinned"` + Module string `json:"module"` + JsonData map[string]interface{} `json:"jsonData"` } diff --git a/pkg/api/frontendsettings.go b/pkg/api/frontendsettings.go index 9d00576be06..9334b030201 100644 --- a/pkg/api/frontendsettings.go +++ b/pkg/api/frontendsettings.go @@ -34,6 +34,7 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro if err != nil { return nil, err } + enabledPlugins := plugins.GetEnabledPlugins(orgApps.Result) for _, ds := range orgDataSources { @@ -49,7 +50,7 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro "url": url, } - meta, exists := enabledPlugins.DataSourcePlugins[ds.Type] + meta, exists := enabledPlugins.DataSources[ds.Type] if !exists { log.Error(3, "Could not find plugin definition for data source: %v", ds.Type) continue @@ -117,7 +118,7 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro } panels := map[string]interface{}{} - for _, panel := range enabledPlugins.PanelPlugins { + for _, panel := range enabledPlugins.Panels { panels[panel.Type] = map[string]interface{}{ "module": panel.Module, "name": panel.Name, diff --git a/pkg/api/index.go b/pkg/api/index.go index 4874a24a6f6..af8dfcb99f1 100644 --- a/pkg/api/index.go +++ b/pkg/api/index.go @@ -52,7 +52,7 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) { data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{ Text: "Dashboards", Icon: "fa fa-fw fa-th-large", - Href: "/", + Url: "/", }) orgApps := m.GetAppPluginsQuery{OrgId: c.OrgId} @@ -73,7 +73,7 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) { } if plugin.Pinned && plugin.Page != nil { - if c.userHasRole(plugin.Page.reqRole) { + if c.HasUserRole(plugin.Page.ReqRole) { data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{ Text: plugin.Page.Text, Url: plugin.Page.Url, diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 1debde98a0e..3c433728ba6 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -30,9 +30,9 @@ func newMacaron() *macaron.Macaron { } for _, route := range plugins.StaticRoutes { - pluginRoute := path.Join("/public/plugins/", route.Url) - log.Info("Plugin: Adding static route %s -> %s", pluginRoute, route.Path) - mapStatic(m, route.Path, "", pluginRoute) + pluginRoute := path.Join("/public/plugins/", route.UrlFragment) + log.Info("Plugin: Adding static route %s -> %s", pluginRoute, route.Dir) + mapStatic(m, route.Dir, "", pluginRoute) } mapStatic(m, setting.StaticRootPath, "", "public") diff --git a/pkg/middleware/middleware.go b/pkg/middleware/middleware.go index d2da32b8ed7..9ad417606f5 100644 --- a/pkg/middleware/middleware.go +++ b/pkg/middleware/middleware.go @@ -254,6 +254,6 @@ func (ctx *Context) JsonApiErr(status int, message string, err error) { ctx.JSON(status, resp) } -func (ctx *Context) hasUserRole(role m.RoleType) bool { +func (ctx *Context) HasUserRole(role m.RoleType) bool { return ctx.OrgRole.Includes(role) } diff --git a/pkg/plugins/models.go b/pkg/plugins/models.go index 67172d952d7..15e48409144 100644 --- a/pkg/plugins/models.go +++ b/pkg/plugins/models.go @@ -44,7 +44,7 @@ type ApiPluginRoute struct { type AppPluginPage struct { Text string `json:"text"` Icon string `json:"icon"` - Href string `json:"url"` + Url string `json:"url"` ReqRole models.RoleType `json:"reqRole"` } diff --git a/pkg/services/sqlstore/migrations/app_plugin.go b/pkg/services/sqlstore/migrations/app_plugin.go index 8cd16ed22e1..7a1e67cf191 100644 --- a/pkg/services/sqlstore/migrations/app_plugin.go +++ b/pkg/services/sqlstore/migrations/app_plugin.go @@ -4,7 +4,7 @@ import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator" func addAppPluginMigration(mg *Migrator) { - var appPluginV1 = Table{ + var appPluginV2 = Table{ Name: "app_plugin", Columns: []*Column{ {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true}, @@ -20,8 +20,9 @@ func addAppPluginMigration(mg *Migrator) { {Cols: []string{"org_id", "type"}, Type: UniqueIndex}, }, } - mg.AddMigration("create app_plugin table v1", NewAddTableMigration(appPluginV1)) + + mg.AddMigration("create app_plugin table v2", NewAddTableMigration(appPluginV2)) //------- indexes ------------------ - addTableIndicesMigrations(mg, "v1", appPluginV1) + addTableIndicesMigrations(mg, "v2", appPluginV2) } diff --git a/public/app/features/org/appEditCtrl.js b/public/app/features/org/app_edit_ctrl.ts similarity index 59% rename from public/app/features/org/appEditCtrl.js rename to public/app/features/org/app_edit_ctrl.ts index 63f638a72fd..e04be09fc35 100644 --- a/public/app/features/org/appEditCtrl.js +++ b/public/app/features/org/app_edit_ctrl.ts @@ -1,14 +1,13 @@ -define([ - 'angular', - 'lodash', - 'app/core/config', -], -function (angular, _, config) { - 'use strict'; +/// - var module = angular.module('grafana.controllers'); +import config = require('app/core/config'); +import angular from 'angular'; + +export class AppEditCtrl { + + /** @ngInject */ + constructor(private $scope: any, private appSrv: any, private $routeParams: any) { - module.controller('AppEditCtrl', function($scope, appSrv, $routeParams) { $scope.init = function() { $scope.current = {}; $scope.getApps(); @@ -31,5 +30,8 @@ function (angular, _, config) { }; $scope.init(); - }); -}); \ No newline at end of file + } + +} + +angular.module('grafana.controllers').controller('AppEditCtrl', AppEditCtrl); diff --git a/public/app/features/org/app_srv.js b/public/app/features/org/app_srv.js deleted file mode 100644 index f88f17eaff8..00000000000 --- a/public/app/features/org/app_srv.js +++ /dev/null @@ -1,58 +0,0 @@ -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/app_srv.ts b/public/app/features/org/app_srv.ts new file mode 100644 index 00000000000..eeafe0d311e --- /dev/null +++ b/public/app/features/org/app_srv.ts @@ -0,0 +1,47 @@ +/// + +import config = require('app/core/config'); +import angular from 'angular'; + +export class AppSrv { + apps: any = {}; + + /** @ngInject */ + constructor( + private $rootScope, + private $timeout, + private $q, + private backendSrv) { + } + + get(type) { + if (this.apps[type]) { + return this.$q.when(this.apps[type]); + } + return this.getAll().then(() => { + return this.apps[type]; + }); + } + + + getAll() { + if (!_.isEmpty(this.apps)) { + return this.$q.when(this.apps); + } + + return this.backendSrv.get('api/org/apps').then(results => { + this.apps = results.reduce((prev, current) => { + prev[current.type] = current; + }, {}); + return this.apps; + }); + } + + update(app) { + return this.backendSrv.post('api/org/apps', app).then(resp => { + this.apps[app.type] = app; + }); + } +} + +angular.module('grafana.services').service('appSrv', AppSrv); diff --git a/public/app/features/org/partials/appEdit.html b/public/app/features/org/partials/app_edit.html similarity index 100% rename from public/app/features/org/partials/appEdit.html rename to public/app/features/org/partials/app_edit.html diff --git a/public/app/features/org/partials/apps.html b/public/app/features/org/partials/app_list.html similarity index 100% rename from public/app/features/org/partials/apps.html rename to public/app/features/org/partials/app_list.html diff --git a/public/app/partials/sidemenu.html b/public/app/partials/sidemenu.html index caf90c715c4..b8cbdd84bc3 100644 --- a/public/app/partials/sidemenu.html +++ b/public/app/partials/sidemenu.html @@ -19,7 +19,7 @@
  • - + {{item.text}} diff --git a/public/views/index.html b/public/views/index.html index defd7cfe47f..c70be25ef9e 100644 --- a/public/views/index.html +++ b/public/views/index.html @@ -52,7 +52,7 @@ window.grafanaBootData = { user:[[.User]], settings: [[.Settings]], - pluginModules: [[.PluginJs]], + pluginModules: [[.PluginModules]], mainNavLinks: [[.MainNavLinks]] };