Ver código fonte

Merge remote-tracking branch 'origin/master'

poohr 3 semanas atrás
pai
commit
2f6e9bb4fb

+ 33
- 20
src/app/pages/event/event.ts Ver arquivo

@@ -1,4 +1,4 @@
1
-import { Component } from '@angular/core';
1
+import { Component, OnInit } from '@angular/core';
2 2
 import { FormsModule } from '@angular/forms';
3 3
 import { DankaService } from '../../services/dankaService';
4 4
 import { FamilyService } from '../../services/family-service';
@@ -13,7 +13,7 @@ import { AppSideMenu } from '../../share/side-menu/app-side-menu';
13 13
   templateUrl: './event.html',
14 14
   styleUrl: './event.scss',
15 15
 })
16
-export class EventPage {
16
+export class EventPage implements OnInit{
17 17
   eventTargets: EventTarget[] = [];
18 18
   targetYear: number = new Date().getFullYear();
19 19
   selectedEventType: EventType | 'all' = 'all';
@@ -43,33 +43,45 @@ export class EventPage {
43 43
     private dankaService: DankaService,
44 44
     private familyService: FamilyService,
45 45
     private eventService: EventService,
46
-  ) {
47
-    this.createEventTargetList();
46
+  ) { }
47
+
48
+  ngOnInit(): void {
49
+    this.init();
50
+  }
51
+
52
+  async init(): Promise<void> {
53
+    await this.createEventTargetList();
48 54
   }
49 55
 
50
-  createEventTargetList(): void {
56
+  async createEventTargetList(): Promise<void> {
51 57
     this.eventTargets = [];
52 58
 
53
-    this.familyService.getFamilyList().forEach((family) => {
59
+    const families = await this.familyService.getFamilyList();
60
+
61
+    for (const family of families) {
54 62
       const birthDate = this.parseDate(family.birthDate);
55
-      if (!birthDate) {
56
-        return;
57
-      }
63
+      if (!birthDate) continue;
58 64
 
59 65
       const age = this.targetYear - birthDate.getFullYear();
60 66
       const eventTypes = this.getEventTypes(age);
61
-      if (eventTypes.length === 0) {
62
-        return;
63
-      }
67
+      if (eventTypes.length === 0) continue;
64 68
 
65
-      const danka = this.dankaService.getDankaById(family.dankaId);
66
-      eventTypes.forEach((eventType) => {
67
-        if (this.selectedEventType !== 'all' && this.selectedEventType !== eventType) {
68
-          return;
69
+      // ★ここが修正ポイント(await)
70
+      const danka = await this.dankaService.getDankaById(family.dankaId);
71
+
72
+      for (const eventType of eventTypes) {
73
+        if (
74
+          this.selectedEventType !== 'all' &&
75
+          this.selectedEventType !== eventType
76
+        ) {
77
+          continue;
69 78
         }
70 79
 
71 80
         const id = `${family.id}-${eventType}`;
72
-        const defaultStatus: EventStatus = Number(family.id) % 2 === 0 ? '案内済' : '未案内';
81
+
82
+        const defaultStatus: EventStatus =
83
+          Number(family.id) % 2 === 0 ? '案内済' : '未案内';
84
+
73 85
         this.eventTargets.push({
74 86
           id,
75 87
           dankaId: family.dankaId,
@@ -83,12 +95,13 @@ export class EventPage {
83 95
           note: family.note,
84 96
           status: this.eventService.getEventStatus(id, defaultStatus),
85 97
         });
86
-      });
87
-    });
98
+      }
99
+    }
88 100
 
89 101
     this.eventTargets.sort(
90 102
       (a, b) =>
91
-        this.getEventSortOrder(a.eventType) - this.getEventSortOrder(b.eventType) ||
103
+        this.getEventSortOrder(a.eventType) -
104
+        this.getEventSortOrder(b.eventType) ||
92 105
         a.age - b.age ||
93 106
         a.name.localeCompare(b.name, 'ja'),
94 107
     );

+ 19
- 5
src/app/pages/family-edit/family-edit.ts Ver arquivo

@@ -6,6 +6,7 @@ import {
6 6
   ReactiveFormsModule,
7 7
   Validators,
8 8
 } from '@angular/forms';
9
+import { OnInit } from '@angular/core';
9 10
 import { ActivatedRoute, Router, RouterLink } from '@angular/router';
10 11
 import { AppHeader } from '../../share/header/app-header';
11 12
 import { AppSideMenu } from '../../share/side-menu/app-side-menu';
@@ -22,7 +23,7 @@ import { MarriageRelation } from '../../models/marriage-relation';
22 23
   templateUrl: './family-edit.html',
23 24
   styleUrl: './family-edit.scss',
24 25
 })
25
-export class FamilyEdit {
26
+export class FamilyEdit implements OnInit{
26 27
   danka: Danka | undefined;
27 28
   family: Family | undefined;
28 29
   families: Family[] = [];
@@ -40,14 +41,26 @@ export class FamilyEdit {
40 41
     private route: ActivatedRoute,
41 42
     private router: Router,
42 43
   ) {
44
+  }
45
+
46
+  ngOnInit(): void {
47
+    this.init();
48
+  }
49
+
50
+  async init(): Promise<void> {
43 51
     this.dankaId = this.route.snapshot.params['dankaId'];
44 52
     this.familyId = this.route.snapshot.params['familyId'];
45
-    this.danka = this.dankaService.getDankaById(this.dankaId);
46
-    this.families = this.familyService.getFamiliesByDankaId(this.dankaId);
53
+
47 54
     this.relationMode = this.route.snapshot.queryParamMap.get('relationMode') ?? '';
48 55
     this.baseFamilyId = this.route.snapshot.queryParamMap.get('baseFamilyId') ?? '';
56
+
57
+    // ★ここが重要
58
+    this.danka = await this.dankaService.getDankaById(this.dankaId);
59
+    this.families = await this.familyService.getFamiliesByDankaId(this.dankaId);
60
+
49 61
     if (this.familyId) {
50
-      this.family = this.familyService.getFamilyById(this.familyId);
62
+      this.family = await this.familyService.getFamilyById(this.familyId);
63
+
51 64
       if (this.family) {
52 65
         this.familyForm.patchValue({
53 66
           furigana: this.family.furigana,
@@ -60,6 +73,7 @@ export class FamilyEdit {
60 73
           spouseId: this.family.spouseId,
61 74
           gender: this.family.gender,
62 75
         });
76
+
63 77
         this.patchMarriageRelationFields(this.family.id);
64 78
       }
65 79
     }
@@ -72,7 +86,7 @@ export class FamilyEdit {
72 86
     }
73 87
 
74 88
     if (!this.familyId && this.relationMode === 'child') {
75
-      const baseFamily = this.familyService.getFamilyById(this.baseFamilyId);
89
+      const baseFamily = await this.familyService.getFamilyById(this.baseFamilyId);
76 90
 
77 91
       if (baseFamily?.gender === 'male') {
78 92
         this.familyForm.patchValue({

+ 22
- 23
src/app/pages/kakocho-edit/kakocho-edit.ts Ver arquivo

@@ -1,4 +1,4 @@
1
-import { Component } from '@angular/core';
1
+import { Component, OnInit } from '@angular/core';
2 2
 import {
3 3
   FormBuilder,
4 4
   FormGroup,
@@ -32,7 +32,7 @@ import { Family } from '../../models/family';
32 32
   templateUrl: './kakocho-edit.html',
33 33
   styleUrl: './kakocho-edit.scss',
34 34
 })
35
-export class KakochoEdit {
35
+export class KakochoEdit implements OnInit {
36 36
   danka?: Danka;
37 37
   kakocho?: Kakocho;
38 38
   sourceFamily?: Family;
@@ -48,8 +48,6 @@ export class KakochoEdit {
48 48
     private route: ActivatedRoute,
49 49
     private router: Router,
50 50
   ) {
51
-
52
-    // フォーム初期化
53 51
     this.kakochoForm = this.fb.group({
54 52
       name: ['', Validators.required],
55 53
       furigana: [''],
@@ -59,34 +57,33 @@ export class KakochoEdit {
59 57
       ageAtDeath: [''],
60 58
       note: [''],
61 59
     });
60
+  }
61
+
62
+  ngOnInit(): void {
63
+    this.init();
64
+  }
62 65
 
63
-    // 檀家ID
66
+  async init(): Promise<void> {
64 67
     const dankaId = this.route.snapshot.params['dankaId'];
65
-    this.dankaId = this.route.snapshot.params['dankaId'];
68
+    const familyId = this.route.snapshot.queryParams['familyId'];
69
+    const kakochoId = this.route.snapshot.params['kakochoId'];
70
+
71
+    this.dankaId = dankaId;
66 72
 
67 73
     if (dankaId) {
68
-      this.danka =
69
-        this.dankaService.getDankaById(dankaId);
74
+      this.danka = await this.dankaService.getDankaById(dankaId);
70 75
     }
71 76
 
72
-    const familyId = this.route.snapshot.queryParams['familyId'];
73 77
     if (familyId) {
74
-      this.sourceFamily = this.familyService.getFamilyById(familyId);
78
+      this.sourceFamily = await this.familyService.getFamilyById(familyId);
75 79
       this.returnTab = 'family';
76 80
     }
77 81
 
78
-    // 編集対象ID
79
-    const kakochoId =
80
-      this.route.snapshot.params['kakochoId'];
81
-
82 82
     // 編集モード
83 83
     if (kakochoId) {
84
-
85
-      this.kakocho =
86
-        this.kakochoService.getKakochoById(kakochoId);
84
+      this.kakocho = await this.kakochoService.getKakochoById(kakochoId);
87 85
 
88 86
       if (this.kakocho) {
89
-
90 87
         this.kakochoForm.patchValue({
91 88
           name: this.kakocho.name,
92 89
           furigana: this.kakocho.furigana,
@@ -96,9 +93,11 @@ export class KakochoEdit {
96 93
           ageAtDeath: this.kakocho.ageAtDeath,
97 94
           note: this.kakocho.note,
98 95
         });
99
-
100 96
       }
101
-    } else if (this.sourceFamily) {
97
+    }
98
+
99
+    // 新規(家族からの引き継ぎ)
100
+    else if (this.sourceFamily) {
102 101
       this.kakochoForm.patchValue({
103 102
         name: this.sourceFamily.name,
104 103
         furigana: this.sourceFamily.furigana,
@@ -107,7 +106,7 @@ export class KakochoEdit {
107 106
     }
108 107
   }
109 108
 
110
-  saveKakocho(): void {
109
+  async saveKakocho(): Promise<void> {
111 110
 
112 111
     // form値取得
113 112
     const formValue = this.kakochoForm.value;
@@ -120,7 +119,7 @@ export class KakochoEdit {
120 119
         ...formValue,
121 120
       };
122 121
 
123
-      this.kakochoService.updateKakocho(
122
+      await this.kakochoService.updateKakocho(
124 123
         updatedKakocho
125 124
       );
126 125
 
@@ -148,7 +147,7 @@ export class KakochoEdit {
148 147
       );
149 148
 
150 149
       if (this.sourceFamily) {
151
-        this.familyService.deleteFamily(this.sourceFamily.id);
150
+        await this.familyService.deleteFamily(this.sourceFamily.id);
152 151
       }
153 152
     }
154 153
 

+ 10
- 0
src/app/services/family-service.ts Ver arquivo

@@ -58,4 +58,14 @@ export class FamilyService {
58 58
     const ref = doc(db, this.path, id);
59 59
     await deleteDoc(ref);
60 60
   }
61
+
62
+  //家族情報を全件取得する処理
63
+  async getFamilyList(): Promise<Family[]> {
64
+    const snap = await getDocs(collection(db, this.path));
65
+
66
+    return snap.docs.map(d => ({
67
+      id: d.id,
68
+      ...(d.data() as Omit<Family, 'id'>),
69
+    }));
70
+  }
61 71
 }

Carregando…
Cancelar
Salvar