|
|
@@ -1,4 +1,5 @@
|
|
1
|
|
-import { Component, OnInit } from '@angular/core';
|
|
|
1
|
+import { ChangeDetectorRef, Component, OnInit, computed } from '@angular/core';
|
|
|
2
|
+import { toSignal } from '@angular/core/rxjs-interop';
|
|
2
|
3
|
import { RouterLink } from '@angular/router';
|
|
3
|
4
|
import { DankaService } from '../../services/dankaService';
|
|
4
|
5
|
import { FamilyService } from '../../services/family-service';
|
|
|
@@ -7,18 +8,7 @@ import { AppSideMenu } from '../../share/side-menu/app-side-menu';
|
|
7
|
8
|
import { Danka } from '../../models/danka';
|
|
8
|
9
|
import { FormsModule } from '@angular/forms';
|
|
9
|
10
|
|
|
10
|
|
-type KanaRowValue =
|
|
11
|
|
- | 'all'
|
|
12
|
|
- | 'a'
|
|
13
|
|
- | 'ka'
|
|
14
|
|
- | 'sa'
|
|
15
|
|
- | 'ta'
|
|
16
|
|
- | 'na'
|
|
17
|
|
- | 'ha'
|
|
18
|
|
- | 'ma'
|
|
19
|
|
- | 'ya'
|
|
20
|
|
- | 'ra'
|
|
21
|
|
- | 'wa';
|
|
|
11
|
+type KanaRowValue = 'all' | 'a' | 'ka' | 'sa' | 'ta' | 'na' | 'ha' | 'ma' | 'ya' | 'ra' | 'wa';
|
|
22
|
12
|
|
|
23
|
13
|
@Component({
|
|
24
|
14
|
selector: 'app-danka-list',
|
|
|
@@ -49,21 +39,116 @@ export class DankaList implements OnInit {
|
|
49
|
39
|
];
|
|
50
|
40
|
|
|
51
|
41
|
private readonly kanaRowMap: Record<Exclude<KanaRowValue, 'all'>, string[]> = {
|
|
52
|
|
- a: ['あ','い','う','え','お','ア','イ','ウ','エ','オ'],
|
|
53
|
|
- ka: ['か','き','く','け','こ','が','ぎ','ぐ','げ','ご','カ','キ','ク','ケ','コ','ガ','ギ','グ','ゲ','ゴ'],
|
|
54
|
|
- sa: ['さ','し','す','せ','そ','ざ','じ','ず','ぜ','ぞ','サ','シ','ス','セ','ソ','ザ','ジ','ズ','ゼ','ゾ'],
|
|
55
|
|
- ta: ['た','ち','つ','て','と','だ','ぢ','づ','で','ど','タ','チ','ツ','テ','ト','ダ','ヂ','ヅ','デ','ド'],
|
|
56
|
|
- na: ['な','に','ぬ','ね','の','ナ','ニ','ヌ','ネ','ノ'],
|
|
57
|
|
- ha: ['は','ひ','ふ','へ','ほ','ば','び','ぶ','べ','ぼ','ぱ','ぴ','ぷ','ぺ','ぽ','ハ','ヒ','フ','ヘ','ホ','バ','ビ','ブ','ベ','ボ','パ','ピ','プ','ペ','ポ'],
|
|
58
|
|
- ma: ['ま','み','む','め','も','マ','ミ','ム','メ','モ'],
|
|
59
|
|
- ya: ['や','ゆ','よ','ヤ','ユ','ヨ'],
|
|
60
|
|
- ra: ['ら','り','る','れ','ろ','ラ','リ','ル','レ','ロ'],
|
|
61
|
|
- wa: ['わ','を','ん','ワ','ヲ','ン'],
|
|
|
42
|
+ a: ['あ', 'い', 'う', 'え', 'お', 'ア', 'イ', 'ウ', 'エ', 'オ'],
|
|
|
43
|
+ ka: [
|
|
|
44
|
+ 'か',
|
|
|
45
|
+ 'き',
|
|
|
46
|
+ 'く',
|
|
|
47
|
+ 'け',
|
|
|
48
|
+ 'こ',
|
|
|
49
|
+ 'が',
|
|
|
50
|
+ 'ぎ',
|
|
|
51
|
+ 'ぐ',
|
|
|
52
|
+ 'げ',
|
|
|
53
|
+ 'ご',
|
|
|
54
|
+ 'カ',
|
|
|
55
|
+ 'キ',
|
|
|
56
|
+ 'ク',
|
|
|
57
|
+ 'ケ',
|
|
|
58
|
+ 'コ',
|
|
|
59
|
+ 'ガ',
|
|
|
60
|
+ 'ギ',
|
|
|
61
|
+ 'グ',
|
|
|
62
|
+ 'ゲ',
|
|
|
63
|
+ 'ゴ',
|
|
|
64
|
+ ],
|
|
|
65
|
+ sa: [
|
|
|
66
|
+ 'さ',
|
|
|
67
|
+ 'し',
|
|
|
68
|
+ 'す',
|
|
|
69
|
+ 'せ',
|
|
|
70
|
+ 'そ',
|
|
|
71
|
+ 'ざ',
|
|
|
72
|
+ 'じ',
|
|
|
73
|
+ 'ず',
|
|
|
74
|
+ 'ぜ',
|
|
|
75
|
+ 'ぞ',
|
|
|
76
|
+ 'サ',
|
|
|
77
|
+ 'シ',
|
|
|
78
|
+ 'ス',
|
|
|
79
|
+ 'セ',
|
|
|
80
|
+ 'ソ',
|
|
|
81
|
+ 'ザ',
|
|
|
82
|
+ 'ジ',
|
|
|
83
|
+ 'ズ',
|
|
|
84
|
+ 'ゼ',
|
|
|
85
|
+ 'ゾ',
|
|
|
86
|
+ ],
|
|
|
87
|
+ ta: [
|
|
|
88
|
+ 'た',
|
|
|
89
|
+ 'ち',
|
|
|
90
|
+ 'つ',
|
|
|
91
|
+ 'て',
|
|
|
92
|
+ 'と',
|
|
|
93
|
+ 'だ',
|
|
|
94
|
+ 'ぢ',
|
|
|
95
|
+ 'づ',
|
|
|
96
|
+ 'で',
|
|
|
97
|
+ 'ど',
|
|
|
98
|
+ 'タ',
|
|
|
99
|
+ 'チ',
|
|
|
100
|
+ 'ツ',
|
|
|
101
|
+ 'テ',
|
|
|
102
|
+ 'ト',
|
|
|
103
|
+ 'ダ',
|
|
|
104
|
+ 'ヂ',
|
|
|
105
|
+ 'ヅ',
|
|
|
106
|
+ 'デ',
|
|
|
107
|
+ 'ド',
|
|
|
108
|
+ ],
|
|
|
109
|
+ na: ['な', 'に', 'にょ', 'ぬ', 'ね', 'の', 'ナ', 'ニ', 'ニョ', 'ヌ', 'ネ', 'ノ'],
|
|
|
110
|
+ ha: [
|
|
|
111
|
+ 'は',
|
|
|
112
|
+ 'ひ',
|
|
|
113
|
+ 'ふ',
|
|
|
114
|
+ 'へ',
|
|
|
115
|
+ 'ほ',
|
|
|
116
|
+ 'ば',
|
|
|
117
|
+ 'び',
|
|
|
118
|
+ 'ぶ',
|
|
|
119
|
+ 'べ',
|
|
|
120
|
+ 'ぼ',
|
|
|
121
|
+ 'ぱ',
|
|
|
122
|
+ 'ぴ',
|
|
|
123
|
+ 'ぷ',
|
|
|
124
|
+ 'ぺ',
|
|
|
125
|
+ 'ぽ',
|
|
|
126
|
+ 'ハ',
|
|
|
127
|
+ 'ヒ',
|
|
|
128
|
+ 'フ',
|
|
|
129
|
+ 'ヘ',
|
|
|
130
|
+ 'ホ',
|
|
|
131
|
+ 'バ',
|
|
|
132
|
+ 'ビ',
|
|
|
133
|
+ 'ブ',
|
|
|
134
|
+ 'ベ',
|
|
|
135
|
+ 'ボ',
|
|
|
136
|
+ 'パ',
|
|
|
137
|
+ 'ピ',
|
|
|
138
|
+ 'プ',
|
|
|
139
|
+ 'ペ',
|
|
|
140
|
+ 'ポ',
|
|
|
141
|
+ ],
|
|
|
142
|
+ ma: ['ま', 'み', 'む', 'め', 'も', 'マ', 'ミ', 'ム', 'メ', 'モ'],
|
|
|
143
|
+ ya: ['や', 'ゆ', 'よ', 'ヤ', 'ユ', 'ヨ'],
|
|
|
144
|
+ ra: ['ら', 'り', 'る', 'れ', 'ろ', 'ラ', 'リ', 'ル', 'レ', 'ロ'],
|
|
|
145
|
+ wa: ['わ', 'を', 'ん', 'ワ', 'ヲ', 'ン'],
|
|
62
|
146
|
};
|
|
63
|
147
|
|
|
64
|
148
|
constructor(
|
|
65
|
149
|
private dankaService: DankaService,
|
|
66
|
150
|
private familyService: FamilyService,
|
|
|
151
|
+ private cdr: ChangeDetectorRef,
|
|
67
|
152
|
) {}
|
|
68
|
153
|
|
|
69
|
154
|
// 非同期初期化
|
|
|
@@ -74,6 +159,7 @@ export class DankaList implements OnInit {
|
|
74
|
159
|
async init(): Promise<void> {
|
|
75
|
160
|
this.dankaList = await this.dankaService.getDankaList();
|
|
76
|
161
|
this.showAllDanka();
|
|
|
162
|
+ this.cdr.detectChanges();
|
|
77
|
163
|
}
|
|
78
|
164
|
|
|
79
|
165
|
showAllDanka() {
|
|
|
@@ -89,7 +175,7 @@ export class DankaList implements OnInit {
|
|
89
|
175
|
this.selectedKanaRow = 'all';
|
|
90
|
176
|
|
|
91
|
177
|
this.filterDankaList = this.dankaList.filter((danka) =>
|
|
92
|
|
- danka.phones.some((phone) => phone.tel.trim() !== '')
|
|
|
178
|
+ danka.phones.some((phone) => phone.tel.trim() !== ''),
|
|
93
|
179
|
);
|
|
94
|
180
|
|
|
95
|
181
|
this.dankaDisplay = this.filterDankaList.length;
|
|
|
@@ -106,20 +192,21 @@ export class DankaList implements OnInit {
|
|
106
|
192
|
return;
|
|
107
|
193
|
}
|
|
108
|
194
|
|
|
109
|
|
- this.filterDankaList = this.dankaList.filter((danka) =>
|
|
110
|
|
- danka.householdName.includes(keyword) ||
|
|
111
|
|
- danka.householdFurigana.includes(keyword) ||
|
|
112
|
|
- danka.householder.includes(keyword) ||
|
|
113
|
|
- danka.householderFurigana.includes(keyword) ||
|
|
114
|
|
- danka.postalCode.includes(keyword) ||
|
|
115
|
|
- danka.address.includes(keyword) ||
|
|
116
|
|
- danka.phones.some((p) => p.tel.includes(keyword) || p.note.includes(keyword))
|
|
|
195
|
+ this.filterDankaList = this.dankaList.filter(
|
|
|
196
|
+ (danka) =>
|
|
|
197
|
+ danka.householdName.includes(keyword) ||
|
|
|
198
|
+ danka.householdFurigana.includes(keyword) ||
|
|
|
199
|
+ danka.householder.includes(keyword) ||
|
|
|
200
|
+ danka.householderFurigana.includes(keyword) ||
|
|
|
201
|
+ danka.postalCode.includes(keyword) ||
|
|
|
202
|
+ danka.address.includes(keyword) ||
|
|
|
203
|
+ danka.phones.some((p) => p.tel.includes(keyword) || p.note.includes(keyword)),
|
|
117
|
204
|
);
|
|
118
|
205
|
|
|
119
|
206
|
this.dankaDisplay = this.filterDankaList.length;
|
|
120
|
207
|
}
|
|
121
|
208
|
|
|
122
|
|
- filterByKanaRow(row: KanaRowValue): void {
|
|
|
209
|
+ async filterByKanaRow(row: KanaRowValue): Promise<void> {
|
|
123
|
210
|
this.selectedFilter = 'kana';
|
|
124
|
211
|
this.selectedKanaRow = row;
|
|
125
|
212
|
this.searchKeyword = '';
|
|
|
@@ -129,12 +216,22 @@ export class DankaList implements OnInit {
|
|
129
|
216
|
return;
|
|
130
|
217
|
}
|
|
131
|
218
|
|
|
132
|
|
- this.filterDankaList = this.dankaList.filter(async (danka) => {
|
|
133
|
|
- const firstKana = (await this.getDankaSortText(danka)).charAt(0);
|
|
134
|
|
- return this.kanaRowMap[row].includes(firstKana);
|
|
135
|
|
- });
|
|
|
219
|
+ const filterResults = await Promise.all(
|
|
|
220
|
+ this.dankaList.map(async (danka) => {
|
|
|
221
|
+ const firstKana = (await this.getDankaSortText(danka)).charAt(0);
|
|
|
222
|
+ return {
|
|
|
223
|
+ danka,
|
|
|
224
|
+ isMatch: this.kanaRowMap[row].includes(firstKana),
|
|
|
225
|
+ };
|
|
|
226
|
+ }),
|
|
|
227
|
+ );
|
|
|
228
|
+
|
|
|
229
|
+ this.filterDankaList = filterResults
|
|
|
230
|
+ .filter((result) => result.isMatch)
|
|
|
231
|
+ .map((result) => result.danka);
|
|
136
|
232
|
|
|
137
|
233
|
this.dankaDisplay = this.filterDankaList.length;
|
|
|
234
|
+ this.cdr.detectChanges();
|
|
138
|
235
|
}
|
|
139
|
236
|
|
|
140
|
237
|
clearDanka() {
|
|
|
@@ -147,15 +244,13 @@ export class DankaList implements OnInit {
|
|
147
|
244
|
|
|
148
|
245
|
private async getDankaSortText(danka: Danka): Promise<string> {
|
|
149
|
246
|
const householderName = this.normalizeName(danka.householder);
|
|
150
|
|
-
|
|
151
|
|
- const householderFamily = (await this.familyService
|
|
152
|
|
- .getFamiliesByDankaId(danka.id))
|
|
153
|
|
- .find((f) => this.normalizeName(f.name) === householderName);
|
|
154
|
|
-
|
|
|
247
|
+ const householderFamily = (await this.familyService.getFamiliesByDankaId(danka.id)).find(
|
|
|
248
|
+ (f) => this.normalizeName(f.name) === householderName,
|
|
|
249
|
+ );
|
|
155
|
250
|
return (householderFamily?.furigana || danka.householder).trim();
|
|
156
|
251
|
}
|
|
157
|
252
|
|
|
158
|
253
|
private normalizeName(name: string): string {
|
|
159
|
254
|
return name.replace(/\s/g, '');
|
|
160
|
255
|
}
|
|
161
|
|
-}
|
|
|
256
|
+}
|