2021-04-21 08:38:00 +01:00
|
|
|
import { cloneDeep, isNumber } from 'lodash';
|
2017-12-20 12:33:33 +01:00
|
|
|
import { coreModule } from 'app/core/core';
|
2021-02-11 13:45:25 +01:00
|
|
|
import { AnnotationEvent, dateTime } from '@grafana/data';
|
2021-04-06 14:51:35 +02:00
|
|
|
import { MetricsPanelCtrl } from '../panel/metrics_panel_ctrl';
|
2021-04-26 06:13:03 +02:00
|
|
|
import { deleteAnnotation, saveAnnotation, updateAnnotation } from './api';
|
2017-04-14 10:18:49 +02:00
|
|
|
|
|
|
|
|
export class EventEditorCtrl {
|
2021-04-15 14:21:06 +02:00
|
|
|
// @ts-ignore initialized through Angular not constructor
|
2017-04-14 10:18:49 +02:00
|
|
|
panelCtrl: MetricsPanelCtrl;
|
2021-04-15 14:21:06 +02:00
|
|
|
// @ts-ignore initialized through Angular not constructor
|
2017-04-14 14:43:06 +02:00
|
|
|
event: AnnotationEvent;
|
2021-04-15 14:21:06 +02:00
|
|
|
timeRange?: { from: number; to: number };
|
2017-04-14 10:18:49 +02:00
|
|
|
form: any;
|
2017-04-14 12:23:32 +02:00
|
|
|
close: any;
|
2021-04-15 14:21:06 +02:00
|
|
|
timeFormated?: string;
|
2017-04-14 10:18:49 +02:00
|
|
|
|
2018-08-31 16:40:43 +02:00
|
|
|
/** @ngInject */
|
2021-04-26 06:13:03 +02:00
|
|
|
constructor() {}
|
2020-11-11 12:18:45 +01:00
|
|
|
|
|
|
|
|
$onInit() {
|
2017-04-14 14:43:06 +02:00
|
|
|
this.event.panelId = this.panelCtrl.panel.id;
|
|
|
|
|
this.event.dashboardId = this.panelCtrl.dashboard.id;
|
2017-10-07 10:31:39 +02:00
|
|
|
|
|
|
|
|
// Annotations query returns time as Unix timestamp in milliseconds
|
|
|
|
|
this.event.time = tryEpochToMoment(this.event.time);
|
|
|
|
|
if (this.event.isRegion) {
|
|
|
|
|
this.event.timeEnd = tryEpochToMoment(this.event.timeEnd);
|
|
|
|
|
}
|
|
|
|
|
|
Chore: Fix all Typescript strict null errors (#26204)
* Chore: Fix typescript strict null errors
* Added new limit
* Fixed ts issue
* fixed tests
* trying to fix type inference
* Fixing more ts errors
* Revert tsconfig option
* Fix
* Fixed code
* More fixes
* fix tests
* Updated snapshot
* Chore: More ts strict null fixes
* More fixes in some really messed up azure config components
* More fixes, current count: 441
* 419
* More fixes
* Fixed invalid initial state in explore
* Fixing tests
* Fixed tests
* Explore fix
* More fixes
* Progress
* Sub 300
* Now at 218
* Progress
* Update
* Progress
* Updated tests
* at 159
* fixed tests
* Progress
* YAy blow 100! at 94
* 10,9,8,7,6,5,4,3,2,1... lift off
* Fixed tests
* Fixed more type errors
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2020-07-10 12:46:59 +02:00
|
|
|
this.timeFormated = this.panelCtrl.dashboard.formatDate(this.event.time!);
|
2017-04-14 10:18:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
save() {
|
|
|
|
|
if (!this.form.$valid) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-04-14 11:41:02 +02:00
|
|
|
|
2021-04-21 08:38:00 +01:00
|
|
|
const saveModel = cloneDeep(this.event);
|
Chore: Fix all Typescript strict null errors (#26204)
* Chore: Fix typescript strict null errors
* Added new limit
* Fixed ts issue
* fixed tests
* trying to fix type inference
* Fixing more ts errors
* Revert tsconfig option
* Fix
* Fixed code
* More fixes
* fix tests
* Updated snapshot
* Chore: More ts strict null fixes
* More fixes in some really messed up azure config components
* More fixes, current count: 441
* 419
* More fixes
* Fixed invalid initial state in explore
* Fixing tests
* Fixed tests
* Explore fix
* More fixes
* Progress
* Sub 300
* Now at 218
* Progress
* Update
* Progress
* Updated tests
* at 159
* fixed tests
* Progress
* YAy blow 100! at 94
* 10,9,8,7,6,5,4,3,2,1... lift off
* Fixed tests
* Fixed more type errors
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2020-07-10 12:46:59 +02:00
|
|
|
saveModel.time = saveModel.time!.valueOf();
|
2017-04-14 14:43:06 +02:00
|
|
|
saveModel.timeEnd = 0;
|
|
|
|
|
|
2017-04-14 11:41:02 +02:00
|
|
|
if (saveModel.isRegion) {
|
Chore: Fix all Typescript strict null errors (#26204)
* Chore: Fix typescript strict null errors
* Added new limit
* Fixed ts issue
* fixed tests
* trying to fix type inference
* Fixing more ts errors
* Revert tsconfig option
* Fix
* Fixed code
* More fixes
* fix tests
* Updated snapshot
* Chore: More ts strict null fixes
* More fixes in some really messed up azure config components
* More fixes, current count: 441
* 419
* More fixes
* Fixed invalid initial state in explore
* Fixing tests
* Fixed tests
* Explore fix
* More fixes
* Progress
* Sub 300
* Now at 218
* Progress
* Update
* Progress
* Updated tests
* at 159
* fixed tests
* Progress
* YAy blow 100! at 94
* 10,9,8,7,6,5,4,3,2,1... lift off
* Fixed tests
* Fixed more type errors
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2020-07-10 12:46:59 +02:00
|
|
|
saveModel.timeEnd = this.event.timeEnd!.valueOf();
|
2017-04-14 11:41:02 +02:00
|
|
|
|
2017-04-14 14:43:06 +02:00
|
|
|
if (saveModel.timeEnd < saveModel.time) {
|
2017-12-20 12:33:33 +01:00
|
|
|
console.log('invalid time');
|
2017-04-14 14:43:06 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2017-04-14 11:41:02 +02:00
|
|
|
}
|
|
|
|
|
|
2017-10-07 10:31:39 +02:00
|
|
|
if (saveModel.id) {
|
2021-04-26 06:13:03 +02:00
|
|
|
updateAnnotation(saveModel)
|
2017-12-19 16:06:54 +01:00
|
|
|
.then(() => {
|
|
|
|
|
this.panelCtrl.refresh();
|
|
|
|
|
this.close();
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
this.panelCtrl.refresh();
|
|
|
|
|
this.close();
|
|
|
|
|
});
|
2017-10-07 10:31:39 +02:00
|
|
|
} else {
|
2021-04-26 06:13:03 +02:00
|
|
|
saveAnnotation(saveModel)
|
2017-12-19 16:06:54 +01:00
|
|
|
.then(() => {
|
|
|
|
|
this.panelCtrl.refresh();
|
|
|
|
|
this.close();
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
this.panelCtrl.refresh();
|
|
|
|
|
this.close();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete() {
|
2021-04-26 06:13:03 +02:00
|
|
|
return deleteAnnotation(this.event)
|
2017-10-07 10:31:39 +02:00
|
|
|
.then(() => {
|
|
|
|
|
this.panelCtrl.refresh();
|
|
|
|
|
this.close();
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
this.panelCtrl.refresh();
|
|
|
|
|
this.close();
|
|
|
|
|
});
|
2017-04-14 10:18:49 +02:00
|
|
|
}
|
2017-10-07 10:31:39 +02:00
|
|
|
}
|
2017-04-14 14:43:06 +02:00
|
|
|
|
2019-08-01 14:38:34 +02:00
|
|
|
function tryEpochToMoment(timestamp: any) {
|
2021-04-21 08:38:00 +01:00
|
|
|
if (timestamp && isNumber(timestamp)) {
|
2018-08-26 17:14:40 +02:00
|
|
|
const epoch = Number(timestamp);
|
2019-05-08 13:51:44 +02:00
|
|
|
return dateTime(epoch);
|
2017-10-07 10:31:39 +02:00
|
|
|
} else {
|
|
|
|
|
return timestamp;
|
2017-04-14 14:43:06 +02:00
|
|
|
}
|
2017-04-14 10:18:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function eventEditor() {
|
|
|
|
|
return {
|
2017-12-20 12:33:33 +01:00
|
|
|
restrict: 'E',
|
2017-04-14 10:18:49 +02:00
|
|
|
controller: EventEditorCtrl,
|
|
|
|
|
bindToController: true,
|
2017-12-20 12:33:33 +01:00
|
|
|
controllerAs: 'ctrl',
|
|
|
|
|
templateUrl: 'public/app/features/annotations/partials/event_editor.html',
|
2017-04-14 10:18:49 +02:00
|
|
|
scope: {
|
2017-12-20 12:33:33 +01:00
|
|
|
panelCtrl: '=',
|
|
|
|
|
event: '=',
|
|
|
|
|
close: '&',
|
|
|
|
|
},
|
2017-04-14 10:18:49 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
coreModule.directive('eventEditor', eventEditor);
|