Skip to content

Commit 746cd12

Browse files
authored
Merge pull request #73 from nsnayp13/cursor/bc-c4f07c99-6d42-4fcf-8952-7e24b493c251-b3b4
Исправить отображение предыдущих дней в режиме одного месяца
2 parents 7bc5801 + ac70a86 commit 746cd12

4 files changed

Lines changed: 40 additions & 5 deletions

File tree

projects/angular-datepicker2/src/lib/_service/calendar.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ export class CalendarService {
8080
this.showPrevNextDaysInOneMonth = showPrevNextDaysInOneMonth;
8181
// Trigger calendar recalculation
8282
this.getShownMonths(this.shownDate);
83+
// Notify components about the change
84+
this.updateDate.next(new Date());
8385
}
8486
}
8587

@@ -173,6 +175,8 @@ export class CalendarService {
173175

174176
this.calendar = months;
175177
this.viewSelectorMode = "days";
178+
// Notify components about the change
179+
this.updateDate.next(new Date());
176180
}
177181

178182
goPrev(firstDate: Date) {

projects/angular-datepicker2/src/lib/month-view/month-view.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ export class MonthViewComponent implements OnInit, OnDestroy {
6161
})
6262
);
6363

64+
// Subscribe to calendar updates to recalculate weeks when showPrevNextDaysInOneMonth changes
65+
this.sub.add(
66+
this.calendarService.updateDate.subscribe(() => {
67+
this.recalculateWeeks();
68+
})
69+
);
70+
6471
this.recalculateWeeks();
6572
}
6673

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div *ngFor="let date of dates" class="f1">
2-
<app-day-view *ngIf="date" [dayDirective]="getDayDirective(date)!" [date]="date"
2+
<app-day-view *ngIf="date && (date.getMonth()===firstMonthDate.getMonth()&&date.getFullYear()===firstMonthDate.getFullYear() || shouldShowPrevNextDays())" [dayDirective]="getDayDirective(date)!" [date]="date"
33
[thisMonth]="date.getMonth()===firstMonthDate.getMonth()&&date.getFullYear()===firstMonthDate.getFullYear()"
4-
[isPrevNextMonth]="date.getMonth()!==firstMonthDate.getMonth()||date.getFullYear()!==firstMonthDate.getFullYear()">
4+
[isPrevNextMonth]="shouldShowPrevNextDays() && (date.getMonth()!==firstMonthDate.getMonth()||date.getFullYear()!==firstMonthDate.getFullYear())">
55
</app-day-view>
66
</div>

projects/angular-datepicker2/src/lib/week-view/week-view.component.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { Component, OnInit, Input } from "@angular/core";
1+
import { Component, OnInit, Input, OnDestroy, ChangeDetectorRef } from "@angular/core";
22
import { CommonModule } from "@angular/common";
33
import { DayDirective } from "../day.directive";
44
import { WeekService } from "../_service/week.service";
55
import { DayViewComponent } from "../day-view/day-view.component";
66
import { DateUtils } from "../_utils/date.utils";
7+
import { CalendarService } from "../_service/calendar.service";
8+
import { Subscription } from "rxjs";
79

810
@Component({
911
selector: "app-week-view",
@@ -13,15 +15,32 @@ import { DateUtils } from "../_utils/date.utils";
1315
styleUrls: ["./week-view.component.scss"],
1416
providers: [WeekService],
1517
})
16-
export class WeekViewComponent implements OnInit {
18+
export class WeekViewComponent implements OnInit, OnDestroy {
1719
@Input() date!: Date;
1820
@Input() firstMonthDate!: Date;
1921
@Input() dayDirectives!: DayDirective[];
2022
dates: (Date | null)[] = [];
21-
constructor(private weekService: WeekService) {}
23+
private subscriptions = new Subscription();
24+
25+
constructor(
26+
private weekService: WeekService,
27+
private calendarService: CalendarService,
28+
private cdr: ChangeDetectorRef
29+
) {}
2230

2331
ngOnInit() {
2432
this.dates = this.weekService.getWeek(this.date);
33+
34+
// Subscribe to calendar updates to trigger change detection
35+
this.subscriptions.add(
36+
this.calendarService.updateDate.subscribe(() => {
37+
this.cdr.detectChanges();
38+
})
39+
);
40+
}
41+
42+
ngOnDestroy() {
43+
this.subscriptions.unsubscribe();
2544
}
2645

2746
getDayDirective(date: Date | null): DayDirective | undefined {
@@ -31,4 +50,9 @@ export class WeekViewComponent implements OnInit {
3150
);
3251
return day;
3352
}
53+
54+
shouldShowPrevNextDays(): boolean {
55+
return this.calendarService.showPrevNextDaysInOneMonth &&
56+
this.calendarService.getCountMonths() === 1;
57+
}
3458
}

0 commit comments

Comments
 (0)