2016-01-10 06:34:20 +08:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AppPluginPage struct {
|
2016-01-12 22:39:29 +08:00
|
|
|
Name string `json:"name"`
|
2016-01-10 06:34:20 +08:00
|
|
|
Url string `json:"url"`
|
|
|
|
ReqRole models.RoleType `json:"reqRole"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type AppPluginCss struct {
|
|
|
|
Light string `json:"light"`
|
|
|
|
Dark string `json:"dark"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type AppPlugin struct {
|
|
|
|
FrontendPluginBase
|
2016-01-12 22:39:29 +08:00
|
|
|
Css *AppPluginCss `json:"css"`
|
|
|
|
Pages []*AppPluginPage `json:"pages"`
|
2016-01-11 17:44:04 +08:00
|
|
|
|
|
|
|
Pinned bool `json:"-"`
|
|
|
|
Enabled bool `json:"-"`
|
2016-01-10 06:34:20 +08:00
|
|
|
}
|
|
|
|
|
2016-01-12 17:20:04 +08:00
|
|
|
func (app *AppPlugin) Load(decoder *json.Decoder, pluginDir string) error {
|
|
|
|
if err := decoder.Decode(&app); err != nil {
|
2016-01-10 06:34:20 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-01-12 17:20:04 +08: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()
|
|
|
|
Apps[app.Id] = app
|
2016-01-10 06:34:20 +08:00
|
|
|
return nil
|
|
|
|
}
|