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

atinc / ngx-tethys / 6611325a-2cac-4924-b743-61ecb89171c2

06 Mar 2024 07:48AM UTC coverage: 90.575% (-0.005%) from 90.58%
6611325a-2cac-4924-b743-61ecb89171c2

push

circleci

xinglu01
feat(datepicker): remove date-picker deprecated parameter(#INFR-11790)

5414 of 6634 branches covered (81.61%)

Branch coverage included in aggregate %.

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

29 existing lines in 3 files now uncovered.

13489 of 14236 relevant lines covered (94.75%)

977.31 hits per line

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

86.54
/src/date-picker/abstract-picker.directive.ts
1
import { InputBoolean, InputNumber, ThyPlacement } from 'ngx-tethys/core';
2
import { ThyPopover, ThyPopoverConfig } from 'ngx-tethys/popover';
3
import { coerceBooleanProperty, FunctionProp, warnDeprecation } from 'ngx-tethys/util';
4
import { fromEvent, Observable, Subject } from 'rxjs';
5
import { debounceTime, mapTo, takeUntil, tap } from 'rxjs/operators';
6

7
import { coerceArray } from '@angular/cdk/coercion';
8
import {
9
    AfterViewInit,
10
    ChangeDetectorRef,
11
    Directive,
12
    ElementRef,
13
    EventEmitter,
14
    Input,
15
    OnChanges,
1✔
16
    OnDestroy,
17
    OnInit,
25✔
18
    Output,
19
    SimpleChange,
20
    TemplateRef
13!
21
} from '@angular/core';
22

23
import { AbstractPickerComponent } from './abstract-picker.component';
13!
24
import { DatePopup } from './lib/popups/date-popup.component';
13✔
25
import { ThyDateChangeEvent, ThyPanelMode } from './standard-types';
26
import { CompatibleValue } from './inner-types';
13✔
27
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
28

29
/**
13!
30
 * @private
13✔
31
 */
32
@Directive()
13✔
33
export abstract class PickerDirective extends AbstractPickerComponent implements OnInit, AfterViewInit, OnDestroy, OnChanges {
34
    showWeek = false;
35

31✔
36
    @Input() thyDateRender: FunctionProp<TemplateRef<Date> | string>;
37

38
    panelMode: ThyPanelMode | ThyPanelMode[];
56!
39

56✔
40
    /**
56✔
41
     * @type EventEmitter<ThyPanelMode | ThyPanelMode[]>
29!
42
     */
43
    @Output() readonly thyOnPanelChange = new EventEmitter<ThyPanelMode | ThyPanelMode[]>();
44

27✔
45
    /**
46
     * @type EventEmitter<Date[]>
56✔
47
     */
48
    @Output() readonly thyOnCalendarChange = new EventEmitter<Date[]>();
49

25✔
50
    private _showTime: object | boolean;
25✔
51
    @Input() get thyShowTime(): object | boolean {
52
        return this._showTime;
53
    }
54
    set thyShowTime(value: object | boolean) {
55
        this._showTime = typeof value === 'object' ? value : coerceBooleanProperty(value);
56
    }
57

58
    /**
59
     * 是否展示时间(时、分)
60
     * @default false
61
     */
62
    @Input() @InputBoolean() thyMustShowTime = false;
63

64
    /**
65
     * 弹出位置
66
     * @type top | topLeft | topRight | bottom | bottomLeft | bottomRight | left | leftTop | leftBottom | right | rightTop | rightBottom
67
     */
68
    @Input() thyPlacement: ThyPlacement = 'bottom';
69

70
    private offset = 4;
71

72
    /**
73
     * 弹出 DatePicker 的偏移量
74
     * @default 4
75
     */
76
    @Input()
77
    @InputNumber()
78
    set thyOffset(value: number) {
79
        if (typeof ngDevMode === 'undefined' || ngDevMode) {
25!
80
            warnDeprecation(`thyOffset parameter will be deprecated, please use thyPopoverOptions instead.`);
25✔
81
        }
25✔
82
        this.offset = value;
25✔
83
    }
15✔
84

10✔
85
    private hasBackdrop = true;
86

25✔
87
    /**
88
     * 是否有幕布
×
89
     * @default true
90
     */
25✔
91
    @Input()
25✔
92
    @InputBoolean()
7✔
93
    set thyHasBackdrop(value: boolean) {
94
        if (typeof ngDevMode === 'undefined' || ngDevMode) {
25✔
95
            warnDeprecation(`thyHasBackdrop parameter will be deprecated, please use thyPopoverOptions instead.`);
96
        }
97
        this.hasBackdrop = value;
13✔
98
    }
25✔
99

100
    /**
101
     * popover 的其它参数
7✔
102
     */
103
    @Input() thyPopoverOptions: ThyPopoverConfig;
104

105
    /**
7✔
106
     * 是否阻止冒泡
107
     */
108
    @Input() @InputBoolean() thyStopPropagation = true;
31✔
109

25!
110
    private destroy$ = new Subject<void>();
25✔
111
    private el: HTMLElement = this.elementRef.nativeElement;
112
    readonly $click: Observable<boolean> = fromEvent(this.el, 'click').pipe(
113
        tap(e => {
114
            if (this.thyStopPropagation) {
115
                e.stopPropagation();
32✔
116
            }
32✔
117
        }),
32✔
118
        mapTo(true)
32✔
119
    );
32✔
120

32✔
121
    takeUntilDestroyed = takeUntilDestroyed();
32✔
122

32✔
123
    ngOnInit() {
32✔
124
        this.getInitialState();
32✔
125
    }
32✔
126

32✔
127
    private getInitialState() {
32✔
128
        this.thyMode = this.thyMode || 'date';
32✔
129
        this.flexible = this.thyMode === 'flexible';
32✔
130

27✔
131
        if (this.isRange) {
26✔
132
            this.panelMode = this.flexible ? ['date', 'date'] : [this.thyMode, this.thyMode];
133
        } else {
134
            this.panelMode = this.thyMode;
32✔
135
        }
136
        this.showWeek = this.thyMode === 'week';
137
    }
31✔
138

31✔
139
    private openOverlay(): void {
140
        this.getInitialState();
141
        const popoverRef = this.thyPopover.open(
32✔
142
            DatePopup,
32✔
143
            Object.assign(
144
                {
145
                    origin: this.el,
7✔
146
                    hasBackdrop: this.hasBackdrop,
7✔
147
                    backdropClass: 'thy-overlay-transparent-backdrop',
7!
148
                    offset: this.offset,
7✔
149
                    outsideClosable: true,
150
                    initialState: {
151
                        isRange: this.isRange,
152
                        panelMode: this.panelMode,
153
                        showWeek: this.showWeek,
31✔
154
                        value: this.thyValue,
155
                        showTime: this.thyShowTime,
156
                        mustShowTime: this.withTime,
157
                        format: this.thyFormat,
7!
UNCOV
158
                        dateRender: this.thyDateRender,
×
159
                        disabledDate: this.thyDisabledDate,
160
                        placeholder: this.thyPlaceHolder,
161
                        className: this.thyPanelClassName,
UNCOV
162
                        defaultPickerValue: this.thyDefaultPickerValue,
×
163
                        minDate: this.thyMinDate,
164
                        maxDate: this.thyMaxDate,
1✔
165
                        showShortcut: this.thyShowShortcut,
166
                        shortcutPresets: this.shortcutPresets,
167
                        shortcutPosition: this.shortcutPosition,
168
                        flexible: this.flexible,
169
                        flexibleDateGranularity: this.flexibleDateGranularity
1✔
170
                    },
171
                    placement: this.thyPlacement
172
                },
173
                this.thyPopoverOptions
174
            )
175
        );
176
        if (popoverRef) {
177
            const componentInstance = popoverRef.componentInstance;
178
            componentInstance.valueChange.pipe(takeUntil(this.destroy$)).subscribe((event: CompatibleValue) => this.onValueChange(event));
179
            componentInstance.calendarChange.pipe(takeUntil(this.destroy$)).subscribe((event: CompatibleValue) => {
180
                const rangeValue = coerceArray(event).map(x => x.nativeDate);
181
                this.thyOnCalendarChange.emit(rangeValue);
182
            });
1✔
183
            componentInstance.showTimePickerChange
184
                .pipe(takeUntil(this.destroy$))
185
                .subscribe((event: boolean) => this.onShowTimePickerChange(event));
186
            // eslint-disable-next-line max-len
1✔
187
            componentInstance.ngOnChanges({ value: {} as SimpleChange }); // dynamically created components don't call ngOnChanges, manual call
188
            componentInstance.dateValueChange?.pipe(this.takeUntilDestroyed).subscribe((event: ThyDateChangeEvent) => {
189
                this.thyDateChange.emit(event);
190
            });
191
            popoverRef
1✔
192
                .afterOpened()
193
                .pipe(takeUntil(this.destroy$))
194
                .subscribe(() => this.thyOpenChange.emit(true));
195
            popoverRef
196
                .afterClosed()
1✔
197
                .pipe(takeUntil(this.destroy$))
198
                .subscribe(() => this.thyOpenChange.emit(false));
199
        }
200
    }
1✔
201

202
    closeOverlay(): void {
203
        this.thyPopover.close();
204
    }
205

206
    initActionSubscribe(): void {
207
        this.$click.pipe(debounceTime(50), takeUntil(this.destroy$)).subscribe(() => {
208
            if (!this.thyDisabled && !this.thyReadonly) {
209
                this.openOverlay();
210
            }
211
        });
212
    }
213

214
    constructor(public elementRef: ElementRef, public cdr: ChangeDetectorRef, private thyPopover: ThyPopover) {
215
        super(cdr);
216
    }
217

218
    ngAfterViewInit(): void {
219
        this.setDefaultTimePickerState();
220
        this.initActionSubscribe();
221
    }
222

223
    ngOnDestroy(): void {
224
        this.destroy$.next();
225
        this.destroy$.complete();
226
    }
227

228
    onValueChange(value: CompatibleValue): void {
229
        this.restoreTimePickerState(value);
230
        super.onValueChange(value);
231
        if (!this.flexible) {
232
            this.closeOverlay();
233
        }
234
    }
235

236
    // Displays the time directly when the time must be displayed by default
237
    setDefaultTimePickerState() {
238
        this.withTime = this.thyMustShowTime;
239
    }
240

241
    // Restore after clearing time to select whether the original picker time is displayed or not
242
    restoreTimePickerState(value: CompatibleValue | null) {
243
        if (!value) {
244
            this.withTime = this.thyMustShowTime || this.originWithTime;
245
        }
246
    }
247
    onShowTimePickerChange(show: boolean): void {
248
        this.withTime = show;
249
    }
250
}
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