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

atinc / ngx-tethys / cd64db52-e563-41a3-85f3-a0adb87ce135

30 Oct 2024 08:03AM UTC coverage: 90.402% (-0.04%) from 90.438%
cd64db52-e563-41a3-85f3-a0adb87ce135

push

circleci

web-flow
refactor: refactor constructor to the inject function (#3222)

5503 of 6730 branches covered (81.77%)

Branch coverage included in aggregate %.

422 of 429 new or added lines in 170 files covered. (98.37%)

344 existing lines in 81 files now uncovered.

13184 of 13941 relevant lines covered (94.57%)

997.19 hits per line

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

80.7
/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
    InjectionToken,
8
    Input,
9
    OnInit,
1✔
10
    Output,
11
    TemplateRef,
12
    ViewEncapsulation,
13
    inject
14
} from '@angular/core';
15
import { coerceBooleanProperty, isArray, isObject } from 'ngx-tethys/util';
1✔
16
import { ThyTableSortDirection, ThyTableSortEvent } from './table.interface';
17

400✔
18
export interface IThyTableColumnParentComponent {
400✔
19
    rowKey: string;
400✔
20
    updateColumnSelections(key: string, selections: any): void;
400✔
21
}
400✔
22

400✔
23
/**
400✔
24
 * Injection token used to provide the parent component to options.
400✔
25
 */
400✔
26
export const THY_TABLE_COLUMN_PARENT_COMPONENT = new InjectionToken<IThyTableColumnParentComponent>('THY_TABLE_COLUMN_PARENT_COMPONENT');
400✔
27

400✔
28
export type FixedDirection = 'left' | 'right';
400✔
29

400✔
30
/**
400✔
31
 * 表格列组件
400✔
32
 * @name thy-table-column
33
 * @order 20
34
 */
75✔
35
@Component({
36
    selector: 'thy-table-column',
UNCOV
37
    template: '<ng-content></ng-content>',
×
38
    encapsulation: ViewEncapsulation.None,
39
    standalone: true
40
})
99✔
41
export class ThyTableColumnComponent implements OnInit {
89!
42
    private el = inject(ElementRef);
89✔
NEW
43
    parent = inject(THY_TABLE_COLUMN_PARENT_COMPONENT, { optional: true })!;
×
44

45
    /**
89!
UNCOV
46
     * 设置数据属性 Key,读取数组中对象的当前 Key 值
×
47
     * @type string
48
     */
49
    @Input('thyModelKey') model = '';
50

51
    /**
2,349✔
52
     * 设置列名,显示在表头
53
     * @type string
54
     */
4✔
55
    @Input('thyTitle') title = '';
3!
56

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

63
    public width: string = '';
1✔
64

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

73
    public minWidth: string = '';
74

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

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

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

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

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

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

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

130
    public sortable: boolean;
131

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

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

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

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

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

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

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

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

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

190
    public key?: string;
191

192
    public left: number;
193

194
    public right: number;
195

196
    private _selections: any;
197

198
    private _firstChange = true;
199

200
    ngOnInit() {
201
        this.key = this._generateKey();
202
        this._firstChange = false;
203
    }
204

205
    private _generateKey() {
206
        return '[$$column]' + Math.random().toString(16).slice(2, 10);
207
    }
208
}
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