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
e371e036
Commit
e371e036
authored
Mar 14, 2016
by
utkarshcmu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Able to save preference version, created, updated fields
parent
0bf721a7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
13 deletions
+29
-13
pkg/api/api.go
+1
-1
pkg/api/preferences.go
+3
-3
pkg/models/preferences.go
+6
-6
pkg/services/sqlstore/migrations/preferences_mig.go
+3
-3
pkg/services/sqlstore/preferences.go
+16
-0
No files found.
pkg/api/api.go
View file @
e371e036
...
...
@@ -164,7 +164,7 @@ func Register(r *macaron.Macaron) {
r
.
Delete
(
"/:id"
,
wrap
(
DeleteApiKey
))
},
reqOrgAdmin
)
r
.
Combo
(
"/preferences"
)
.
Get
(
GetPreferences
)
.
Put
(
bind
(
m
.
SavePreferencesCommand
{}),
wrap
(
SavePreferences
))
r
.
Combo
(
"/preferences"
)
.
Get
(
GetPreferences
)
.
Put
(
bind
(
m
.
SavePreferencesCommand
{}),
wrap
(
SavePreferences
))
// Data sources
r
.
Group
(
"/datasources"
,
func
()
{
...
...
pkg/api/preferences.go
View file @
e371e036
...
...
@@ -10,10 +10,10 @@ import (
func
SavePreferences
(
c
*
middleware
.
Context
,
cmd
m
.
SavePreferencesCommand
)
Response
{
cmd
.
UserId
=
c
.
UserId
cmd
.
OrgId
=
c
.
OrgId
cmd
.
OrgId
=
c
.
OrgId
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to save
d
preferences"
,
err
)
return
ApiError
(
500
,
"Failed to save preferences"
,
err
)
}
return
ApiSuccess
(
"Preferences saved"
)
...
...
@@ -32,7 +32,7 @@ func GetPreferences(c *middleware.Context) {
dto
:=
m
.
PreferencesDTO
{
Id
:
query
.
Result
.
Id
,
UserId
:
query
.
Result
.
UserId
,
OrgId
:
query
.
Result
.
OrgId
,
OrgId
:
query
.
Result
.
OrgId
,
Preference
:
query
.
Result
.
Preference
,
}
...
...
pkg/models/preferences.go
View file @
e371e036
...
...
@@ -2,7 +2,7 @@ package models
import
(
"errors"
"time"
"time"
)
// Typed errors
...
...
@@ -14,10 +14,10 @@ type Preferences struct {
Id
int64
OrgId
int64
UserId
int64
Version
int
Version
int
Preference
map
[
string
]
interface
{}
Created
time
.
Time
Updated
time
.
Time
Created
time
.
Time
Updated
time
.
Time
}
// ---------------------
...
...
@@ -26,7 +26,7 @@ type Preferences struct {
type
GetPreferencesQuery
struct
{
Id
int64
OrgId
int64
UserId
int64
UserId
int64
Result
*
Preferences
}
...
...
@@ -46,6 +46,6 @@ type SavePreferencesCommand struct {
type
PreferencesDTO
struct
{
Id
int64
`json:"Id"`
UserId
int64
`json:"UserId"`
OrgId
int64
`json:"OrgId"`
OrgId
int64
`json:"OrgId"`
Preference
map
[
string
]
interface
{}
`json:"Preference"`
}
pkg/services/sqlstore/migrations/preferences_mig.go
View file @
e371e036
...
...
@@ -10,10 +10,10 @@ func addPreferencesMigrations(mg *Migrator) {
{
Name
:
"id"
,
Type
:
DB_BigInt
,
IsPrimaryKey
:
true
,
IsAutoIncrement
:
true
},
{
Name
:
"org_id"
,
Type
:
DB_Int
,
Nullable
:
false
},
{
Name
:
"user_id"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
false
},
{
Name
:
"version"
,
Type
:
DB_Int
,
Nullable
:
false
},
{
Name
:
"version"
,
Type
:
DB_Int
,
Nullable
:
false
},
{
Name
:
"preference"
,
Type
:
DB_Text
,
Nullable
:
false
},
{
Name
:
"created"
,
Type
:
DB_DateTime
,
Nullable
:
false
},
{
Name
:
"updated"
,
Type
:
DB_DateTime
,
Nullable
:
false
},
{
Name
:
"created"
,
Type
:
DB_DateTime
,
Nullable
:
false
},
{
Name
:
"updated"
,
Type
:
DB_DateTime
,
Nullable
:
false
},
},
}
...
...
pkg/services/sqlstore/preferences.go
View file @
e371e036
...
...
@@ -3,6 +3,7 @@ package sqlstore
import
(
"github.com/grafana/grafana/pkg/bus"
m
"github.com/grafana/grafana/pkg/models"
"time"
)
func
init
()
{
...
...
@@ -54,10 +55,12 @@ func SavePreferences(cmd *m.SavePreferencesCommand) error {
savePref
.
UserId
=
cmd
.
UserId
savePref
.
OrgId
=
cmd
.
OrgId
savePref
.
Preference
=
cmd
.
Preference
savePref
=
SetPreferencesModel
(
savePref
,
false
)
affectedRows
,
saveErr
=
sess
.
Insert
(
&
savePref
)
}
else
{
savePref
=
prefResults
[
0
]
savePref
.
Preference
=
cmd
.
Preference
savePref
=
SetPreferencesModel
(
savePref
,
true
)
affectedRows
,
saveErr
=
sess
.
Id
(
savePref
.
Id
)
.
Update
(
&
savePref
)
}
...
...
@@ -68,3 +71,16 @@ func SavePreferences(cmd *m.SavePreferencesCommand) error {
return
saveErr
})
}
func
SetPreferencesModel
(
pref
m
.
Preferences
,
updating
bool
)
m
.
Preferences
{
if
updating
{
pref
.
Version
=
pref
.
Version
+
1
}
else
{
pref
.
Version
=
0
pref
.
Created
=
time
.
Now
()
}
pref
.
Updated
=
time
.
Now
()
return
pref
}
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