segment_srv.js 2.6 KB

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