mirror of https://github.com/grafana/grafana
parent
60ef7d8768
commit
03ef1fd758
@ -1,9 +1,12 @@ |
||||
|
||||
import {AnnotationsSrv} from './annotations_srv'; |
||||
import {eventEditor, EventManager} from './event_editor'; |
||||
import {eventEditor} from './event_editor'; |
||||
import {EventManager} from './event_manager'; |
||||
import {AnnotationEvent} from './event'; |
||||
|
||||
export { |
||||
AnnotationsSrv, |
||||
eventEditor, |
||||
EventManager |
||||
EventManager, |
||||
AnnotationEvent, |
||||
}; |
||||
|
@ -0,0 +1,10 @@ |
||||
|
||||
export class AnnotationEvent { |
||||
dashboardId: number; |
||||
panelId: number; |
||||
time: any; |
||||
timeEnd: any; |
||||
isRegion: boolean; |
||||
title: string; |
||||
text: string; |
||||
} |
@ -0,0 +1,117 @@ |
||||
|
||||
import moment from 'moment'; |
||||
import {MetricsPanelCtrl} from 'app/plugins/sdk'; |
||||
import {AnnotationEvent} from './event'; |
||||
|
||||
export class EventManager { |
||||
event: AnnotationEvent; |
||||
|
||||
constructor(private panelCtrl: MetricsPanelCtrl, private elem, private popoverSrv) { |
||||
} |
||||
|
||||
editorClosed() { |
||||
console.log('editorClosed'); |
||||
this.event = null; |
||||
this.panelCtrl.render(); |
||||
} |
||||
|
||||
updateTime(range) { |
||||
let newEvent = true; |
||||
|
||||
if (this.event) { |
||||
newEvent = false; |
||||
} else { |
||||
// init new event
|
||||
this.event = new AnnotationEvent(); |
||||
this.event.dashboardId = this.panelCtrl.dashboard.id; |
||||
this.event.panelId = this.panelCtrl.panel.id; |
||||
} |
||||
|
||||
// update time
|
||||
this.event.time = moment(range.from); |
||||
this.event.isRegion = false; |
||||
if (range.to) { |
||||
this.event.timeEnd = moment(range.to); |
||||
this.event.isRegion = true; |
||||
} |
||||
|
||||
// newEvent means the editor is not visible
|
||||
if (!newEvent) { |
||||
this.panelCtrl.render(); |
||||
return; |
||||
} |
||||
|
||||
this.popoverSrv.show({ |
||||
element: this.elem[0], |
||||
classNames: 'drop-popover drop-popover--form', |
||||
position: 'bottom center', |
||||
openOn: null, |
||||
template: '<event-editor panel-ctrl="panelCtrl" event="event" close="dismiss()"></event-editor>', |
||||
onClose: this.editorClosed.bind(this), |
||||
model: { |
||||
event: this.event, |
||||
panelCtrl: this.panelCtrl, |
||||
}, |
||||
}); |
||||
|
||||
this.panelCtrl.render(); |
||||
} |
||||
|
||||
addPlotEvents(annotations) { |
||||
if (this.event || annotations.length === 0) { |
||||
return; |
||||
} |
||||
|
||||
var types = { |
||||
'$__alerting': { |
||||
color: 'rgba(237, 46, 24, 1)', |
||||
position: 'BOTTOM', |
||||
markerSize: 5, |
||||
}, |
||||
'$__ok': { |
||||
color: 'rgba(11, 237, 50, 1)', |
||||
position: 'BOTTOM', |
||||
markerSize: 5, |
||||
}, |
||||
'$__no_data': { |
||||
color: 'rgba(150, 150, 150, 1)', |
||||
position: 'BOTTOM', |
||||
markerSize: 5, |
||||
}, |
||||
}; |
||||
|
||||
if (this.event) { |
||||
annotations = [ |
||||
{ |
||||
min: this.event.time.valueOf(), |
||||
title: this.event.title, |
||||
text: this.event.text, |
||||
eventType: '$__alerting', |
||||
} |
||||
]; |
||||
} else { |
||||
// annotations from query
|
||||
for (var i = 0; i < annotations.length; i++) { |
||||
var item = annotations[i]; |
||||
if (item.newState) { |
||||
item.eventType = '$__' + item.newState; |
||||
continue; |
||||
} |
||||
|
||||
if (!types[item.source.name]) { |
||||
types[item.source.name] = { |
||||
color: item.source.iconColor, |
||||
position: 'BOTTOM', |
||||
markerSize: 5, |
||||
}; |
||||
} |
||||
} |
||||
} |
||||
|
||||
options.events = { |
||||
levels: _.keys(types).length + 1, |
||||
data: annotations, |
||||
types: types, |
||||
}; |
||||
} |
||||
} |
Loading…
Reference in new issue