editor.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. ///<reference path="../../headers/common.d.ts" />
  2. import angular = require('angular');
  3. import $ = require('jquery');
  4. import _ = require('lodash');
  5. import kbn = require('app/core/utils/kbn');
  6. import moment = require('moment');
  7. import {transformers} from './transformers';
  8. export function tablePanelEditor() {
  9. 'use strict';
  10. return {
  11. restrict: 'E',
  12. scope: true,
  13. templateUrl: 'app/panels/table/editor.html',
  14. link: function(scope, elem) {
  15. scope.transformers = transformers;
  16. scope.unitFormats = kbn.getUnitFormats();
  17. scope.colorModes = [
  18. {text: 'Disabled', value: null},
  19. {text: 'Cell', value: 'cell'},
  20. {text: 'Value', value: 'value'},
  21. {text: 'Row', value: 'row'},
  22. ];
  23. scope.columnTypes = [
  24. {text: 'Number', value: 'number'},
  25. {text: 'String', value: 'string'},
  26. {text: 'Date', value: 'date'},
  27. ];
  28. scope.fontSizes = ['80%', '90%', '100%', '110%', '120%', '130%', '150%', '160%', '180%', '200%', '220%', '250%'];
  29. scope.dateFormats = [
  30. {text: 'YYYY-MM-DD HH:mm:ss', value: 'YYYY-MM-DD HH:mm:ss'},
  31. {text: 'MM/DD/YY h:mm:ss a', value: 'MM/DD/YY h:mm:ss a'},
  32. {text: 'MMMM D, YYYY LT', value: 'MMMM D, YYYY LT'},
  33. ];
  34. scope.updateColumnsMenu = function(data) {
  35. scope.columnsMenu = [];
  36. if (!data || data.length === 0) {
  37. return;
  38. }
  39. var names = {};
  40. for (var i = 0; i < data.length; i++) {
  41. var series = data[i];
  42. if (series.type !== 'docs') {
  43. continue;
  44. }
  45. for (var y = 0; y < series.datapoints.length; y++) {
  46. var doc = series.datapoints[y];
  47. for (var propName in doc) {
  48. names[propName] = true;
  49. }
  50. }
  51. }
  52. _.each(names, function(value, key) {
  53. scope.columnsMenu.push({text: key});
  54. });
  55. };
  56. scope.updateColumnsMenu(scope.dataRaw);
  57. scope.$on('render', function(event, table, rawData) {
  58. scope.updateColumnsMenu(rawData);
  59. });
  60. scope.addColumn = function(menuItem) {
  61. scope.panel.columns.push({name: menuItem.text});
  62. scope.render();
  63. };
  64. scope.transformChanged = function() {
  65. scope.render();
  66. };
  67. scope.removeColumn = function(column) {
  68. scope.panel.column = _.without(scope.panel.column, column);
  69. scope.render();
  70. };
  71. scope.setUnitFormat = function(column, subItem) {
  72. column.unit = subItem.value;
  73. scope.render();
  74. };
  75. scope.addColumnStyle = function() {
  76. var columnStyleDefaults = {
  77. unit: 'short',
  78. type: 'number',
  79. decimals: 2,
  80. colors: ["rgba(245, 54, 54, 0.9)", "rgba(237, 129, 40, 0.89)", "rgba(50, 172, 45, 0.97)"],
  81. colorMode: null,
  82. pattern: '/.*/',
  83. dateFormat: 'YYYY-MM-DD HH:mm:ss',
  84. thresholds: [],
  85. };
  86. scope.panel.styles.push(angular.copy(columnStyleDefaults));
  87. };
  88. scope.removeColumnStyle = function(style) {
  89. scope.panel.styles = _.without(scope.panel.styles, style);
  90. };
  91. scope.getColumnNames = function() {
  92. if (!scope.table) {
  93. return [];
  94. }
  95. return _.map(scope.table.columns, function(col: any) {
  96. return col.text;
  97. });
  98. };
  99. }
  100. };
  101. }