column_options.ts 3.0 KB

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