Parcourir la source

[add]

家系図に関係があると父、母、配偶者に初期値が出力
poohr il y a 3 semaines
Parent
révision
20c440e5e3

+ 29
- 52
src/app/pages/family-edit/family-edit.html Voir le fichier

22
               <div class="form-row">
22
               <div class="form-row">
23
                 <label for="name">氏名</label>
23
                 <label for="name">氏名</label>
24
                 <div class="form-field">
24
                 <div class="form-field">
25
-                  <input
26
-                    id="name"
27
-                    type="text"
28
-                    formControlName="name"
29
-                  />
25
+                  <input id="name" type="text"
26
+                         formControlName="name"/>
30
                   @if (familyForm.get('name')?.invalid && familyForm.get('name')?.touched) {
27
                   @if (familyForm.get('name')?.invalid && familyForm.get('name')?.touched) {
31
                     <p class="error-message">氏名を入力してください。</p>
28
                     <p class="error-message">氏名を入力してください。</p>
32
                   }
29
                   }
36
               <div class="form-row">
33
               <div class="form-row">
37
                 <label for="furigana">ふりがな</label>
34
                 <label for="furigana">ふりがな</label>
38
                 <div class="form-field">
35
                 <div class="form-field">
39
-                  <input
40
-                    id="furigana"
41
-                    type="text"
42
-                    formControlName="furigana"
43
-                  />
36
+                  <input id="furigana" type="text"
37
+                         formControlName="furigana"/>
44
                   @if (familyForm.get('furigana')?.invalid && familyForm.get('furigana')?.touched) {
38
                   @if (familyForm.get('furigana')?.invalid && familyForm.get('furigana')?.touched) {
45
                     <p class="error-message">ふりがなを入力してください。</p>
39
                     <p class="error-message">ふりがなを入力してください。</p>
46
                   }
40
                   }
50
               <div class="form-row">
44
               <div class="form-row">
51
                 <label for="relationship">世帯主との関係</label>
45
                 <label for="relationship">世帯主との関係</label>
52
                 <div class="form-field">
46
                 <div class="form-field">
53
-                  <select
54
-                    id="relationship"
55
-                    formControlName="relationship"
56
-                  >
47
+                  <select id="relationship"
48
+                          formControlName="relationship">
57
                     <option value="">選択してください</option>
49
                     <option value="">選択してください</option>
58
                     <option value="世帯主">世帯主</option>
50
                     <option value="世帯主">世帯主</option>
59
                     <option value="配偶者">配偶者</option>
51
                     <option value="配偶者">配偶者</option>
65
                     <option value="次女">次女</option>
57
                     <option value="次女">次女</option>
66
                     <option value="その他">その他</option>
58
                     <option value="その他">その他</option>
67
                   </select>
59
                   </select>
68
-
69
                   @if (familyForm.get('relationship')?.invalid && familyForm.get('relationship')?.touched) {
60
                   @if (familyForm.get('relationship')?.invalid && familyForm.get('relationship')?.touched) {
70
                     <p class="error-message">世帯主との関係を選択してください。</p>
61
                     <p class="error-message">世帯主との関係を選択してください。</p>
71
                   }
62
                   }
72
                 </div>
63
                 </div>
73
               </div>
64
               </div>
74
 
65
 
66
+              <div class="form-row">
67
+                <label for="gender">性別</label>
68
+                <div class="form-field">
69
+                  <select id="gender" formControlName="gender">
70
+                    <option value="unknown">未設定</option>
71
+                    <option value="male">男性</option>
72
+                    <option value="female">女性</option>
73
+                  </select>
74
+                </div>
75
+              </div>
76
+
75
               <div class="form-row">
77
               <div class="form-row">
76
                 <label for="birthDate">生年月日</label>
78
                 <label for="birthDate">生年月日</label>
77
                 <div class="form-field">
79
                 <div class="form-field">
78
-                  <input
79
-                    id="birthDate"
80
-                    type="date"
81
-                    formControlName="birthDate"
82
-                  />
80
+                  <input id="birthDate" type="date"
81
+                         formControlName="birthDate"/>
83
                 </div>
82
                 </div>
84
               </div>
83
               </div>
85
 
84
 
103
               <div class="form-row">
102
               <div class="form-row">
104
                 <label for="fatherId">父</label>
103
                 <label for="fatherId">父</label>
105
                 <div class="form-field">
104
                 <div class="form-field">
106
-                  <select
107
-                    id="fatherId"
108
-                    formControlName="fatherId"
109
-                  >
105
+                  <select id="fatherId" formControlName="fatherId">
110
                     <option value="">選択なし</option>
106
                     <option value="">選択なし</option>
111
                     @for (family of getFamilyOptions(); track family.id) {
107
                     @for (family of getFamilyOptions(); track family.id) {
112
                       <option [value]="family.id">
108
                       <option [value]="family.id">
120
               <div class="form-row">
116
               <div class="form-row">
121
                 <label for="motherId">母</label>
117
                 <label for="motherId">母</label>
122
                 <div class="form-field">
118
                 <div class="form-field">
123
-                  <select
124
-                    id="motherId"
125
-                    formControlName="motherId"
126
-                  >
119
+                  <select id="motherId" formControlName="motherId">
127
                     <option value="">選択なし</option>
120
                     <option value="">選択なし</option>
128
                     @for (family of getFamilyOptions(); track family.id) {
121
                     @for (family of getFamilyOptions(); track family.id) {
129
                       <option [value]="family.id">
122
                       <option [value]="family.id">
137
               <div class="form-row">
130
               <div class="form-row">
138
                 <label for="spouseId">配偶者</label>
131
                 <label for="spouseId">配偶者</label>
139
                 <div class="form-field">
132
                 <div class="form-field">
140
-                  <select
141
-                    id="spouseId"
142
-                    formControlName="spouseId"
143
-                  >
133
+                  <select id="spouseId" formControlName="spouseId">
144
                     <option value="">選択なし</option>
134
                     <option value="">選択なし</option>
145
                     @for (family of getFamilyOptions(); track family.id) {
135
                     @for (family of getFamilyOptions(); track family.id) {
146
                       <option [value]="family.id">
136
                       <option [value]="family.id">
154
               <div class="form-row">
144
               <div class="form-row">
155
                 <label for="note">備考</label>
145
                 <label for="note">備考</label>
156
                 <div class="form-field">
146
                 <div class="form-field">
157
-                  <textarea
158
-                    id="note"
159
-                    formControlName="note"
160
-                    rows="4"
161
-                  ></textarea>
147
+                  <textarea id="note" formControlName="note" rows="4"></textarea>
162
                 </div>
148
                 </div>
163
               </div>
149
               </div>
164
 
150
 
169
             <div class="householder-area">
155
             <div class="householder-area">
170
               <h3>この方を世帯主にする</h3>
156
               <h3>この方を世帯主にする</h3>
171
 
157
 
172
-              <button
173
-                type="button"
174
-                class="set-householder-button"
175
-                (click)="setAsHouseholder()"
176
-              >
158
+              <button type="button"
159
+                      class="set-householder-button"
160
+                      (click)="setAsHouseholder()">
177
                 世帯主に設定
161
                 世帯主に設定
178
               </button>
162
               </button>
179
             </div>
163
             </div>
181
         </div>
165
         </div>
182
 
166
 
183
         <div class="bottom-actions">
167
         <div class="bottom-actions">
184
-          <button
185
-            type="button"
186
-            class="delete-button"
187
-            (click)="deleteFamily()">
168
+          <button type="button" class="delete-button" (click)="deleteFamily()">
188
             削除
169
             削除
189
           </button>
170
           </button>
190
 
171
 
192
             キャンセル
173
             キャンセル
193
           </button>
174
           </button>
194
 
175
 
195
-          <button
196
-            type="button"
197
-            class="save-button"
198
-            [disabled]="familyForm.invalid"
199
-            (click)="saveFamily()"
200
-          >
176
+          <button type="button" class="save-button"
177
+                  [disabled]="familyForm.invalid" (click)="saveFamily()">
201
             保存
178
             保存
202
           </button>
179
           </button>
203
         </div>
180
         </div>

+ 19
- 1
src/app/pages/family-edit/family-edit.ts Voir le fichier

25
   families: Family[] = [];
25
   families: Family[] = [];
26
   dankaId: string = '';
26
   dankaId: string = '';
27
   familyId: string | null = null;
27
   familyId: string | null = null;
28
+  relationMode: string = '';
29
+  baseFamilyId: string = '';
28
 
30
 
29
   constructor(
31
   constructor(
30
     private familyService: FamilyService,
32
     private familyService: FamilyService,
34
     this.dankaId = this.route.snapshot.params['dankaId'];
36
     this.dankaId = this.route.snapshot.params['dankaId'];
35
     this.familyId = this.route.snapshot.params['familyId'];
37
     this.familyId = this.route.snapshot.params['familyId'];
36
     this.families = this.familyService.getFamiliesByDankaId(this.dankaId);
38
     this.families = this.familyService.getFamiliesByDankaId(this.dankaId);
39
+    this.relationMode = this.route.snapshot.queryParamMap.get('relationMode') ?? '';
40
+    this.baseFamilyId = this.route.snapshot.queryParamMap.get('baseFamilyId') ?? '';
37
     if (this.familyId) {
41
     if (this.familyId) {
38
       this.family = this.familyService.getFamilyById(this.familyId);
42
       this.family = this.familyService.getFamilyById(this.familyId);
39
       if (this.family) {
43
       if (this.family) {
46
         });
50
         });
47
       }
51
       }
48
     }
52
     }
53
+
54
+    if (!this.familyId && this.relationMode === 'spouse') {
55
+      this.familyForm.patchValue({
56
+        spouseId: this.baseFamilyId,
57
+      });
58
+    }
59
+
60
+    if (!this.familyId && this.relationMode === 'child') {
61
+      this.familyForm.patchValue({
62
+        fatherId: this.baseFamilyId,
63
+      });
64
+    }
49
   }
65
   }
50
 
66
 
51
   familyForm = new FormGroup({
67
   familyForm = new FormGroup({
57
     fatherId: new FormControl(''),
73
     fatherId: new FormControl(''),
58
     motherId: new FormControl(''),
74
     motherId: new FormControl(''),
59
     spouseId: new FormControl(''),
75
     spouseId: new FormControl(''),
76
+    gender: new FormControl('unknown'),
60
   });
77
   });
61
 
78
 
62
   getAgeText() {
79
   getAgeText() {
63
     const birthDate = this.familyForm.get('birthDate')?.value;
80
     const birthDate = this.familyForm.get('birthDate')?.value;
64
     if (!birthDate) {
81
     if (!birthDate) {
65
-      return "生年月日を入力すると自動計算されます";
82
+      return '生年月日を入力すると自動計算されます';
66
     }
83
     }
67
     const birth = new Date(birthDate);
84
     const birth = new Date(birthDate);
68
     const today = new Date();
85
     const today = new Date();
98
       fatherId: this.familyForm.value.fatherId ?? '',
115
       fatherId: this.familyForm.value.fatherId ?? '',
99
       motherId: this.familyForm.value.motherId ?? '',
116
       motherId: this.familyForm.value.motherId ?? '',
100
       spouseId: this.familyForm.value.spouseId ?? '',
117
       spouseId: this.familyForm.value.spouseId ?? '',
118
+      gender: this.familyForm.value.gender ?? 'unknown',
101
     };
119
     };
102
     this.familyService.saveFamily(updatedFamily);
120
     this.familyService.saveFamily(updatedFamily);
103
     this.router.navigate(['/danka-detail', dankaId], { queryParams: { tab: 'family' } });
121
     this.router.navigate(['/danka-detail', dankaId], { queryParams: { tab: 'family' } });

Chargement…
Annuler
Enregistrer