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
660d3fa1
Commit
660d3fa1
authored
Mar 06, 2016
by
utkarshcmu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented savePreferences API
parent
1ef332e8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
73 additions
and
58 deletions
+73
-58
pkg/api/api.go
+1
-1
pkg/api/preferences.go
+21
-0
pkg/api/user.go
+1
-17
pkg/models/preferences.go
+8
-10
pkg/services/sqlstore/preferences.go
+37
-0
pkg/services/sqlstore/user.go
+0
-25
public/app/features/profile/partials/preferences.html
+3
-3
public/app/features/profile/preferencesCtrl.js
+2
-2
No files found.
pkg/api/api.go
View file @
660d3fa1
...
@@ -96,7 +96,7 @@ func Register(r *macaron.Macaron) {
...
@@ -96,7 +96,7 @@ func Register(r *macaron.Macaron) {
r
.
Delete
(
"/stars/dashboard/:id"
,
wrap
(
UnstarDashboard
))
r
.
Delete
(
"/stars/dashboard/:id"
,
wrap
(
UnstarDashboard
))
r
.
Put
(
"/password"
,
bind
(
m
.
ChangeUserPasswordCommand
{}),
wrap
(
ChangeUserPassword
))
r
.
Put
(
"/password"
,
bind
(
m
.
ChangeUserPasswordCommand
{}),
wrap
(
ChangeUserPassword
))
r
.
Get
(
"/quotas"
,
wrap
(
GetUserQuotas
))
r
.
Get
(
"/quotas"
,
wrap
(
GetUserQuotas
))
r
.
Put
(
"/prefs"
,
bind
(
m
.
SavePreference
Command
{}),
wrap
(
SaveUserPreferences
))
r
.
Put
(
"/prefs"
,
bind
(
m
.
SavePreferences
Command
{}),
wrap
(
SaveUserPreferences
))
})
})
// users (admin permission required)
// users (admin permission required)
...
...
pkg/api/preferences.go
0 → 100644
View file @
660d3fa1
package
api
import
(
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/middleware"
m
"github.com/grafana/grafana/pkg/models"
)
// PUT /api/user/prefs
func
SaveUserPreferences
(
c
*
middleware
.
Context
,
cmd
m
.
SavePreferencesCommand
)
Response
{
cmd
.
PrefId
=
c
.
UserId
cmd
.
PrefType
=
`user`
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to saved user preferences"
,
err
)
}
return
ApiSuccess
(
"User preferences saved"
)
}
pkg/api/user.go
View file @
660d3fa1
...
@@ -5,7 +5,6 @@ import (
...
@@ -5,7 +5,6 @@ import (
"github.com/grafana/grafana/pkg/middleware"
"github.com/grafana/grafana/pkg/middleware"
m
"github.com/grafana/grafana/pkg/models"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/util"
"github.com/grafana/grafana/pkg/util"
"github.com/grafana/grafana/pkg/log"
)
)
// GET /api/user (current authenticated user)
// GET /api/user (current authenticated user)
...
@@ -111,7 +110,7 @@ func UserSetUsingOrg(c *middleware.Context) Response {
...
@@ -111,7 +110,7 @@ func UserSetUsingOrg(c *middleware.Context) Response {
}
}
func
ChangeUserPassword
(
c
*
middleware
.
Context
,
cmd
m
.
ChangeUserPasswordCommand
)
Response
{
func
ChangeUserPassword
(
c
*
middleware
.
Context
,
cmd
m
.
ChangeUserPasswordCommand
)
Response
{
userQuery
:=
m
.
GetUserByIdQuery
{
Id
:
c
.
UserId
}
userQuery
:=
m
.
GetUserByIdQuery
{
Id
:
c
.
UserId
}
if
err
:=
bus
.
Dispatch
(
&
userQuery
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
userQuery
);
err
!=
nil
{
return
ApiError
(
500
,
"Could not read user from database"
,
err
)
return
ApiError
(
500
,
"Could not read user from database"
,
err
)
...
@@ -145,18 +144,3 @@ func SearchUsers(c *middleware.Context) Response {
...
@@ -145,18 +144,3 @@ func SearchUsers(c *middleware.Context) Response {
return
Json
(
200
,
query
.
Result
)
return
Json
(
200
,
query
.
Result
)
}
}
func
SaveUserPreferences
(
c
*
middleware
.
Context
,
cmd
m
.
SavePreferenceCommand
)
Response
{
log
.
Info
(
"%v"
,
cmd
.
PrefData
)
cmd
.
PrefId
=
c
.
UserId
cmd
.
PrefType
=
`user`
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to saved user preferences"
,
err
)
}
return
ApiSuccess
(
"User preferences saved"
)
}
pkg/models/preferences.go
View file @
660d3fa1
...
@@ -9,20 +9,18 @@ var (
...
@@ -9,20 +9,18 @@ var (
ErrPreferenceNotFound
=
errors
.
New
(
"Preference not found"
)
ErrPreferenceNotFound
=
errors
.
New
(
"Preference not found"
)
)
)
type
Preference
struct
{
type
Preference
s
struct
{
Id
int64
Id
int64
PrefId
int64
PrefId
int64
PrefType
string
PrefType
string
PrefData
map
[
string
]
interface
{}
PrefData
map
[
string
]
interface
{}
}
}
// ---------------------
// ---------------------
// COMMANDS
// COMMANDS
type
SavePreferenceCommand
struct
{
type
SavePreferencesCommand
struct
{
PrefData
map
[
string
]
interface
{}
`json:"prefData" binding:"Required"`
PrefData
map
[
string
]
interface
{}
`json:"prefData"`
PrefId
int64
`json:"-"`
PrefId
int64
`json:"-"`
PrefType
string
`json:"-"`
PrefType
string
`json:"-"`
}
}
pkg/services/sqlstore/preferences.go
0 → 100644
View file @
660d3fa1
package
sqlstore
import
(
"github.com/grafana/grafana/pkg/bus"
m
"github.com/grafana/grafana/pkg/models"
)
func
init
()
{
bus
.
AddHandler
(
"sql"
,
SavePreferences
)
}
func
SavePreferences
(
cmd
*
m
.
SavePreferencesCommand
)
error
{
return
inTransaction2
(
func
(
sess
*
session
)
error
{
sql
:=
`SELECT * FROM preferences WHERE pref_id = ? `
+
`AND pref_type = ?`
var
prefResults
=
make
([]
m
.
Preferences
,
0
)
resultsErr
:=
sess
.
Sql
(
sql
,
cmd
.
PrefId
,
cmd
.
PrefType
)
.
Find
(
&
prefResults
)
if
resultsErr
!=
nil
{
return
resultsErr
}
var
matchedPref
m
.
Preferences
matchedPref
=
prefResults
[
0
]
matchedPref
.
PrefData
=
cmd
.
PrefData
affectedRows
,
updateErr
:=
sess
.
Id
(
matchedPref
.
Id
)
.
Update
(
&
matchedPref
)
if
affectedRows
==
0
{
return
m
.
ErrPreferenceNotFound
}
return
updateErr
})
}
pkg/services/sqlstore/user.go
View file @
660d3fa1
...
@@ -11,7 +11,6 @@ import (
...
@@ -11,7 +11,6 @@ import (
m
"github.com/grafana/grafana/pkg/models"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
"github.com/grafana/grafana/pkg/util"
"github.com/grafana/grafana/pkg/log"
)
)
func
init
()
{
func
init
()
{
...
@@ -28,7 +27,6 @@ func init() {
...
@@ -28,7 +27,6 @@ func init() {
bus
.
AddHandler
(
"sql"
,
DeleteUser
)
bus
.
AddHandler
(
"sql"
,
DeleteUser
)
bus
.
AddHandler
(
"sql"
,
SetUsingOrg
)
bus
.
AddHandler
(
"sql"
,
SetUsingOrg
)
bus
.
AddHandler
(
"sql"
,
UpdateUserPermissions
)
bus
.
AddHandler
(
"sql"
,
UpdateUserPermissions
)
bus
.
AddHandler
(
"sql"
,
SaveUserPreferences
)
}
}
func
getOrgIdForNewUser
(
cmd
*
m
.
CreateUserCommand
,
sess
*
session
)
(
int64
,
error
)
{
func
getOrgIdForNewUser
(
cmd
*
m
.
CreateUserCommand
,
sess
*
session
)
(
int64
,
error
)
{
...
@@ -348,26 +346,3 @@ func UpdateUserPermissions(cmd *m.UpdateUserPermissionsCommand) error {
...
@@ -348,26 +346,3 @@ func UpdateUserPermissions(cmd *m.UpdateUserPermissionsCommand) error {
return
err
return
err
})
})
}
}
func
SaveUserPreferences
(
cmd
*
m
.
SavePreferenceCommand
)
error
{
return
inTransaction2
(
func
(
sess
*
session
)
error
{
log
.
Info
(
"%v"
,
cmd
)
pref
:=
m
.
Preference
{
PrefId
:
cmd
.
PrefId
,
PrefType
:
cmd
.
PrefType
,
PrefData
:
cmd
.
PrefData
,
}
sess
.
Table
(
"preferences"
)
.
Where
(
"pref_id"
,
pref
.
PrefId
)
.
And
(
"pref_type"
,
pref
.
PrefType
)
if
_
,
err
:=
sess
.
Update
(
&
pref
);
err
!=
nil
{
return
err
}
log
.
Info
(
"%v"
,
pref
)
return
nil
})
}
public/app/features/profile/partials/preferences.html
View file @
660d3fa1
...
@@ -9,17 +9,17 @@
...
@@ -9,17 +9,17 @@
<form
name=
"userForm"
class=
"gf-form-group"
>
<form
name=
"userForm"
class=
"gf-form-group"
>
<div
class=
"gf-form"
>
<div
class=
"gf-form"
>
<span
class=
"gf-form-label width-10"
>
Home Dashboard
</span>
<span
class=
"gf-form-label width-10"
>
Home Dashboard
</span>
<input
class=
"gf-form-input max-width-21"
type=
"text"
ng-model=
"
command
.homeDashboard"
>
<input
class=
"gf-form-input max-width-21"
type=
"text"
ng-model=
"
prefData
.homeDashboard"
>
</div>
</div>
<div
class=
"gf-form"
>
<div
class=
"gf-form"
>
<span
class=
"gf-form-label width-10"
>
Time Range
</span>
<span
class=
"gf-form-label width-10"
>
Time Range
</span>
<input
class=
"gf-form-input max-width-21"
type=
"text"
ng-model=
"
command
.timeRange"
>
<input
class=
"gf-form-input max-width-21"
type=
"text"
ng-model=
"
prefData
.timeRange"
>
</div>
</div>
<div
class=
"gf-form"
>
<div
class=
"gf-form"
>
<span
class=
"gf-form-label width-10"
>
Theme
</span>
<span
class=
"gf-form-label width-10"
>
Theme
</span>
<input
class=
"gf-form-input max-width-21"
type=
"text"
ng-model=
"
command
.theme"
>
<input
class=
"gf-form-input max-width-21"
type=
"text"
ng-model=
"
prefData
.theme"
>
</div>
</div>
<div
class=
"gf-form-button-row"
>
<div
class=
"gf-form-button-row"
>
...
...
public/app/features/profile/preferencesCtrl.js
View file @
660d3fa1
...
@@ -9,14 +9,14 @@ function (angular) {
...
@@ -9,14 +9,14 @@ function (angular) {
module
.
controller
(
'PreferencesCtrl'
,
function
(
$scope
,
backendSrv
,
$location
)
{
module
.
controller
(
'PreferencesCtrl'
,
function
(
$scope
,
backendSrv
,
$location
)
{
$scope
.
command
=
{};
$scope
.
prefData
=
{};
$scope
.
setUserPreferences
=
function
()
{
$scope
.
setUserPreferences
=
function
()
{
if
(
!
$scope
.
userForm
.
$valid
)
{
return
;
}
if
(
!
$scope
.
userForm
.
$valid
)
{
return
;
}
console
.
log
(
$scope
.
command
);
console
.
log
(
$scope
.
command
);
backendSrv
.
put
(
'/api/user/prefs'
,
$scope
.
command
).
then
(
function
()
{
backendSrv
.
put
(
'/api/user/prefs'
,
{
prefData
:
$scope
.
prefData
}
).
then
(
function
()
{
$location
.
path
(
"profile"
);
$location
.
path
(
"profile"
);
});
});
};
};
...
...
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