2016-01-09 16:34:20 -06:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2016-01-19 11:18:53 -06:00
|
|
|
"strings"
|
2016-01-09 16:34:20 -06:00
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AppPluginPage struct {
|
2016-01-12 08:39:29 -06:00
|
|
|
Name string `json:"name"`
|
2016-01-09 16:34:20 -06:00
|
|
|
Url string `json:"url"`
|
|
|
|
ReqRole models.RoleType `json:"reqRole"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type AppPluginCss struct {
|
|
|
|
Light string `json:"light"`
|
|
|
|
Dark string `json:"dark"`
|
|
|
|
}
|
|
|
|
|
2016-01-19 11:18:53 -06:00
|
|
|
type AppIncludeInfo struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
}
|
|
|
|
|
2016-01-09 16:34:20 -06:00
|
|
|
type AppPlugin struct {
|
|
|
|
FrontendPluginBase
|
2016-01-19 11:18:53 -06:00
|
|
|
Css *AppPluginCss `json:"css"`
|
|
|
|
Pages []AppPluginPage `json:"pages"`
|
|
|
|
Includes []AppIncludeInfo `json:"-"`
|
2016-01-11 03:44:04 -06:00
|
|
|
|
|
|
|
Pinned bool `json:"-"`
|
|
|
|
Enabled bool `json:"-"`
|
2016-01-09 16:34:20 -06:00
|
|
|
}
|
|
|
|
|
2016-01-12 03:20:04 -06:00
|
|
|
func (app *AppPlugin) Load(decoder *json.Decoder, pluginDir string) error {
|
|
|
|
if err := decoder.Decode(&app); err != nil {
|
2016-01-09 16:34:20 -06:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-01-12 03:20:04 -06:00
|
|
|
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()
|
2016-01-19 11:18:53 -06:00
|
|
|
|
|
|
|
// check if we have child panels
|
|
|
|
for _, panel := range Panels {
|
|
|
|
if strings.HasPrefix(panel.PluginDir, app.PluginDir) {
|
|
|
|
panel.IncludedInAppId = app.Id
|
|
|
|
app.Includes = append(app.Includes, AppIncludeInfo{
|
|
|
|
Name: panel.Name,
|
|
|
|
Id: panel.Id,
|
|
|
|
Type: panel.Type,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-20 21:39:51 -06:00
|
|
|
// check if we have child apiPlugins
|
|
|
|
for _, plugin := range ApiPlugins {
|
|
|
|
if strings.HasPrefix(plugin.PluginDir, app.PluginDir) {
|
|
|
|
plugin.IncludedInAppId = app.Id
|
|
|
|
app.Includes = append(app.Includes, AppIncludeInfo{
|
|
|
|
Name: plugin.Name,
|
|
|
|
Id: plugin.Id,
|
|
|
|
Type: plugin.Type,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-12 03:20:04 -06:00
|
|
|
Apps[app.Id] = app
|
2016-01-09 16:34:20 -06:00
|
|
|
return nil
|
|
|
|
}
|