mirror of
https://github.com/grafana/grafana.git
synced 2024-11-24 18:00:31 -06:00
I18n: Add locale to user preference (#49425)
* Add __debug_bin file to gitignore * Add locale user preference * undo defaulting to existing JSONData in preferences save
This commit is contained in:
parent
b4c8b6d672
commit
3cebd87bbb
2
.gitignore
vendored
2
.gitignore
vendored
@ -99,6 +99,7 @@ debug.test
|
|||||||
/packaging/**/*.deb
|
/packaging/**/*.deb
|
||||||
/packaging/**/*.tar.gz
|
/packaging/**/*.tar.gz
|
||||||
/packaging/**/*.tar.gz.sha256
|
/packaging/**/*.tar.gz.sha256
|
||||||
|
pkg/cmd/grafana-server/__debug_bin
|
||||||
|
|
||||||
# Ignore OSX indexing
|
# Ignore OSX indexing
|
||||||
.DS_Store
|
.DS_Store
|
||||||
@ -165,4 +166,3 @@ public/locales/_build/
|
|||||||
public/locales/**/*.js
|
public/locales/**/*.js
|
||||||
|
|
||||||
deployment_tools_config.json
|
deployment_tools_config.json
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ type Prefs struct {
|
|||||||
HomeDashboardUID string `json:"homeDashboardUID,omitempty"`
|
HomeDashboardUID string `json:"homeDashboardUID,omitempty"`
|
||||||
Timezone string `json:"timezone"`
|
Timezone string `json:"timezone"`
|
||||||
WeekStart string `json:"weekStart"`
|
WeekStart string `json:"weekStart"`
|
||||||
|
Locale string `json:"locale"`
|
||||||
Navbar pref.NavbarPreference `json:"navbar,omitempty"`
|
Navbar pref.NavbarPreference `json:"navbar,omitempty"`
|
||||||
QueryHistory pref.QueryHistoryPreference `json:"queryHistory,omitempty"`
|
QueryHistory pref.QueryHistoryPreference `json:"queryHistory,omitempty"`
|
||||||
}
|
}
|
||||||
@ -27,6 +28,7 @@ type UpdatePrefsCmd struct {
|
|||||||
WeekStart string `json:"weekStart"`
|
WeekStart string `json:"weekStart"`
|
||||||
Navbar *pref.NavbarPreference `json:"navbar,omitempty"`
|
Navbar *pref.NavbarPreference `json:"navbar,omitempty"`
|
||||||
QueryHistory *pref.QueryHistoryPreference `json:"queryHistory,omitempty"`
|
QueryHistory *pref.QueryHistoryPreference `json:"queryHistory,omitempty"`
|
||||||
|
Locale string `json:"locale"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// swagger:model
|
// swagger:model
|
||||||
@ -39,6 +41,7 @@ type PatchPrefsCmd struct {
|
|||||||
// Enum: utc,browser
|
// Enum: utc,browser
|
||||||
Timezone *string `json:"timezone,omitempty"`
|
Timezone *string `json:"timezone,omitempty"`
|
||||||
WeekStart *string `json:"weekStart,omitempty"`
|
WeekStart *string `json:"weekStart,omitempty"`
|
||||||
|
Locale *string `json:"locale,omitempty"`
|
||||||
Navbar *pref.NavbarPreference `json:"navbar,omitempty"`
|
Navbar *pref.NavbarPreference `json:"navbar,omitempty"`
|
||||||
QueryHistory *pref.QueryHistoryPreference `json:"queryHistory,omitempty"`
|
QueryHistory *pref.QueryHistoryPreference `json:"queryHistory,omitempty"`
|
||||||
HomeDashboardUID *string `json:"homeDashboardUID,omitempty"`
|
HomeDashboardUID *string `json:"homeDashboardUID,omitempty"`
|
||||||
|
@ -80,6 +80,7 @@ func (hs *HTTPServer) getPreferencesFor(ctx context.Context, orgID, userID, team
|
|||||||
}
|
}
|
||||||
|
|
||||||
if preference.JSONData != nil {
|
if preference.JSONData != nil {
|
||||||
|
dto.Locale = preference.JSONData.Locale
|
||||||
dto.Navbar = preference.JSONData.Navbar
|
dto.Navbar = preference.JSONData.Navbar
|
||||||
dto.QueryHistory = preference.JSONData.QueryHistory
|
dto.QueryHistory = preference.JSONData.QueryHistory
|
||||||
}
|
}
|
||||||
@ -117,6 +118,7 @@ func (hs *HTTPServer) updatePreferencesFor(ctx context.Context, orgID, userID, t
|
|||||||
OrgID: orgID,
|
OrgID: orgID,
|
||||||
TeamID: teamId,
|
TeamID: teamId,
|
||||||
Theme: dtoCmd.Theme,
|
Theme: dtoCmd.Theme,
|
||||||
|
Locale: dtoCmd.Locale,
|
||||||
Timezone: dtoCmd.Timezone,
|
Timezone: dtoCmd.Timezone,
|
||||||
WeekStart: dtoCmd.WeekStart,
|
WeekStart: dtoCmd.WeekStart,
|
||||||
HomeDashboardID: dtoCmd.HomeDashboardID,
|
HomeDashboardID: dtoCmd.HomeDashboardID,
|
||||||
@ -165,6 +167,7 @@ func (hs *HTTPServer) patchPreferencesFor(ctx context.Context, orgID, userID, te
|
|||||||
Timezone: dtoCmd.Timezone,
|
Timezone: dtoCmd.Timezone,
|
||||||
WeekStart: dtoCmd.WeekStart,
|
WeekStart: dtoCmd.WeekStart,
|
||||||
HomeDashboardID: dtoCmd.HomeDashboardID,
|
HomeDashboardID: dtoCmd.HomeDashboardID,
|
||||||
|
Locale: dtoCmd.Locale,
|
||||||
Navbar: dtoCmd.Navbar,
|
Navbar: dtoCmd.Navbar,
|
||||||
QueryHistory: dtoCmd.QueryHistory,
|
QueryHistory: dtoCmd.QueryHistory,
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,7 @@ type SavePreferenceCommand struct {
|
|||||||
Timezone string `json:"timezone,omitempty"`
|
Timezone string `json:"timezone,omitempty"`
|
||||||
WeekStart string `json:"weekStart,omitempty"`
|
WeekStart string `json:"weekStart,omitempty"`
|
||||||
Theme string `json:"theme,omitempty"`
|
Theme string `json:"theme,omitempty"`
|
||||||
|
Locale string `json:"locale,omitempty"`
|
||||||
Navbar *NavbarPreference `json:"navbar,omitempty"`
|
Navbar *NavbarPreference `json:"navbar,omitempty"`
|
||||||
QueryHistory *QueryHistoryPreference `json:"queryHistory,omitempty"`
|
QueryHistory *QueryHistoryPreference `json:"queryHistory,omitempty"`
|
||||||
}
|
}
|
||||||
@ -61,6 +62,7 @@ type PatchPreferenceCommand struct {
|
|||||||
Timezone *string `json:"timezone,omitempty"`
|
Timezone *string `json:"timezone,omitempty"`
|
||||||
WeekStart *string `json:"weekStart,omitempty"`
|
WeekStart *string `json:"weekStart,omitempty"`
|
||||||
Theme *string `json:"theme,omitempty"`
|
Theme *string `json:"theme,omitempty"`
|
||||||
|
Locale *string `json:"locale,omitempty"`
|
||||||
Navbar *NavbarPreference `json:"navbar,omitempty"`
|
Navbar *NavbarPreference `json:"navbar,omitempty"`
|
||||||
QueryHistory *QueryHistoryPreference `json:"queryHistory,omitempty"`
|
QueryHistory *QueryHistoryPreference `json:"queryHistory,omitempty"`
|
||||||
}
|
}
|
||||||
@ -77,6 +79,7 @@ type NavbarPreference struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PreferenceJSONData struct {
|
type PreferenceJSONData struct {
|
||||||
|
Locale string `json:"locale"`
|
||||||
Navbar NavbarPreference `json:"navbar"`
|
Navbar NavbarPreference `json:"navbar"`
|
||||||
QueryHistory QueryHistoryPreference `json:"queryHistory"`
|
QueryHistory QueryHistoryPreference `json:"queryHistory"`
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,9 @@ func (s *Service) Save(ctx context.Context, cmd *pref.SavePreferenceCommand) err
|
|||||||
Theme: cmd.Theme,
|
Theme: cmd.Theme,
|
||||||
Created: time.Now(),
|
Created: time.Now(),
|
||||||
Updated: time.Now(),
|
Updated: time.Now(),
|
||||||
|
JSONData: &pref.PreferenceJSONData{
|
||||||
|
Locale: cmd.Locale,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
_, err = s.store.Insert(ctx, preference)
|
_, err = s.store.Insert(ctx, preference)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -106,8 +109,10 @@ func (s *Service) Save(ctx context.Context, cmd *pref.SavePreferenceCommand) err
|
|||||||
preference.Theme = cmd.Theme
|
preference.Theme = cmd.Theme
|
||||||
preference.Updated = time.Now()
|
preference.Updated = time.Now()
|
||||||
preference.Version += 1
|
preference.Version += 1
|
||||||
preference.JSONData = &pref.PreferenceJSONData{}
|
|
||||||
preference.HomeDashboardID = cmd.HomeDashboardID
|
preference.HomeDashboardID = cmd.HomeDashboardID
|
||||||
|
preference.JSONData = &pref.PreferenceJSONData{
|
||||||
|
Locale: cmd.Locale,
|
||||||
|
}
|
||||||
|
|
||||||
if cmd.Navbar != nil {
|
if cmd.Navbar != nil {
|
||||||
preference.JSONData.Navbar = *cmd.Navbar
|
preference.JSONData.Navbar = *cmd.Navbar
|
||||||
@ -141,6 +146,13 @@ func (s *Service) Patch(ctx context.Context, cmd *pref.PatchPreferenceCommand) e
|
|||||||
exists = true
|
exists = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cmd.Locale != nil {
|
||||||
|
if preference.JSONData == nil {
|
||||||
|
preference.JSONData = &pref.PreferenceJSONData{}
|
||||||
|
}
|
||||||
|
preference.JSONData.Locale = *cmd.Locale
|
||||||
|
}
|
||||||
|
|
||||||
if cmd.Navbar != nil {
|
if cmd.Navbar != nil {
|
||||||
if preference.JSONData == nil {
|
if preference.JSONData == nil {
|
||||||
preference.JSONData = &pref.PreferenceJSONData{}
|
preference.JSONData = &pref.PreferenceJSONData{}
|
||||||
|
Loading…
Reference in New Issue
Block a user