mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 15:45:43 -06:00
feat(apps): lots of work making apps easier to develop, module paths are handled automatically
This commit is contained in:
parent
fe2e6b8a80
commit
baff9b0267
@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"type": "panel",
|
"type": "panel",
|
||||||
"name": "Nginx Panel",
|
"name": "Nginx Panel",
|
||||||
"id": "nginx-panel",
|
"id": "nginx-panel"
|
||||||
"staticRoot": "."
|
|
||||||
}
|
}
|
||||||
|
@ -57,18 +57,24 @@ func (app *AppPlugin) Load(decoder *json.Decoder, pluginDir string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.PluginDir = pluginDir
|
||||||
|
|
||||||
|
Apps[app.Id] = app
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *AppPlugin) initApp() {
|
||||||
|
app.initFrontendPlugin()
|
||||||
|
|
||||||
if app.Css != nil {
|
if app.Css != nil {
|
||||||
app.Css.Dark = evalRelativePluginUrlPath(app.Css.Dark, app.Id)
|
app.Css.Dark = evalRelativePluginUrlPath(app.Css.Dark, app.Id)
|
||||||
app.Css.Light = evalRelativePluginUrlPath(app.Css.Light, app.Id)
|
app.Css.Light = evalRelativePluginUrlPath(app.Css.Light, app.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.PluginDir = pluginDir
|
|
||||||
app.initFrontendPlugin()
|
|
||||||
|
|
||||||
// check if we have child panels
|
// check if we have child panels
|
||||||
for _, panel := range Panels {
|
for _, panel := range Panels {
|
||||||
if strings.HasPrefix(panel.PluginDir, app.PluginDir) {
|
if strings.HasPrefix(panel.PluginDir, app.PluginDir) {
|
||||||
panel.IncludedInAppId = app.Id
|
panel.setPathsBasedOnApp(app)
|
||||||
app.Includes = append(app.Includes, &AppIncludeInfo{
|
app.Includes = append(app.Includes, &AppIncludeInfo{
|
||||||
Name: panel.Name,
|
Name: panel.Name,
|
||||||
Id: panel.Id,
|
Id: panel.Id,
|
||||||
@ -80,7 +86,7 @@ func (app *AppPlugin) Load(decoder *json.Decoder, pluginDir string) error {
|
|||||||
// check if we have child datasources
|
// check if we have child datasources
|
||||||
for _, ds := range DataSources {
|
for _, ds := range DataSources {
|
||||||
if strings.HasPrefix(ds.PluginDir, app.PluginDir) {
|
if strings.HasPrefix(ds.PluginDir, app.PluginDir) {
|
||||||
ds.IncludedInAppId = app.Id
|
ds.setPathsBasedOnApp(app)
|
||||||
app.Includes = append(app.Includes, &AppIncludeInfo{
|
app.Includes = append(app.Includes, &AppIncludeInfo{
|
||||||
Name: ds.Name,
|
Name: ds.Name,
|
||||||
Id: ds.Id,
|
Id: ds.Id,
|
||||||
@ -95,7 +101,4 @@ func (app *AppPlugin) Load(decoder *json.Decoder, pluginDir string) error {
|
|||||||
page.Slug = slug.Make(page.Name)
|
page.Slug = slug.Make(page.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Apps[app.Id] = app
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ func (p *DataSourcePlugin) Load(decoder *json.Decoder, pluginDir string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.PluginDir = pluginDir
|
p.PluginDir = pluginDir
|
||||||
p.initFrontendPlugin()
|
|
||||||
DataSources[p.Id] = p
|
DataSources[p.Id] = p
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -4,6 +4,10 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/log"
|
||||||
|
"github.com/grafana/grafana/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FrontendPluginBase struct {
|
type FrontendPluginBase struct {
|
||||||
@ -23,18 +27,27 @@ func (fp *FrontendPluginBase) initFrontendPlugin() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fp.handleModuleDefaults()
|
||||||
|
|
||||||
fp.Info.Logos.Small = evalRelativePluginUrlPath(fp.Info.Logos.Small, 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.Info.Logos.Large = evalRelativePluginUrlPath(fp.Info.Logos.Large, fp.Id)
|
||||||
for i := -0; i < len(fp.Info.Screenshots); i++ {
|
|
||||||
|
for i := 0; i < len(fp.Info.Screenshots); i++ {
|
||||||
fp.Info.Screenshots[i].Path = evalRelativePluginUrlPath(fp.Info.Screenshots[i].Path, fp.Id)
|
fp.Info.Screenshots[i].Path = evalRelativePluginUrlPath(fp.Info.Screenshots[i].Path, fp.Id)
|
||||||
}
|
}
|
||||||
fp.handleModuleDefaults()
|
}
|
||||||
|
|
||||||
|
func (fp *FrontendPluginBase) setPathsBasedOnApp(app *AppPlugin) {
|
||||||
|
// log.Info("Module Before: %v", fp.Module)
|
||||||
|
// find out plugins path relative to app static root
|
||||||
|
appSubPath := strings.Replace(fp.PluginDir, app.StaticRootAbs, "", 1)
|
||||||
|
fp.IncludedInAppId = app.Id
|
||||||
|
fp.BaseUrl = app.BaseUrl
|
||||||
|
fp.Module = util.JoinUrlFragments("plugins/"+app.Id, appSubPath) + "/module"
|
||||||
|
log.Info("setting paths based on app: subpath = %v, module: %v", appSubPath, fp.Module)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fp *FrontendPluginBase) handleModuleDefaults() {
|
func (fp *FrontendPluginBase) handleModuleDefaults() {
|
||||||
if fp.Module != "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if fp.StaticRoot != "" {
|
if fp.StaticRoot != "" {
|
||||||
fp.Module = path.Join("plugins", fp.Id, "module")
|
fp.Module = path.Join("plugins", fp.Id, "module")
|
||||||
|
@ -12,7 +12,6 @@ func (p *PanelPlugin) Load(decoder *json.Decoder, pluginDir string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.PluginDir = pluginDir
|
p.PluginDir = pluginDir
|
||||||
p.initFrontendPlugin()
|
|
||||||
Panels[p.Id] = p
|
Panels[p.Id] = p
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -41,7 +41,17 @@ func Init() error {
|
|||||||
scan(path.Join(setting.StaticRootPath, "app/plugins"))
|
scan(path.Join(setting.StaticRootPath, "app/plugins"))
|
||||||
scan(setting.PluginsPath)
|
scan(setting.PluginsPath)
|
||||||
checkPluginPaths()
|
checkPluginPaths()
|
||||||
// checkDependencies()
|
|
||||||
|
for _, panel := range Panels {
|
||||||
|
panel.initFrontendPlugin()
|
||||||
|
}
|
||||||
|
for _, panel := range DataSources {
|
||||||
|
panel.initFrontendPlugin()
|
||||||
|
}
|
||||||
|
for _, app := range Apps {
|
||||||
|
app.initApp()
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user