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
ecafc7bf
Commit
ecafc7bf
authored
Sep 17, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for delete dashboard
parent
2380a269
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
57 additions
and
11 deletions
+57
-11
grafana
+1
-1
grafana-pro
+0
-0
pkg/api/api_dashboard.go
+27
-3
pkg/stores/rethinkdb.go
+18
-1
pkg/stores/rethinkdb_accounts.go
+10
-6
pkg/stores/store.go
+1
-0
No files found.
grafana
@
4b382e0f
Subproject commit
c00384ad0644f9db7cdfa426c559d8fc3347a1d2
Subproject commit
4b382e0faff3fa2e5c05ca3306d54d8e5f8ca89c
grafana-pro
View file @
ecafc7bf
No preview for this file type
pkg/api/api_dashboard.go
View file @
ecafc7bf
...
@@ -8,25 +8,49 @@ import (
...
@@ -8,25 +8,49 @@ import (
func
init
()
{
func
init
()
{
addRoutes
(
func
(
self
*
HttpServer
)
{
addRoutes
(
func
(
self
*
HttpServer
)
{
self
.
router
.
GET
(
"/api/dashboards/:
id
"
,
self
.
auth
(),
self
.
getDashboard
)
self
.
router
.
GET
(
"/api/dashboards/:
slug
"
,
self
.
auth
(),
self
.
getDashboard
)
self
.
router
.
GET
(
"/api/search/"
,
self
.
auth
(),
self
.
search
)
self
.
router
.
GET
(
"/api/search/"
,
self
.
auth
(),
self
.
search
)
self
.
router
.
POST
(
"/api/dashboard"
,
self
.
auth
(),
self
.
postDashboard
)
self
.
router
.
POST
(
"/api/dashboard"
,
self
.
auth
(),
self
.
postDashboard
)
self
.
router
.
DELETE
(
"/api/dashboard/:slug"
,
self
.
auth
(),
self
.
deleteDashboard
)
})
})
}
}
func
(
self
*
HttpServer
)
getDashboard
(
c
*
gin
.
Context
)
{
func
(
self
*
HttpServer
)
getDashboard
(
c
*
gin
.
Context
)
{
id
:=
c
.
Params
.
ByName
(
"id
"
)
slug
:=
c
.
Params
.
ByName
(
"slug
"
)
accountId
,
err
:=
c
.
Get
(
"accountId"
)
accountId
,
err
:=
c
.
Get
(
"accountId"
)
dash
,
err
:=
self
.
store
.
GetDashboard
(
id
,
accountId
.
(
int
))
dash
,
err
:=
self
.
store
.
GetDashboard
(
slug
,
accountId
.
(
int
))
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
404
,
newErrorResponse
(
"Dashboard not found"
))
c
.
JSON
(
404
,
newErrorResponse
(
"Dashboard not found"
))
return
return
}
}
dash
.
Data
[
"id"
]
=
dash
.
Id
c
.
JSON
(
200
,
dash
.
Data
)
c
.
JSON
(
200
,
dash
.
Data
)
}
}
func
(
self
*
HttpServer
)
deleteDashboard
(
c
*
gin
.
Context
)
{
slug
:=
c
.
Params
.
ByName
(
"slug"
)
accountId
,
err
:=
c
.
Get
(
"accountId"
)
dash
,
err
:=
self
.
store
.
GetDashboard
(
slug
,
accountId
.
(
int
))
if
err
!=
nil
{
c
.
JSON
(
404
,
newErrorResponse
(
"Dashboard not found"
))
return
}
err
=
self
.
store
.
DeleteDashboard
(
slug
,
accountId
.
(
int
))
if
err
!=
nil
{
c
.
JSON
(
500
,
newErrorResponse
(
"Failed to delete dashboard: "
+
err
.
Error
()))
return
}
var
resp
=
map
[
string
]
interface
{}{
"title"
:
dash
.
Title
}
c
.
JSON
(
200
,
resp
)
}
func
(
self
*
HttpServer
)
search
(
c
*
gin
.
Context
)
{
func
(
self
*
HttpServer
)
search
(
c
*
gin
.
Context
)
{
query
:=
c
.
Params
.
ByName
(
"q"
)
query
:=
c
.
Params
.
ByName
(
"q"
)
accountId
,
err
:=
c
.
Get
(
"accountId"
)
accountId
,
err
:=
c
.
Get
(
"accountId"
)
...
...
pkg/stores/rethinkdb.go
View file @
ecafc7bf
package
stores
package
stores
import
(
import
(
"errors"
"time"
"time"
log
"github.com/alecthomas/log4go"
log
"github.com/alecthomas/log4go"
...
@@ -63,7 +64,7 @@ func NewRethinkStore(config *RethinkCfg) *rethinkStore {
...
@@ -63,7 +64,7 @@ func NewRethinkStore(config *RethinkCfg) *rethinkStore {
}
}
func
(
self
*
rethinkStore
)
SaveDashboard
(
dash
*
models
.
Dashboard
)
error
{
func
(
self
*
rethinkStore
)
SaveDashboard
(
dash
*
models
.
Dashboard
)
error
{
resp
,
err
:=
r
.
Table
(
"dashboards"
)
.
Insert
(
dash
,
r
.
InsertOpts
{
Upsert
:
true
})
.
RunWrite
(
self
.
session
)
resp
,
err
:=
r
.
Table
(
"dashboards"
)
.
Insert
(
dash
,
r
.
InsertOpts
{
Conflict
:
"update"
})
.
RunWrite
(
self
.
session
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -92,6 +93,22 @@ func (self *rethinkStore) GetDashboard(slug string, accountId int) (*models.Dash
...
@@ -92,6 +93,22 @@ func (self *rethinkStore) GetDashboard(slug string, accountId int) (*models.Dash
return
&
dashboard
,
nil
return
&
dashboard
,
nil
}
}
func
(
self
*
rethinkStore
)
DeleteDashboard
(
slug
string
,
accountId
int
)
error
{
resp
,
err
:=
r
.
Table
(
"dashboards"
)
.
GetAllByIndex
(
"AccountIdSlug"
,
[]
interface
{}{
accountId
,
slug
})
.
Delete
()
.
RunWrite
(
self
.
session
)
if
err
!=
nil
{
return
err
}
if
resp
.
Deleted
!=
1
{
return
errors
.
New
(
"Did not find dashboard to delete"
)
}
return
nil
}
func
(
self
*
rethinkStore
)
Query
(
query
string
,
accountId
int
)
([]
*
models
.
SearchResult
,
error
)
{
func
(
self
*
rethinkStore
)
Query
(
query
string
,
accountId
int
)
([]
*
models
.
SearchResult
,
error
)
{
docs
,
err
:=
r
.
Table
(
"dashboards"
)
.
GetAllByIndex
(
"AccountId"
,
[]
interface
{}{
accountId
})
.
Filter
(
r
.
Row
.
Field
(
"Title"
)
.
Match
(
".*"
))
.
Run
(
self
.
session
)
docs
,
err
:=
r
.
Table
(
"dashboards"
)
.
GetAllByIndex
(
"AccountId"
,
[]
interface
{}{
accountId
})
.
Filter
(
r
.
Row
.
Field
(
"Title"
)
.
Match
(
".*"
))
.
Run
(
self
.
session
)
...
...
pkg/stores/rethinkdb_accounts.go
View file @
ecafc7bf
...
@@ -10,17 +10,19 @@ import (
...
@@ -10,17 +10,19 @@ import (
func
(
self
*
rethinkStore
)
getNextAccountId
()
(
int
,
error
)
{
func
(
self
*
rethinkStore
)
getNextAccountId
()
(
int
,
error
)
{
resp
,
err
:=
r
.
Table
(
"master"
)
.
Get
(
"ids"
)
.
Update
(
map
[
string
]
interface
{}{
resp
,
err
:=
r
.
Table
(
"master"
)
.
Get
(
"ids"
)
.
Update
(
map
[
string
]
interface
{}{
"NextAccountId"
:
r
.
Row
.
Field
(
"NextAccountId"
)
.
Add
(
1
),
"NextAccountId"
:
r
.
Row
.
Field
(
"NextAccountId"
)
.
Add
(
1
),
},
r
.
UpdateOpts
{
Return
Val
s
:
true
})
.
RunWrite
(
self
.
session
)
},
r
.
UpdateOpts
{
Return
Change
s
:
true
})
.
RunWrite
(
self
.
session
)
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
err
return
0
,
err
}
}
if
resp
.
NewValue
==
nil
{
change
:=
resp
.
Changes
[
0
]
if
change
.
NewValue
==
nil
{
return
0
,
errors
.
New
(
"Failed to get new value after incrementing account id"
)
return
0
,
errors
.
New
(
"Failed to get new value after incrementing account id"
)
}
}
return
int
(
resp
.
NewValue
.
(
map
[
string
]
interface
{})[
"NextAccountId"
]
.
(
float64
)),
nil
return
int
(
change
.
NewValue
.
(
map
[
string
]
interface
{})[
"NextAccountId"
]
.
(
float64
)),
nil
}
}
func
(
self
*
rethinkStore
)
SaveUserAccount
(
account
*
models
.
UserAccount
)
error
{
func
(
self
*
rethinkStore
)
SaveUserAccount
(
account
*
models
.
UserAccount
)
error
{
...
@@ -62,15 +64,17 @@ func (self *rethinkStore) GetUserAccountLogin(emailOrName string) (*models.UserA
...
@@ -62,15 +64,17 @@ func (self *rethinkStore) GetUserAccountLogin(emailOrName string) (*models.UserA
func
(
self
*
rethinkStore
)
getNextDashboardNumber
(
accountId
int
)
(
int
,
error
)
{
func
(
self
*
rethinkStore
)
getNextDashboardNumber
(
accountId
int
)
(
int
,
error
)
{
resp
,
err
:=
r
.
Table
(
"accounts"
)
.
Get
(
accountId
)
.
Update
(
map
[
string
]
interface
{}{
resp
,
err
:=
r
.
Table
(
"accounts"
)
.
Get
(
accountId
)
.
Update
(
map
[
string
]
interface
{}{
"NextDashboardId"
:
r
.
Row
.
Field
(
"NextDashboardId"
)
.
Add
(
1
),
"NextDashboardId"
:
r
.
Row
.
Field
(
"NextDashboardId"
)
.
Add
(
1
),
},
r
.
UpdateOpts
{
Return
Val
s
:
true
})
.
RunWrite
(
self
.
session
)
},
r
.
UpdateOpts
{
Return
Change
s
:
true
})
.
RunWrite
(
self
.
session
)
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
err
return
0
,
err
}
}
if
resp
.
NewValue
==
nil
{
change
:=
resp
.
Changes
[
0
]
if
change
.
NewValue
==
nil
{
return
0
,
errors
.
New
(
"Failed to get next dashboard id, no new value after update"
)
return
0
,
errors
.
New
(
"Failed to get next dashboard id, no new value after update"
)
}
}
return
int
(
resp
.
NewValue
.
(
map
[
string
]
interface
{})[
"NextDashboardId"
]
.
(
float64
)),
nil
return
int
(
change
.
NewValue
.
(
map
[
string
]
interface
{})[
"NextDashboardId"
]
.
(
float64
)),
nil
}
}
pkg/stores/store.go
View file @
ecafc7bf
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
type
Store
interface
{
type
Store
interface
{
GetDashboard
(
slug
string
,
accountId
int
)
(
*
models
.
Dashboard
,
error
)
GetDashboard
(
slug
string
,
accountId
int
)
(
*
models
.
Dashboard
,
error
)
SaveDashboard
(
dash
*
models
.
Dashboard
)
error
SaveDashboard
(
dash
*
models
.
Dashboard
)
error
DeleteDashboard
(
slug
string
,
accountId
int
)
error
Query
(
query
string
,
acccountId
int
)
([]
*
models
.
SearchResult
,
error
)
Query
(
query
string
,
acccountId
int
)
([]
*
models
.
SearchResult
,
error
)
SaveUserAccount
(
acccount
*
models
.
UserAccount
)
error
SaveUserAccount
(
acccount
*
models
.
UserAccount
)
error
GetUserAccountLogin
(
emailOrName
string
)
(
*
models
.
UserAccount
,
error
)
GetUserAccountLogin
(
emailOrName
string
)
(
*
models
.
UserAccount
,
error
)
...
...
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