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