column_options.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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: 'MM/DD/YY h:mm:ss a', value: 'MM/DD/YY h:mm:ss a'},
  39. {text: 'MMMM D, YYYY LT', value: 'MMMM D, YYYY LT'},
  40. ];
  41. this.getColumnNames = () => {
  42. if (!this.panelCtrl.table) {
  43. return [];
  44. }
  45. return _.map(this.panelCtrl.table.columns, function(col: any) {
  46. return col.text;
  47. });
  48. };
  49. }
  50. render() {
  51. this.panelCtrl.render();
  52. }
  53. setUnitFormat(column, subItem) {
  54. column.unit = subItem.value;
  55. this.panelCtrl.render();
  56. }
  57. addColumnStyle() {
  58. var newStyleRule = {
  59. unit: 'short',
  60. type: 'number',
  61. alias: '',
  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. var styles = this.panel.styles;
  70. var stylesCount = styles.length;
  71. var indexToInsert = stylesCount;
  72. // check if last is a catch all rule, then add it before that one
  73. if (stylesCount > 0) {
  74. var last = styles[stylesCount-1];
  75. if (last.pattern === '/.*/') {
  76. indexToInsert = stylesCount-1;
  77. }
  78. }
  79. styles.splice(indexToInsert, 0, newStyleRule);
  80. this.activeStyleIndex = indexToInsert;
  81. }
  82. removeColumnStyle(style) {
  83. this.panel.styles = _.without(this.panel.styles, style);
  84. }
  85. invertColorOrder(index) {
  86. var ref = this.panel.styles[index].colors;
  87. var copy = ref[0];
  88. ref[0] = ref[2];
  89. ref[2] = copy;
  90. this.panelCtrl.render();
  91. }
  92. }
  93. /** @ngInject */
  94. export function columnOptionsTab($q, uiSegmentSrv) {
  95. 'use strict';
  96. return {
  97. restrict: 'E',
  98. scope: true,
  99. templateUrl: 'public/app/plugins/panel/table/column_options.html',
  100. controller: ColumnOptionsCtrl,
  101. };
  102. }