f953033ba7
Allow plugin creators to include screenshots of their plugin in action. Primarily for use in Grafana.net info pages.
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package plugins
|
|
|
|
import (
|
|
"net/url"
|
|
"path"
|
|
"path/filepath"
|
|
)
|
|
|
|
type FrontendPluginBase struct {
|
|
PluginBase
|
|
Module string `json:"module"`
|
|
StaticRoot string `json:"staticRoot"`
|
|
StaticRootAbs string `json:"-"`
|
|
}
|
|
|
|
func (fp *FrontendPluginBase) initFrontendPlugin() {
|
|
if fp.StaticRoot != "" {
|
|
fp.StaticRootAbs = filepath.Join(fp.PluginDir, fp.StaticRoot)
|
|
StaticRoutes = append(StaticRoutes, &PluginStaticRoute{
|
|
Directory: fp.StaticRootAbs,
|
|
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)
|
|
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) handleModuleDefaults() {
|
|
if fp.Module != "" {
|
|
return
|
|
}
|
|
|
|
if fp.StaticRoot != "" {
|
|
fp.Module = path.Join("plugins", 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)
|
|
}
|