Skip to content

Commit

Permalink
feat(apps): lots of work making apps easier to develop, module paths …
Browse files Browse the repository at this point in the history
…are handled automatically
  • Loading branch information
torkelo committed Feb 9, 2016
1 parent fe2e6b8 commit baff9b0
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 18 deletions.
3 changes: 1 addition & 2 deletions examples/nginx-app/panel/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"type": "panel",
"name": "Nginx Panel",
"id": "nginx-panel",
"staticRoot": "."
"id": "nginx-panel"
}
19 changes: 11 additions & 8 deletions pkg/plugins/app_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,24 @@ func (app *AppPlugin) Load(decoder *json.Decoder, pluginDir string) error {
return err
}

app.PluginDir = pluginDir

Apps[app.Id] = app
return nil
}

func (app *AppPlugin) initApp() {
app.initFrontendPlugin()

if app.Css != nil {
app.Css.Dark = evalRelativePluginUrlPath(app.Css.Dark, app.Id)
app.Css.Light = evalRelativePluginUrlPath(app.Css.Light, app.Id)
}

app.PluginDir = pluginDir
app.initFrontendPlugin()

// check if we have child panels
for _, panel := range Panels {
if strings.HasPrefix(panel.PluginDir, app.PluginDir) {
panel.IncludedInAppId = app.Id
panel.setPathsBasedOnApp(app)
app.Includes = append(app.Includes, &AppIncludeInfo{
Name: panel.Name,
Id: panel.Id,
Expand All @@ -80,7 +86,7 @@ func (app *AppPlugin) Load(decoder *json.Decoder, pluginDir string) error {
// check if we have child datasources
for _, ds := range DataSources {
if strings.HasPrefix(ds.PluginDir, app.PluginDir) {
ds.IncludedInAppId = app.Id
ds.setPathsBasedOnApp(app)
app.Includes = append(app.Includes, &AppIncludeInfo{
Name: ds.Name,
Id: ds.Id,
Expand All @@ -95,7 +101,4 @@ func (app *AppPlugin) Load(decoder *json.Decoder, pluginDir string) error {
page.Slug = slug.Make(page.Name)
}
}

Apps[app.Id] = app
return nil
}
1 change: 0 additions & 1 deletion pkg/plugins/datasource_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func (p *DataSourcePlugin) Load(decoder *json.Decoder, pluginDir string) error {
}

p.PluginDir = pluginDir
p.initFrontendPlugin()
DataSources[p.Id] = p

return nil
Expand Down
23 changes: 18 additions & 5 deletions pkg/plugins/frontend_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
"net/url"
"path"
"path/filepath"
"strings"

"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/util"
)

type FrontendPluginBase struct {
Expand All @@ -23,18 +27,27 @@ func (fp *FrontendPluginBase) initFrontendPlugin() {
})
}

fp.handleModuleDefaults()

fp.Info.Logos.Small = evalRelativePluginUrlPath(fp.Info.Logos.Small, 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.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() {
if fp.Module != "" {
return
}

if fp.StaticRoot != "" {
fp.Module = path.Join("plugins", fp.Id, "module")
Expand Down
1 change: 0 additions & 1 deletion pkg/plugins/panel_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ func (p *PanelPlugin) Load(decoder *json.Decoder, pluginDir string) error {
}

p.PluginDir = pluginDir
p.initFrontendPlugin()
Panels[p.Id] = p

return nil
Expand Down
12 changes: 11 additions & 1 deletion pkg/plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ func Init() error {
scan(path.Join(setting.StaticRootPath, "app/plugins"))
scan(setting.PluginsPath)
checkPluginPaths()
// checkDependencies()

for _, panel := range Panels {
panel.initFrontendPlugin()
}
for _, panel := range DataSources {
panel.initFrontendPlugin()
}
for _, app := range Apps {
app.initApp()
}

return nil
}

Expand Down

0 comments on commit baff9b0

Please sign in to comment.