Skip to content

Commit

Permalink
feat(abc:st): add enum type (#884)
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk authored May 6, 2020
1 parent 48702ac commit 41e25d5
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 7 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
"karma-junit-reporter": "^2.0.1",
"karma-spec-reporter": "0.0.32",
"karma-viewport": "^1.0.6",
"puppeteer": "^2.1.1",
"@types/aos": "^3.0.3",
"@schematics/schematics": "^0.901.1",
"@angularclass/hmr": "^2.1.3",
Expand Down
6 changes: 4 additions & 2 deletions packages/abc/st/demo/type.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ title:

## zh-CN

支持十种不同列类型:行号、多选、单选、徽标、标签、图片、数字、货币、日期、布尔徽章。也可以使用自定义列完成更复杂渲染。
支持十种不同列类型:行号、多选、单选、徽标、标签、图片、数字、货币、日期、布尔徽章、枚举。也可以使用自定义列完成更复杂渲染。

## en-US

Support for ten different column types: no, checkbox, radio, badge, tag, image, number, currency, date, boolean badge.
Support for ten different column types: no, checkbox, radio, badge, tag, image, number, currency, date, boolean badge, enum.

```ts
import { Component } from '@angular/core';
Expand Down Expand Up @@ -48,6 +48,7 @@ export class DemoComponent {
{ title: '年龄', index: 'age', type: 'number' },
{ title: 'tag', index: 'tag', type: 'tag', tag: TAG },
{ title: 'badge', index: 'badge', type: 'badge', badge: BADGE },
{ title: 'Enum', index: 'enum', type: 'enum', enum: { 1: '', 2: '', 3: '' } },
{ title: 'yn', index: 'yn', type: 'yn' },
];

Expand All @@ -61,6 +62,7 @@ export class DemoComponent {
age: r(10, 50),
tag: r(1, 5),
badge: r(1, 5),
enum: r(1, 3),
yn: [true, false][r(1, 5) % 2],
};
});
Expand Down
1 change: 1 addition & 0 deletions packages/abc/st/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ class TestComponent {
| `[click]` | Callback of type is link | `(record: STData, instance?: STComponent) => void` | - |
| `[badge]` | Config of type is badge | `STColumnBadge` | - |
| `[tag]` | Config of type is tag | `STColumnTag` | - |
| `[enum]` | Config of type is enum | `{ [key: string]: string; [key: number]: string }` | - |
| `[widget]` | Config of type is widget | `STWidgetColumn` | - |
| `[noIndex]` | Line number index start value | `number,(item: STData, col: STColumn, idx: number) => number` | `1` |
| `[iif]` | Custom conditional expression<br>1. Execute only once when `columns` is assigned<br>2. Call `resetColumns()` to trigger again | `(item: STColumn) => boolean` | - |
Expand Down
1 change: 1 addition & 0 deletions packages/abc/st/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ class TestComponent {
| `[click]` | 链接回调 | `(record: STData, instance?: STComponent) => void` | - |
| `[badge]` | 徽标配置项 | `STColumnBadge` | - |
| `[tag]` | 徽标配置项 | `STColumnTag` | - |
| `[enum]` | 枚举配置项 | `{ [key: string]: string; [key: number]: string }` | - |
| `[widget]` | 小部件配置项 | `STWidgetColumn` | - |
| `[noIndex]` | 行号索引开始值 | `number,(item: STData, col: STColumn, idx: number) => number` | `1` |
| `[iif]` | 条件表达式<br>1、仅赋值 `columns` 时执行一次<br>2、可调用 `resetColumns()` 再一次触发 | `(item: STColumn) => boolean` | - |
Expand Down
3 changes: 2 additions & 1 deletion packages/abc/st/st-column-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ export class STColumnSource {
if (
(item.type === 'link' && typeof item.click !== 'function') ||
(item.type === 'badge' && item.badge == null) ||
(item.type === 'tag' && item.tag == null)
(item.type === 'tag' && item.tag == null) ||
(item.type === 'enum' && item.enum == null)
) {
(item as any).type = '';
}
Expand Down
3 changes: 3 additions & 0 deletions packages/abc/st/st-data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ export class STDataSource {
case 'yn':
text = this.ynPipe.transform(value === col.yn!.truth, col.yn!.yes!, col.yn!.no!, col.yn!.mode!, false);
break;
case 'enum':
text = col.enum![value];
break;
case 'tag':
case 'badge':
const data = col.type === 'tag' ? col.tag : col.badge;
Expand Down
5 changes: 4 additions & 1 deletion packages/abc/st/st.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,15 @@ export interface STColumn {
* - `link` 链接,务必指定 `click`
* - `badge` [徽标](https://ng.ant.design/components/badge/zh),务必指定 `badge` 参数配置徽标对应值
* - `tag` [标签](https://ng.ant.design/components/tag/zh),务必指定 `tag` 参数配置标签对应值
* - `enum` 枚举转换,务必指定 `enum` 参数配置标签对应值
* - `img` 图片且居中(若 `className` 存在则优先)
* - `number` 数字且居右(若 `className` 存在则优先)
* - `currency` 货币且居右(若 `className` 存在则优先)
* - `date` 日期格式且居中(若 `className` 存在则优先),使用 `dateFormat` 自定义格式
* - `yn` 将`boolean`类型徽章化 [document](https://ng-alain.com/docs/data-render#yn)
* - `widget` 使用自定义小部件动态创建
*/
type?: 'checkbox' | 'link' | 'badge' | 'tag' | 'radio' | 'img' | 'currency' | 'number' | 'date' | 'yn' | 'no' | 'widget';
type?: 'checkbox' | 'link' | 'badge' | 'tag' | 'enum' | 'radio' | 'img' | 'currency' | 'number' | 'date' | 'yn' | 'no' | 'widget';
/**
* 链接回调,若返回一个字符串表示导航URL会自动触发 `router.navigateByUrl`
*/
Expand Down Expand Up @@ -333,6 +334,8 @@ export interface STColumn {

widget?: STWidgetColumn;

enum?: { [key: string]: string; [key: number]: string };

/**
* 分组表头
*/
Expand Down
11 changes: 11 additions & 0 deletions packages/abc/st/test/st-data-source.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,17 @@ describe('abc: table: data-souce', () => {
done();
});
});
it('via enum', done => {
options.columns[0].type = 'enum';
options.columns[0].enum = {
1: '一',
};
srv.process(options).subscribe(res => {
expect(res.list[0]._values[0].text).toBe('一');
expect(res.list[1]._values[0].text).toBe('');
done();
});
});
});
it('#rowClassName', done => {
options.rowClassName = () => `aaa`;
Expand Down
2 changes: 0 additions & 2 deletions packages/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/0.13/config/configuration-file.html
const tags = process.env && process.env['NG_TEST_TAGS'];
const processENV = require('process');
processENV.env.CHROME_BIN = require('puppeteer').executablePath();

module.exports = function (config) {
const configuration = {
Expand Down

0 comments on commit 41e25d5

Please sign in to comment.