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
f5eac2e9
Commit
f5eac2e9
authored
Dec 01, 2017
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboards as cfg: expose dashboard service as interface
parent
16f072b3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
7 deletions
+23
-7
pkg/api/dashboard.go
+1
-1
pkg/services/dashboards/dashboards.go
+16
-3
pkg/services/provisioning/dashboards/file_reader.go
+6
-3
No files found.
pkg/api/dashboard.go
View file @
f5eac2e9
...
...
@@ -142,7 +142,7 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response {
UserId
:
c
.
UserId
,
}
dashboard
,
err
:=
dashboards
.
SaveDashboard
(
dashItem
)
dashboard
,
err
:=
dashboards
.
GetRepository
()
.
SaveDashboard
(
dashItem
)
if
err
==
m
.
ErrDashboardTitleEmpty
{
return
ApiError
(
400
,
m
.
ErrDashboardTitleEmpty
.
Error
(),
nil
)
...
...
pkg/services/dashboards/dashboards.go
View file @
f5eac2e9
package
dashboards
import
(
"time"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting"
"time"
)
type
Repository
interface
{
SaveDashboard
(
*
SaveDashboardItem
)
error
SaveDashboard
(
*
SaveDashboardItem
)
(
*
models
.
Dashboard
,
error
)
}
var
repositoryInstance
Repository
func
GetRepository
()
Repository
{
return
repositoryInstance
}
func
SetRepository
(
rep
Repository
)
{
repositoryInstance
=
rep
}
type
SaveDashboardItem
struct
{
...
...
@@ -22,7 +33,9 @@ type SaveDashboardItem struct {
Dashboard
*
models
.
Dashboard
}
func
SaveDashboard
(
json
*
SaveDashboardItem
)
(
*
models
.
Dashboard
,
error
)
{
type
dashboardRepository
struct
{}
func
(
dr
*
dashboardRepository
)
SaveDashboard
(
json
*
SaveDashboardItem
)
(
*
models
.
Dashboard
,
error
)
{
dashboard
:=
json
.
Dashboard
if
dashboard
.
Title
==
""
{
...
...
pkg/services/provisioning/dashboards/file_reader.go
View file @
f5eac2e9
...
...
@@ -3,12 +3,13 @@ package dashboards
import
(
"context"
"fmt"
"github.com/grafana/grafana/pkg/services/dashboards"
"os"
"path/filepath"
"strings"
"time"
"github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/components/simplejson"
...
...
@@ -21,6 +22,7 @@ type fileReader struct {
Path
string
log
log
.
Logger
dashboardCache
*
dashboardCache
dashboardRepo
dashboards
.
Repository
}
func
NewDashboardFilereader
(
cfg
*
DashboardsAsConfig
,
log
log
.
Logger
)
(
*
fileReader
,
error
)
{
...
...
@@ -37,6 +39,7 @@ func NewDashboardFilereader(cfg *DashboardsAsConfig, log log.Logger) (*fileReade
Cfg
:
cfg
,
Path
:
path
,
log
:
log
,
dashboardRepo
:
dashboards
.
GetRepository
(),
dashboardCache
:
newDashboardCache
(),
},
nil
}
...
...
@@ -96,7 +99,7 @@ func (fr *fileReader) walkFolder() error {
if
err
==
models
.
ErrDashboardNotFound
{
fr
.
log
.
Debug
(
"saving new dashboard"
,
"file"
,
path
)
_
,
err
=
dashboards
.
SaveDashboard
(
dash
)
_
,
err
=
fr
.
dashboardRepo
.
SaveDashboard
(
dash
)
return
err
}
...
...
@@ -110,7 +113,7 @@ func (fr *fileReader) walkFolder() error {
}
fr
.
log
.
Debug
(
"no dashboard in cache. loading dashboard from disk into database."
,
"file"
,
path
)
_
,
err
=
dashboards
.
SaveDashboard
(
dash
)
_
,
err
=
fr
.
dashboardRepo
.
SaveDashboard
(
dash
)
return
err
})
}
...
...
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