queryDef.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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: "Standard Deviations", value: 'std_dev' },
  14. ],
  15. bucketAggTypes: [
  16. {text: "Terms", value: 'terms' },
  17. {text: "Date Histogram", value: 'date_histogram' },
  18. ],
  19. orderByOptions: [
  20. {text: "Doc Count", value: '_count' },
  21. {text: "Term value", value: '_term' },
  22. ],
  23. orderOptions: [
  24. {text: "Top", value: 'desc' },
  25. {text: "Bottom", value: 'asc' },
  26. ],
  27. sizeOptions: [
  28. {text: "No limit", value: '0' },
  29. {text: "1", value: '1' },
  30. {text: "2", value: '2' },
  31. {text: "3", value: '4' },
  32. {text: "5", value: '5' },
  33. {text: "10", value: '10' },
  34. {text: "15", value: '15' },
  35. {text: "20", value: '20' },
  36. ],
  37. getOrderByOptions: function(target) {
  38. var self = this;
  39. var metricRefs = [];
  40. _.each(target.metrics, function(metric) {
  41. if (metric.type !== 'count') {
  42. metricRefs.push({text: self.describeMetric(metric), value: metric.id});
  43. }
  44. });
  45. return this.orderByOptions.concat(metricRefs);
  46. },
  47. describeOrder: function(order) {
  48. var def = _.findWhere(this.orderOptions, {value: order});
  49. return def.text;
  50. },
  51. describeMetric: function(metric) {
  52. var def = _.findWhere(this.metricAggTypes, {value: metric.type});
  53. return def.text + ' ' + metric.field;
  54. },
  55. describeOrderBy: function(orderBy, target) {
  56. var def = _.findWhere(this.orderByOptions, {value: orderBy});
  57. if (def) {
  58. return def.text;
  59. }
  60. var metric = _.findWhere(target.metrics, {id: orderBy});
  61. if (metric) {
  62. return this.describeMetric(metric);
  63. } else {
  64. return "metric not found";
  65. }
  66. },
  67. };
  68. });