column_options.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. }
  51. render() {
  52. this.panelCtrl.render();
  53. }
  54. setUnitFormat(column, subItem) {
  55. column.unit = subItem.value;
  56. this.panelCtrl.render();
  57. }
  58. addColumnStyle() {
  59. var newStyleRule = {
  60. unit: 'short',
  61. type: 'number',
  62. alias: '',
  63. decimals: 2,
  64. colors: ["rgba(245, 54, 54, 0.9)", "rgba(237, 129, 40, 0.89)", "rgba(50, 172, 45, 0.97)"],
  65. colorMode: null,
  66. pattern: '',
  67. dateFormat: 'YYYY-MM-DD HH:mm:ss',
  68. thresholds: [],
  69. };
  70. var styles = this.panel.styles;
  71. var stylesCount = styles.length;
  72. var indexToInsert = stylesCount;
  73. // check if last is a catch all rule, then add it before that one
  74. if (stylesCount > 0) {
  75. var last = styles[stylesCount-1];
  76. if (last.pattern === '/.*/') {
  77. indexToInsert = stylesCount-1;
  78. }
  79. }
  80. styles.splice(indexToInsert, 0, newStyleRule);
  81. this.activeStyleIndex = indexToInsert;
  82. }
  83. removeColumnStyle(style) {
  84. this.panel.styles = _.without(this.panel.styles, style);
  85. }
  86. invertColorOrder(index) {
  87. var ref = this.panel.styles[index].colors;
  88. var copy = ref[0];
  89. ref[0] = ref[2];
  90. ref[2] = copy;
  91. this.panelCtrl.render();
  92. }
  93. }
  94. /** @ngInject */
  95. export function columnOptionsTab($q, uiSegmentSrv) {
  96. 'use strict';
  97. return {
  98. restrict: 'E',
  99. scope: true,
  100. templateUrl: 'public/app/plugins/panel/table/column_options.html',
  101. controller: ColumnOptionsCtrl,
  102. };
  103. }