column_options.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. ///<reference path="../../../headers/common.d.ts" />
  2. import _ from 'lodash';
  3. import kbn from 'app/core/utils/kbn';
  4. export class ColumnOptionsCtrl {
  5. panel: any;
  6. panelCtrl: any;
  7. colorModes: any;
  8. columnStyles: any;
  9. columnTypes: any;
  10. fontSizes: any;
  11. dateFormats: any;
  12. addColumnSegment: any;
  13. unitFormats: any;
  14. getColumnNames: any;
  15. activeStyleIndex: number;
  16. /** @ngInject */
  17. constructor($scope) {
  18. $scope.editor = this;
  19. this.activeStyleIndex = 0;
  20. this.panelCtrl = $scope.ctrl;
  21. this.panel = this.panelCtrl.panel;
  22. this.unitFormats = kbn.getUnitFormats();
  23. this.colorModes = [
  24. {text: 'Disabled', value: null},
  25. {text: 'Cell', value: 'cell'},
  26. {text: 'Value', value: 'value'},
  27. {text: 'Row', value: 'row'},
  28. ];
  29. this.columnTypes = [
  30. {text: 'Number', value: 'number'},
  31. {text: 'String', value: 'string'},
  32. {text: 'Date', value: 'date'},
  33. {text: 'Hidden', value: 'hidden'}
  34. ];
  35. this.fontSizes = ['80%', '90%', '100%', '110%', '120%', '130%', '150%', '160%', '180%', '200%', '220%', '250%'];
  36. this.dateFormats = [
  37. {text: 'YYYY-MM-DD HH:mm:ss', value: 'YYYY-MM-DD HH:mm:ss'},
  38. {text: 'YYYY-MM-DD HH:mm:ss.SSS', value: 'YYYY-MM-DD HH:mm:ss.SSS'},
  39. {text: 'MM/DD/YY h:mm:ss a', value: 'MM/DD/YY h:mm:ss a'},
  40. {text: 'MMMM D, YYYY LT', value: 'MMMM D, YYYY LT'},
  41. ];
  42. this.getColumnNames = () => {
  43. if (!this.panelCtrl.table) {
  44. return [];
  45. }
  46. return _.map(this.panelCtrl.table.columns, function(col: any) {
  47. return col.text;
  48. });
  49. };
  50. this.onColorChange = this.onColorChange.bind(this);
  51. }
  52. render() {
  53. this.panelCtrl.render();
  54. }
  55. setUnitFormat(column, subItem) {
  56. column.unit = subItem.value;
  57. this.panelCtrl.render();
  58. }
  59. addColumnStyle() {
  60. var newStyleRule = {
  61. unit: 'short',
  62. type: 'number',
  63. alias: '',
  64. decimals: 2,
  65. colors: ["rgba(245, 54, 54, 0.9)", "rgba(237, 129, 40, 0.89)", "rgba(50, 172, 45, 0.97)"],
  66. colorMode: null,
  67. pattern: '',
  68. dateFormat: 'YYYY-MM-DD HH:mm:ss',
  69. thresholds: [],
  70. };
  71. var styles = this.panel.styles;
  72. var stylesCount = styles.length;
  73. var indexToInsert = stylesCount;
  74. // check if last is a catch all rule, then add it before that one
  75. if (stylesCount > 0) {
  76. var last = styles[stylesCount-1];
  77. if (last.pattern === '/.*/') {
  78. indexToInsert = stylesCount-1;
  79. }
  80. }
  81. styles.splice(indexToInsert, 0, newStyleRule);
  82. this.activeStyleIndex = indexToInsert;
  83. }
  84. removeColumnStyle(style) {
  85. this.panel.styles = _.without(this.panel.styles, style);
  86. }
  87. invertColorOrder(index) {
  88. var ref = this.panel.styles[index].colors;
  89. var copy = ref[0];
  90. ref[0] = ref[2];
  91. ref[2] = copy;
  92. this.panelCtrl.render();
  93. }
  94. onColorChange(styleIndex, colorIndex) {
  95. return (newColor) => {
  96. this.panel.styles[styleIndex].colors[colorIndex] = newColor;
  97. this.render();
  98. };
  99. }
  100. }
  101. /** @ngInject */
  102. export function columnOptionsTab($q, uiSegmentSrv) {
  103. 'use strict';
  104. return {
  105. restrict: 'E',
  106. scope: true,
  107. templateUrl: 'public/app/plugins/panel/table/column_options.html',
  108. controller: ColumnOptionsCtrl,
  109. };
  110. }