editor.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 = transformers[scope.panel.transform].getColumns(data);
  36. scope.showColumnOptions = true;
  37. };
  38. scope.$on('render', function(event, table, rawData) {
  39. scope.updateColumnsMenu(rawData);
  40. });
  41. scope.addColumn = function(menuItem) {
  42. scope.panel.columns.push({text: menuItem.text, value: menuItem.value});
  43. scope.render();
  44. };
  45. scope.transformChanged = function() {
  46. scope.panel.columns = [];
  47. scope.updateColumnsMenu();
  48. scope.render();
  49. };
  50. scope.removeColumn = function(column) {
  51. scope.panel.columns = _.without(scope.panel.columns, column);
  52. scope.render();
  53. };
  54. scope.setUnitFormat = function(column, subItem) {
  55. column.unit = subItem.value;
  56. scope.render();
  57. };
  58. scope.addColumnStyle = function() {
  59. var columnStyleDefaults = {
  60. unit: 'short',
  61. type: 'number',
  62. decimals: 2,
  63. colors: ["rgba(245, 54, 54, 0.9)", "rgba(237, 129, 40, 0.89)", "rgba(50, 172, 45, 0.97)"],
  64. colorMode: null,
  65. pattern: '/.*/',
  66. dateFormat: 'YYYY-MM-DD HH:mm:ss',
  67. thresholds: [],
  68. };
  69. scope.panel.styles.push(angular.copy(columnStyleDefaults));
  70. };
  71. scope.removeColumnStyle = function(style) {
  72. scope.panel.styles = _.without(scope.panel.styles, style);
  73. };
  74. scope.getColumnNames = function() {
  75. if (!scope.table) {
  76. return [];
  77. }
  78. return _.map(scope.table.columns, function(col: any) {
  79. return col.text;
  80. });
  81. };
  82. scope.updateColumnsMenu(scope.dataRaw);
  83. }
  84. };
  85. }