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

atinc / ngx-tethys / 3b0f2033-3042-471a-8924-af474a7789df

03 Apr 2024 08:06AM UTC coverage: 90.399% (-0.005%) from 90.404%
3b0f2033-3042-471a-8924-af474a7789df

Pull #3063

circleci

minlovehua
Merge branch 'master' of github.com:atinc/ngx-tethys into minlovehua/use-cdk-coercion
Pull Request #3063: refactor(util): mark coerceBooleanProperty, coerceNumberValue, and coerceCssPixelValue as deprecated, and use angular cdk to replace them #INFR-12096

5410 of 6635 branches covered (81.54%)

Branch coverage included in aggregate %.

14 of 16 new or added lines in 4 files covered. (87.5%)

6 existing lines in 2 files now uncovered.

13176 of 13925 relevant lines covered (94.62%)

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

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

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

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

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

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

56
    /**
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

400✔
72
    public minWidth: string = '';
73

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

82
    /**
83
     * 设置列的样式
84
     */
1✔
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) => {
107
                return isObject(item) ? item[this.parent.rowKey] : item;
1✔
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