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
749fd618
Commit
749fd618
authored
Mar 16, 2016
by
utkarshcmu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Saving home dashboard id in table
parent
a88176e0
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
6 deletions
+30
-6
pkg/api/api.go
+6
-1
pkg/api/preferences.go
+16
-2
pkg/models/preferences.go
+3
-3
pkg/services/sqlstore/preferences.go
+5
-0
No files found.
pkg/api/api.go
View file @
749fd618
...
@@ -160,7 +160,12 @@ func Register(r *macaron.Macaron) {
...
@@ -160,7 +160,12 @@ func Register(r *macaron.Macaron) {
r
.
Delete
(
"/:id"
,
wrap
(
DeleteApiKey
))
r
.
Delete
(
"/:id"
,
wrap
(
DeleteApiKey
))
},
reqOrgAdmin
)
},
reqOrgAdmin
)
r
.
Combo
(
"/preferences"
)
.
Get
(
GetPreferences
)
.
Put
(
bind
(
m
.
SavePreferencesCommand
{}),
wrap
(
SavePreferences
))
// Preferences
r
.
Group
(
"/preferences"
,
func
()
{
r
.
Get
(
"/"
,
wrap
(
GetPreferences
))
r
.
Put
(
"/"
,
bind
(
m
.
SavePreferencesCommand
{}),
wrap
(
SavePreferences
))
r
.
Post
(
"/set-home-dash"
,
bind
(
m
.
SavePreferencesCommand
{}),
wrap
(
SetHomeDashboard
))
})
// Data sources
// Data sources
r
.
Group
(
"/datasources"
,
func
()
{
r
.
Group
(
"/datasources"
,
func
()
{
...
...
pkg/api/preferences.go
View file @
749fd618
...
@@ -7,7 +7,7 @@ import (
...
@@ -7,7 +7,7 @@ import (
m
"github.com/grafana/grafana/pkg/models"
m
"github.com/grafana/grafana/pkg/models"
)
)
// PUT /api/
user/pref
s
// PUT /api/
preference
s
func
SavePreferences
(
c
*
middleware
.
Context
,
cmd
m
.
SavePreferencesCommand
)
Response
{
func
SavePreferences
(
c
*
middleware
.
Context
,
cmd
m
.
SavePreferencesCommand
)
Response
{
cmd
.
UserId
=
c
.
UserId
cmd
.
UserId
=
c
.
UserId
...
@@ -21,7 +21,7 @@ func SavePreferences(c *middleware.Context, cmd m.SavePreferencesCommand) Respon
...
@@ -21,7 +21,7 @@ func SavePreferences(c *middleware.Context, cmd m.SavePreferencesCommand) Respon
}
}
// GET /api/
user/pref
s
// GET /api/
preference
s
func
GetPreferences
(
c
*
middleware
.
Context
)
{
func
GetPreferences
(
c
*
middleware
.
Context
)
{
query
:=
m
.
GetPreferencesQuery
{
UserId
:
c
.
UserId
,
OrgId
:
c
.
OrgId
}
query
:=
m
.
GetPreferencesQuery
{
UserId
:
c
.
UserId
,
OrgId
:
c
.
OrgId
}
...
@@ -38,3 +38,17 @@ func GetPreferences(c *middleware.Context) {
...
@@ -38,3 +38,17 @@ func GetPreferences(c *middleware.Context) {
c
.
JSON
(
200
,
dto
)
c
.
JSON
(
200
,
dto
)
}
}
// POST /api/preferences/set-home-dash
func
SetHomeDashboard
(
c
*
middleware
.
Context
,
cmd
m
.
SavePreferencesCommand
)
Response
{
cmd
.
UserId
=
c
.
UserId
cmd
.
OrgId
=
c
.
OrgId
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to set home dashboard"
,
err
)
}
return
ApiSuccess
(
"Home dashboard set"
)
}
pkg/models/preferences.go
View file @
749fd618
...
@@ -39,7 +39,7 @@ type SavePreferencesCommand struct {
...
@@ -39,7 +39,7 @@ type SavePreferencesCommand struct {
UserId
int64
UserId
int64
OrgId
int64
OrgId
int64
HomeDashboardId
int64
HomeDashboardId
int64
`json:"dashboardId"`
Timezone
string
Timezone
string
`json:"timezone"`
Theme
string
Theme
string
`json:"theme"`
}
}
pkg/services/sqlstore/preferences.go
View file @
749fd618
package
sqlstore
package
sqlstore
import
(
import
(
"time"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/bus"
m
"github.com/grafana/grafana/pkg/models"
m
"github.com/grafana/grafana/pkg/models"
)
)
...
@@ -41,6 +42,8 @@ func SavePreferences(cmd *m.SavePreferencesCommand) error {
...
@@ -41,6 +42,8 @@ func SavePreferences(cmd *m.SavePreferencesCommand) error {
HomeDashboardId
:
cmd
.
HomeDashboardId
,
HomeDashboardId
:
cmd
.
HomeDashboardId
,
Timezone
:
cmd
.
Timezone
,
Timezone
:
cmd
.
Timezone
,
Theme
:
cmd
.
Theme
,
Theme
:
cmd
.
Theme
,
Created
:
time
.
Now
(),
Updated
:
time
.
Now
(),
}
}
_
,
err
=
sess
.
Insert
(
&
prefs
)
_
,
err
=
sess
.
Insert
(
&
prefs
)
return
err
return
err
...
@@ -48,6 +51,8 @@ func SavePreferences(cmd *m.SavePreferencesCommand) error {
...
@@ -48,6 +51,8 @@ func SavePreferences(cmd *m.SavePreferencesCommand) error {
prefs
.
HomeDashboardId
=
cmd
.
HomeDashboardId
prefs
.
HomeDashboardId
=
cmd
.
HomeDashboardId
prefs
.
Timezone
=
cmd
.
Timezone
prefs
.
Timezone
=
cmd
.
Timezone
prefs
.
Theme
=
cmd
.
Theme
prefs
.
Theme
=
cmd
.
Theme
prefs
.
Updated
=
time
.
Now
()
prefs
.
Version
+=
1
_
,
err
=
sess
.
Id
(
prefs
.
Id
)
.
Update
(
&
prefs
)
_
,
err
=
sess
.
Id
(
prefs
.
Id
)
.
Update
(
&
prefs
)
return
err
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