queryDef.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. define([
  2. 'lodash'
  3. ],
  4. function (_) {
  5. 'use strict';
  6. return {
  7. metricAggTypes: [
  8. {text: "Count", value: 'count' },
  9. {text: "Average of", value: 'avg' },
  10. {text: "Sum of", value: 'sum' },
  11. {text: "Max of", value: 'max' },
  12. {text: "Min of", value: 'min' },
  13. {text: "Extended Stats", value: 'extended_stats' },
  14. {text: "Percentiles", value: 'percentiles' },
  15. ],
  16. bucketAggTypes: [
  17. {text: "Terms", value: 'terms' },
  18. {text: "Date Histogram", value: 'date_histogram' },
  19. ],
  20. orderByOptions: [
  21. {text: "Doc Count", value: '_count' },
  22. {text: "Term value", value: '_term' },
  23. ],
  24. orderOptions: [
  25. {text: "Top", value: 'desc' },
  26. {text: "Bottom", value: 'asc' },
  27. ],
  28. sizeOptions: [
  29. {text: "No limit", value: '0' },
  30. {text: "1", value: '1' },
  31. {text: "2", value: '2' },
  32. {text: "3", value: '4' },
  33. {text: "5", value: '5' },
  34. {text: "10", value: '10' },
  35. {text: "15", value: '15' },
  36. {text: "20", value: '20' },
  37. ],
  38. getOrderByOptions: function(target) {
  39. var self = this;
  40. var metricRefs = [];
  41. _.each(target.metrics, function(metric) {
  42. if (metric.type !== 'count') {
  43. metricRefs.push({text: self.describeMetric(metric), value: metric.id});
  44. }
  45. });
  46. return this.orderByOptions.concat(metricRefs);
  47. },
  48. describeOrder: function(order) {
  49. var def = _.findWhere(this.orderOptions, {value: order});
  50. return def.text;
  51. },
  52. describeMetric: function(metric) {
  53. var def = _.findWhere(this.metricAggTypes, {value: metric.type});
  54. return def.text + ' ' + metric.field;
  55. },
  56. describeOrderBy: function(orderBy, target) {
  57. var def = _.findWhere(this.orderByOptions, {value: orderBy});
  58. if (def) {
  59. return def.text;
  60. }
  61. var metric = _.findWhere(target.metrics, {id: orderBy});
  62. if (metric) {
  63. return this.describeMetric(metric);
  64. } else {
  65. return "metric not found";
  66. }
  67. },
  68. };
  69. });