kuni преди 3 седмици
родител
ревизия
5a3ba3f4e4
променени са 3 файла, в които са добавени 43 реда и са изтрити 30 реда
  1. 2
    2
      src/app/pages/event/event.ts
  2. 19
    5
      src/app/pages/family-edit/family-edit.ts
  3. 22
    23
      src/app/pages/kakocho-edit/kakocho-edit.ts

+ 2
- 2
src/app/pages/event/event.ts Целия файл

@@ -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';

+ 19
- 5
src/app/pages/family-edit/family-edit.ts Целия файл

@@ -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 Целия файл

@@ -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
 

Loading…
Отказ
Запис