|
|
@@ -1,5 +1,6 @@
|
|
1
|
1
|
import { Component } from '@angular/core';
|
|
2
|
|
-import { RouterLink } from '@angular/router';
|
|
|
2
|
+import { Router, RouterLink } from '@angular/router';
|
|
|
3
|
+import { FormsModule } from '@angular/forms';
|
|
3
|
4
|
import { KakochoService } from '../../services/kakocho-service';
|
|
4
|
5
|
import { DankaService } from '../../services/dankaService';
|
|
5
|
6
|
import { Danka } from '../../models/danka';
|
|
|
@@ -25,11 +26,13 @@ interface RecentDanka {
|
|
25
|
26
|
|
|
26
|
27
|
@Component({
|
|
27
|
28
|
selector: 'app-dashboard',
|
|
28
|
|
- imports: [AppHeader, AppSideMenu, RouterLink],
|
|
|
29
|
+ imports: [AppHeader, AppSideMenu, RouterLink, FormsModule],
|
|
29
|
30
|
templateUrl: './dashboard.html',
|
|
30
|
31
|
styleUrl: './dashboard.scss',
|
|
31
|
32
|
})
|
|
32
|
33
|
export class Dashboard {
|
|
|
34
|
+ searchKeyword = '';
|
|
|
35
|
+ todayLabel = this.formatTodayLabel(new Date());
|
|
33
|
36
|
weeklyMemorialCount = 0;
|
|
34
|
37
|
todayMemorialCount = 0;
|
|
35
|
38
|
upcomingWeeklyMemorialCount = 0;
|
|
|
@@ -42,6 +45,7 @@ export class Dashboard {
|
|
42
|
45
|
constructor(
|
|
43
|
46
|
private kakochoService: KakochoService,
|
|
44
|
47
|
private dankaService: DankaService,
|
|
|
48
|
+ private router: Router,
|
|
45
|
49
|
) {
|
|
46
|
50
|
this.setWeeklyMemorialSummary();
|
|
47
|
51
|
this.setMonthlyMemorialSummary();
|
|
|
@@ -49,6 +53,14 @@ export class Dashboard {
|
|
49
|
53
|
this.setUpcomingMemorials();
|
|
50
|
54
|
}
|
|
51
|
55
|
|
|
|
56
|
+ searchAll(): void {
|
|
|
57
|
+ const keyword = this.searchKeyword.trim();
|
|
|
58
|
+
|
|
|
59
|
+ this.router.navigate(['/search'], {
|
|
|
60
|
+ queryParams: keyword ? { keyword } : undefined,
|
|
|
61
|
+ });
|
|
|
62
|
+ }
|
|
|
63
|
+
|
|
52
|
64
|
private async setRecentDankaList(): Promise<void> {
|
|
53
|
65
|
const dankaList = await this.dankaService.getRecentDankaList(5);
|
|
54
|
66
|
|
|
|
@@ -104,9 +116,10 @@ export class Dashboard {
|
|
104
|
116
|
const today = this.toDateOnly(new Date());
|
|
105
|
117
|
const endDate = this.addDays(today, 30);
|
|
106
|
118
|
|
|
107
|
|
- this.upcomingMemorials = (await this.kakochoService
|
|
108
|
|
- .getKakochoList())
|
|
109
|
|
- .map((kakocho): UpcomingMemorial | null => {
|
|
|
119
|
+ const upcomingMemorials = await Promise.all(
|
|
|
120
|
+ (await this.kakochoService
|
|
|
121
|
+ .getKakochoList())
|
|
|
122
|
+ .map(async (kakocho): Promise<UpcomingMemorial | null> => {
|
|
110
|
123
|
const deathDate = this.parseDate(kakocho.deathDate);
|
|
111
|
124
|
if (!deathDate) {
|
|
112
|
125
|
return null;
|
|
|
@@ -118,7 +131,7 @@ export class Dashboard {
|
|
118
|
131
|
}
|
|
119
|
132
|
|
|
120
|
133
|
const memorialType = this.getMemorialType(deathDate);
|
|
121
|
|
- const danka = this.dankaService.getDankaById(kakocho.dankaId);
|
|
|
134
|
+ const danka = await this.dankaService.getDankaById(kakocho.dankaId);
|
|
122
|
135
|
const type = memorialType ? '年忌法要' : '命日';
|
|
123
|
136
|
const status = memorialType ? '準備確認' : '要確認';
|
|
124
|
137
|
|
|
|
@@ -132,7 +145,10 @@ export class Dashboard {
|
|
132
|
145
|
type,
|
|
133
|
146
|
status,
|
|
134
|
147
|
};
|
|
135
|
|
- })
|
|
|
148
|
+ }),
|
|
|
149
|
+ );
|
|
|
150
|
+
|
|
|
151
|
+ this.upcomingMemorials = upcomingMemorials
|
|
136
|
152
|
.filter((memorial): memorial is UpcomingMemorial => memorial !== null)
|
|
137
|
153
|
.sort((a, b) => a.date.getTime() - b.date.getTime() || a.title.localeCompare(b.title, 'ja'))
|
|
138
|
154
|
.slice(0, 3);
|
|
|
@@ -219,6 +235,11 @@ export class Dashboard {
|
|
219
|
235
|
return `${updatedDate.getMonth() + 1}月${updatedDate.getDate()}日`;
|
|
220
|
236
|
}
|
|
221
|
237
|
|
|
|
238
|
+ private formatTodayLabel(date: Date): string {
|
|
|
239
|
+ const weekdays = ['日曜日', '月曜日', '火曜日', '水曜日', '木曜日', '金曜日', '土曜日'];
|
|
|
240
|
+ return `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日 ${weekdays[date.getDay()]}`;
|
|
|
241
|
+ }
|
|
|
242
|
+
|
|
222
|
243
|
private getWeekStart(date: Date): Date {
|
|
223
|
244
|
const day = date.getDay();
|
|
224
|
245
|
const diff = day === 0 ? -6 : 1 - day;
|