mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(plugins): made panels work as plugins
This commit is contained in:
@@ -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{}{
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user