mirror of https://github.com/grafana/grafana
parent
35f40b7312
commit
1ffcea1952
@ -0,0 +1,38 @@ |
||||
package plugins |
||||
|
||||
import ( |
||||
"encoding/json" |
||||
|
||||
"github.com/grafana/grafana/pkg/models" |
||||
) |
||||
|
||||
type AppPluginPage struct { |
||||
Text string `json:"text"` |
||||
Icon string `json:"icon"` |
||||
Url string `json:"url"` |
||||
ReqRole models.RoleType `json:"reqRole"` |
||||
} |
||||
|
||||
type AppPluginCss struct { |
||||
Light string `json:"light"` |
||||
Dark string `json:"dark"` |
||||
} |
||||
|
||||
type AppPlugin struct { |
||||
FrontendPluginBase |
||||
Enabled bool `json:"enabled"` |
||||
Pinned bool `json:"pinned"` |
||||
Css *AppPluginCss `json:"css"` |
||||
Page *AppPluginPage `json:"page"` |
||||
} |
||||
|
||||
func (p *AppPlugin) Load(decoder *json.Decoder, pluginDir string) error { |
||||
if err := decoder.Decode(&p); err != nil { |
||||
return err |
||||
} |
||||
|
||||
p.PluginDir = pluginDir |
||||
p.initFrontendPlugin() |
||||
Apps[p.Id] = p |
||||
return nil |
||||
} |
@ -0,0 +1,25 @@ |
||||
package plugins |
||||
|
||||
import "encoding/json" |
||||
|
||||
type DataSourcePlugin struct { |
||||
FrontendPluginBase |
||||
DefaultMatchFormat string `json:"defaultMatchFormat"` |
||||
Annotations bool `json:"annotations"` |
||||
Metrics bool `json:"metrics"` |
||||
BuiltIn bool `json:"builtIn"` |
||||
Mixed bool `json:"mixed"` |
||||
App string `json:"app"` |
||||
} |
||||
|
||||
func (p *DataSourcePlugin) Load(decoder *json.Decoder, pluginDir string) error { |
||||
if err := decoder.Decode(&p); err != nil { |
||||
return err |
||||
} |
||||
|
||||
p.PluginDir = pluginDir |
||||
p.initFrontendPlugin() |
||||
DataSources[p.Id] = p |
||||
|
||||
return nil |
||||
} |
@ -0,0 +1,47 @@ |
||||
package plugins |
||||
|
||||
import ( |
||||
"net/url" |
||||
"path" |
||||
) |
||||
|
||||
type FrontendPluginBase struct { |
||||
PluginBase |
||||
Module string `json:"module"` |
||||
StaticRoot string `json:"staticRoot"` |
||||
} |
||||
|
||||
func (fp *FrontendPluginBase) initFrontendPlugin() { |
||||
if fp.StaticRoot != "" { |
||||
StaticRoutes = append(StaticRoutes, &PluginStaticRoute{ |
||||
Directory: fp.StaticRoot, |
||||
PluginId: fp.Id, |
||||
}) |
||||
} |
||||
|
||||
fp.Info.Logos.Small = evalRelativePluginUrlPath(fp.Info.Logos.Small, fp.Id) |
||||
fp.Info.Logos.Large = evalRelativePluginUrlPath(fp.Info.Logos.Large, fp.Id) |
||||
|
||||
fp.handleModuleDefaults() |
||||
} |
||||
|
||||
func (fp *FrontendPluginBase) handleModuleDefaults() { |
||||
if fp.Module != "" { |
||||
return |
||||
} |
||||
|
||||
if fp.StaticRoot != "" { |
||||
fp.Module = path.Join("plugins", fp.Type, fp.Id, "module") |
||||
return |
||||
} |
||||
|
||||
fp.Module = path.Join("app/plugins", fp.Type, fp.Id, "module") |
||||
} |
||||
|
||||
func evalRelativePluginUrlPath(pathStr string, pluginId string) string { |
||||
u, _ := url.Parse(pathStr) |
||||
if u.IsAbs() { |
||||
return pathStr |
||||
} |
||||
return path.Join("public/plugins", pluginId, pathStr) |
||||
} |
@ -0,0 +1,19 @@ |
||||
package plugins |
||||
|
||||
import "encoding/json" |
||||
|
||||
type PanelPlugin struct { |
||||
FrontendPluginBase |
||||
} |
||||
|
||||
func (p *PanelPlugin) Load(decoder *json.Decoder, pluginDir string) error { |
||||
if err := decoder.Decode(&p); err != nil { |
||||
return err |
||||
} |
||||
|
||||
p.PluginDir = pluginDir |
||||
p.initFrontendPlugin() |
||||
Panels[p.Id] = p |
||||
|
||||
return nil |
||||
} |
@ -0,0 +1,3 @@ |
||||
declare var Datasource: any; |
||||
export default Datasource; |
||||
|
Loading…
Reference in new issue