editor.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. ///<reference path="../../headers/common.d.ts" />
  2. import angular = require('angular');
  3. import $ = require('jquery');
  4. import _ = require('lodash');
  5. import kbn = require('app/core/utils/kbn');
  6. import moment = require('moment');
  7. import {transformers} from './transformers';
  8. export class TablePanelEditorCtrl {
  9. /** @ngInject */
  10. constructor($scope, $q, uiSegmentSrv) {
  11. $scope.transformers = transformers;
  12. $scope.unitFormats = kbn.getUnitFormats();
  13. $scope.colorModes = [
  14. {text: 'Disabled', value: null},
  15. {text: 'Cell', value: 'cell'},
  16. {text: 'Value', value: 'value'},
  17. {text: 'Row', value: 'row'},
  18. ];
  19. $scope.columnTypes = [
  20. {text: 'Number', value: 'number'},
  21. {text: 'String', value: 'string'},
  22. {text: 'Date', value: 'date'},
  23. ];
  24. $scope.fontSizes = ['80%', '90%', '100%', '110%', '120%', '130%', '150%', '160%', '180%', '200%', '220%', '250%'];
  25. $scope.dateFormats = [
  26. {text: 'YYYY-MM-DD HH:mm:ss', value: 'YYYY-MM-DD HH:mm:ss'},
  27. {text: 'MM/DD/YY h:mm:ss a', value: 'MM/DD/YY h:mm:ss a'},
  28. {text: 'MMMM D, YYYY LT', value: 'MMMM D, YYYY LT'},
  29. ];
  30. $scope.addColumnSegment = uiSegmentSrv.newPlusButton();
  31. $scope.getColumnOptions = function() {
  32. if (!$scope.dataRaw) {
  33. return $q.when([]);
  34. }
  35. var columns = transformers[$scope.panel.transform].getColumns($scope.dataRaw);
  36. var segments = _.map(columns, (c: any) => uiSegmentSrv.newSegment({value: c.text}));
  37. return $q.when(segments);
  38. };
  39. $scope.addColumn = function() {
  40. var columns = transformers[$scope.panel.transform].getColumns($scope.dataRaw);
  41. var column = _.findWhere(columns, {text: $scope.addColumnSegment.value});
  42. if (column) {
  43. $scope.panel.columns.push(column);
  44. $scope.render();
  45. }
  46. var plusButton = uiSegmentSrv.newPlusButton();
  47. $scope.addColumnSegment.html = plusButton.html;
  48. $scope.addColumnSegment.value = plusButton.value;
  49. };
  50. $scope.transformChanged = function() {
  51. $scope.panel.columns = [];
  52. $scope.render();
  53. };
  54. $scope.removeColumn = function(column) {
  55. $scope.panel.columns = _.without($scope.panel.columns, column);
  56. $scope.render();
  57. };
  58. $scope.setUnitFormat = function(column, subItem) {
  59. column.unit = subItem.value;
  60. $scope.render();
  61. };
  62. $scope.addColumnStyle = function() {
  63. var columnStyleDefaults = {
  64. unit: 'short',
  65. type: 'number',
  66. decimals: 2,
  67. colors: ["rgba(245, 54, 54, 0.9)", "rgba(237, 129, 40, 0.89)", "rgba(50, 172, 45, 0.97)"],
  68. colorMode: null,
  69. pattern: '/.*/',
  70. dateFormat: 'YYYY-MM-DD HH:mm:ss',
  71. thresholds: [],
  72. };
  73. $scope.panel.styles.push(angular.copy(columnStyleDefaults));
  74. };
  75. $scope.removeColumnStyle = function(style) {
  76. $scope.panel.styles = _.without($scope.panel.styles, style);
  77. };
  78. $scope.getColumnNames = function() {
  79. if (!$scope.table) {
  80. return [];
  81. }
  82. return _.map($scope.table.columns, function(col: any) {
  83. return col.text;
  84. });
  85. };
  86. }
  87. }
  88. export function tablePanelEditor($q, uiSegmentSrv) {
  89. 'use strict';
  90. return {
  91. restrict: 'E',
  92. scope: true,
  93. templateUrl: 'app/panels/table/editor.html',
  94. controller: TablePanelEditorCtrl,
  95. };
  96. }