• 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

4.0
/projects/igniteui-angular/src/lib/calendar/years-view/years-view.component.ts
1
import {
2
    Component,
3
    Input,
4
    HostBinding,
5
    ElementRef,
6
    Inject,
7
} from "@angular/core";
8
import { IgxCalendarYearDirective } from "../calendar.directives";
9
import { NgFor } from "@angular/common";
10
import {
11
    IgxCalendarViewDirective,
12
    DAY_INTERVAL_TOKEN,
13
} from "../common/calendar-view.directive";
14
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from "@angular/forms";
15
import { CalendarDay } from "../common/model";
16
import type { DayInterval } from "../common/model";
17
import { calendarRange } from "../common/helpers";
18

19
@Component({
20
    providers: [
21
        {
22
            provide: NG_VALUE_ACCESSOR,
23
            useExisting: IgxYearsViewComponent,
24
            multi: true,
25
        },
26
        {
27
            provide: DAY_INTERVAL_TOKEN,
28
            useValue: "year",
29
        },
30
    ],
31
    selector: "igx-years-view",
32
    templateUrl: "years-view.component.html",
33
    imports: [NgFor, IgxCalendarYearDirective]
34
})
35
export class IgxYearsViewComponent extends IgxCalendarViewDirective implements ControlValueAccessor {
2✔
UNCOV
36
    #standalone = true;
×
37

38
    /**
39
     * The default css class applied to the component.
40
     *
41
     * @hidden
42
     */
43
    @HostBinding("class.igx-calendar-view")
UNCOV
44
    public readonly viewClass = true;
×
45

46
    /**
47
     * @hidden @internal
48
     */
49
    @Input()
50
        @HostBinding('class.igx-calendar-view--standalone')
51
        public get standalone() {
UNCOV
52
        return this.#standalone;
×
53
    }
54

55
        public set standalone(value: boolean) {
UNCOV
56
        this.#standalone = value;
×
57
    }
58

59
    /**
60
     * @hidden
61
     */
UNCOV
62
    private _yearFormat = "numeric";
×
63

64
    /**
65
     * @hidden
66
     */
UNCOV
67
    private _yearsPerPage = 15;
×
68

69
    /**
70
     * Gets the year format option of the years view.
71
     * ```typescript
72
     * let yearFormat = this.yearsView.yearFormat.
73
     * ```
74
     */
75
    @Input()
76
    public get yearFormat(): any {
UNCOV
77
        return this._yearFormat;
×
78
    }
79

80
    /**
81
     * Sets the year format option of the years view.
82
     * ```html
83
     * <igx-years-view [yearFormat]="numeric"></igx-years-view>
84
     * ```
85
     *
86
     * @memberof IgxYearsViewComponent
87
     */
88
    public set yearFormat(value: any) {
UNCOV
89
        this._yearFormat = value;
×
UNCOV
90
        this.initFormatter();
×
91
    }
92

93
    /**
94
     * Returns an array of date objects which are then used to properly
95
     * render the years.
96
     *
97
     * Used in the template of the component.
98
     *
99
     * @hidden @internal
100
     */
101
    public get range(): Date[] {
UNCOV
102
        const year = this.date.getFullYear();
×
UNCOV
103
        const start = new CalendarDay({
×
104
            year: Math.floor(year / this._yearsPerPage) * this._yearsPerPage,
105
            month: this.date.getMonth(),
106
        });
UNCOV
107
        const end = start.add(this.dayInterval, this._yearsPerPage);
×
108

UNCOV
109
        return Array.from(calendarRange({ start, end, unit: this.dayInterval })).map(
×
UNCOV
110
            (m) => m.native,
×
111
        );
112
    }
113

114
    constructor(
UNCOV
115
        public el: ElementRef,
×
116
        @Inject(DAY_INTERVAL_TOKEN) dayInterval: DayInterval,
117
    ) {
UNCOV
118
        super(dayInterval);
×
119
    }
120

121
    /**
122
     * Returns the locale representation of the year in the years view.
123
     *
124
     * @hidden
125
     */
126
    public formattedYear(value: Date): {long: string, formatted: string} {
UNCOV
127
        const rawFormatter = new Intl.DateTimeFormat(this.locale, { year: 'numeric' });
×
128

UNCOV
129
        if (this.formatView) {
×
UNCOV
130
            return {
×
131
                long: rawFormatter.format(value),
132
                formatted: this._formatter.format(value)
133
            }
134
        }
135

UNCOV
136
        return {
×
137
            long: rawFormatter.format(value),
138
            formatted: `${value.getFullYear()}`
139
        }
140
    }
141

142
    /**
143
     * @hidden
144
     */
145
    public yearTracker(_: number, item: Date): string {
UNCOV
146
        return `${item.getFullYear()}}`;
×
147
    }
148

149
    /**
150
     * @hidden
151
     */
152
    protected initFormatter() {
UNCOV
153
        this._formatter = new Intl.DateTimeFormat(this._locale, {
×
154
            year: this.yearFormat,
155
        });
156
    }
157

158
    /**
159
     * @hidden
160
     */
161
    protected onMouseDown() {
UNCOV
162
        if (this.tabIndex !== -1) {
×
163
            this.el.nativeElement.focus();
×
164
        }
165
    }
166
}
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