Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
9943b9a2
Commit
9943b9a2
authored
Jan 09, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(plugin): more work on plugin schema
parent
3bb20dbf
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
52 deletions
+60
-52
pkg/cmd/web.go
+3
-3
pkg/plugins/models.go
+17
-19
pkg/plugins/plugins.go
+23
-9
pkg/plugins/plugins_test.go
+1
-1
tests/app-plugin-json/plugin.json
+16
-20
No files found.
pkg/cmd/web.go
View file @
9943b9a2
...
...
@@ -30,9 +30,9 @@ func newMacaron() *macaron.Macaron {
}
for
_
,
route
:=
range
plugins
.
StaticRoutes
{
pluginRoute
:=
path
.
Join
(
"/public/plugins/"
,
route
.
UrlFragment
)
log
.
Info
(
"Plugin: Adding static route %s -> %s"
,
pluginRoute
,
route
.
Dir
)
mapStatic
(
m
,
route
.
Dir
,
""
,
pluginRoute
)
pluginRoute
:=
path
.
Join
(
"/public/plugins/"
,
route
.
PluginId
)
log
.
Info
(
"Plugin: Adding static route %s -> %s"
,
pluginRoute
,
route
.
Dir
ectory
)
mapStatic
(
m
,
route
.
Dir
ectory
,
""
,
pluginRoute
)
}
mapStatic
(
m
,
setting
.
StaticRootPath
,
""
,
"public"
)
...
...
pkg/plugins/models.go
View file @
9943b9a2
...
...
@@ -5,10 +5,11 @@ import (
)
type
PluginCommon
struct
{
Type
string
`json:"type"`
Name
string
`json:"name"`
Id
string
`json:"id"`
Info
PluginInfo
`json:"info"`
Type
string
`json:"type"`
Name
string
`json:"name"`
Id
string
`json:"id"`
StaticRoot
string
`json:"staticRoot"`
Info
PluginInfo
`json:"info"`
}
type
PluginInfo
struct
{
...
...
@@ -38,19 +39,17 @@ type DataSourcePlugin struct {
Metrics
bool
`json:"metrics"`
BuiltIn
bool
`json:"builtIn"`
App
string
`json:"app"`
PublicContent
*
PublicContent
`json:"public"`
}
type
PanelPlugin
struct
{
PluginCommon
Module
string
`json:"module"`
PublicContent
*
PublicContent
`json:"public"`
App
string
`json:"app"`
type
PluginStaticRoute
struct
{
Directory
string
PluginId
string
}
type
PublicContent
struct
{
UrlFragment
string
`json:"urlFragment"`
Dir
string
`json:"dir"`
type
PanelPlugin
struct
{
PluginCommon
Module
string
`json:"module"`
App
string
`json:"app"`
}
type
ApiPluginRoute
struct
{
...
...
@@ -83,12 +82,11 @@ type ApiPlugin struct {
type
AppPlugin
struct
{
PluginCommon
Enabled
bool
`json:"enabled"`
Pinned
bool
`json:"pinned"`
Module
string
`json:"module"`
Css
*
AppPluginCss
`json:"css"`
Page
*
AppPluginPage
`json:"page"`
PublicContent
*
PublicContent
`json:"public"`
Enabled
bool
`json:"enabled"`
Pinned
bool
`json:"pinned"`
Module
string
`json:"module"`
Css
*
AppPluginCss
`json:"css"`
Page
*
AppPluginPage
`json:"page"`
}
type
EnabledPlugins
struct
{
...
...
pkg/plugins/plugins.go
View file @
9943b9a2
...
...
@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"io"
"net/url"
"os"
"path"
"path/filepath"
...
...
@@ -21,7 +22,7 @@ var (
DataSources
map
[
string
]
*
DataSourcePlugin
Panels
map
[
string
]
*
PanelPlugin
ApiPlugins
map
[
string
]
*
ApiPlugin
StaticRoutes
[]
*
P
ublicContent
StaticRoutes
[]
*
P
luginStaticRoute
Apps
map
[
string
]
*
AppPlugin
)
...
...
@@ -33,7 +34,7 @@ type PluginScanner struct {
func
Init
()
error
{
DataSources
=
make
(
map
[
string
]
*
DataSourcePlugin
)
ApiPlugins
=
make
(
map
[
string
]
*
ApiPlugin
)
StaticRoutes
=
make
([]
*
P
ublicContent
,
0
)
StaticRoutes
=
make
([]
*
P
luginStaticRoute
,
0
)
Panels
=
make
(
map
[
string
]
*
PanelPlugin
)
Apps
=
make
(
map
[
string
]
*
AppPlugin
)
...
...
@@ -114,11 +115,24 @@ func (scanner *PluginScanner) walker(currentPath string, f os.FileInfo, err erro
return
nil
}
func
addPublicContent
(
public
*
PublicContent
,
currentDir
string
)
{
if
public
!=
nil
{
public
.
Dir
=
path
.
Join
(
currentDir
,
public
.
Dir
)
StaticRoutes
=
append
(
StaticRoutes
,
public
)
func
evalRelativePluginUrlPath
(
pathStr
string
,
pluginId
string
)
string
{
u
,
_
:=
url
.
Parse
(
pathStr
)
if
u
.
IsAbs
()
{
return
pathStr
}
return
path
.
Join
(
"public/plugins"
,
pluginId
,
pathStr
)
}
func
addPublicContent
(
plugin
*
PluginCommon
,
currentDir
string
)
{
if
plugin
.
StaticRoot
!=
""
{
StaticRoutes
=
append
(
StaticRoutes
,
&
PluginStaticRoute
{
Directory
:
path
.
Join
(
currentDir
,
plugin
.
StaticRoot
),
PluginId
:
plugin
.
Id
,
})
}
plugin
.
Info
.
Logos
.
Small
=
evalRelativePluginUrlPath
(
plugin
.
Info
.
Logos
.
Small
,
plugin
.
Id
)
plugin
.
Info
.
Logos
.
Large
=
evalRelativePluginUrlPath
(
plugin
.
Info
.
Logos
.
Large
,
plugin
.
Id
)
}
func
interpolatePluginJson
(
reader
io
.
Reader
,
pluginCommon
*
PluginCommon
)
(
io
.
Reader
,
error
)
{
...
...
@@ -178,7 +192,7 @@ func (scanner *PluginScanner) loadPluginJson(pluginJsonFilePath string) error {
}
DataSources
[
p
.
Id
]
=
&
p
addPublicContent
(
p
.
PublicContent
,
currentDir
)
addPublicContent
(
&
p
.
PluginCommon
,
currentDir
)
case
"panel"
:
p
:=
PanelPlugin
{}
...
...
@@ -188,7 +202,7 @@ func (scanner *PluginScanner) loadPluginJson(pluginJsonFilePath string) error {
}
Panels
[
p
.
Id
]
=
&
p
addPublicContent
(
p
.
PublicContent
,
currentDir
)
addPublicContent
(
&
p
.
PluginCommon
,
currentDir
)
case
"api"
:
p
:=
ApiPlugin
{}
reader
.
Seek
(
0
,
0
)
...
...
@@ -203,7 +217,7 @@ func (scanner *PluginScanner) loadPluginJson(pluginJsonFilePath string) error {
return
err
}
Apps
[
p
.
Id
]
=
&
p
addPublicContent
(
p
.
PublicContent
,
currentDir
)
addPublicContent
(
&
p
.
PluginCommon
,
currentDir
)
default
:
return
errors
.
New
(
"Unkown plugin type "
+
pluginCommon
.
Type
)
}
...
...
pkg/plugins/plugins_test.go
View file @
9943b9a2
...
...
@@ -29,7 +29,7 @@ func TestPluginScans(t *testing.T) {
So
(
err
,
ShouldBeNil
)
So
(
len
(
Apps
),
ShouldBeGreaterThan
,
0
)
So
(
Apps
[
"app-
test"
]
.
Info
.
Logos
.
Large
,
ShouldEqual
,
"public/plugins/app-test
/logo_large.png"
)
So
(
Apps
[
"app-
example"
]
.
Info
.
Logos
.
Large
,
ShouldEqual
,
"public/plugins/app-example/img
/logo_large.png"
)
})
}
tests/app-plugin-json/plugin.json
View file @
9943b9a2
{
"name"
:
"App Example"
,
"id"
:
"app-test"
,
"type"
:
"app"
,
"name"
:
"App Example"
,
"id"
:
"app-example"
,
"staticRoot"
:
" ./public"
,
"module"
:
"app"
,
"pages"
:
[
{
"name"
:
"Example1"
,
"url"
:
"/app-example"
,
"reqRole"
:
"Editor"
}
],
"css"
:
{
"light"
:
"css/plugin.dark.css"
,
"dark"
:
"css/plugin.light.css"
},
"info"
:
{
"description"
:
"Example Grafana App"
,
...
...
@@ -11,8 +23,8 @@
},
"keywords"
:
[
"example"
],
"logos"
:
{
"small"
:
"
{{.PluginPublicRoot}}/
img/logo_small.png"
,
"large"
:
"
{{.PluginPublicRoot}}
/logo_large.png"
"small"
:
"img/logo_small.png"
,
"large"
:
"
img
/logo_large.png"
},
"links"
:
[
{
"name"
:
"Project site"
,
"url"
:
"http://project.com"
},
...
...
@@ -22,22 +34,6 @@
"updated"
:
"2015-02-10"
},
"css"
:
{
"light"
:
"plugin.dark.css"
,
"dark"
:
"plugin.light.css"
},
"module"
:
"app"
,
"pages"
:
[
{
"name"
:
"Example1"
,
"url"
:
"/app-example"
,
"reqRole"
:
"Editor"
}
],
"public"
:
{
"urlFragment"
:
"app-example"
,
"path"
:
"./public"
},
"dependencies"
:
{
"grafanaVersion"
:
"2.6.x"
,
"plugins"
:
[
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment