feat(plugins): WIP on new apps concept

This commit is contained in:
Torkel Ödegaard
2015-12-21 23:09:27 +01:00
parent 0903d5541b
commit eacc46da6d
10 changed files with 141 additions and 146 deletions
+26 -34
View File
@@ -15,20 +15,20 @@ type DataSourcePlugin struct {
Metrics bool `json:"metrics"`
BuiltIn bool `json:"builtIn"`
App string `json:"app"`
StaticRootConfig *StaticRootConfig `json:"staticRoot"`
PublicContent *PublicContent `json:"public"`
}
type PanelPlugin struct {
Type string `json:"type"`
Name string `json:"name"`
Module string `json:"module"`
StaticRootConfig *StaticRootConfig `json:"staticRoot"`
App string `json:"app"`
Type string `json:"type"`
Name string `json:"name"`
Module string `json:"module"`
PublicContent *PublicContent `json:"public"`
App string `json:"app"`
}
type StaticRootConfig struct {
Url string `json:"url"`
Path string `json:"path"`
type PublicContent struct {
UrlFragment string `json:"urlFragment"`
Dir string `json:"dir"`
}
type ApiPluginRoute struct {
@@ -41,14 +41,10 @@ type ApiPluginRoute struct {
App string `json:"app"`
}
type AppPluginJs struct {
Module string `json:"module"`
}
type AppPluginNavLink struct {
type AppPluginPage struct {
Text string `json:"text"`
Icon string `json:"icon"`
Href string `json:"href"`
Href string `json:"url"`
ReqRole models.RoleType `json:"reqRole"`
}
@@ -64,31 +60,27 @@ type ApiPlugin struct {
}
type AppPlugin struct {
Type string `json:"type"`
Enabled bool `json:"enabled"`
PanelPlugins []string `json:"panelPlugins"`
DatasourcePlugins []string `json:"datasourcePlugins"`
ApiPlugins []string `json:"apiPlugins"`
Module string `json:"module"`
Js []*AppPluginJs `json:"js"`
Css []*AppPluginCss `json:"css"`
MainNavLinks []*AppPluginNavLink `json:"mainNavLinks"`
PinNavLinks bool `json:"pinNavLinks"`
StaticRootConfig *StaticRootConfig `json:"staticRoot"`
Type string `json:"type"`
Enabled bool `json:"enabled"`
Pinned bool `json:"pinned"`
Module string `json:"module"`
Css *AppPluginCss `json:"css"`
Page *AppPluginPage `json:"page"`
PublicContent *PublicContent `json:"public"`
}
type EnabledPlugins struct {
PanelPlugins []*PanelPlugin
DataSourcePlugins map[string]*DataSourcePlugin
ApiPlugins []*ApiPlugin
AppPlugins []*AppPlugin
Panels []*PanelPlugin
DataSources map[string]*DataSourcePlugin
ApiList []*ApiPlugin
Apps []*AppPlugin
}
func NewEnabledPlugins() EnabledPlugins {
return EnabledPlugins{
PanelPlugins: make([]*PanelPlugin, 0),
DataSourcePlugins: make(map[string]*DataSourcePlugin),
ApiPlugins: make([]*ApiPlugin, 0),
AppPlugins: make([]*AppPlugin, 0),
Panels: make([]*PanelPlugin, 0),
DataSources: make(map[string]*DataSourcePlugin),
ApiList: make([]*ApiPlugin, 0),
Apps: make([]*AppPlugin, 0),
}
}
+59 -57
View File
@@ -18,7 +18,7 @@ var (
DataSources map[string]*DataSourcePlugin
Panels map[string]*PanelPlugin
ApiPlugins map[string]*ApiPlugin
StaticRoutes []*StaticRootConfig
StaticRoutes []*PublicContent
Apps map[string]*AppPlugin
)
@@ -30,35 +30,35 @@ type PluginScanner struct {
func Init() error {
DataSources = make(map[string]*DataSourcePlugin)
ApiPlugins = make(map[string]*ApiPlugin)
StaticRoutes = make([]*StaticRootConfig, 0)
StaticRoutes = make([]*PublicContent, 0)
Panels = make(map[string]*PanelPlugin)
Apps = make(map[string]*AppPlugin)
scan(path.Join(setting.StaticRootPath, "app/plugins"))
checkPluginPaths()
checkDependencies()
// checkDependencies()
return nil
}
func checkDependencies() {
for appType, app := range Apps {
for _, reqPanel := range app.PanelPlugins {
if _, ok := Panels[reqPanel]; !ok {
log.Fatal(4, "App %s requires Panel type %s, but it is not present.", appType, reqPanel)
}
}
for _, reqDataSource := range app.DatasourcePlugins {
if _, ok := DataSources[reqDataSource]; !ok {
log.Fatal(4, "App %s requires DataSource type %s, but it is not present.", appType, reqDataSource)
}
}
for _, reqApiPlugin := range app.ApiPlugins {
if _, ok := ApiPlugins[reqApiPlugin]; !ok {
log.Fatal(4, "App %s requires ApiPlugin type %s, but it is not present.", appType, reqApiPlugin)
}
}
}
}
// func checkDependencies() {
// for appType, app := range Apps {
// for _, reqPanel := range app.PanelPlugins {
// if _, ok := Panels[reqPanel]; !ok {
// log.Fatal(4, "App %s requires Panel type %s, but it is not present.", appType, reqPanel)
// }
// }
// for _, reqDataSource := range app.DatasourcePlugins {
// if _, ok := DataSources[reqDataSource]; !ok {
// log.Fatal(4, "App %s requires DataSource type %s, but it is not present.", appType, reqDataSource)
// }
// }
// for _, reqApiPlugin := range app.ApiPlugins {
// if _, ok := ApiPlugins[reqApiPlugin]; !ok {
// log.Fatal(4, "App %s requires ApiPlugin type %s, but it is not present.", appType, reqApiPlugin)
// }
// }
// }
// }
func checkPluginPaths() error {
for _, section := range setting.Cfg.Sections() {
@@ -108,10 +108,10 @@ func (scanner *PluginScanner) walker(currentPath string, f os.FileInfo, err erro
return nil
}
func addStaticRoot(staticRootConfig *StaticRootConfig, currentDir string) {
if staticRootConfig != nil {
staticRootConfig.Path = path.Join(currentDir, staticRootConfig.Path)
StaticRoutes = append(StaticRoutes, staticRootConfig)
func addPublicContent(public *PublicContent, currentDir string) {
if public != nil {
public.Dir = path.Join(currentDir, public.Dir)
StaticRoutes = append(StaticRoutes, public)
}
}
@@ -148,7 +148,7 @@ func (scanner *PluginScanner) loadPluginJson(pluginJsonFilePath string) error {
}
DataSources[p.Type] = &p
addStaticRoot(p.StaticRootConfig, currentDir)
addPublicContent(p.PublicContent, currentDir)
}
if pluginType == "panel" {
@@ -163,7 +163,7 @@ func (scanner *PluginScanner) loadPluginJson(pluginJsonFilePath string) error {
}
Panels[p.Type] = &p
addStaticRoot(p.StaticRootConfig, currentDir)
addPublicContent(p.PublicContent, currentDir)
}
if pluginType == "api" {
@@ -188,7 +188,7 @@ func (scanner *PluginScanner) loadPluginJson(pluginJsonFilePath string) error {
return errors.New("Did not find type property in plugin.json")
}
Apps[p.Type] = &p
addStaticRoot(p.StaticRootConfig, currentDir)
addPublicContent(p.PublicContent, currentDir)
}
return nil
@@ -212,54 +212,56 @@ func GetEnabledPlugins(orgApps []*models.AppPlugin) EnabledPlugins {
// state stored there.
if b, ok := orgAppsMap[appType]; ok {
app.Enabled = b.Enabled
app.PinNavLinks = b.PinNavLinks
app.Pinned = b.Pinned
}
if app.Enabled {
for _, d := range app.DatasourcePlugins {
if ds, ok := DataSources[d]; ok {
enabledPlugins.DataSourcePlugins[d] = ds
}
}
for _, p := range app.PanelPlugins {
if panel, ok := Panels[p]; ok {
if _, ok := seenPanels[p]; !ok {
seenPanels[p] = true
enabledPlugins.PanelPlugins = append(enabledPlugins.PanelPlugins, panel)
}
}
}
for _, a := range app.ApiPlugins {
if api, ok := ApiPlugins[a]; ok {
if _, ok := seenApi[a]; !ok {
seenApi[a] = true
enabledPlugins.ApiPlugins = append(enabledPlugins.ApiPlugins, api)
}
}
}
enabledPlugins.AppPlugins = append(enabledPlugins.AppPlugins, &app)
}
// if app.Enabled {
// for _, d := range app.DatasourcePlugins {
// if ds, ok := DataSources[d]; ok {
// enabledPlugins.DataSourcePlugins[d] = ds
// }
// }
// for _, p := range app.PanelPlugins {
// if panel, ok := Panels[p]; ok {
// if _, ok := seenPanels[p]; !ok {
// seenPanels[p] = true
// enabledPlugins.PanelPlugins = append(enabledPlugins.PanelPlugins, panel)
// }
// }
// }
// for _, a := range app.ApiPlugins {
// if api, ok := ApiPlugins[a]; ok {
// if _, ok := seenApi[a]; !ok {
// seenApi[a] = true
// enabledPlugins.ApiPlugins = append(enabledPlugins.ApiPlugins, api)
// }
// }
// }
// enabledPlugins.AppPlugins = append(enabledPlugins.AppPlugins, &app)
// }
}
// add all plugins that are not part of an App.
for d, installedDs := range DataSources {
if installedDs.App == "" {
enabledPlugins.DataSourcePlugins[d] = installedDs
enabledPlugins.DataSources[d] = installedDs
}
}
for p, panel := range Panels {
if panel.App == "" {
if _, ok := seenPanels[p]; !ok {
seenPanels[p] = true
enabledPlugins.PanelPlugins = append(enabledPlugins.PanelPlugins, panel)
enabledPlugins.Panels = append(enabledPlugins.Panels, panel)
}
}
}
for a, api := range ApiPlugins {
if api.App == "" {
if _, ok := seenApi[a]; !ok {
seenApi[a] = true
enabledPlugins.ApiPlugins = append(enabledPlugins.ApiPlugins, api)
enabledPlugins.ApiList = append(enabledPlugins.ApiList, api)
}
}
}