選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

159 行
6.9 KiB

  1. import {GridFactory} from '../grid-cellrenderer/grid-factory';
  2. import {IGridCellParams} from '../grid-cellrenderer/grid-cell-params';
  3. import {Const} from '../utils/const';
  4. export class AgGridComponentConst {
  5. // Key for cell type (must be used in data of grid item)
  6. public static CELL_KEY_TYPE = 'cellKeyType';
  7. // Cell renderers
  8. public static CELL_RENDERER_CHECKBOX = 'gridCheckboxRenderer';
  9. public static CELL_RENDERER_TEXT = 'gridTextRenderer';
  10. public static CELL_RENDERER_DATE = 'gridDateRenderer';
  11. public static CELL_RENDERER_INPUT = 'gridInputRenderer';
  12. public static CELL_RENDERER_SELECT = 'gridSelectRenderer';
  13. public static CELL_RENDERER_BLOCKED = 'gridBlockedRenderer';
  14. public static CELL_RENDERER_DEFAULT = '';
  15. // Cell editors
  16. public static CELL_EDITOR_CHECKBOX = 'gridCheckboxEditor';
  17. public static CELL_EDITOR_TEXT = 'gridTextEditor';
  18. public static CELL_EDITOR_DATE = 'gridDateEditor';
  19. public static CELL_EDITOR_INPUT = 'gridInputEditor';
  20. public static CELL_EDITOR_SELECT = 'gridSelectEditor';
  21. public static CELL_EDITOR_BLOCKED = 'gridBlockedEditor';
  22. public static CELL_EDITOR_DEFAULT = '';
  23. // Cell types
  24. public static CELL_TYPE_DEFAULT = 'default';
  25. public static CELL_TYPE_CHECKBOX = 'checkbox';
  26. public static CELL_TYPE_TEXT = 'text';
  27. public static CELL_TYPE_DATE = 'date';
  28. public static CELL_TYPE_INPUT = 'input';
  29. public static CELL_TYPE_SELECT = 'select';
  30. public static CELL_TYPE_BLOCKED = 'blocked';
  31. // Cell units
  32. public static CELL_UNIT_PERCENT = '%';
  33. public static CELL_UNIT_EURO = '€';
  34. public static CELL_UNIT_DAYS = ' Tage';
  35. public static CELL_UNIT_SQUARE_METER: string = ' ' + Const.UNIT_SQUARE_METER;
  36. // Cell value types
  37. public static CELL_VALUE_TYPE_BOOL = 'bool';
  38. public static CELL_VALUE_TYPE_INT = 'int';
  39. public static CELL_VALUE_TYPE_FLOAT = 'float';
  40. public static CELL_VALUE_TYPE_STRING = 'string';
  41. public static validCellUnits: string[] = [
  42. AgGridComponentConst.CELL_UNIT_PERCENT,
  43. AgGridComponentConst.CELL_UNIT_EURO,
  44. AgGridComponentConst.CELL_UNIT_DAYS,
  45. AgGridComponentConst.CELL_UNIT_SQUARE_METER,
  46. ];
  47. public static validCellValueTypes: string[] = [
  48. AgGridComponentConst.CELL_VALUE_TYPE_BOOL,
  49. AgGridComponentConst.CELL_VALUE_TYPE_INT,
  50. AgGridComponentConst.CELL_VALUE_TYPE_FLOAT,
  51. AgGridComponentConst.CELL_VALUE_TYPE_STRING,
  52. ];
  53. public static gridInputError: string;
  54. /**
  55. * Sets input error
  56. */
  57. public static setGridInputError(errorMessage: string = null): void {
  58. AgGridComponentConst.gridInputError = errorMessage;
  59. if (null !== errorMessage) {
  60. setTimeout(() => {
  61. AgGridComponentConst.setGridInputError();
  62. }, 10);
  63. }
  64. }
  65. /**
  66. * Returns a cell renderer for given type with given parameters
  67. */
  68. public static cellRendererSelector(params: any, gridCellParams: IGridCellParams = null): {} {
  69. if (null === gridCellParams) {
  70. gridCellParams = GridFactory.getGridCellParams();
  71. }
  72. AgGridComponentConst.checkCellValueType(gridCellParams.type);
  73. AgGridComponentConst.checkCellUnit(gridCellParams.unit);
  74. switch (params.data[AgGridComponentConst.CELL_KEY_TYPE]) {
  75. case AgGridComponentConst.CELL_TYPE_CHECKBOX:
  76. return {component: AgGridComponentConst.CELL_RENDERER_CHECKBOX, params: gridCellParams};
  77. case AgGridComponentConst.CELL_TYPE_TEXT:
  78. return {component: AgGridComponentConst.CELL_RENDERER_TEXT, params: gridCellParams};
  79. case AgGridComponentConst.CELL_TYPE_INPUT:
  80. return {component: AgGridComponentConst.CELL_RENDERER_INPUT, params: gridCellParams};
  81. case AgGridComponentConst.CELL_TYPE_DATE:
  82. return {component: AgGridComponentConst.CELL_RENDERER_DATE, params: gridCellParams};
  83. case AgGridComponentConst.CELL_TYPE_SELECT:
  84. return {component: AgGridComponentConst.CELL_RENDERER_SELECT, params: gridCellParams};
  85. case AgGridComponentConst.CELL_TYPE_BLOCKED:
  86. return {component: AgGridComponentConst.CELL_RENDERER_BLOCKED, params: gridCellParams};
  87. case AgGridComponentConst.CELL_TYPE_DEFAULT:
  88. // Nothing specific, so ag grid will take it's own default cell renderer
  89. return;
  90. default:
  91. throw new Error('Unknown cell type');
  92. }
  93. }
  94. /**
  95. * Returns a cell editor for given type with given parameters
  96. */
  97. public static cellEditorSelector(params: any, gridCellParams: IGridCellParams = null) {
  98. if (null === gridCellParams) {
  99. gridCellParams = GridFactory.getGridCellParams();
  100. }
  101. AgGridComponentConst.checkCellValueType(gridCellParams.type);
  102. AgGridComponentConst.checkCellUnit(gridCellParams.unit);
  103. switch (params.data[AgGridComponentConst.CELL_KEY_TYPE]) {
  104. case AgGridComponentConst.CELL_TYPE_CHECKBOX:
  105. // NOTE: Overwrite any given type for checkbox with boolean, since checkbox can only hold boolean values
  106. gridCellParams.type = AgGridComponentConst.CELL_VALUE_TYPE_BOOL;
  107. return {component: AgGridComponentConst.CELL_EDITOR_CHECKBOX, params: gridCellParams};
  108. case AgGridComponentConst.CELL_TYPE_TEXT:
  109. return {component: AgGridComponentConst.CELL_EDITOR_TEXT, params: gridCellParams};
  110. case AgGridComponentConst.CELL_TYPE_INPUT:
  111. return {component: AgGridComponentConst.CELL_EDITOR_INPUT, params: gridCellParams};
  112. case AgGridComponentConst.CELL_TYPE_DATE:
  113. return {component: AgGridComponentConst.CELL_EDITOR_DATE, params: gridCellParams};
  114. case AgGridComponentConst.CELL_TYPE_SELECT:
  115. return {component: AgGridComponentConst.CELL_EDITOR_SELECT, params: gridCellParams};
  116. case AgGridComponentConst.CELL_TYPE_BLOCKED:
  117. return {component: AgGridComponentConst.CELL_EDITOR_BLOCKED, params: gridCellParams};
  118. case AgGridComponentConst.CELL_TYPE_DEFAULT:
  119. // Nothing specific, so ag grid will take it's own default cell editor
  120. return;
  121. default:
  122. throw new Error('Unknown cell type');
  123. }
  124. }
  125. /**
  126. * Checks if cell value type is valid
  127. * @param {string} type
  128. */
  129. private static checkCellValueType(type: string = null): void {
  130. if (null !== type && AgGridComponentConst.validCellValueTypes.indexOf(type) < 0) {
  131. throw new Error('Unknown cell value type');
  132. }
  133. }
  134. /**
  135. * Checks if cell unit is valid
  136. * @param {string} type
  137. */
  138. private static checkCellUnit(type: string = null): void {
  139. if (null !== type && AgGridComponentConst.validCellUnits.indexOf(type) < 0) {
  140. throw new Error('Unknown cell value type');
  141. }
  142. }
  143. }