Kaynağa Gözat

Merge remote-tracking branch 'origin/master'

poohr 3 hafta önce
ebeveyn
işleme
2f6e9bb4fb

+ 33
- 20
src/app/pages/event/event.ts Dosyayı Görüntüle

1
-import { Component } from '@angular/core';
1
+import { Component, OnInit } from '@angular/core';
2
 import { FormsModule } from '@angular/forms';
2
 import { FormsModule } from '@angular/forms';
3
 import { DankaService } from '../../services/dankaService';
3
 import { DankaService } from '../../services/dankaService';
4
 import { FamilyService } from '../../services/family-service';
4
 import { FamilyService } from '../../services/family-service';
13
   templateUrl: './event.html',
13
   templateUrl: './event.html',
14
   styleUrl: './event.scss',
14
   styleUrl: './event.scss',
15
 })
15
 })
16
-export class EventPage {
16
+export class EventPage implements OnInit{
17
   eventTargets: EventTarget[] = [];
17
   eventTargets: EventTarget[] = [];
18
   targetYear: number = new Date().getFullYear();
18
   targetYear: number = new Date().getFullYear();
19
   selectedEventType: EventType | 'all' = 'all';
19
   selectedEventType: EventType | 'all' = 'all';
43
     private dankaService: DankaService,
43
     private dankaService: DankaService,
44
     private familyService: FamilyService,
44
     private familyService: FamilyService,
45
     private eventService: EventService,
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
     this.eventTargets = [];
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
       const birthDate = this.parseDate(family.birthDate);
62
       const birthDate = this.parseDate(family.birthDate);
55
-      if (!birthDate) {
56
-        return;
57
-      }
63
+      if (!birthDate) continue;
58
 
64
 
59
       const age = this.targetYear - birthDate.getFullYear();
65
       const age = this.targetYear - birthDate.getFullYear();
60
       const eventTypes = this.getEventTypes(age);
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
         const id = `${family.id}-${eventType}`;
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
         this.eventTargets.push({
85
         this.eventTargets.push({
74
           id,
86
           id,
75
           dankaId: family.dankaId,
87
           dankaId: family.dankaId,
83
           note: family.note,
95
           note: family.note,
84
           status: this.eventService.getEventStatus(id, defaultStatus),
96
           status: this.eventService.getEventStatus(id, defaultStatus),
85
         });
97
         });
86
-      });
87
-    });
98
+      }
99
+    }
88
 
100
 
89
     this.eventTargets.sort(
101
     this.eventTargets.sort(
90
       (a, b) =>
102
       (a, b) =>
91
-        this.getEventSortOrder(a.eventType) - this.getEventSortOrder(b.eventType) ||
103
+        this.getEventSortOrder(a.eventType) -
104
+        this.getEventSortOrder(b.eventType) ||
92
         a.age - b.age ||
105
         a.age - b.age ||
93
         a.name.localeCompare(b.name, 'ja'),
106
         a.name.localeCompare(b.name, 'ja'),
94
     );
107
     );

+ 19
- 5
src/app/pages/family-edit/family-edit.ts Dosyayı Görüntüle

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

+ 22
- 23
src/app/pages/kakocho-edit/kakocho-edit.ts Dosyayı Görüntüle

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

58
     const ref = doc(db, this.path, id);
58
     const ref = doc(db, this.path, id);
59
     await deleteDoc(ref);
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
 }

Loading…
İptal
Kaydet