kuni 3 viikkoa sitten
vanhempi
commit
148dd5a47c
2 muutettua tiedostoa jossa 82 lisäystä ja 53 poistoa
  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 Näytä tiedosto

1
-import { Component } from '@angular/core';
1
+import { Component, OnInit } from '@angular/core';
2
 import { ActivatedRoute, Router, RouterLink } from '@angular/router';
2
 import { ActivatedRoute, Router, RouterLink } from '@angular/router';
3
 import { Memorial } from '../../models/memorial';
3
 import { Memorial } from '../../models/memorial';
4
 import { DankaService } from '../../services/dankaService';
4
 import { DankaService } from '../../services/dankaService';
13
   templateUrl: './memorial-list.html',
13
   templateUrl: './memorial-list.html',
14
   styleUrl: './memorial-list.scss',
14
   styleUrl: './memorial-list.scss',
15
 })
15
 })
16
-export class MemorialList {
16
+export class MemorialList implements OnInit{
17
   memorialList: Memorial[] = [];
17
   memorialList: Memorial[] = [];
18
   targetYear: number = new Date().getFullYear();
18
   targetYear: number = new Date().getFullYear();
19
   selectedMemorialType = 'all';
19
   selectedMemorialType = 'all';
46
     private dankaService: DankaService,
46
     private dankaService: DankaService,
47
     private kakochoService: KakochoService,
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
     this.memorialList = [];
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
       const deathYear = Number(kakocho.deathDate.slice(0, 4));
65
       const deathYear = Number(kakocho.deathDate.slice(0, 4));
57
       const yearDiff = this.targetYear - deathYear;
66
       const yearDiff = this.targetYear - deathYear;
67
+
58
       const memorialType = this.getMemorialType(yearDiff);
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
       const memorialTarget: Memorial = {
80
       const memorialTarget: Memorial = {
67
         id: kakocho.id,
81
         id: kakocho.id,
68
         dankaId: kakocho.dankaId,
82
         dankaId: kakocho.dankaId,
71
         relationship: kakocho.relationship,
85
         relationship: kakocho.relationship,
72
         householdName: danka?.householdName ?? '不明',
86
         householdName: danka?.householdName ?? '不明',
73
         deathDate: kakocho.deathDate,
87
         deathDate: kakocho.deathDate,
74
-        memorialType: memorialType,
88
+        memorialType,
75
         note: kakocho.note,
89
         note: kakocho.note,
76
       };
90
       };
91
+
77
       this.memorialList.push(memorialTarget);
92
       this.memorialList.push(memorialTarget);
78
-    });
93
+    }
94
+
79
     this.memorialList.sort((a, b) => {
95
     this.memorialList.sort((a, b) => {
80
       const deathDateA = new Date(a.deathDate).getTime();
96
       const deathDateA = new Date(a.deathDate).getTime();
81
       const deathDateB = new Date(b.deathDate).getTime();
97
       const deathDateB = new Date(b.deathDate).getTime();
98
+
82
       if (deathDateA !== deathDateB) {
99
       if (deathDateA !== deathDateB) {
83
         return deathDateA - deathDateB;
100
         return deathDateA - deathDateB;
84
       }
101
       }
102
+
85
       return a.name.localeCompare(b.name, 'ja');
103
       return a.name.localeCompare(b.name, 'ja');
86
     });
104
     });
87
   }
105
   }

+ 50
- 39
src/app/pages/search/search.ts Näytä tiedosto

1
-import { Component } from '@angular/core';
1
+import { Component, OnInit } from '@angular/core';
2
 import { FormBuilder, FormsModule } from '@angular/forms';
2
 import { FormBuilder, FormsModule } from '@angular/forms';
3
 import { Router, RouterLink } from '@angular/router';
3
 import { Router, RouterLink } from '@angular/router';
4
 import { Danka } from '../../models/danka';
4
 import { Danka } from '../../models/danka';
16
   templateUrl: './search.html',
16
   templateUrl: './search.html',
17
   styleUrl: './search.scss',
17
   styleUrl: './search.scss',
18
 })
18
 })
19
-export class Search {
19
+export class Search implements OnInit{
20
   searchKeyword = '';
20
   searchKeyword = '';
21
   selectedSearchType = 'all';
21
   selectedSearchType = 'all';
22
   searchTypeFilters = [
22
   searchTypeFilters = [
34
     private dankaService: DankaService,
34
     private dankaService: DankaService,
35
     private familyService: FamilyService,
35
     private familyService: FamilyService,
36
     private kakochoService: KakochoService,
36
     private kakochoService: KakochoService,
37
-  ) {}
37
+  ) { }
38
+
39
+  ngOnInit(): void {
40
+  }
38
 
41
 
39
   // フィルタータブの選択処理
42
   // フィルタータブの選択処理
40
   changeSearchType(searchType: string): void {
43
   changeSearchType(searchType: string): void {
43
   }
46
   }
44
 
47
 
45
   // 全検索の処理
48
   // 全検索の処理
46
-  searchAll() {
49
+  async searchAll(): Promise<void> {
47
     const keyword = this.searchKeyword.trim();
50
     const keyword = this.searchKeyword.trim();
51
+
48
     this.dankaResults = [];
52
     this.dankaResults = [];
49
     this.familyResults = [];
53
     this.familyResults = [];
50
     this.kakochoResults = [];
54
     this.kakochoResults = [];
51
     this.totalResultCount = 0;
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
     if (this.selectedSearchType === 'all' || this.selectedSearchType === 'danka') {
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
     if (this.selectedSearchType === 'all' || this.selectedSearchType === 'family') {
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
     if (this.selectedSearchType === 'all' || this.selectedSearchType === 'kakocho') {
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
     this.totalResultCount =
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
   clearSearch(): void {
110
   clearSearch(): void {

Loading…
Peruuta
Tallenna