kuni 3 veckor sedan
förälder
incheckning
148dd5a47c
2 ändrade filer med 82 tillägg och 53 borttagningar
  1. 32
    14
      src/app/pages/memorial-list/memorial-list.ts
  2. 50
    39
      src/app/pages/search/search.ts

+ 32
- 14
src/app/pages/memorial-list/memorial-list.ts Visa fil

@@ -1,4 +1,4 @@
1
-import { Component } from '@angular/core';
1
+import { Component, OnInit } from '@angular/core';
2 2
 import { ActivatedRoute, Router, RouterLink } from '@angular/router';
3 3
 import { Memorial } from '../../models/memorial';
4 4
 import { DankaService } from '../../services/dankaService';
@@ -13,7 +13,7 @@ import { FormsModule } from '@angular/forms';
13 13
   templateUrl: './memorial-list.html',
14 14
   styleUrl: './memorial-list.scss',
15 15
 })
16
-export class MemorialList {
16
+export class MemorialList implements OnInit{
17 17
   memorialList: Memorial[] = [];
18 18
   targetYear: number = new Date().getFullYear();
19 19
   selectedMemorialType = 'all';
@@ -46,23 +46,37 @@ export class MemorialList {
46 46
     private dankaService: DankaService,
47 47
     private kakochoService: KakochoService,
48 48
   ) {
49
-    this.createMemorialList();
49
+
50
+  }
51
+  ngOnInit(): void {
52
+    this.init();
53
+  }
54
+
55
+  async init(): Promise<void> {
56
+    await this.createMemorialList();
50 57
   }
51 58
 
52
-  createMemorialList(): void {
59
+  async createMemorialList(): Promise<void> {
53 60
     this.memorialList = [];
54
-    const kakochoList = this.kakochoService.getKakochoList();
55
-    kakochoList.forEach((kakocho) => {
61
+
62
+    const kakochoList = await this.kakochoService.getKakochoList();
63
+
64
+    for (const kakocho of kakochoList) {
56 65
       const deathYear = Number(kakocho.deathDate.slice(0, 4));
57 66
       const yearDiff = this.targetYear - deathYear;
67
+
58 68
       const memorialType = this.getMemorialType(yearDiff);
59
-      if (memorialType === '') {
60
-        return;
61
-      }
62
-      if (this.selectedMemorialType !== 'all' && this.selectedMemorialType !== memorialType) {
63
-        return;
69
+      if (memorialType === '') continue;
70
+
71
+      if (
72
+        this.selectedMemorialType !== 'all' &&
73
+        this.selectedMemorialType !== memorialType
74
+      ) {
75
+        continue;
64 76
       }
65
-      const danka = this.dankaService.getDankaById(kakocho.dankaId);
77
+
78
+      const danka = await this.dankaService.getDankaById(kakocho.dankaId);
79
+
66 80
       const memorialTarget: Memorial = {
67 81
         id: kakocho.id,
68 82
         dankaId: kakocho.dankaId,
@@ -71,17 +85,21 @@ export class MemorialList {
71 85
         relationship: kakocho.relationship,
72 86
         householdName: danka?.householdName ?? '不明',
73 87
         deathDate: kakocho.deathDate,
74
-        memorialType: memorialType,
88
+        memorialType,
75 89
         note: kakocho.note,
76 90
       };
91
+
77 92
       this.memorialList.push(memorialTarget);
78
-    });
93
+    }
94
+
79 95
     this.memorialList.sort((a, b) => {
80 96
       const deathDateA = new Date(a.deathDate).getTime();
81 97
       const deathDateB = new Date(b.deathDate).getTime();
98
+
82 99
       if (deathDateA !== deathDateB) {
83 100
         return deathDateA - deathDateB;
84 101
       }
102
+
85 103
       return a.name.localeCompare(b.name, 'ja');
86 104
     });
87 105
   }

+ 50
- 39
src/app/pages/search/search.ts Visa fil

@@ -1,4 +1,4 @@
1
-import { Component } from '@angular/core';
1
+import { Component, OnInit } from '@angular/core';
2 2
 import { FormBuilder, FormsModule } from '@angular/forms';
3 3
 import { Router, RouterLink } from '@angular/router';
4 4
 import { Danka } from '../../models/danka';
@@ -16,7 +16,7 @@ import { AppSideMenu } from '../../share/side-menu/app-side-menu';
16 16
   templateUrl: './search.html',
17 17
   styleUrl: './search.scss',
18 18
 })
19
-export class Search {
19
+export class Search implements OnInit{
20 20
   searchKeyword = '';
21 21
   selectedSearchType = 'all';
22 22
   searchTypeFilters = [
@@ -34,7 +34,10 @@ export class Search {
34 34
     private dankaService: DankaService,
35 35
     private familyService: FamilyService,
36 36
     private kakochoService: KakochoService,
37
-  ) {}
37
+  ) { }
38
+
39
+  ngOnInit(): void {
40
+  }
38 41
 
39 42
   // フィルタータブの選択処理
40 43
   changeSearchType(searchType: string): void {
@@ -43,57 +46,65 @@ export class Search {
43 46
   }
44 47
 
45 48
   // 全検索の処理
46
-  searchAll() {
49
+  async searchAll(): Promise<void> {
47 50
     const keyword = this.searchKeyword.trim();
51
+
48 52
     this.dankaResults = [];
49 53
     this.familyResults = [];
50 54
     this.kakochoResults = [];
51 55
     this.totalResultCount = 0;
52
-    if (keyword === '') {
53
-      return;
54
-    }
55
-    // 檀家・家族・過去帳の情報を取得
56
-    const dankaList = this.dankaService.getDankaList();
57
-    const familyList = this.familyService.getFamilyList();
58
-    const kakochoList = this.kakochoService.getKakochoList();
59
-    //檀家のキーワード検索
56
+
57
+    if (keyword === '') return;
58
+
59
+    const [dankaList, familyList, kakochoList] = await Promise.all([
60
+      this.dankaService.getDankaList(),
61
+      this.familyService.getFamilyList(),
62
+      this.kakochoService.getKakochoList(),
63
+    ]);
64
+
65
+    // 檀家検索
60 66
     if (this.selectedSearchType === 'all' || this.selectedSearchType === 'danka') {
61
-      this.dankaResults = dankaList.filter(
62
-        (danka) =>
63
-          danka.householdName.includes(keyword) ||
64
-          danka.householder.includes(keyword) ||
65
-          danka.postalCode.includes(keyword) ||
66
-          danka.address.includes(keyword) ||
67
-          danka.phones.some((phone) => phone.tel.includes(keyword) || phone.note.includes(keyword)),
67
+      this.dankaResults = dankaList.filter((danka) =>
68
+        danka.householdName.includes(keyword) ||
69
+        danka.householder.includes(keyword) ||
70
+        danka.postalCode.includes(keyword) ||
71
+        danka.address.includes(keyword) ||
72
+        danka.phones.some(
73
+          (phone) =>
74
+            phone.tel.includes(keyword) ||
75
+            phone.note.includes(keyword)
76
+        )
68 77
       );
69 78
     }
70
-    //家族のキーワード検索
79
+
80
+    // 家族検索
71 81
     if (this.selectedSearchType === 'all' || this.selectedSearchType === 'family') {
72
-      this.familyResults = familyList.filter(
73
-        (family) =>
74
-          family.name.includes(keyword) ||
75
-          family.furigana.includes(keyword) ||
76
-          family.relationship.includes(keyword) ||
77
-          family.birthDate.includes(keyword) ||
78
-          family.note.includes(keyword),
82
+      this.familyResults = familyList.filter((family) =>
83
+        family.name.includes(keyword) ||
84
+        family.furigana.includes(keyword) ||
85
+        family.relationship.includes(keyword) ||
86
+        family.birthDate.includes(keyword) ||
87
+        family.note.includes(keyword)
79 88
       );
80 89
     }
81
-    //過去帳のキーワード検索
90
+
91
+    // 過去帳検索
82 92
     if (this.selectedSearchType === 'all' || this.selectedSearchType === 'kakocho') {
83
-      this.kakochoResults = kakochoList.filter(
84
-        (kakocho) =>
85
-          kakocho.name.includes(keyword) ||
86
-          kakocho.furigana.includes(keyword) ||
87
-          kakocho.relationship.includes(keyword) ||
88
-          kakocho.kaimyo.includes(keyword) ||
89
-          kakocho.deathDate.includes(keyword) ||
90
-          kakocho.ageAtDeath.includes(keyword) ||
91
-          kakocho.note.includes(keyword),
93
+      this.kakochoResults = kakochoList.filter((kakocho) =>
94
+        kakocho.name.includes(keyword) ||
95
+        kakocho.furigana.includes(keyword) ||
96
+        kakocho.relationship.includes(keyword) ||
97
+        kakocho.kaimyo.includes(keyword) ||
98
+        kakocho.deathDate.includes(keyword) ||
99
+        kakocho.ageAtDeath.includes(keyword) ||
100
+        kakocho.note.includes(keyword)
92 101
       );
93 102
     }
94
-    //検索結果の件数カウント
103
+
95 104
     this.totalResultCount =
96
-      this.dankaResults.length + this.familyResults.length + this.kakochoResults.length;
105
+      this.dankaResults.length +
106
+      this.familyResults.length +
107
+      this.kakochoResults.length;
97 108
   }
98 109
 
99 110
   clearSearch(): void {

Laddar…
Avbryt
Spara