uiSegmentSrv.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. define([
  2. 'angular',
  3. 'lodash',
  4. ],
  5. function (angular, _) {
  6. 'use strict';
  7. var module = angular.module('grafana.services');
  8. module.service('uiSegmentSrv', function($sce, templateSrv) {
  9. function MetricSegment(options) {
  10. if (options === '*' || options.value === '*') {
  11. this.value = '*';
  12. this.html = $sce.trustAsHtml('<i class="fa fa-asterisk"><i>');
  13. this.expandable = true;
  14. return;
  15. }
  16. if (_.isString(options)) {
  17. this.value = options;
  18. this.html = $sce.trustAsHtml(this.value);
  19. return;
  20. }
  21. this.cssClass = options.cssClass;
  22. this.type = options.type;
  23. this.fake = options.fake;
  24. this.value = options.value;
  25. this.type = options.type;
  26. this.expandable = options.expandable;
  27. this.html = options.html || $sce.trustAsHtml(templateSrv.highlightVariablesAsHtml(this.value));
  28. }
  29. this.getSegmentForValue = function(value, fallbackText) {
  30. if (value) {
  31. return this.newSegment(value);
  32. } else {
  33. return this.newSegment({value: fallbackText, fake: true});
  34. }
  35. };
  36. this.newSelectMeasurement = function() {
  37. return new MetricSegment({value: 'select measurement', fake: true});
  38. };
  39. this.newFake = function(text, type, cssClass) {
  40. return new MetricSegment({value: text, fake: true, type: type, cssClass: cssClass});
  41. };
  42. this.newSegment = function(options) {
  43. return new MetricSegment(options);
  44. };
  45. this.newKey = function(key) {
  46. return new MetricSegment({value: key, type: 'key', cssClass: 'query-segment-key' });
  47. };
  48. this.newKeyValue = function(value) {
  49. return new MetricSegment({value: value, type: 'value', cssClass: 'query-segment-value' });
  50. };
  51. this.newCondition = function(condition) {
  52. return new MetricSegment({value: condition, type: 'condition', cssClass: 'query-keyword' });
  53. };
  54. this.newOperator = function(op) {
  55. return new MetricSegment({value: op, type: 'operator', cssClass: 'query-segment-operator' });
  56. };
  57. this.newOperators = function(ops) {
  58. return _.map(ops, function(op) {
  59. return new MetricSegment({value: op, type: 'operator', cssClass: 'query-segment-operator' });
  60. });
  61. };
  62. this.newSelectMetric = function() {
  63. return new MetricSegment({value: 'select metric', fake: true});
  64. };
  65. this.newPlusButton = function() {
  66. return new MetricSegment({fake: true, html: '<i class="fa fa-plus "></i>', type: 'plus-button' });
  67. };
  68. this.newSelectTagValue = function() {
  69. return new MetricSegment({value: 'select tag value', fake: true});
  70. };
  71. });
  72. });