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
746d6cdc
Commit
746d6cdc
authored
Jun 05, 2017
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring: changed name on compare command to make properties more explainatory
parent
9c140184
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
29 deletions
+32
-29
pkg/api/dashboard.go
+21
-18
pkg/models/dashboard_version.go
+2
-2
pkg/services/sqlstore/dashboard_version.go
+3
-3
pkg/services/sqlstore/dashboard_version_test.go
+6
-6
No files found.
pkg/api/dashboard.go
View file @
746d6cdc
...
@@ -2,6 +2,7 @@ package api
...
@@ -2,6 +2,7 @@ package api
import
(
import
(
"encoding/json"
"encoding/json"
"errors"
"fmt"
"fmt"
"os"
"os"
"path"
"path"
...
@@ -323,34 +324,34 @@ func GetDashboardVersion(c *middleware.Context) Response {
...
@@ -323,34 +324,34 @@ func GetDashboardVersion(c *middleware.Context) Response {
return
Json
(
200
,
dashVersionMeta
)
return
Json
(
200
,
dashVersionMeta
)
}
}
func
createCompareDashboardVersionCommand
(
c
*
middleware
.
Context
)
(
m
.
CompareDashboardVersionsCommand
,
error
)
{
func
createCompareDashboardVersionCommand
(
c
*
middleware
.
Context
)
(
*
m
.
CompareDashboardVersionsCommand
,
error
)
{
cmd
:=
m
.
CompareDashboardVersionsCommand
{}
cmd
:=
&
m
.
CompareDashboardVersionsCommand
{}
dashboardIdStr
:=
c
.
Params
(
":dashboardId"
)
dashId
:=
c
.
ParamsInt64
(
":dashboardId"
)
dashboardId
,
err
:=
strconv
.
Atoi
(
dashboardIdStr
)
if
dashId
==
0
{
if
err
!=
nil
{
return
nil
,
errors
.
New
(
"Missing dashboardId"
)
return
cmd
,
err
}
}
versionStrings
:=
strings
.
Split
(
c
.
Params
(
":versions"
),
"..."
)
versionStrings
:=
strings
.
Split
(
c
.
Params
(
":versions"
),
"..."
)
if
len
(
versionStrings
)
!=
2
{
if
len
(
versionStrings
)
!=
2
{
return
cmd
,
fmt
.
Errorf
(
"bad format: urls should be in the format /versions/0...1"
)
return
nil
,
fmt
.
Errorf
(
"bad format: urls should be in the format /versions/0...1"
)
}
}
originalDash
,
err
:=
strconv
.
Atoi
(
versionStrings
[
0
])
BaseVersion
,
err
:=
strconv
.
Atoi
(
versionStrings
[
0
])
if
err
!=
nil
{
if
err
!=
nil
{
return
cmd
,
fmt
.
Errorf
(
"bad format: first argument is not of type int"
)
return
nil
,
fmt
.
Errorf
(
"bad format: first argument is not of type int"
)
}
}
new
Dash
,
err
:=
strconv
.
Atoi
(
versionStrings
[
1
])
new
Version
,
err
:=
strconv
.
Atoi
(
versionStrings
[
1
])
if
err
!=
nil
{
if
err
!=
nil
{
return
cmd
,
fmt
.
Errorf
(
"bad format: second argument is not of type int"
)
return
nil
,
fmt
.
Errorf
(
"bad format: second argument is not of type int"
)
}
}
cmd
.
DashboardId
=
int64
(
dashboardId
)
cmd
.
DashboardId
=
dashId
cmd
.
OrgId
=
c
.
OrgId
cmd
.
OrgId
=
c
.
OrgId
cmd
.
Original
=
originalDash
cmd
.
BaseVersion
=
BaseVersion
cmd
.
New
=
newDash
cmd
.
NewVersion
=
newVersion
return
cmd
,
nil
return
cmd
,
nil
}
}
...
@@ -360,6 +361,7 @@ func CompareDashboardVersions(c *middleware.Context) Response {
...
@@ -360,6 +361,7 @@ func CompareDashboardVersions(c *middleware.Context) Response {
if
err
!=
nil
{
if
err
!=
nil
{
return
ApiError
(
500
,
err
.
Error
(),
err
)
return
ApiError
(
500
,
err
.
Error
(),
err
)
}
}
cmd
.
DiffType
=
m
.
DiffDelta
cmd
.
DiffType
=
m
.
DiffDelta
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
...
@@ -376,8 +378,8 @@ func CompareDashboardVersions(c *middleware.Context) Response {
...
@@ -376,8 +378,8 @@ func CompareDashboardVersions(c *middleware.Context) Response {
return
Json
(
200
,
util
.
DynMap
{
return
Json
(
200
,
util
.
DynMap
{
"meta"
:
util
.
DynMap
{
"meta"
:
util
.
DynMap
{
"
original"
:
cmd
.
Original
,
"
baseVersion"
:
cmd
.
BaseVersion
,
"new
"
:
cmd
.
New
,
"new
Version"
:
cmd
.
NewVersion
,
},
},
"delta"
:
deltaMap
,
"delta"
:
deltaMap
,
})
})
...
@@ -392,7 +394,7 @@ func CompareDashboardVersionsJSON(c *middleware.Context) Response {
...
@@ -392,7 +394,7 @@ func CompareDashboardVersionsJSON(c *middleware.Context) Response {
}
}
cmd
.
DiffType
=
m
.
DiffJSON
cmd
.
DiffType
=
m
.
DiffJSON
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
cmd
);
err
!=
nil
{
return
ApiError
(
500
,
err
.
Error
(),
err
)
return
ApiError
(
500
,
err
.
Error
(),
err
)
}
}
...
@@ -406,9 +408,10 @@ func CompareDashboardVersionsBasic(c *middleware.Context) Response {
...
@@ -406,9 +408,10 @@ func CompareDashboardVersionsBasic(c *middleware.Context) Response {
if
err
!=
nil
{
if
err
!=
nil
{
return
ApiError
(
500
,
err
.
Error
(),
err
)
return
ApiError
(
500
,
err
.
Error
(),
err
)
}
}
cmd
.
DiffType
=
m
.
DiffBasic
cmd
.
DiffType
=
m
.
DiffBasic
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
cmd
);
err
!=
nil
{
return
ApiError
(
500
,
err
.
Error
(),
err
)
return
ApiError
(
500
,
err
.
Error
(),
err
)
}
}
...
...
pkg/models/dashboard_version.go
View file @
746d6cdc
...
@@ -86,8 +86,8 @@ type GetDashboardVersionsQuery struct {
...
@@ -86,8 +86,8 @@ type GetDashboardVersionsQuery struct {
type
CompareDashboardVersionsCommand
struct
{
type
CompareDashboardVersionsCommand
struct
{
OrgId
int64
OrgId
int64
DashboardId
int64
DashboardId
int64
Original
int
BaseVersion
int
New
int
New
Version
int
DiffType
DiffType
DiffType
DiffType
Delta
[]
byte
`json:"delta"`
Delta
[]
byte
`json:"delta"`
...
...
pkg/services/sqlstore/dashboard_version.go
View file @
746d6cdc
...
@@ -30,17 +30,17 @@ func init() {
...
@@ -30,17 +30,17 @@ func init() {
// CompareDashboardVersionsCommand computes the JSON diff of two versions,
// CompareDashboardVersionsCommand computes the JSON diff of two versions,
// assigning the delta of the diff to the `Delta` field.
// assigning the delta of the diff to the `Delta` field.
func
CompareDashboardVersionsCommand
(
cmd
*
m
.
CompareDashboardVersionsCommand
)
error
{
func
CompareDashboardVersionsCommand
(
cmd
*
m
.
CompareDashboardVersionsCommand
)
error
{
original
,
err
:=
getDashboardVersion
(
cmd
.
DashboardId
,
cmd
.
Original
)
baseVersion
,
err
:=
getDashboardVersion
(
cmd
.
DashboardId
,
cmd
.
BaseVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
new
Dashboard
,
err
:=
getDashboardVersion
(
cmd
.
DashboardId
,
cmd
.
New
)
new
Version
,
err
:=
getDashboardVersion
(
cmd
.
DashboardId
,
cmd
.
NewVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
left
,
jsonDiff
,
err
:=
getDiff
(
original
,
newDashboard
)
left
,
jsonDiff
,
err
:=
getDiff
(
baseVersion
,
newVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
pkg/services/sqlstore/dashboard_version_test.go
View file @
746d6cdc
...
@@ -117,8 +117,8 @@ func TestCompareDashboardVersions(t *testing.T) {
...
@@ -117,8 +117,8 @@ func TestCompareDashboardVersions(t *testing.T) {
cmd
:=
m
.
CompareDashboardVersionsCommand
{
cmd
:=
m
.
CompareDashboardVersionsCommand
{
DashboardId
:
savedDash
.
Id
,
DashboardId
:
savedDash
.
Id
,
Original
:
query
.
Result
[
0
]
.
Version
,
BaseVersion
:
query
.
Result
[
0
]
.
Version
,
New
:
query
.
Result
[
1
]
.
Version
,
New
Version
:
query
.
Result
[
1
]
.
Version
,
DiffType
:
m
.
DiffDelta
,
DiffType
:
m
.
DiffDelta
,
}
}
...
@@ -130,8 +130,8 @@ func TestCompareDashboardVersions(t *testing.T) {
...
@@ -130,8 +130,8 @@ func TestCompareDashboardVersions(t *testing.T) {
Convey
(
"Compare two versions that are the same"
,
func
()
{
Convey
(
"Compare two versions that are the same"
,
func
()
{
cmd
:=
m
.
CompareDashboardVersionsCommand
{
cmd
:=
m
.
CompareDashboardVersionsCommand
{
DashboardId
:
savedDash
.
Id
,
DashboardId
:
savedDash
.
Id
,
Original
:
savedDash
.
Version
,
BaseVersion
:
savedDash
.
Version
,
New
:
savedDash
.
Version
,
New
Version
:
savedDash
.
Version
,
DiffType
:
m
.
DiffDelta
,
DiffType
:
m
.
DiffDelta
,
}
}
...
@@ -143,8 +143,8 @@ func TestCompareDashboardVersions(t *testing.T) {
...
@@ -143,8 +143,8 @@ func TestCompareDashboardVersions(t *testing.T) {
Convey
(
"Compare two versions that don't exist"
,
func
()
{
Convey
(
"Compare two versions that don't exist"
,
func
()
{
cmd
:=
m
.
CompareDashboardVersionsCommand
{
cmd
:=
m
.
CompareDashboardVersionsCommand
{
DashboardId
:
savedDash
.
Id
,
DashboardId
:
savedDash
.
Id
,
Original
:
123
,
BaseVersion
:
123
,
New
:
456
,
New
Version
:
456
,
DiffType
:
m
.
DiffDelta
,
DiffType
:
m
.
DiffDelta
,
}
}
...
...
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