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

IgniteUI / igniteui-angular / 13331632524

14 Feb 2025 02:51PM UTC coverage: 22.015% (-69.6%) from 91.622%
13331632524

Pull #15372

github

web-flow
Merge d52d57714 into bcb78ae0a
Pull Request #15372: chore(*): test ci passing

1990 of 15592 branches covered (12.76%)

431 of 964 new or added lines in 18 files covered. (44.71%)

19956 existing lines in 307 files now uncovered.

6452 of 29307 relevant lines covered (22.02%)

249.17 hits per line

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

18.6
/projects/igniteui-angular/src/lib/calendar/calendar.directives.ts
1
/**
2
 * This file contains all the directives used by the @link IgxCalendarComponent.
3
 * Except for the directives which are used for templating the calendar itself
4
 * you should generally not use them directly.
5
 *
6
 * @preferred
7
 */
8
import {
9
    Directive,
10
    EventEmitter,
11
    HostBinding,
12
    HostListener,
13
    Input,
14
    InjectionToken,
15
    Output,
16
    TemplateRef,
17
    ElementRef,
18
    AfterViewInit,
19
    OnDestroy,
20
    NgZone
21
} from '@angular/core';
22
import { fromEvent, Subject, interval } from 'rxjs';
23
import { takeUntil, debounce, tap } from 'rxjs/operators';
24
import { PlatformUtil } from '../core/utils';
25
import { CalendarDay } from './common/model';
26

27
export const IGX_CALENDAR_VIEW_ITEM =
28
    new InjectionToken<IgxCalendarMonthDirective | IgxCalendarYearDirective>('IgxCalendarViewItem');
2✔
29

30
@Directive()
31
export abstract class IgxCalendarViewBaseDirective {
2✔
32
    @Input()
33
    public value: Date;
34

35
    @Input()
36
    public date: Date;
37

38
    @Input()
UNCOV
39
    public showActive = false;
×
40

41
    @Output()
UNCOV
42
    public itemSelection = new EventEmitter<Date>();
×
43

44
    public get nativeElement() {
45
        return this.elementRef.nativeElement;
×
46
    }
47

UNCOV
48
    constructor(public elementRef: ElementRef) { }
×
49

50
    @HostListener('mousedown', ['$event'])
51
    public onMouseDown(event: MouseEvent) {
UNCOV
52
        event.preventDefault();
×
UNCOV
53
        this.itemSelection.emit(this.value);
×
54
    }
55

56
    public abstract get isCurrent(): boolean;
57
    public abstract get isSelected(): boolean;
58
    public abstract get isActive(): boolean;
59
}
60

61
/**
62
 * @hidden
63
 */
64
@Directive({
65
    selector: '[igxCalendarYear]',
66
    providers: [
67
        { provide: IGX_CALENDAR_VIEW_ITEM, useExisting: IgxCalendarYearDirective }
68
    ],
69
    exportAs: 'igxCalendarYear',
70
    standalone: true
71
})
72
export class IgxCalendarYearDirective extends IgxCalendarViewBaseDirective {
2✔
73
    @HostBinding('class.igx-calendar-view__item--current')
74
    public get isCurrent(): boolean {
UNCOV
75
        return CalendarDay.today.year === this.value.getFullYear();
×
76
    }
77

78
    @HostBinding('class.igx-calendar-view__item--selected')
79
    public get isSelected(): boolean {
UNCOV
80
        return this.value.getFullYear() === this.date.getFullYear();
×
81
    }
82

83
    @HostBinding('class.igx-calendar-view__item--active')
84
    public get isActive(): boolean {
UNCOV
85
        return this.isSelected && this.showActive;
×
86
    }
87
}
88

89
@Directive({
90
    selector: '[igxCalendarMonth]',
91
    providers: [
92
        { provide: IGX_CALENDAR_VIEW_ITEM, useExisting: IgxCalendarMonthDirective }
93
    ],
94
    exportAs: 'igxCalendarMonth',
95
    standalone: true
96
})
97
export class IgxCalendarMonthDirective extends IgxCalendarViewBaseDirective {
2✔
98
    @HostBinding('class.igx-calendar-view__item--current')
99
    public get isCurrent(): boolean {
UNCOV
100
        const today = CalendarDay.today;
×
UNCOV
101
        const date = CalendarDay.from(this.value);
×
UNCOV
102
        return date.year === today.year && date.month === today.month;
×
103
    }
104

105
    @HostBinding('class.igx-calendar-view__item--selected')
106
    public get isSelected(): boolean {
UNCOV
107
        return (this.value.getFullYear() === this.date.getFullYear() &&
×
108
            this.value.getMonth() === this.date.getMonth()
109
        );
110
    }
111

112
    @HostBinding('class.igx-calendar-view__item--active')
113
    public get isActive(): boolean {
UNCOV
114
        return this.isSelected && this.showActive;
×
115
    }
116
}
117

118
/**
119
 * @hidden
120
 */
121
@Directive({
122
    selector: '[igxCalendarHeaderTitle]',
123
    standalone: true
124
})
125
export class IgxCalendarHeaderTitleTemplateDirective {
2✔
UNCOV
126
    constructor(public template: TemplateRef<any>) { }
×
127
}
128

129
/**
130
 * @hidden
131
 */
132
@Directive({
133
    selector: '[igxCalendarHeader]',
134
    standalone: true
135
})
136
export class IgxCalendarHeaderTemplateDirective {
2✔
UNCOV
137
    constructor(public template: TemplateRef<any>) { }
×
138
}
139

140
/**
141
 * @hidden
142
 */
143
@Directive({
144
    selector: '[igxCalendarSubheader]',
145
    standalone: true
146
})
147
export class IgxCalendarSubheaderTemplateDirective {
2✔
148
    constructor(public template: TemplateRef<any>) { }
×
149
}
150

151
/**
152
 * @hidden
153
 */
154
@Directive({
155
    selector: '[igxCalendarScrollPage]',
156
    standalone: true
157
})
158
export class IgxCalendarScrollPageDirective implements AfterViewInit, OnDestroy {
2✔
159
    /**
160
     * A callback function to be invoked when increment/decrement page is triggered.
161
     *
162
     * @hidden
163
     */
164
    @Input()
165
    public startScroll: (keydown?: boolean) => void;
166

167
    /**
168
     * A callback function to be invoked when increment/decrement page stops.
169
     *
170
     * @hidden
171
     */
172
    @Input()
173
    public stopScroll: (event: any) => void;
174

175
    /**
176
     * @hidden
177
     */
UNCOV
178
    private destroy$ = new Subject<boolean>();
×
179

UNCOV
180
    constructor(private element: ElementRef, private zone: NgZone, protected platform: PlatformUtil) { }
×
181

182
    /**
183
     * @hidden
184
     */
185
    @HostListener('mousedown', ['$event'])
186
    public onMouseDown(event: MouseEvent) {
UNCOV
187
        event.preventDefault();
×
UNCOV
188
        this.startScroll();
×
189
    }
190

191
    /**
192
     * @hidden
193
     */
194
    @HostListener('mouseup', ['$event'])
195
    public onMouseUp(event: MouseEvent) {
UNCOV
196
        this.stopScroll(event);
×
197
    }
198

199
    /**
200
     * @hidden
201
     */
202
    public ngAfterViewInit() {
UNCOV
203
        fromEvent(this.element.nativeElement, 'keyup').pipe(
×
204
            debounce(() => interval(100)),
×
205
            takeUntil(this.destroy$)
206
        ).subscribe((event: KeyboardEvent) => {
207
            this.stopScroll(event);
×
208
        });
209

UNCOV
210
        this.zone.runOutsideAngular(() => {
×
UNCOV
211
            fromEvent(this.element.nativeElement, 'keydown').pipe(
×
212
                tap((event: KeyboardEvent) => {
UNCOV
213
                    if (this.platform.isActivationKey(event)) {
×
UNCOV
214
                        event.preventDefault();
×
UNCOV
215
                        event.stopPropagation();
×
216
                    }
217
                }),
UNCOV
218
                debounce(() => interval(100)),
×
219
                takeUntil(this.destroy$)
220
            ).subscribe((event: KeyboardEvent) => {
UNCOV
221
                if (this.platform.isActivationKey(event)) {
×
UNCOV
222
                    this.zone.run(() => this.startScroll(true));
×
223
                }
224
            });
225
        });
226
    }
227

228
    /**
229
     * @hidden
230
     */
231
    public ngOnDestroy() {
UNCOV
232
        this.destroy$.next(true);
×
UNCOV
233
        this.destroy$.complete();
×
234
    }
235
}
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