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
import
(
"encoding/json"
"errors"
"fmt"
"os"
"path"
...
...
@@ -323,34 +324,34 @@ func GetDashboardVersion(c *middleware.Context) Response {
return
Json
(
200
,
dashVersionMeta
)
}
func
createCompareDashboardVersionCommand
(
c
*
middleware
.
Context
)
(
m
.
CompareDashboardVersionsCommand
,
error
)
{
cmd
:=
m
.
CompareDashboardVersionsCommand
{}
func
createCompareDashboardVersionCommand
(
c
*
middleware
.
Context
)
(
*
m
.
CompareDashboardVersionsCommand
,
error
)
{
cmd
:=
&
m
.
CompareDashboardVersionsCommand
{}
dashboardIdStr
:=
c
.
Params
(
":dashboardId"
)
dashboardId
,
err
:=
strconv
.
Atoi
(
dashboardIdStr
)
if
err
!=
nil
{
return
cmd
,
err
dashId
:=
c
.
ParamsInt64
(
":dashboardId"
)
if
dashId
==
0
{
return
nil
,
errors
.
New
(
"Missing dashboardId"
)
}
versionStrings
:=
strings
.
Split
(
c
.
Params
(
":versions"
),
"..."
)
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
{
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
{
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
.
Original
=
originalDash
cmd
.
New
=
newDash
cmd
.
BaseVersion
=
BaseVersion
cmd
.
NewVersion
=
newVersion
return
cmd
,
nil
}
...
...
@@ -360,6 +361,7 @@ func CompareDashboardVersions(c *middleware.Context) Response {
if
err
!=
nil
{
return
ApiError
(
500
,
err
.
Error
(),
err
)
}
cmd
.
DiffType
=
m
.
DiffDelta
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
...
...
@@ -376,8 +378,8 @@ func CompareDashboardVersions(c *middleware.Context) Response {
return
Json
(
200
,
util
.
DynMap
{
"meta"
:
util
.
DynMap
{
"
original"
:
cmd
.
Original
,
"new
"
:
cmd
.
New
,
"
baseVersion"
:
cmd
.
BaseVersion
,
"new
Version"
:
cmd
.
NewVersion
,
},
"delta"
:
deltaMap
,
})
...
...
@@ -392,7 +394,7 @@ func CompareDashboardVersionsJSON(c *middleware.Context) Response {
}
cmd
.
DiffType
=
m
.
DiffJSON
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
cmd
);
err
!=
nil
{
return
ApiError
(
500
,
err
.
Error
(),
err
)
}
...
...
@@ -406,9 +408,10 @@ func CompareDashboardVersionsBasic(c *middleware.Context) Response {
if
err
!=
nil
{
return
ApiError
(
500
,
err
.
Error
(),
err
)
}
cmd
.
DiffType
=
m
.
DiffBasic
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
cmd
);
err
!=
nil
{
return
ApiError
(
500
,
err
.
Error
(),
err
)
}
...
...
pkg/models/dashboard_version.go
View file @
746d6cdc
...
...
@@ -86,8 +86,8 @@ type GetDashboardVersionsQuery struct {
type
CompareDashboardVersionsCommand
struct
{
OrgId
int64
DashboardId
int64
Original
int
New
int
BaseVersion
int
New
Version
int
DiffType
DiffType
Delta
[]
byte
`json:"delta"`
...
...
pkg/services/sqlstore/dashboard_version.go
View file @
746d6cdc
...
...
@@ -30,17 +30,17 @@ func init() {
// CompareDashboardVersionsCommand computes the JSON diff of two versions,
// assigning the delta of the diff to the `Delta` field.
func
CompareDashboardVersionsCommand
(
cmd
*
m
.
CompareDashboardVersionsCommand
)
error
{
original
,
err
:=
getDashboardVersion
(
cmd
.
DashboardId
,
cmd
.
Original
)
baseVersion
,
err
:=
getDashboardVersion
(
cmd
.
DashboardId
,
cmd
.
BaseVersion
)
if
err
!=
nil
{
return
err
}
new
Dashboard
,
err
:=
getDashboardVersion
(
cmd
.
DashboardId
,
cmd
.
New
)
new
Version
,
err
:=
getDashboardVersion
(
cmd
.
DashboardId
,
cmd
.
NewVersion
)
if
err
!=
nil
{
return
err
}
left
,
jsonDiff
,
err
:=
getDiff
(
original
,
newDashboard
)
left
,
jsonDiff
,
err
:=
getDiff
(
baseVersion
,
newVersion
)
if
err
!=
nil
{
return
err
}
...
...
pkg/services/sqlstore/dashboard_version_test.go
View file @
746d6cdc
...
...
@@ -117,8 +117,8 @@ func TestCompareDashboardVersions(t *testing.T) {
cmd
:=
m
.
CompareDashboardVersionsCommand
{
DashboardId
:
savedDash
.
Id
,
Original
:
query
.
Result
[
0
]
.
Version
,
New
:
query
.
Result
[
1
]
.
Version
,
BaseVersion
:
query
.
Result
[
0
]
.
Version
,
New
Version
:
query
.
Result
[
1
]
.
Version
,
DiffType
:
m
.
DiffDelta
,
}
...
...
@@ -130,8 +130,8 @@ func TestCompareDashboardVersions(t *testing.T) {
Convey
(
"Compare two versions that are the same"
,
func
()
{
cmd
:=
m
.
CompareDashboardVersionsCommand
{
DashboardId
:
savedDash
.
Id
,
Original
:
savedDash
.
Version
,
New
:
savedDash
.
Version
,
BaseVersion
:
savedDash
.
Version
,
New
Version
:
savedDash
.
Version
,
DiffType
:
m
.
DiffDelta
,
}
...
...
@@ -143,8 +143,8 @@ func TestCompareDashboardVersions(t *testing.T) {
Convey
(
"Compare two versions that don't exist"
,
func
()
{
cmd
:=
m
.
CompareDashboardVersionsCommand
{
DashboardId
:
savedDash
.
Id
,
Original
:
123
,
New
:
456
,
BaseVersion
:
123
,
New
Version
:
456
,
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