column_options.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 = [
  36. "80%",
  37. "90%",
  38. "100%",
  39. "110%",
  40. "120%",
  41. "130%",
  42. "150%",
  43. "160%",
  44. "180%",
  45. "200%",
  46. "220%",
  47. "250%"
  48. ];
  49. this.dateFormats = [
  50. { text: "YYYY-MM-DD HH:mm:ss", value: "YYYY-MM-DD HH:mm:ss" },
  51. { text: "YYYY-MM-DD HH:mm:ss.SSS", value: "YYYY-MM-DD HH:mm:ss.SSS" },
  52. { text: "MM/DD/YY h:mm:ss a", value: "MM/DD/YY h:mm:ss a" },
  53. { text: "MMMM D, YYYY LT", value: "MMMM D, YYYY LT" }
  54. ];
  55. this.getColumnNames = () => {
  56. if (!this.panelCtrl.table) {
  57. return [];
  58. }
  59. return _.map(this.panelCtrl.table.columns, function(col: any) {
  60. return col.text;
  61. });
  62. };
  63. this.onColorChange = this.onColorChange.bind(this);
  64. }
  65. render() {
  66. this.panelCtrl.render();
  67. }
  68. setUnitFormat(column, subItem) {
  69. column.unit = subItem.value;
  70. this.panelCtrl.render();
  71. }
  72. addColumnStyle() {
  73. var newStyleRule = {
  74. unit: "short",
  75. type: "number",
  76. alias: "",
  77. decimals: 2,
  78. colors: [
  79. "rgba(245, 54, 54, 0.9)",
  80. "rgba(237, 129, 40, 0.89)",
  81. "rgba(50, 172, 45, 0.97)"
  82. ],
  83. colorMode: null,
  84. pattern: "",
  85. dateFormat: "YYYY-MM-DD HH:mm:ss",
  86. thresholds: []
  87. };
  88. var styles = this.panel.styles;
  89. var stylesCount = styles.length;
  90. var indexToInsert = stylesCount;
  91. // check if last is a catch all rule, then add it before that one
  92. if (stylesCount > 0) {
  93. var last = styles[stylesCount - 1];
  94. if (last.pattern === "/.*/") {
  95. indexToInsert = stylesCount - 1;
  96. }
  97. }
  98. styles.splice(indexToInsert, 0, newStyleRule);
  99. this.activeStyleIndex = indexToInsert;
  100. }
  101. removeColumnStyle(style) {
  102. this.panel.styles = _.without(this.panel.styles, style);
  103. }
  104. invertColorOrder(index) {
  105. var ref = this.panel.styles[index].colors;
  106. var copy = ref[0];
  107. ref[0] = ref[2];
  108. ref[2] = copy;
  109. this.panelCtrl.render();
  110. }
  111. onColorChange(styleIndex, colorIndex) {
  112. return newColor => {
  113. this.panel.styles[styleIndex].colors[colorIndex] = newColor;
  114. this.render();
  115. };
  116. }
  117. }
  118. /** @ngInject */
  119. export function columnOptionsTab($q, uiSegmentSrv) {
  120. "use strict";
  121. return {
  122. restrict: "E",
  123. scope: true,
  124. templateUrl: "public/app/plugins/panel/table/column_options.html",
  125. controller: ColumnOptionsCtrl
  126. };
  127. }