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
071237d3
Commit
071237d3
authored
Mar 20, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4399 from utkarshcmu/preferences
Set home dashboard per user per org #3214
parents
a88176e0
cb42cfc6
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
88 additions
and
10 deletions
+88
-10
pkg/api/api.go
+6
-1
pkg/api/dashboard.go
+22
-0
pkg/api/dtos/models.go
+4
-0
pkg/api/preferences.go
+16
-2
pkg/models/dashboards.go
+5
-0
pkg/models/preferences.go
+3
-3
pkg/services/sqlstore/dashboard.go
+15
-0
pkg/services/sqlstore/preferences.go
+5
-0
public/app/core/routes/dashboard_loaders.js
+11
-3
public/app/features/dashboard/dashnav/dashnav.ts
+1
-1
No files found.
pkg/api/api.go
View file @
071237d3
...
...
@@ -160,7 +160,12 @@ func Register(r *macaron.Macaron) {
r
.
Delete
(
"/:id"
,
wrap
(
DeleteApiKey
))
},
reqOrgAdmin
)
r
.
Combo
(
"/preferences"
)
.
Get
(
GetPreferences
)
.
Put
(
bind
(
m
.
SavePreferencesCommand
{}),
wrap
(
SavePreferences
))
// Preferences
r
.
Group
(
"/preferences"
,
func
()
{
r
.
Get
(
"/"
,
GetPreferences
)
r
.
Put
(
"/"
,
bind
(
m
.
SavePreferencesCommand
{}),
wrap
(
SavePreferences
))
r
.
Post
(
"/set-home-dash"
,
bind
(
m
.
SavePreferencesCommand
{}),
wrap
(
SetHomeDashboard
))
})
// Data sources
r
.
Group
(
"/datasources"
,
func
()
{
...
...
pkg/api/dashboard.go
View file @
071237d3
...
...
@@ -159,6 +159,28 @@ func canEditDashboard(role m.RoleType) bool {
}
func
GetHomeDashboard
(
c
*
middleware
.
Context
)
{
// Checking if there is any preference set for home dashboard
query
:=
m
.
GetPreferencesQuery
{
UserId
:
c
.
UserId
,
OrgId
:
c
.
OrgId
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Failed to get preferences"
,
err
)
}
if
query
.
Result
.
HomeDashboardId
!=
0
{
query
:=
m
.
GetDashboardSlugByIdQuery
{
Id
:
query
.
Result
.
HomeDashboardId
}
err
:=
bus
.
Dispatch
(
&
query
)
if
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Failed to get slug from database"
,
err
)
return
}
slug
:=
dtos
.
DashboardSlug
{
Slug
:
query
.
Result
}
c
.
JSON
(
200
,
&
slug
)
return
}
filePath
:=
path
.
Join
(
setting
.
StaticRootPath
,
"dashboards/home.json"
)
file
,
err
:=
os
.
Open
(
filePath
)
if
err
!=
nil
{
...
...
pkg/api/dtos/models.go
View file @
071237d3
...
...
@@ -57,6 +57,10 @@ type DashboardFullWithMeta struct {
Dashboard
*
simplejson
.
Json
`json:"dashboard"`
}
type
DashboardSlug
struct
{
Slug
string
`json:"slug"`
}
type
DataSource
struct
{
Id
int64
`json:"id"`
OrgId
int64
`json:"orgId"`
...
...
pkg/api/preferences.go
View file @
071237d3
...
...
@@ -7,7 +7,7 @@ import (
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
{
cmd
.
UserId
=
c
.
UserId
...
...
@@ -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
)
{
query
:=
m
.
GetPreferencesQuery
{
UserId
:
c
.
UserId
,
OrgId
:
c
.
OrgId
}
...
...
@@ -38,3 +38,17 @@ func GetPreferences(c *middleware.Context) {
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/dashboards.go
View file @
071237d3
...
...
@@ -148,3 +148,8 @@ type GetDashboardsQuery struct {
DashboardIds
[]
int64
Result
*
[]
Dashboard
}
type
GetDashboardSlugByIdQuery
struct
{
Id
int64
Result
string
}
pkg/models/preferences.go
View file @
071237d3
...
...
@@ -39,7 +39,7 @@ type SavePreferencesCommand struct {
UserId
int64
OrgId
int64
HomeDashboardId
int64
Timezone
string
Theme
string
HomeDashboardId
int64
`json:"homeDashboardId"`
Timezone
string
`json:"timezone"`
Theme
string
`json:"theme"`
}
pkg/services/sqlstore/dashboard.go
View file @
071237d3
...
...
@@ -18,6 +18,7 @@ func init() {
bus
.
AddHandler
(
"sql"
,
DeleteDashboard
)
bus
.
AddHandler
(
"sql"
,
SearchDashboards
)
bus
.
AddHandler
(
"sql"
,
GetDashboardTags
)
bus
.
AddHandler
(
"sql"
,
GetDashboardSlugById
)
}
func
SaveDashboard
(
cmd
*
m
.
SaveDashboardCommand
)
error
{
...
...
@@ -255,3 +256,17 @@ func GetDashboards(query *m.GetDashboardsQuery) error {
return
nil
}
func
GetDashboardSlugById
(
query
*
m
.
GetDashboardSlugByIdQuery
)
error
{
dashboard
:=
m
.
Dashboard
{
Id
:
query
.
Id
}
has
,
err
:=
x
.
Get
(
&
dashboard
)
query
.
Result
=
dashboard
.
Slug
if
err
!=
nil
{
return
err
}
else
if
has
==
false
{
return
m
.
ErrDashboardNotFound
}
return
nil
}
pkg/services/sqlstore/preferences.go
View file @
071237d3
...
...
@@ -3,6 +3,7 @@ package sqlstore
import
(
"github.com/grafana/grafana/pkg/bus"
m
"github.com/grafana/grafana/pkg/models"
"time"
)
func
init
()
{
...
...
@@ -41,6 +42,8 @@ func SavePreferences(cmd *m.SavePreferencesCommand) error {
HomeDashboardId
:
cmd
.
HomeDashboardId
,
Timezone
:
cmd
.
Timezone
,
Theme
:
cmd
.
Theme
,
Created
:
time
.
Now
(),
Updated
:
time
.
Now
(),
}
_
,
err
=
sess
.
Insert
(
&
prefs
)
return
err
...
...
@@ -48,6 +51,8 @@ func SavePreferences(cmd *m.SavePreferencesCommand) error {
prefs
.
HomeDashboardId
=
cmd
.
HomeDashboardId
prefs
.
Timezone
=
cmd
.
Timezone
prefs
.
Theme
=
cmd
.
Theme
prefs
.
Updated
=
time
.
Now
()
prefs
.
Version
+=
1
_
,
err
=
sess
.
Id
(
prefs
.
Id
)
.
Update
(
&
prefs
)
return
err
}
...
...
public/app/core/routes/dashboard_loaders.js
View file @
071237d3
...
...
@@ -8,9 +8,17 @@ function (coreModule) {
if
(
!
$routeParams
.
slug
)
{
backendSrv
.
get
(
'/api/dashboards/home'
).
then
(
function
(
result
)
{
var
meta
=
result
.
meta
;
meta
.
canSave
=
meta
.
canShare
=
meta
.
canStar
=
false
;
$scope
.
initDashboard
(
result
,
$scope
);
if
(
result
.
slug
==
null
)
{
var
meta
=
result
.
meta
;
meta
.
canSave
=
meta
.
canShare
=
meta
.
canStar
=
false
;
$scope
.
initDashboard
(
result
,
$scope
);
}
else
{
$routeParams
.
type
=
'db'
;
$routeParams
.
slug
=
result
.
slug
;
dashboardLoaderSrv
.
loadDashboard
(
$routeParams
.
type
,
$routeParams
.
slug
).
then
(
function
(
result
)
{
$scope
.
initDashboard
(
result
,
$scope
);
});
}
});
return
;
}
...
...
public/app/features/dashboard/dashnav/dashnav.ts
View file @
071237d3
...
...
@@ -106,7 +106,7 @@ export class DashNavCtrl {
$scope
.
saveDashboardAsHome
=
function
()
{
// TODO: this backend method needs to be implemented
backendSrv
.
post
(
'/api/preferences/set-home-dash'
,
{
d
ashboardId
:
$scope
.
dashboard
.
id
homeD
ashboardId
:
$scope
.
dashboard
.
id
});
};
...
...
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