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

atinc / ngx-tethys / 8dcac4a2-3556-45a1-b448-61ebeb09ecba

29 May 2024 07:34AM UTC coverage: 90.409% (+0.003%) from 90.406%
8dcac4a2-3556-45a1-b448-61ebeb09ecba

Pull #3098

circleci

invalid-email-address
feat(breadcrumb): 面包屑导航支持传入items时省略展示
Pull Request #3098: feat(breadcrumb): 面包屑导航支持传入items时省略展示 #INFR-12463 @wangkai @xuhaifeng @wumeimin

5453 of 6677 branches covered (81.67%)

Branch coverage included in aggregate %.

19 of 19 new or added lines in 1 file covered. (100.0%)

18 existing lines in 3 files now uncovered.

13202 of 13957 relevant lines covered (94.59%)

982.42 hits per line

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

82.19
/src/date-picker/abstract-picker.component.ts
1
import { TabIndexDisabledControlValueAccessorMixin } from 'ngx-tethys/core';
2
import { TinyDate, warnDeprecation } from 'ngx-tethys/util';
3
import { Subject } from 'rxjs';
4

5
import {
6
    booleanAttribute,
7
    ChangeDetectorRef,
8
    Directive,
9
    EventEmitter,
10
    Input,
1✔
11
    OnChanges,
12
    OnDestroy,
65✔
13
    OnInit,
14
    Output,
15
    SimpleChanges,
253✔
16
    ViewChild
17
} from '@angular/core';
18
import { ControlValueAccessor } from '@angular/forms';
64!
19

64✔
20
import { CompatibleValue, RangeAdvancedValue } from './inner-types';
21
import { ThyPicker } from './picker.component';
22
import { makeValue, transformDateValue } from './picker.util';
23
import {
64✔
24
    CompatibleDate,
25
    DateEntry,
26
    DisabledDateFn,
336✔
27
    ThyDateRangeEntry,
28
    ThyPanelMode,
29
    ThyShortcutPosition,
2,999✔
30
    CompatiblePresets,
31
    ThyDateGranularity,
32
    ThyDateChangeEvent
13✔
33
} from './standard-types';
34

35
/**
686✔
36
 * @private
37
 */
38
@Directive()
152✔
39
export abstract class AbstractPickerComponent
40
    extends TabIndexDisabledControlValueAccessorMixin
41
    implements OnInit, OnChanges, OnDestroy, ControlValueAccessor
184✔
42
{
184✔
43
    thyValue: CompatibleValue | null;
184✔
44

184✔
45
    _panelMode: ThyPanelMode = 'date';
184✔
46

184✔
47
    /**
184✔
48
     * 模式
184✔
49
     * @type decade | year | month | date | week | flexible
184✔
50
     */
184✔
51
    @Input() set thyMode(value: ThyPanelMode) {
184✔
52
        this._panelMode = value ?? 'date';
184✔
53
    }
184✔
54

184✔
55
    get thyMode() {
184✔
56
        return this._panelMode;
184✔
57
    }
184✔
58

59
    /**
60
     * 是否显示清除按钮
152✔
61
     */
152✔
62
    @Input({ transform: booleanAttribute }) thyAllowClear = true;
152✔
63

64
    /**
65
     * 是否自动获取焦点
152✔
66
     * @default false
67
     */
68
    @Input({ transform: booleanAttribute }) thyAutoFocus = false;
40✔
69

70
    @Input({ transform: booleanAttribute }) thyOpen: boolean;
71

227✔
72
    @Input() thyDisabledDate: DisabledDateFn;
37✔
73

74
    /**
75
     * 最小值
76
     * @type Date | number
152✔
77
     */
152✔
78
    @Input() thyMinDate: Date | number;
79

80
    /**
44✔
81
     * 最大值
82
     * @type Date | number
83
     */
UNCOV
84
    @Input() thyMaxDate: Date | number;
×
85

UNCOV
86
    /**
×
87
     * 输入框提示文字
88
     * @type string | string[]
89
     */
UNCOV
90
    @Input() thyPlaceHolder: string | string[];
×
91

UNCOV
92
    /**
×
93
     * 是否只读
94
     * @default false
95
     */
UNCOV
96
    @Input({ transform: booleanAttribute }) thyReadonly: boolean;
×
97

UNCOV
98
    /**
×
99
     * 选择器 className
100
     */
101
    @Input() thyOriginClassName: string;
UNCOV
102

×
103
    /**
UNCOV
104
     * 弹出层 className
×
105
     */
106
    @Input() thyPanelClassName: string;
107

UNCOV
108
    /**
×
109
     * 输入框的大小
UNCOV
110
     * @type xs | sm | md | lg | default
×
111
     */
112
    @Input() thySize: 'lg' | 'md' | 'sm' | 'xs' | 'default' = 'default';
113

UNCOV
114
    /**
×
115
     * 展示的日期格式
UNCOV
116
     * @default yyyy-MM-dd
×
117
     */
118
    @Input() thyFormat: string;
119

67✔
120
    /**
67✔
121
     * @description.en-us only for range picker, Whether to automatically take the beginning and ending unixTime of the day
67✔
122
     * @description.zh-cn 是否取值开始日期的00:00以及截止日期的24:00
67✔
123
     * @default false
67✔
124
     */
28✔
125
    @Input({ transform: booleanAttribute }) thyAutoStartAndEnd = false;
28✔
126

28✔
127
    /**
25✔
128
     * 面板默认日期
25!
UNCOV
129
     * @type CompatibleDate | number | null
×
130
     */
131
    @Input() thyDefaultPickerValue: CompatibleDate | number | null = null;
132

25✔
133
    /**
134
     * 自定义的后缀图标
135
     */
136
    @Input() thySuffixIcon = 'calendar';
137

138
    /**
28✔
139
     * 是否展示快捷选项面板
8✔
140
     * @default false
141
     */
28✔
142
    @Input({ transform: booleanAttribute }) thyShowShortcut: boolean;
143

144
    /**
39✔
145
     * 快捷选项面板的显示位置
39✔
146
     * @type left | bottom
29✔
147
     */
148
    @Input() set thyShortcutPosition(position: ThyShortcutPosition) {
39✔
149
        if (!!position) {
36✔
150
            this.shortcutPosition = position;
151
        }
152
    }
3✔
153

154
    /**
155
     * 自定义快捷选项
156
     * @type ThyShortcutPreset[]
157
     */
441✔
158
    @Input() set thyShortcutPresets(presets: CompatiblePresets) {
68!
UNCOV
159
        this.shortcutPresets = presets;
×
160
    }
161

162
    /**
68!
UNCOV
163
     * 日期变化的回调
×
164
     */
165
    @Output() readonly thyDateChange = new EventEmitter<ThyDateChangeEvent>();
166

167
    @Output() readonly thyOpenChange = new EventEmitter<boolean>();
168

UNCOV
169
    @ViewChild(ThyPicker, { static: true }) public picker: ThyPicker;
×
170

×
171
    /**
172
     * 是否禁用
173
     * @default false
374✔
174
     */
374✔
175
    @Input({ transform: booleanAttribute })
374✔
176
    set thyDisabled(value: boolean) {
3✔
177
        this.disabled = value;
2✔
178
    }
179
    get thyDisabled(): boolean {
180
        return this.disabled;
374✔
181
    }
374✔
182

374✔
183
    disabled = false;
374✔
184

374✔
185
    shortcutPosition: ThyShortcutPosition = 'left';
374✔
186

187
    shortcutPresets: CompatiblePresets;
188

375✔
189
    isRange: boolean;
190

191
    withTime: boolean;
179✔
192

179✔
193
    flexible: boolean;
194

195
    flexibleDateGranularity: ThyDateGranularity;
152✔
196

115✔
197
    protected destroyed$: Subject<void> = new Subject();
198
    protected isCustomPlaceHolder = false;
152✔
199
    private onlyEmitDate = false;
200
    protected originWithTime: boolean;
201

441✔
202
    get realOpenState(): boolean {
203
        return this.picker.realOpenState;
1✔
204
    }
205

206
    get isShowDatePopup(): boolean {
1✔
207
        return this.picker.isShowDatePopup;
208
    }
209

210
    initValue(): void {
211
        this.thyValue = this.isRange ? [] : null;
212
    }
213

214
    constructor(public cdr: ChangeDetectorRef) {
215
        super();
216
    }
217

218
    ngOnInit(): void {
219
        this.setDefaultPlaceHolder();
220
        this.initValue();
221
        this.isFlexible();
222
    }
223

224
    isFlexible() {
225
        this.flexible = this.thyMode === 'flexible';
226
    }
227

228
    onDateValueChange(event: ThyDateChangeEvent) {
229
        this.thyDateChange.emit(event);
230
    }
231

232
    ngOnChanges(changes: SimpleChanges): void {
1✔
233
        if (changes.thyPlaceHolder && changes.thyPlaceHolder.firstChange && typeof this.thyPlaceHolder !== 'undefined') {
234
            this.isCustomPlaceHolder = true;
235
        }
236
    }
237

238
    ngOnDestroy(): void {
239
        this.destroyed$.next();
240
        this.destroyed$.complete();
241
    }
242

243
    closeOverlay(): void {
244
        this.picker.hideOverlay();
245
    }
246

247
    getAutoStartAndEndValue(begin: TinyDate, end: TinyDate) {
248
        let value: { begin: number; end: number };
249
        switch (this.thyMode) {
250
            case 'date':
251
                value = {
252
                    begin: begin.startOfDay().getUnixTime(),
253
                    end: end.endOfDay().getUnixTime()
254
                };
255
                break;
256
            case 'week':
257
                value = {
258
                    begin: begin.startOfWeek().getUnixTime(),
259
                    end: end.endOfWeek().getUnixTime()
260
                };
261
                break;
262
            case 'month':
263
                value = {
264
                    begin: begin.startOfMonth().getUnixTime(),
265
                    end: end.endOfMonth().getUnixTime()
266
                };
267
                break;
268
            case 'year':
269
                value = {
270
                    begin: begin.startOfYear().getUnixTime(),
271
                    end: end.endOfYear().getUnixTime()
272
                };
273
                break;
274
            default:
275
                value = {
276
                    begin: begin.startOfDay().getUnixTime(),
277
                    end: end.endOfDay().getUnixTime()
278
                };
279
                break;
280
        }
281
        return value;
282
    }
283

284
    onValueChange(originalValue: CompatibleValue | RangeAdvancedValue): void {
285
        this.setFormatRule();
286
        const { value, withTime, flexibleDateGranularity } = transformDateValue(originalValue);
287
        this.flexibleDateGranularity = flexibleDateGranularity;
288
        this.setValue(value);
289
        if (this.isRange) {
290
            const vAsRange: any = this.thyValue;
291
            let value = { begin: null, end: null } as ThyDateRangeEntry;
292
            if (vAsRange.length) {
293
                const [begin, end] = vAsRange as TinyDate[];
294
                if (this.thyAutoStartAndEnd) {
295
                    value = this.getAutoStartAndEndValue(begin, end);
296
                } else {
297
                    value = {
298
                        begin: begin.getUnixTime(),
299
                        end: end.getUnixTime()
300
                    };
301
                }
302
            }
303
            if (this.flexible) {
304
                value.granularity = flexibleDateGranularity;
305
            }
306
            this.onChangeFn(value);
307
        } else {
308
            const value = { date: null, with_time: this.withTime ? 1 : 0 } as DateEntry;
309
            if (this.thyValue) {
310
                value.date = (this.thyValue as TinyDate).getUnixTime();
311
            }
312
            if (this.onlyEmitDate) {
313
                this.onChangeFn(value.date);
314
            } else {
315
                this.onChangeFn(value);
316
            }
317
        }
318
    }
319

320
    setFormatRule() {
321
        if (!this.thyFormat) {
322
            if (this.withTime) {
323
                this.thyFormat = 'yyyy-MM-dd HH:mm';
324
            } else {
325
                if (!this.onlyEmitDate) {
326
                    this.thyFormat = 'yyyy-MM-dd';
327
                }
328
            }
329
        }
330
    }
331

332
    onOpenChange(open: boolean): void {
333
        this.thyOpen = open;
334
        this.thyOpenChange.emit(open);
335
    }
336

337
    onChangeFn: (val: CompatibleDate | DateEntry | ThyDateRangeEntry | number | null) => void = () => void 0;
338

339
    writeValue(originalValue: CompatibleDate | ThyDateRangeEntry): void {
340
        const { value, withTime, flexibleDateGranularity } = transformDateValue(originalValue);
341
        this.flexibleDateGranularity = flexibleDateGranularity;
342
        if (this.flexible && value && (value as Date[]).length) {
343
            if (!this.flexibleDateGranularity) {
344
                this.flexibleDateGranularity = 'day';
345
            }
346
        }
347

348
        this.setValue(value);
349
        this.setTimePickerState(withTime);
350
        this.onlyEmitDate = typeof withTime === 'undefined';
351
        this.originWithTime = withTime;
352
        this.setFormatRule();
353
        this.cdr.markForCheck();
354
    }
355

356
    setTimePickerState(withTime: boolean): void {
357
        this.withTime = withTime;
358
    }
359

360
    setDisabledState(disabled: boolean): void {
361
        this.thyDisabled = disabled;
362
        this.cdr.markForCheck();
363
    }
364

365
    private setDefaultPlaceHolder(): void {
366
        if (!this.isCustomPlaceHolder) {
367
            this.thyPlaceHolder = this.isRange ? ['开始日期', '结束日期'] : '请选择日期';
368
        }
369
        this.cdr.markForCheck();
370
    }
371

372
    public setValue(value: CompatibleDate): void {
373
        this.thyValue = makeValue(value, this.isRange);
374
    }
375
}
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