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

IgniteUI / igniteui-angular / 13331632524

14 Feb 2025 02:51PM CUT 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

8.77
/projects/igniteui-angular/src/lib/calendar/common/calendar-view.directive.ts
1
import {
2
    Output,
3
    EventEmitter,
4
    Input,
5
    HostListener,
6
    ViewChildren,
7
    QueryList,
8
    booleanAttribute,
9
    Directive,
10
    HostBinding,
11
    InjectionToken,
12
    Inject,
13
} from "@angular/core";
14
import { noop } from "rxjs";
15
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from "@angular/forms";
16
import {
17
    IGX_CALENDAR_VIEW_ITEM,
18
    IgxCalendarMonthDirective,
19
    IgxCalendarYearDirective,
20
} from "../calendar.directives";
21
import { CalendarDay, DayInterval } from "../common/model";
22
import { getNextActiveDate, isDateInRanges } from "./helpers";
23
import { DateRangeType } from "../../core/dates";
24
import { isDate } from "../../core/utils";
25

26
export enum Direction {
2✔
27
    NEXT = 1,
2✔
28
    PREV = -1,
2✔
29
}
30

31
export const DAY_INTERVAL_TOKEN = new InjectionToken<DayInterval>(
2✔
32
    "DAY_INTERVAL",
33
);
34

35
@Directive({
36
    providers: [
37
        {
38
            provide: NG_VALUE_ACCESSOR,
39
            useExisting: IgxCalendarViewDirective,
40
            multi: true,
41
        },
42
    ],
43
    standalone: true,
44
})
45
export abstract class IgxCalendarViewDirective implements ControlValueAccessor {
2✔
46
    @HostBinding("attr.role")
47
    @Input()
UNCOV
48
    public role = 'grid';
×
49

50
    @HostBinding("attr.tabIndex")
51
    @Input()
UNCOV
52
    public tabIndex = 0;
×
53

54
    @HostBinding('attr.aria-activeDescendant')
55
    protected get activeDescendant() {
UNCOV
56
        if (this.tabIndex === -1) return;
×
57

58
        return this.date.getTime();
×
59
    }
60

61
    /**
62
     * Gets/sets whether the view should be rendered
63
     * according to the locale and format, if any.
64
     */
65
    @Input({ transform: booleanAttribute })
66
    public formatView: boolean;
67

68
    /**
69
     * Applies styles to the active item on view focus.
70
     */
71
    @Input({ transform: booleanAttribute })
UNCOV
72
    public showActive = false;
×
73

74
    /**
75
     * Emits an event when a selection is made in the view.
76
     * Provides reference the `date` property in the component.
77
     * @memberof IgxCalendarViewDirective
78
     */
79
    @Output()
UNCOV
80
    public selected = new EventEmitter<Date>();
×
81

82
    /**
83
     * Emits an event when a page changes in the view.
84
     * Provides reference the `date` property in the component.
85
     * @memberof IgxCalendarViewDirective
86
     * @hidden @internal
87
     */
88
    @Output()
UNCOV
89
    public pageChanged = new EventEmitter<Date>();
×
90

91
    /**
92
     * Emits an event when the active date has changed.
93
     * @memberof IgxCalendarViewDirective
94
     * @hidden @internal
95
     */
96
    @Output()
UNCOV
97
    public activeDateChanged = new EventEmitter<Date>();
×
98

99
    /**
100
     * @hidden
101
     * @internal
102
     */
103
    @ViewChildren(IGX_CALENDAR_VIEW_ITEM, { read: IGX_CALENDAR_VIEW_ITEM })
104
    public viewItems: QueryList<
105
        IgxCalendarMonthDirective | IgxCalendarYearDirective
106
    >;
107

108
    /**
109
     * @hidden
110
     */
111
    protected _formatter: Intl.DateTimeFormat;
112

113
    /**
114
     * @hidden
115
     */
UNCOV
116
    protected _locale = "en";
×
117

118
    /**
119
     * @hidden
120
     * @internal
121
     */
UNCOV
122
    private _date = new Date();
×
123

124
    /**
125
     * @hidden
126
     */
UNCOV
127
    protected _onTouchedCallback: () => void = noop;
×
128

129
    /**
130
     * @hidden
131
     */
UNCOV
132
    protected _onChangeCallback: (_: Date) => void = noop;
×
133

134
    /**
135
     * Gets/sets the selected date of the view.
136
     * By default it's the current date.
137
     * ```typescript
138
     * let date = this.view.date;
139
     * ```
140
     *
141
     * @memberof IgxYearsViewComponent
142
     */
143
    @Input()
144
    public set date(value: Date) {
UNCOV
145
        if (!isDate(value)) return;
×
146

UNCOV
147
        this._date = value;
×
148
    }
149

150
    public get date() {
UNCOV
151
        return this._date;
×
152
    }
153

154
    /**
155
     * Gets the `locale` of the view.
156
     * Default value is `"en"`.
157
     * ```typescript
158
     * let locale = this.view.locale;
159
     * ```
160
     *
161
     * @memberof IgxCalendarViewDirective
162
     */
163
    @Input()
164
    public get locale(): string {
UNCOV
165
        return this._locale;
×
166
    }
167

168
    /**
169
     * Sets the `locale` of the view.
170
     * Expects a valid BCP 47 language tag.
171
     * Default value is `"en"`.
172
     *
173
     * @memberof IgxCalendarViewDirective
174
     */
175
    public set locale(value: string) {
UNCOV
176
        this._locale = value;
×
UNCOV
177
        this.initFormatter();
×
178
    }
179

UNCOV
180
    constructor(@Inject(DAY_INTERVAL_TOKEN) protected dayInterval?: DayInterval) {
×
UNCOV
181
        this.initFormatter();
×
182
    }
183

184
    /**
185
     * @hidden
186
     */
187
    @HostListener("keydown.arrowdown", ["$event"])
188
    public onKeydownArrowDown(event: KeyboardEvent) {
UNCOV
189
        this.navigateTo(event, Direction.NEXT, 3);
×
190
    }
191

192
    /**
193
     * @hidden
194
     */
195
    @HostListener("keydown.arrowup", ["$event"])
196
    public onKeydownArrowUp(event: KeyboardEvent) {
UNCOV
197
        this.navigateTo(event, Direction.PREV, 3);
×
198
    }
199

200
    /**
201
     * @hidden
202
     */
203
    @HostListener("keydown.arrowright", ["$event"])
204
    public onKeydownArrowRight(event: KeyboardEvent) {
UNCOV
205
        this.navigateTo(event, Direction.NEXT, 1);
×
206
    }
207

208
    /**
209
     * @hidden
210
     */
211
    @HostListener("keydown.arrowleft", ["$event"])
212
    public onKeydownArrowLeft(event: KeyboardEvent) {
UNCOV
213
        this.navigateTo(event, Direction.PREV, 1);
×
214
    }
215

216
    /**
217
     * @hidden
218
     */
219
    @HostListener("keydown.home", ["$event"])
220
    public onKeydownHome(event: KeyboardEvent) {
UNCOV
221
        event.preventDefault();
×
UNCOV
222
        event.stopPropagation();
×
223

UNCOV
224
        this.date = this.range.at(0);
×
UNCOV
225
        this.activeDateChanged.emit(this.date);
×
226
    }
227

228
    /**
229
     * @hidden
230
     */
231
    @HostListener("keydown.end", ["$event"])
232
    public onKeydownEnd(event: KeyboardEvent) {
UNCOV
233
        event.preventDefault();
×
UNCOV
234
        event.stopPropagation();
×
235

UNCOV
236
        this.date = this.range.at(-1);
×
UNCOV
237
        this.activeDateChanged.emit(this.date);
×
238
    }
239

240
    /**
241
     * @hidden
242
     */
243
    @HostListener("keydown.enter", ["$event"])
244
    public onKeydownEnter(event: KeyboardEvent) {
UNCOV
245
        event.stopPropagation();
×
246

UNCOV
247
        this.selected.emit(this.date);
×
UNCOV
248
        this._onChangeCallback(this.date);
×
249
    }
250

251
    /**
252
     * @hidden
253
     */
254
    @HostListener("focus")
255
    protected handleFocus() {
UNCOV
256
        this.showActive = true;
×
257
    }
258

259
    /**
260
     * @hidden
261
     */
262
    @HostListener("blur")
263
    protected handleBlur() {
264
        this.showActive = false;
×
265
    }
266

267
    /**
268
     * @hidden
269
     */
270
    public selectDate(value: Date) {
UNCOV
271
        this.date = value;
×
272

UNCOV
273
        this.selected.emit(this.date);
×
UNCOV
274
        this._onChangeCallback(this.date);
×
275
    }
276

277
    /**
278
     * @hidden
279
     */
280
    public registerOnChange(fn: (v: Date) => void) {
281
        this._onChangeCallback = fn;
×
282
    }
283

284
    /**
285
     * @hidden
286
     */
287
    public registerOnTouched(fn: () => void) {
288
        this._onTouchedCallback = fn;
×
289
    }
290

291
    /**
292
     * @hidden
293
     */
294
    public writeValue(value: Date) {
295
        if (value) {
×
296
            this.date = value;
×
297
        }
298
    }
299

300
    /**
301
     * @hidden
302
     */
303
    protected navigateTo(
304
        event: KeyboardEvent,
305
        direction: Direction,
306
        delta: number,
307
    ) {
UNCOV
308
        event.preventDefault();
×
UNCOV
309
        event.stopPropagation();
×
310

UNCOV
311
        const date = getNextActiveDate(
×
312
            CalendarDay.from(this.date).add(this.dayInterval, direction * delta),
313
            [],
314
        );
315

UNCOV
316
        const outOfRange = !isDateInRanges(date, [
×
317
            {
318
                type: DateRangeType.Between,
319
                dateRange: [this.range.at(0), this.range.at(-1)],
320
            },
321
        ]);
322

UNCOV
323
        if (outOfRange) {
×
UNCOV
324
            this.pageChanged.emit(date.native);
×
325
        }
326

UNCOV
327
        this.date = date.native;
×
UNCOV
328
        this.activeDateChanged.emit(this.date);
×
329
    }
330

331
    /**
332
     * @hidden
333
     */
334
    protected abstract initFormatter(): void;
335

336
    /**
337
     * @hidden
338
     */
339
    protected abstract get range(): Date[];
340
}
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