editor.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 {transformers} from './transformers';
  7. import kbn from 'app/core/utils/kbn';
  8. export class TablePanelEditorCtrl {
  9. panel: any;
  10. panelCtrl: any;
  11. transformers: any;
  12. fontSizes: any;
  13. addColumnSegment: any;
  14. getColumnNames: any;
  15. /** @ngInject */
  16. constructor($scope, private $q, private uiSegmentSrv) {
  17. $scope.editor = this;
  18. this.panelCtrl = $scope.ctrl;
  19. this.panel = this.panelCtrl.panel;
  20. this.transformers = transformers;
  21. this.fontSizes = ['80%', '90%', '100%', '110%', '120%', '130%', '150%', '160%', '180%', '200%', '220%', '250%'];
  22. this.addColumnSegment = uiSegmentSrv.newPlusButton();
  23. }
  24. getColumnOptions() {
  25. if (!this.panelCtrl.dataRaw) {
  26. return this.$q.when([]);
  27. }
  28. var columns = this.transformers[this.panel.transform].getColumns(this.panelCtrl.dataRaw);
  29. var segments = _.map(columns, (c: any) => this.uiSegmentSrv.newSegment({value: c.text}));
  30. return this.$q.when(segments);
  31. }
  32. addColumn() {
  33. var columns = transformers[this.panel.transform].getColumns(this.panelCtrl.dataRaw);
  34. var column = _.find(columns, {text: this.addColumnSegment.value});
  35. if (column) {
  36. this.panel.columns.push(column);
  37. this.render();
  38. }
  39. var plusButton = this.uiSegmentSrv.newPlusButton();
  40. this.addColumnSegment.html = plusButton.html;
  41. this.addColumnSegment.value = plusButton.value;
  42. }
  43. transformChanged() {
  44. this.panel.columns = [];
  45. if (this.panel.transform === 'timeseries_aggregations') {
  46. this.panel.columns.push({text: 'Avg', value: 'avg'});
  47. }
  48. this.render();
  49. }
  50. render() {
  51. this.panelCtrl.render();
  52. }
  53. removeColumn(column) {
  54. this.panel.columns = _.without(this.panel.columns, column);
  55. this.panelCtrl.render();
  56. }
  57. }
  58. /** @ngInject */
  59. export function tablePanelEditor($q, uiSegmentSrv) {
  60. 'use strict';
  61. return {
  62. restrict: 'E',
  63. scope: true,
  64. templateUrl: 'public/app/plugins/panel/table/editor.html',
  65. controller: TablePanelEditorCtrl,
  66. };
  67. }