• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

atinc / ngx-tethys / 881c8997-29c3-4d01-9ef1-22092f16cec2

03 Apr 2024 03:31AM UTC coverage: 90.404% (-0.2%) from 90.585%
881c8997-29c3-4d01-9ef1-22092f16cec2

Pull #3062

circleci

minlovehua
refactor(all): use the transform attribute of @input() instead of @InputBoolean() and @InputNumber()
Pull Request #3062: refactor(all): use the transform attribute of @input() instead of @InputBoolean() and @InputNumber()

5411 of 6635 branches covered (81.55%)

Branch coverage included in aggregate %.

217 of 223 new or added lines in 82 files covered. (97.31%)

201 existing lines in 53 files now uncovered.

13176 of 13925 relevant lines covered (94.62%)

980.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.03
/src/table/table-column.component.ts
1
import { _isNumberValue } from '@angular/cdk/coercion';
2
import {
3
    Component,
4
    ContentChild,
5
    ElementRef,
6
    EventEmitter,
7
    Inject,
8
    InjectionToken,
1✔
9
    Input,
10
    OnInit,
11
    Optional,
12
    Output,
13
    TemplateRef,
14
    ViewEncapsulation,
1✔
15
    booleanAttribute
16
} from '@angular/core';
75✔
17
import { coerceCssPixelValue, isArray, isObject } from 'ngx-tethys/util';
18
import { ThyTableSortDirection, ThyTableSortEvent } from './table.interface';
UNCOV
19

×
20
export interface IThyTableColumnParentComponent {
21
    rowKey: string;
22
    updateColumnSelections(key: string, selections: any): void;
99✔
23
}
89!
24

89✔
UNCOV
25
/**
×
26
 * Injection token used to provide the parent component to options.
27
 */
89!
UNCOV
28
export const THY_TABLE_COLUMN_PARENT_COMPONENT = new InjectionToken<IThyTableColumnParentComponent>('THY_TABLE_COLUMN_PARENT_COMPONENT');
×
29

30
export type FixedDirection = 'left' | 'right';
31

32
/**
33
 * 表格列组件
2,349✔
34
 * @name thy-table-column
35
 * @order 20
36
 */
4✔
37
@Component({
3!
38
    selector: 'thy-table-column',
3✔
39
    template: '<ng-content></ng-content>',
40
    encapsulation: ViewEncapsulation.None,
UNCOV
41
    standalone: true
×
42
})
43
export class ThyTableColumnComponent implements OnInit {
44
    /**
45
     * 设置数据属性 Key,读取数组中对象的当前 Key 值
1✔
46
     * @type string
47
     */
48
    @Input('thyModelKey') model = '';
49

400✔
50
    /**
109!
UNCOV
51
     * 设置列名,显示在表头
×
52
     * @type string
53
     */
54
    @Input('thyTitle') title = '';
55

56
    /**
400✔
57
     * 设置列的特殊类型,序列号、选择框、单选框、切换按钮
400✔
58
     * @type string
400✔
59
     */
400✔
60
    @Input('thyType') type = '';
400✔
61

400✔
62
    public width: string = '';
400✔
63

400✔
64
    /**
400✔
65
     * 设置列的宽度
400✔
66
     */
400✔
67
    @Input()
400✔
68
    set thyWidth(value: string | number) {
400✔
69
        this.width = coerceCssPixelValue(value);
400✔
70
    }
400✔
71

72
    public minWidth: string = '';
73

377✔
74
    /**
377✔
75
     * 设置列的最小宽度
76
     */
77
    @Input()
377✔
78
    set thyMinWidth(value: string | number) {
79
        this.minWidth = coerceCssPixelValue(value);
1✔
80
    }
81

82
    /**
83
     * 设置列的样式
1✔
84
     */
85
    @Input('thyClassName') className = '';
86

87
    /**
88
     * 设置列头部的 Class,即 th 元素上的样式
89
     * @type string
90
     */
91
    @Input('thyHeaderClassName') headerClassName = '';
92

93
    /**
94
     * 设置自定义类型的禁用状态
95
     * @type boolean
96
     */
97
    @Input({ alias: 'thyDisabled', transform: booleanAttribute }) disabled = false;
98

99
    /**
100
     * thyType 为 checkbox 或者 radio 类型时选中的数据 ,支持单个对象,单个 Id,同时支持多个 Id,多个对象
101
     */
102
    @Input('thySelections')
103
    set selections(value: any) {
104
        if (value) {
105
            this._selections = isArray(value) ? value : [value];
106
            this._selections = this._selections.map((item: string | number | object) => {
1✔
107
                return isObject(item) ? item[this.parent.rowKey] : item;
108
            });
109
            if (!this._firstChange) {
110
                this.parent.updateColumnSelections(this.key, this._selections);
111
            }
112
        }
113
    }
114

115
    get selections() {
116
        return this._selections;
117
    }
118
    /**
119
     * 设置数据为空的时候显示的文本
120
     * @type string
121
     */
122
    @Input('thyDefaultText') defaultText = '';
123

124
    /**
125
     * 设置 Tree 模式下折叠展开按钮展示列,不传默认第一列
126
     */
127
    @Input({ alias: 'thyExpand', transform: booleanAttribute }) expand = false;
128

129
    public sortable: boolean;
130

131
    /**
132
     * 是否开启列排序功能(开启时 thyModelKey 为 必传)
133
     * @default false
134
     */
135
    @Input({ transform: booleanAttribute })
136
    set thySortable(value: boolean) {
137
        if (value) {
138
            if (this.model) {
139
                this.sortable = true;
140
            } else {
141
                throw new Error(`thyModelKey is required when sortable`);
142
            }
143
        } else {
144
            this.sortable = false;
145
        }
146
    }
147

148
    /**
149
     * 默认列排序顺序
150
     * @type 'asc' | 'desc' | ''
151
     */
152
    @Input('thySortDirection') sortDirection = ThyTableSortDirection.default;
153

154
    /**
155
     * 设置固定列
156
     */
157
    @Input('thyFixed') fixed: FixedDirection;
158

159
    /**
160
     * 当前列是否是操作列,设置为 true 时会追加 thy-operation-links 样式类,文字居中
161
     * @default false
162
     */
163
    @Input({ alias: 'thyOperational', transform: booleanAttribute }) operational: boolean;
164

165
    /**
166
     * 当前列是否是次要列,设置为 true 时会追加 thy-table-column-secondary 样式类,文字颜色为 $gray-600
167
     * @default false
168
     */
169
    @Input({ alias: 'thySecondary', transform: booleanAttribute }) secondary: boolean;
170

171
    /**
172
     * 列排序修改事件
173
     */
174
    @Output('thySortChange') sortChange: EventEmitter<ThyTableSortEvent> = new EventEmitter<ThyTableSortEvent>();
175

176
    @ContentChild('header', { static: true }) headerTemplateRef: TemplateRef<any>;
177

178
    @ContentChild('cell', { static: true }) cellTemplateRef: TemplateRef<any>;
179

180
    @ContentChild(TemplateRef, { static: true })
181
    set templateRef(value: TemplateRef<any>) {
182
        if (value) {
183
            if (!this.headerTemplateRef && !this.cellTemplateRef) {
184
                this.cellTemplateRef = value;
185
            }
186
        }
187
    }
188

189
    public key?: string;
190

191
    public left: number;
192

193
    public right: number;
194

195
    private _selections: any;
196

197
    private _firstChange = true;
198

199
    constructor(
200
        private el: ElementRef,
201
        @Optional()
202
        @Inject(THY_TABLE_COLUMN_PARENT_COMPONENT)
203
        public parent: IThyTableColumnParentComponent
204
    ) {}
205

206
    ngOnInit() {
207
        this.key = this._generateKey();
208
        this._firstChange = false;
209
    }
210

211
    private _generateKey() {
212
        return '[$$column]' + Math.random().toString(16).slice(2, 10);
213
    }
214
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc