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
e229f8ae
Commit
e229f8ae
authored
Jan 29, 2018
by
Marcus Efraimsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboards: extract short uid generator to util package. #7883
parent
fc7bab8b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
9 deletions
+27
-9
pkg/models/dashboards.go
+3
-9
pkg/util/shortid_generator.go
+24
-0
No files found.
pkg/models/dashboards.go
View file @
e229f8ae
...
@@ -7,7 +7,7 @@ import (
...
@@ -7,7 +7,7 @@ import (
"github.com/gosimple/slug"
"github.com/gosimple/slug"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/
teris-io/shortid
"
"github.com/
grafana/grafana/pkg/util
"
)
)
// Typed errors
// Typed errors
...
@@ -63,7 +63,7 @@ type Dashboard struct {
...
@@ -63,7 +63,7 @@ type Dashboard struct {
// NewDashboard creates a new dashboard
// NewDashboard creates a new dashboard
func
NewDashboard
(
title
string
)
*
Dashboard
{
func
NewDashboard
(
title
string
)
*
Dashboard
{
dash
:=
&
Dashboard
{}
dash
:=
&
Dashboard
{}
dash
.
Uid
=
Dashboard
Uid
()
dash
.
Uid
,
_
=
util
.
GenerateShort
Uid
()
dash
.
Data
=
simplejson
.
New
()
dash
.
Data
=
simplejson
.
New
()
dash
.
Data
.
Set
(
"title"
,
title
)
dash
.
Data
.
Set
(
"title"
,
title
)
dash
.
Title
=
title
dash
.
Title
=
title
...
@@ -113,18 +113,12 @@ func NewDashboardFromJson(data *simplejson.Json) *Dashboard {
...
@@ -113,18 +113,12 @@ func NewDashboardFromJson(data *simplejson.Json) *Dashboard {
if
uid
,
err
:=
dash
.
Data
.
Get
(
"uid"
)
.
String
();
err
==
nil
{
if
uid
,
err
:=
dash
.
Data
.
Get
(
"uid"
)
.
String
();
err
==
nil
{
dash
.
Uid
=
uid
dash
.
Uid
=
uid
}
else
{
}
else
{
dash
.
Uid
=
Dashboard
Uid
()
dash
.
Uid
,
_
=
util
.
GenerateShort
Uid
()
}
}
return
dash
return
dash
}
}
func
DashboardUid
()
string
{
gen
,
_
:=
shortid
.
New
(
1
,
shortid
.
DefaultABC
,
1
)
uid
,
_
:=
gen
.
Generate
()
return
uid
}
// GetDashboardModel turns the command into the savable model
// GetDashboardModel turns the command into the savable model
func
(
cmd
*
SaveDashboardCommand
)
GetDashboardModel
()
*
Dashboard
{
func
(
cmd
*
SaveDashboardCommand
)
GetDashboardModel
()
*
Dashboard
{
dash
:=
NewDashboardFromJson
(
cmd
.
Dashboard
)
dash
:=
NewDashboardFromJson
(
cmd
.
Dashboard
)
...
...
pkg/util/shortid_generator.go
0 → 100644
View file @
e229f8ae
package
util
import
(
"github.com/teris-io/shortid"
)
func
init
()
{
gen
,
_
:=
shortid
.
New
(
1
,
shortid
.
DefaultABC
,
1
)
shortid
.
SetDefault
(
gen
)
}
// GenerateShortUid generates a short unique identifier.
func
GenerateShortUid
()
(
uid
string
,
err
error
)
{
if
uid
,
err
=
shortid
.
Generate
();
err
!=
nil
{
if
uid
,
err
=
shortid
.
Generate
();
err
!=
nil
{
if
uid
,
err
=
shortid
.
Generate
();
err
!=
nil
{
return
""
,
err
}
}
}
return
uid
,
nil
}
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