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

atinc / ngx-tethys / 82f575a8-2f12-4689-80e6-398f6f1685a3

15 Aug 2024 08:19AM UTC coverage: 90.473%. Remained the same
82f575a8-2f12-4689-80e6-398f6f1685a3

push

circleci

web-flow
build: bump prettier to 3.3.3 and other deps, refactor notify use @if (#3152)

5502 of 6726 branches covered (81.8%)

Branch coverage included in aggregate %.

112 of 116 new or added lines in 57 files covered. (96.55%)

59 existing lines in 15 files now uncovered.

13254 of 14005 relevant lines covered (94.64%)

997.41 hits per line

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

93.0
/src/date-picker/lib/date/date-table.component.ts
1
import { TinyDate, valueFunctionProp } from 'ngx-tethys/util';
2
import { ChangeDetectionStrategy, Component, EventEmitter, OnChanges, Output } from '@angular/core';
3
import { DateHelperService } from '../../date-helper.service';
4
import { DateCell, DateBodyRow } from './types';
5
import { CalendarTable } from '../calendar/calendar-table.component';
6
import { DateTableCell } from './date-table-cell.component';
7
import { NgIf, NgFor, NgClass } from '@angular/common';
8
import { ThyDatePickerConfigService } from '../../date-picker.service';
9

10
/**
11
 * @private
12
 */
13
@Component({
1✔
14
    changeDetection: ChangeDetectionStrategy.OnPush,
15
    // eslint-disable-next-line @angular-eslint/component-selector
188✔
16
    selector: 'date-table',
188✔
17
    exportAs: 'dateTable',
188✔
18
    templateUrl: 'date-table.component.html',
188✔
19
    standalone: true,
20
    imports: [NgIf, NgFor, NgClass, DateTableCell]
21
})
22
export class DateTable extends CalendarTable implements OnChanges {
30✔
23
    @Output() readonly dayHover = new EventEmitter<TinyDate>(); // Emitted when hover on a day by mouse enter
30✔
24

25
    constructor(
26
        private dateHelper: DateHelperService,
523✔
27
        private datePickerConfigService: ThyDatePickerConfigService
523✔
28
    ) {
523✔
29
        super();
3,661✔
30
    }
3,661✔
31

3,661!
32
    private chooseDate(value: TinyDate): void {
33
        // Only change date not change time
34
        const newValue = this.activeDate.setYear(value.getYear()).setMonth(value.getMonth()).setDate(value.getDate());
35
        this.valueChange.emit(newValue);
36
    }
37

38
    makeHeadRow(): DateCell[] {
39
        const weekDays: DateCell[] = [];
523✔
40
        const start = this.activeDate.calendarStart({ weekStartsOn: this.datePickerConfigService.config.weekStartsOn });
41
        for (let colIndex = 0; colIndex < this.MAX_COL; colIndex++) {
42
            const day = start.addDays(colIndex);
3,661!
43
            weekDays[colIndex] = {
3,661✔
44
                title: this.dateHelper.format(day.nativeDate, this.dateHelper.relyOnDatePipe ? 'E' : 'ddd'),
UNCOV
45
                content: this.dateHelper.format(day.nativeDate, this.getVeryShortWeekFormat()),
×
46
                isSelected: false,
47
                isDisabled: false,
48
                onClick(): void {},
523✔
49
                onMouseEnter(): void {}
523✔
50
            };
523✔
51
        }
3,138✔
52
        return weekDays;
3,138✔
53
    }
54

55
    private getVeryShortWeekFormat(): string {
56
        if (this.dateHelper.relyOnDatePipe) {
57
            return 'EEEEE'; // eg. 二
58
        }
3,138✔
59
        return 'dd';
21,966✔
60
    }
21,966!
61

21,966✔
62
    makeBodyRows(): DateBodyRow[] {
21,966!
63
        const dateRows: DateBodyRow[] = [];
21,966✔
64
        const firstDayOfMonth = this.activeDate.calendarStart({ weekStartsOn: this.datePickerConfigService.config.weekStartsOn });
65
        for (let week = 0; week < this.MAX_ROW; week++) {
66
            const weekStart = firstDayOfMonth.addDays(week * 7);
67
            const row: DateBodyRow = {
68
                isActive: false,
69
                isCurrent: false,
70
                dateCells: [],
71
                year: weekStart.getYear()
72
            };
30✔
UNCOV
73

×
74
            for (let day = 0; day < 7; day++) {
75
                const date = weekStart.addDays(day);
21,966✔
76
                const dateFormat = this.dateHelper.relyOnDatePipe ? 'longDate' : 'YYYY-MM-DD';
21,966✔
77
                const title = this.dateHelper.format(date.nativeDate, dateFormat);
96✔
78
                const label = this.dateHelper.format(date.nativeDate, this.dateHelper.relyOnDatePipe ? 'dd' : 'DD');
79

21,966✔
80
                const cell: DateCell = {
292✔
81
                    value: date.nativeDate,
292✔
82
                    label: label,
83
                    isSelected: false,
21,966✔
84
                    isDisabled: false,
4,074✔
85
                    isToday: false,
4,074✔
86
                    title: title,
54✔
87
                    dateCellRender: valueFunctionProp(this.cellRender, date),
88
                    content: `${date.getDate()}`,
4,074✔
89
                    onClick: () => this.chooseDate(date),
35✔
90
                    onMouseEnter: () => this.dayHover.emit(date)
91
                };
92
                this.addCellProperty(cell, date);
17,892✔
93

126✔
94
                if (this.showWeek && !row.weekNum) {
95
                    row.weekNum = this.dateHelper.getISOWeek(date.nativeDate);
21,966✔
96
                }
97

3,138✔
98
                if (date.isToday()) {
99
                    cell.isToday = true;
100
                    row.isCurrent = true;
101
                }
3,138✔
102

103
                if (this.selectedValue?.length > 0) {
523✔
104
                    const [startSelected, endSelected] = this.selectedValue;
105
                    if (date.isSameDay(startSelected)) {
106
                        row.isActive = true;
21,966✔
107
                    }
4,074✔
108
                    if (date.isSameDay(endSelected)) {
4,074✔
109
                        row.isActive = true;
54✔
110
                    }
111
                } else if (date.isSameDay(this.value)) {
4,074✔
112
                    row.isActive = true;
35✔
113
                }
114

4,074✔
115
                row.dateCells.push(cell);
4,074!
116
            }
4,074✔
117

118
            row.classMap = {
119
                [`${this.prefixCls}-current-week`]: row.isCurrent,
17,892✔
120
                [`${this.prefixCls}-active-week`]: row.isActive
121
            };
21,966✔
122

21,966✔
123
            dateRows.push(row);
21,966✔
124
        }
21,966✔
125

21,966✔
126
        return dateRows;
127
    }
128

21,966✔
129
    addCellProperty(cell: DateCell, date: TinyDate): void {
130
        if (this.selectedValue?.length > 0) {
131
            const [startSelected, endSelected] = this.selectedValue;
132
            if (startSelected?.isSameDay(date)) {
133
                cell.isSelected = true;
134
            }
135
            if (endSelected?.isSameDay(date)) {
136
                cell.isSelected = true;
137
            }
138
            cell.isStartSingle = startSelected && !endSelected;
139
            cell.isEndSingle = !startSelected && !!endSelected;
140
            cell.isInRange = startSelected?.isBeforeDay(date) && date.isBeforeDay(endSelected);
1✔
141
        } else {
142
            cell.isSelected = date.isSameDay(this.value);
143
        }
144
        cell.isLastMonthCell = date.isBeforeMonth(this.activeDate);
1✔
145
        cell.isNextMonthCell = date.isAfterMonth(this.activeDate);
146
        cell.isToday = date.isToday();
147
        cell.isDisabled = !!this.disabledDate?.(date.nativeDate);
148
        cell.classMap = this.getClassMap(cell);
1✔
149
    }
150

151
    getClassMap(cell: DateCell): { [key: string]: boolean } {
152
        return {
153
            [`${this.prefixCls}-cell`]: true,
154
            [`${this.prefixCls}-today`]: cell.isToday,
155
            [`${this.prefixCls}-last-month-cell`]: cell.isLastMonthCell,
156
            [`${this.prefixCls}-next-month-btn-day`]: cell.isNextMonthCell,
157
            [`${this.prefixCls}-selected-day`]: cell.isSelected,
158
            [`${this.prefixCls}-disabled-cell`]: cell.isDisabled,
159
            [`${this.prefixCls}-selected-start-date`]: !!cell.isSelectedStartDate,
160
            [`${this.prefixCls}-selected-end-date`]: !!cell.isSelectedEndDate,
161
            [`${this.prefixCls}-in-range-cell`]: !!cell.isInRange
162
        };
163
    }
164
}
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

© 2026 Coveralls, Inc