editor.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. $scope.panel.columns.push({text: $scope.addColumnSegment.value, value: $scope.addColumnSegment.value});
  41. $scope.render();
  42. var plusButton = uiSegmentSrv.newPlusButton();
  43. $scope.addColumnSegment.html = plusButton.html;
  44. };
  45. $scope.transformChanged = function() {
  46. $scope.panel.columns = [];
  47. $scope.render();
  48. };
  49. $scope.removeColumn = function(column) {
  50. $scope.panel.columns = _.without($scope.panel.columns, column);
  51. $scope.render();
  52. };
  53. $scope.setUnitFormat = function(column, subItem) {
  54. column.unit = subItem.value;
  55. $scope.render();
  56. };
  57. $scope.addColumnStyle = function() {
  58. var columnStyleDefaults = {
  59. unit: 'short',
  60. type: 'number',
  61. decimals: 2,
  62. colors: ["rgba(245, 54, 54, 0.9)", "rgba(237, 129, 40, 0.89)", "rgba(50, 172, 45, 0.97)"],
  63. colorMode: null,
  64. pattern: '/.*/',
  65. dateFormat: 'YYYY-MM-DD HH:mm:ss',
  66. thresholds: [],
  67. };
  68. $scope.panel.styles.push(angular.copy(columnStyleDefaults));
  69. };
  70. $scope.removeColumnStyle = function(style) {
  71. $scope.panel.styles = _.without($scope.panel.styles, style);
  72. };
  73. $scope.getColumnNames = function() {
  74. if (!$scope.table) {
  75. return [];
  76. }
  77. return _.map($scope.table.columns, function(col: any) {
  78. return col.text;
  79. });
  80. };
  81. }
  82. }
  83. export function tablePanelEditor($q, uiSegmentSrv) {
  84. 'use strict';
  85. return {
  86. restrict: 'E',
  87. scope: true,
  88. templateUrl: 'app/panels/table/editor.html',
  89. controller: TablePanelEditorCtrl,
  90. };
  91. }