editor.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. this.render();
  46. }
  47. render() {
  48. this.panelCtrl.render();
  49. }
  50. removeColumn(column) {
  51. this.panel.columns = _.without(this.panel.columns, column);
  52. this.panelCtrl.render();
  53. }
  54. }
  55. /** @ngInject */
  56. export function tablePanelEditor($q, uiSegmentSrv) {
  57. 'use strict';
  58. return {
  59. restrict: 'E',
  60. scope: true,
  61. templateUrl: 'public/app/plugins/panel/table/editor.html',
  62. controller: TablePanelEditorCtrl,
  63. };
  64. }