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
593b2ef8
Commit
593b2ef8
authored
Apr 12, 2017
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
annotation: added region support to annoations
parent
b867921b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
3 deletions
+41
-3
pkg/api/annotations.go
+19
-3
pkg/api/dtos/annotations.go
+5
-0
pkg/services/annotations/annotations.go
+2
-0
pkg/services/sqlstore/annotation.go
+11
-0
pkg/services/sqlstore/migrations/annotation_mig.go
+4
-0
No files found.
pkg/api/annotations.go
View file @
593b2ef8
...
...
@@ -40,6 +40,7 @@ func GetAnnotations(c *middleware.Context) Response {
Metric
:
item
.
Metric
,
Title
:
item
.
Title
,
PanelId
:
item
.
PanelId
,
RegionId
:
item
.
RegionId
,
})
}
...
...
@@ -57,15 +58,30 @@ func PostAnnotation(c *middleware.Context, cmd dtos.PostAnnotationsCmd) Response
Title
:
cmd
.
Title
,
Text
:
cmd
.
Text
,
CategoryId
:
cmd
.
CategoryId
,
NewState
:
cmd
.
FillColor
,
Type
:
annotations
.
EventType
,
}
err
:=
repo
.
Save
(
&
item
)
if
err
!=
nil
{
if
err
:=
repo
.
Save
(
&
item
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to save annotation"
,
err
)
}
// handle regions
if
cmd
.
IsRegion
{
item
.
RegionId
=
item
.
Id
if
err
:=
repo
.
Update
(
&
item
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed set regionId on annotation"
,
err
)
}
item
.
Id
=
0
item
.
Epoch
=
cmd
.
EndTime
if
err
:=
repo
.
Save
(
&
item
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed save annotation for region end time"
,
err
)
}
}
return
ApiSuccess
(
"Annotation added"
)
}
...
...
pkg/api/dtos/annotations.go
View file @
593b2ef8
...
...
@@ -12,6 +12,7 @@ type Annotation struct {
Title
string
`json:"title"`
Text
string
`json:"text"`
Metric
string
`json:"metric"`
RegionId
int64
`json:"regionId"`
Data
*
simplejson
.
Json
`json:"data"`
}
...
...
@@ -23,6 +24,10 @@ type PostAnnotationsCmd struct {
Time
int64
`json:"time"`
Title
string
`json:"title"`
Text
string
`json:"text"`
FillColor
string
`json:"fillColor"`
IsRegion
bool
`json:"isRegion"`
EndTime
int64
`json:"endTime"`
}
type
DeleteAnnotationsCmd
struct
{
...
...
pkg/services/annotations/annotations.go
View file @
593b2ef8
...
...
@@ -4,6 +4,7 @@ import "github.com/grafana/grafana/pkg/components/simplejson"
type
Repository
interface
{
Save
(
item
*
Item
)
error
Update
(
item
*
Item
)
error
Find
(
query
*
ItemQuery
)
([]
*
Item
,
error
)
Delete
(
params
*
DeleteParams
)
error
}
...
...
@@ -58,6 +59,7 @@ type Item struct {
DashboardId
int64
`json:"dashboardId"`
PanelId
int64
`json:"panelId"`
CategoryId
int64
`json:"categoryId"`
RegionId
int64
`json:"regionId"`
Type
ItemType
`json:"type"`
Title
string
`json:"title"`
Text
string
`json:"text"`
...
...
pkg/services/sqlstore/annotation.go
View file @
593b2ef8
...
...
@@ -23,6 +23,17 @@ func (r *SqlAnnotationRepo) Save(item *annotations.Item) error {
})
}
func
(
r
*
SqlAnnotationRepo
)
Update
(
item
*
annotations
.
Item
)
error
{
return
inTransaction
(
func
(
sess
*
xorm
.
Session
)
error
{
if
_
,
err
:=
sess
.
Table
(
"annotation"
)
.
Id
(
item
.
Id
)
.
Update
(
item
);
err
!=
nil
{
return
err
}
return
nil
})
}
func
(
r
*
SqlAnnotationRepo
)
Find
(
query
*
annotations
.
ItemQuery
)
([]
*
annotations
.
Item
,
error
)
{
var
sql
bytes
.
Buffer
params
:=
make
([]
interface
{},
0
)
...
...
pkg/services/sqlstore/migrations/annotation_mig.go
View file @
593b2ef8
...
...
@@ -54,4 +54,8 @@ func addAnnotationMig(mg *Migrator) {
{
Name
:
"new_state"
,
Type
:
DB_NVarchar
,
Length
:
25
,
Nullable
:
false
},
{
Name
:
"data"
,
Type
:
DB_Text
,
Nullable
:
false
},
}))
mg
.
AddMigration
(
"Add column region_id to annotation table"
,
NewAddColumnMigration
(
table
,
&
Column
{
Name
:
"region_id"
,
Type
:
DB_BigInt
,
Nullable
:
true
,
Default
:
"0"
,
}))
}
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