Ver código fonte

[fix]

檀家一覧表の初期表示を修正
・かな検索機能のfilterの非同期処理を修正
poohr 1 semana atrás
pai
commit
01b43ea70d
1 arquivos alterados com 133 adições e 41 exclusões
  1. 133
    41
      src/app/pages/danka-list/danka-list.ts

+ 133
- 41
src/app/pages/danka-list/danka-list.ts Ver arquivo

@@ -8,18 +8,7 @@ import { AppSideMenu } from '../../share/side-menu/app-side-menu';
8 8
 import { Danka } from '../../models/danka';
9 9
 import { FormsModule } from '@angular/forms';
10 10
 
11
-type KanaRowValue =
12
-  | 'all'
13
-  | 'a'
14
-  | 'ka'
15
-  | 'sa'
16
-  | 'ta'
17
-  | 'na'
18
-  | 'ha'
19
-  | 'ma'
20
-  | 'ya'
21
-  | 'ra'
22
-  | 'wa';
11
+type KanaRowValue = 'all' | 'a' | 'ka' | 'sa' | 'ta' | 'na' | 'ha' | 'ma' | 'ya' | 'ra' | 'wa';
23 12
 
24 13
 @Component({
25 14
   selector: 'app-danka-list',
@@ -50,16 +39,110 @@ export class DankaList implements OnInit {
50 39
   ];
51 40
 
52 41
   private readonly kanaRowMap: Record<Exclude<KanaRowValue, 'all'>, string[]> = {
53
-    a: ['あ','い','う','え','お','ア','イ','ウ','エ','オ'],
54
-    ka: ['か','き','く','け','こ','が','ぎ','ぐ','げ','ご','カ','キ','ク','ケ','コ','ガ','ギ','グ','ゲ','ゴ'],
55
-    sa: ['さ','し','す','せ','そ','ざ','じ','ず','ぜ','ぞ','サ','シ','ス','セ','ソ','ザ','ジ','ズ','ゼ','ゾ'],
56
-    ta: ['た','ち','つ','て','と','だ','ぢ','づ','で','ど','タ','チ','ツ','テ','ト','ダ','ヂ','ヅ','デ','ド'],
57
-    na: ['な','に','ぬ','ね','の','ナ','ニ','ヌ','ネ','ノ'],
58
-    ha: ['は','ひ','ふ','へ','ほ','ば','び','ぶ','べ','ぼ','ぱ','ぴ','ぷ','ぺ','ぽ','ハ','ヒ','フ','ヘ','ホ','バ','ビ','ブ','ベ','ボ','パ','ピ','プ','ペ','ポ'],
59
-    ma: ['ま','み','む','め','も','マ','ミ','ム','メ','モ'],
60
-    ya: ['や','ゆ','よ','ヤ','ユ','ヨ'],
61
-    ra: ['ら','り','る','れ','ろ','ラ','リ','ル','レ','ロ'],
62
-    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: ['わ', 'を', 'ん', 'ワ', 'ヲ', 'ン'],
63 146
   };
64 147
 
65 148
   constructor(
@@ -92,7 +175,7 @@ export class DankaList implements OnInit {
92 175
     this.selectedKanaRow = 'all';
93 176
 
94 177
     this.filterDankaList = this.dankaList.filter((danka) =>
95
-      danka.phones.some((phone) => phone.tel.trim() !== '')
178
+      danka.phones.some((phone) => phone.tel.trim() !== ''),
96 179
     );
97 180
 
98 181
     this.dankaDisplay = this.filterDankaList.length;
@@ -109,20 +192,21 @@ export class DankaList implements OnInit {
109 192
       return;
110 193
     }
111 194
 
112
-    this.filterDankaList = this.dankaList.filter((danka) =>
113
-      danka.householdName.includes(keyword) ||
114
-      danka.householdFurigana.includes(keyword) ||
115
-      danka.householder.includes(keyword) ||
116
-      danka.householderFurigana.includes(keyword) ||
117
-      danka.postalCode.includes(keyword) ||
118
-      danka.address.includes(keyword) ||
119
-      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)),
120 204
     );
121 205
 
122 206
     this.dankaDisplay = this.filterDankaList.length;
123 207
   }
124 208
 
125
-  filterByKanaRow(row: KanaRowValue): void {
209
+  async filterByKanaRow(row: KanaRowValue): Promise<void> {
126 210
     this.selectedFilter = 'kana';
127 211
     this.selectedKanaRow = row;
128 212
     this.searchKeyword = '';
@@ -132,12 +216,22 @@ export class DankaList implements OnInit {
132 216
       return;
133 217
     }
134 218
 
135
-    this.filterDankaList = this.dankaList.filter(async (danka) => {
136
-      const firstKana = (await this.getDankaSortText(danka)).charAt(0);
137
-      return this.kanaRowMap[row].includes(firstKana);
138
-    });
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);
139 232
 
140 233
     this.dankaDisplay = this.filterDankaList.length;
234
+    this.cdr.detectChanges();
141 235
   }
142 236
 
143 237
   clearDanka() {
@@ -150,11 +244,9 @@ export class DankaList implements OnInit {
150 244
 
151 245
   private async getDankaSortText(danka: Danka): Promise<string> {
152 246
     const householderName = this.normalizeName(danka.householder);
153
-
154
-    const householderFamily = (await this.familyService
155
-      .getFamiliesByDankaId(danka.id))
156
-      .find((f) => this.normalizeName(f.name) === householderName);
157
-
247
+    const householderFamily = (await this.familyService.getFamiliesByDankaId(danka.id)).find(
248
+      (f) => this.normalizeName(f.name) === householderName,
249
+    );
158 250
     return (householderFamily?.furigana || danka.householder).trim();
159 251
   }
160 252
 

Carregando…
Cancelar
Salvar