feat(plugins): made panels work as plugins

This commit is contained in:
Torkel Ödegaard
2015-11-21 13:46:18 +01:00
parent bd6e2d6ca4
commit 4a69de1f30
51 changed files with 113 additions and 79 deletions

View File

@@ -106,9 +106,18 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro
defaultDatasource = "-- Grafana --"
}
panels := map[string]interface{}{}
for _, panel := range plugins.Panels {
panels[panel.Type] = map[string]interface{}{
"module": panel.Module,
"name": panel.Name,
}
}
jsonObj := map[string]interface{}{
"defaultDatasource": defaultDatasource,
"datasources": datasources,
"panels": panels,
"appSubUrl": setting.AppSubUrl,
"allowOrgCreate": (setting.AllowUserOrgCreate && c.IsSignedIn) || c.IsGrafanaAdmin,
"buildInfo": map[string]interface{}{

View File

@@ -15,6 +15,13 @@ type DataSourcePlugin struct {
StaticRootConfig *StaticRootConfig `json:"staticRoot"`
}
type PanelPlugin struct {
Type string `json:"type"`
Name string `json:"name"`
Module string `json:"module"`
StaticRootConfig *StaticRootConfig `json:"staticRoot"`
}
type StaticRootConfig struct {
Url string `json:"url"`
Path string `json:"path"`

View File

@@ -14,6 +14,7 @@ import (
var (
DataSources map[string]DataSourcePlugin
Panels []PanelPlugin
ExternalPlugins []ExternalPlugin
StaticRoutes []*StaticRootConfig
)
@@ -27,6 +28,7 @@ func Init() error {
DataSources = make(map[string]DataSourcePlugin)
ExternalPlugins = make([]ExternalPlugin, 0)
StaticRoutes = make([]*StaticRootConfig, 0)
Panels = make([]PanelPlugin, 0)
scan(path.Join(setting.StaticRootPath, "app/plugins"))
checkExternalPluginPaths()
@@ -124,6 +126,21 @@ func (scanner *PluginScanner) loadPluginJson(pluginJsonFilePath string) error {
addStaticRoot(p.StaticRootConfig, currentDir)
}
if pluginType == "panel" {
p := PanelPlugin{}
reader.Seek(0, 0)
if err := jsonParser.Decode(&p); err != nil {
return err
}
if p.Type == "" {
return errors.New("Did not find type property in plugin.json")
}
Panels = append(Panels, p)
addStaticRoot(p.StaticRootConfig, currentDir)
}
if pluginType == "external" {
p := ExternalPlugin{}
reader.Seek(0, 0)