grafana/public/app/angular/services/annotations_srv.ts

88 lines
2.9 KiB
TypeScript
Raw Normal View History

import { cloneDeep } from 'lodash';
import { AnnotationEvent, deprecationWarning } from '@grafana/data';
import { deleteAnnotation, saveAnnotation, updateAnnotation } from 'app/features/annotations/api';
import { AnnotationQueryOptions } from 'app/features/annotations/types';
/**
* @deprecated AnnotationsSrv is deprecated in favor of DashboardQueryRunner
*/
export class AnnotationsSrv {
/**
* @deprecated clearPromiseCaches is deprecated
*/
clearPromiseCaches() {
deprecationWarning('annotations_srv.ts', 'clearPromiseCaches', 'DashboardQueryRunner');
}
/**
* @deprecated getAnnotations is deprecated in favor of DashboardQueryRunner.getResult
*/
getAnnotations(options: AnnotationQueryOptions) {
deprecationWarning('annotations_srv.ts', 'getAnnotations', 'DashboardQueryRunner.getResult');
return Promise.resolve({ annotations: [], alertState: undefined });
}
/**
* @deprecated getAlertStates is deprecated in favor of DashboardQueryRunner.getResult
*/
getAlertStates(options: any) {
deprecationWarning('annotations_srv.ts', 'getAlertStates', 'DashboardQueryRunner.getResult');
return Promise.resolve(undefined);
}
/**
* @deprecated getGlobalAnnotations is deprecated in favor of DashboardQueryRunner.getResult
*/
getGlobalAnnotations(options: AnnotationQueryOptions) {
deprecationWarning('annotations_srv.ts', 'getGlobalAnnotations', 'DashboardQueryRunner.getResult');
return Promise.resolve([]);
}
/**
* @deprecated saveAnnotationEvent is deprecated
*/
saveAnnotationEvent(annotation: AnnotationEvent) {
deprecationWarning('annotations_srv.ts', 'saveAnnotationEvent', 'api/saveAnnotation');
Annotations: Adds DashboardQueryRunner (#32834) * WIP: initial commit * Fix: Fixed $timeout call when testing snapshots * Chore: reverts changes to metrics_panel_ctrl.ts * Chore: reverts changes to annotations_srv * Refactor: adds DashboardQueryRunner.run to initdashboard * Refactor: adds run to dashboard model start refresh * Refactor: move to own folder and split up into smaller files * Tests: adds tests for LegacyAnnotationQueryRunner * Tests: adds tests for AnnotationsQueryRunner * Tests: adds tests for SnapshotWorker * Refactor: renames from canRun|run to canWork|work * Tests: adds tests for AlertStatesWorker * Tests: adds tests for AnnotationsWorker * Refactor: renames operators * Refactor: renames operators * Tests: adds tests for DashboardQueryRunner * Refactor: adds mergePanelAndDashboardData function * Tests: fixes broken tests * Chore: Fixes errors after merge with master * Chore: Removes usage of AnnotationSrv from event_editor and initDashboard * WIP: getting annotations and alerts working in graph (snapshot not working) * Refactor: fixes snapshot data for React panels * Refactor: Fixes so snapshots work for Graph * Refactor: moves alert types to grafana-data * Refactor: changes to some for readability * Tests: skipping tests for now, needs rewrite * Refactor: refactors out common static functions to utils * Refactor: fixes resolving annotations from dataframes * Refactor: removes getRunners/Workers functions * Docs: fixes docs errors * Docs: trying to fix doc error * Refactor: changes after PR comments * Refactor: hides everything behind a factory instead * Refactor: adds cancellation between runs and explicitly
2021-04-25 23:13:03 -05:00
return saveAnnotation(annotation);
}
/**
* @deprecated updateAnnotationEvent is deprecated
*/
updateAnnotationEvent(annotation: AnnotationEvent) {
deprecationWarning('annotations_srv.ts', 'updateAnnotationEvent', 'api/updateAnnotation');
Annotations: Adds DashboardQueryRunner (#32834) * WIP: initial commit * Fix: Fixed $timeout call when testing snapshots * Chore: reverts changes to metrics_panel_ctrl.ts * Chore: reverts changes to annotations_srv * Refactor: adds DashboardQueryRunner.run to initdashboard * Refactor: adds run to dashboard model start refresh * Refactor: move to own folder and split up into smaller files * Tests: adds tests for LegacyAnnotationQueryRunner * Tests: adds tests for AnnotationsQueryRunner * Tests: adds tests for SnapshotWorker * Refactor: renames from canRun|run to canWork|work * Tests: adds tests for AlertStatesWorker * Tests: adds tests for AnnotationsWorker * Refactor: renames operators * Refactor: renames operators * Tests: adds tests for DashboardQueryRunner * Refactor: adds mergePanelAndDashboardData function * Tests: fixes broken tests * Chore: Fixes errors after merge with master * Chore: Removes usage of AnnotationSrv from event_editor and initDashboard * WIP: getting annotations and alerts working in graph (snapshot not working) * Refactor: fixes snapshot data for React panels * Refactor: Fixes so snapshots work for Graph * Refactor: moves alert types to grafana-data * Refactor: changes to some for readability * Tests: skipping tests for now, needs rewrite * Refactor: refactors out common static functions to utils * Refactor: fixes resolving annotations from dataframes * Refactor: removes getRunners/Workers functions * Docs: fixes docs errors * Docs: trying to fix doc error * Refactor: changes after PR comments * Refactor: hides everything behind a factory instead * Refactor: adds cancellation between runs and explicitly
2021-04-25 23:13:03 -05:00
return updateAnnotation(annotation);
Create annotations (#8197) * annotations: add 25px space for events section * annotations: restored create annotation action * annotations: able to use fa icons as event markers * annotations: initial emoji support from twemoji lib * annotations: adjust fa icon position * annotations: initial emoji picker * annotation: include user info into annotation requests * annotation: add icon info * annotation: display user info in tooltip * annotation: fix region saving * annotation: initial region markers * annotation: fix region clearing (add flot-temp-elem class) * annotation: adjust styles a bit * annotations: minor fixes * annoations: removed userId look in loop, need a sql join or a user cache for this * annotation: fix invisible events * lib: changed twitter emoij lib to be npm dependency * annotation: add icon picker to Add Annotation dialog * annotation: save icon to annotation table * annotation: able to set custom icon for annotation added by user * annotations: fix emoji after library upgrade (switch to 72px) * emoji: temporary remove bad code points * annotations: improve icon picker * annotations: icon show icon picker at the top * annotations: use svg for emoji * annotations: fix region drawing when add annotation editor opened * annotations: use flot lib for drawing region fill * annotations: move regions building into event_manager * annotations: don't draw additional space if no events are got * annotations: deduplicate events * annotations: properly render cut regions * annotations: fix cut region building * annotations: refactor * annotations: adjust event section size * add-annotations: fix undefined default icon * create-annotations: edit event (frontend part) * fixed bug causes error when hover event marker * create-annotations: update event (backend) * ignore grafana-server debug binary in git (created VS Code) * create-annotations: use PUT request for updating annotation. * create-annotations: fixed time format when editing existing event * create-annotations: support for region update * create-annotations: fix bug with limit and event type * create-annotations: delete annotation * create-annotations: show only selected icon in edit mode * create-annotations: show event editor only for users with at least Editor role * create-annotations: handle double-sized emoji codepoints * create-annotations: refactor use CP_SEPARATOR from emojiDef * create-annotations: update emoji list, add categories. * create-annotations: copy SVG emoji into public/vendor/npm and use it as a base path * create-annotations: initial tabs for emoji picker * emoji-picker: adjust styles * emoji-picker: minor refactor * emoji-picker: refactor - rename and move into one directory * emoji-picker: build emoji elements on app load, not on picker open * emoji-picker: fix emoji searching * emoji-picker: refactor * emoji-picker: capitalize category name * emoji-picker: refactor move buildEmojiElem() into emoji_converter.ts for future reuse. * jquery.flot.events: refactor use buildEmojiElem() for making emojis, remove unused code for font awesome based icons. * emoji_converter: handle converting error * tech: updated * merged with master * shore: clean up some stuff * annotation: wip tags * annotation: filtering by tags * tags: parse out spaces etc. from a tags string * annotations: use tagsinput component for tag filtering * annotation: wip work on how we query alert & panel annotations * annotations: support for updating tags in an annotation * linting * annotations: work on unifying how alert history annotations and manual panel annotations are created * tslint: fixes * tags: create tag on blur as well Currently, the tags directive only creates the tag when the user presses enter. This change means the tag is created on blur as well (when the user clicks outside the input field). * annotations: fix update after refactoring * annotations: progress on how alert annotations are fetched * annotations: minor progress * annotations: progress * annotation: minor progress * annotations: move tag parsing from tooltip to ds Instead of parsing a tag string into an array in the annotation_tooltip class, this moves the parsing to the datasources. InfluxDB ds already does that parsing. Graphite now has it. * annotations: more work on querying * annotations: change from tags as string to array when saving in the db and in the api. * annotations: delete tag link if removed on edit * annotation: more work on depricating annotation title * annotations: delete tag links on delete * annotations: fix for find * annotation: added user to annotation tooltip and added alertName to annoation dto * annotations: use id from route instead from cmd for updating * annotations: http api docs * create annotation: last edits * annotations: minor fix for querying annotations before dashboard saved * annotations: fix for popover placement when legend is on the side (and doubel render pass is causing original marker to be removed) * annotations: changing how the built in query gets added * annotation: added time to header in edit mode * tests: fixed jshint built issue
2017-10-07 03:31:39 -05:00
}
/**
* @deprecated deleteAnnotationEvent is deprecated
*/
deleteAnnotationEvent(annotation: AnnotationEvent) {
deprecationWarning('annotations_srv.ts', 'deleteAnnotationEvent', 'api/deleteAnnotation');
Annotations: Adds DashboardQueryRunner (#32834) * WIP: initial commit * Fix: Fixed $timeout call when testing snapshots * Chore: reverts changes to metrics_panel_ctrl.ts * Chore: reverts changes to annotations_srv * Refactor: adds DashboardQueryRunner.run to initdashboard * Refactor: adds run to dashboard model start refresh * Refactor: move to own folder and split up into smaller files * Tests: adds tests for LegacyAnnotationQueryRunner * Tests: adds tests for AnnotationsQueryRunner * Tests: adds tests for SnapshotWorker * Refactor: renames from canRun|run to canWork|work * Tests: adds tests for AlertStatesWorker * Tests: adds tests for AnnotationsWorker * Refactor: renames operators * Refactor: renames operators * Tests: adds tests for DashboardQueryRunner * Refactor: adds mergePanelAndDashboardData function * Tests: fixes broken tests * Chore: Fixes errors after merge with master * Chore: Removes usage of AnnotationSrv from event_editor and initDashboard * WIP: getting annotations and alerts working in graph (snapshot not working) * Refactor: fixes snapshot data for React panels * Refactor: Fixes so snapshots work for Graph * Refactor: moves alert types to grafana-data * Refactor: changes to some for readability * Tests: skipping tests for now, needs rewrite * Refactor: refactors out common static functions to utils * Refactor: fixes resolving annotations from dataframes * Refactor: removes getRunners/Workers functions * Docs: fixes docs errors * Docs: trying to fix doc error * Refactor: changes after PR comments * Refactor: hides everything behind a factory instead * Refactor: adds cancellation between runs and explicitly
2021-04-25 23:13:03 -05:00
return deleteAnnotation(annotation);
Create annotations (#8197) * annotations: add 25px space for events section * annotations: restored create annotation action * annotations: able to use fa icons as event markers * annotations: initial emoji support from twemoji lib * annotations: adjust fa icon position * annotations: initial emoji picker * annotation: include user info into annotation requests * annotation: add icon info * annotation: display user info in tooltip * annotation: fix region saving * annotation: initial region markers * annotation: fix region clearing (add flot-temp-elem class) * annotation: adjust styles a bit * annotations: minor fixes * annoations: removed userId look in loop, need a sql join or a user cache for this * annotation: fix invisible events * lib: changed twitter emoij lib to be npm dependency * annotation: add icon picker to Add Annotation dialog * annotation: save icon to annotation table * annotation: able to set custom icon for annotation added by user * annotations: fix emoji after library upgrade (switch to 72px) * emoji: temporary remove bad code points * annotations: improve icon picker * annotations: icon show icon picker at the top * annotations: use svg for emoji * annotations: fix region drawing when add annotation editor opened * annotations: use flot lib for drawing region fill * annotations: move regions building into event_manager * annotations: don't draw additional space if no events are got * annotations: deduplicate events * annotations: properly render cut regions * annotations: fix cut region building * annotations: refactor * annotations: adjust event section size * add-annotations: fix undefined default icon * create-annotations: edit event (frontend part) * fixed bug causes error when hover event marker * create-annotations: update event (backend) * ignore grafana-server debug binary in git (created VS Code) * create-annotations: use PUT request for updating annotation. * create-annotations: fixed time format when editing existing event * create-annotations: support for region update * create-annotations: fix bug with limit and event type * create-annotations: delete annotation * create-annotations: show only selected icon in edit mode * create-annotations: show event editor only for users with at least Editor role * create-annotations: handle double-sized emoji codepoints * create-annotations: refactor use CP_SEPARATOR from emojiDef * create-annotations: update emoji list, add categories. * create-annotations: copy SVG emoji into public/vendor/npm and use it as a base path * create-annotations: initial tabs for emoji picker * emoji-picker: adjust styles * emoji-picker: minor refactor * emoji-picker: refactor - rename and move into one directory * emoji-picker: build emoji elements on app load, not on picker open * emoji-picker: fix emoji searching * emoji-picker: refactor * emoji-picker: capitalize category name * emoji-picker: refactor move buildEmojiElem() into emoji_converter.ts for future reuse. * jquery.flot.events: refactor use buildEmojiElem() for making emojis, remove unused code for font awesome based icons. * emoji_converter: handle converting error * tech: updated * merged with master * shore: clean up some stuff * annotation: wip tags * annotation: filtering by tags * tags: parse out spaces etc. from a tags string * annotations: use tagsinput component for tag filtering * annotation: wip work on how we query alert & panel annotations * annotations: support for updating tags in an annotation * linting * annotations: work on unifying how alert history annotations and manual panel annotations are created * tslint: fixes * tags: create tag on blur as well Currently, the tags directive only creates the tag when the user presses enter. This change means the tag is created on blur as well (when the user clicks outside the input field). * annotations: fix update after refactoring * annotations: progress on how alert annotations are fetched * annotations: minor progress * annotations: progress * annotation: minor progress * annotations: move tag parsing from tooltip to ds Instead of parsing a tag string into an array in the annotation_tooltip class, this moves the parsing to the datasources. InfluxDB ds already does that parsing. Graphite now has it. * annotations: more work on querying * annotations: change from tags as string to array when saving in the db and in the api. * annotations: delete tag link if removed on edit * annotation: more work on depricating annotation title * annotations: delete tag links on delete * annotations: fix for find * annotation: added user to annotation tooltip and added alertName to annoation dto * annotations: use id from route instead from cmd for updating * annotations: http api docs * create annotation: last edits * annotations: minor fix for querying annotations before dashboard saved * annotations: fix for popover placement when legend is on the side (and doubel render pass is causing original marker to be removed) * annotations: changing how the built in query gets added * annotation: added time to header in edit mode * tests: fixed jshint built issue
2017-10-07 03:31:39 -05:00
}
/**
* @deprecated translateQueryResult is deprecated in favor of DashboardQueryRunner/utils/translateQueryResult
*/
translateQueryResult(annotation: any, results: any) {
deprecationWarning('annotations_srv.ts', 'translateQueryResult', 'DashboardQueryRunner/utils/translateQueryResult');
// if annotation has snapshotData
// make clone and remove it
if (annotation.snapshotData) {
Chore: Remove angular dependency from backendSrv (#20999) * Chore: Remove angular dependency from backendSrv * Refactor: Naive soultion for logging out unauthorized users * Refactor: Restructures to different streams * Refactor: Restructures datasourceRequest * Refactor: Flipped back if statement * Refactor: Extracted getFromFetchStream * Refactor: Extracts toFailureStream operation * Refactor: Fixes issue when options.params contains arrays * Refactor: Fixes broken test (but we need a lot more) * Refactor: Adds explaining comments * Refactor: Adds latest RxJs version so cancellations work * Refactor: Cleans up the takeUntil code * Refactor: Adds tests for request function * Refactor: Separates into smaller functions * Refactor: Adds last error tests * Started to changed so we require getBackendSrv from the @grafana-runtime when applicable. * Using the getBackendSrv from @grafana/runtime. * Changed so we use the getBackendSrv from the @grafana-runtime when possible. * Fixed so Server Admin -> Orgs works again. * Removed unused dependency. * Fixed digest issues on the Server Admin -> Users page. * Fix: Fixes digest problems in Playlists * Fix: Fixes digest issues in VersionHistory * Tests: Fixes broken tests * Fix: Fixes digest issues in Alerting => Notification channels * Fixed digest issues on the Intive page. * Fixed so we run digest after password reset email sent. * Fixed digest issue when trying to sign up account. * Fixed so the Server Admin -> Edit Org works with backendSrv * Fixed so Server Admin -> Users works with backend srv. * Fixed digest issues in Server Admin -> Orgs * Fix: Fixes digest issues in DashList plugin * Fixed digest issues on Server Admin -> users. * Fix: Fixes digest issues with Snapshots * Fixed digest issue when deleting a user. * Fix: Fixes digest issues with dashLink * Chore: Changes RxJs version to 6.5.4 which includes the same cancellation fix * Fix: Fixes digest issue when toggling folder in manage dashboards * Fix: Fixes bug in executeInOrder * Fix: Fixes digest issue with CreateFolderCtrl and FolderDashboardsCtrl * Fix: Fixes tslint error in test * Refactor: Changes default behaviour for emitted messages as before migration * Fix: Fixes various digest issues when saving, starring or deleting dashboards * Fix: Fixes digest issues with FolderPickerCtrl * Fixed digest issue. * Fixed digest issues. * Fixed issues with angular digest. * Removed the this.digest pattern. Co-authored-by: Hugo Häggmark <hugo.haggmark@gmail.com> Co-authored-by: Marcus Andersson <systemvetaren@gmail.com>
2020-01-21 03:08:07 -06:00
annotation = cloneDeep(annotation);
delete annotation.snapshotData;
}
for (const item of results) {
item.source = annotation;
item.color = annotation.iconColor;
item.type = annotation.name;
item.isRegion = item.timeEnd && item.time !== item.timeEnd;
}
return results;
}
}