Przeglądaj źródła

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/app/pages/dashboard/dashboard.ts
poohr 3 tygodni temu
rodzic
commit
72b3f06044

+ 13
- 5
src/app/pages/danka-edit/danka-edit.ts Wyświetl plik

1
-import { Component, inject } from '@angular/core';
1
+import { Component, inject, OnInit } from '@angular/core';
2
 import {
2
 import {
3
   FormBuilder,
3
   FormBuilder,
4
   FormGroup,
4
   FormGroup,
19
   templateUrl: './danka-edit.html',
19
   templateUrl: './danka-edit.html',
20
   styleUrl: './danka-edit.scss',
20
   styleUrl: './danka-edit.scss',
21
 })
21
 })
22
-export class DankaEdit {
22
+export class DankaEdit implements OnInit {
23
   danka: Danka | undefined;
23
   danka: Danka | undefined;
24
 
24
 
25
   dankaForm = new FormGroup({
25
   dankaForm = new FormGroup({
38
     private route: ActivatedRoute,
38
     private route: ActivatedRoute,
39
     private router: Router,
39
     private router: Router,
40
   ) {
40
   ) {
41
+  }
42
+
43
+  ngOnInit(): void {
44
+    this.init();
45
+  }
46
+
47
+  async init(): Promise<void> {
41
     const id = this.route.snapshot.params['id'];
48
     const id = this.route.snapshot.params['id'];
49
+
42
     if (id) {
50
     if (id) {
43
-      this.danka = this.dankaService.getDankaById(id);
51
+      this.danka = await this.dankaService.getDankaById(id);
44
 
52
 
45
       if (this.danka) {
53
       if (this.danka) {
46
         this.dankaForm.patchValue({
54
         this.dankaForm.patchValue({
60
         }
68
         }
61
       }
69
       }
62
     }
70
     }
63
-    console.log(this.danka);
71
+
64
   }
72
   }
65
 
73
 
66
   get phones() {
74
   get phones() {
79
   }
87
   }
80
 
88
 
81
   removePhone(index: number) {
89
   removePhone(index: number) {
82
-    if(this.phones.length > 1) {
90
+    if (this.phones.length > 1) {
83
       this.phones.removeAt(index);
91
       this.phones.removeAt(index);
84
     }
92
     }
85
   }
93
   }

+ 11
- 14
src/app/pages/dashboard/dashboard.ts Wyświetl plik

1
 import { Component } from '@angular/core';
1
 import { Component } from '@angular/core';
2
-import { Router, RouterLink } from '@angular/router';
3
-import { FormsModule } from '@angular/forms';
2
+import { RouterLink } from '@angular/router';
4
 import { KakochoService } from '../../services/kakocho-service';
3
 import { KakochoService } from '../../services/kakocho-service';
5
 import { DankaService } from '../../services/dankaService';
4
 import { DankaService } from '../../services/dankaService';
6
 import { Danka } from '../../models/danka';
5
 import { Danka } from '../../models/danka';
116
     const today = this.toDateOnly(new Date());
115
     const today = this.toDateOnly(new Date());
117
     const endDate = this.addDays(today, 30);
116
     const endDate = this.addDays(today, 30);
118
 
117
 
119
-    const upcomingMemorials = await Promise.all(
120
-      (await this.kakochoService
121
-        .getKakochoList())
122
-        .map(async (kakocho): Promise<UpcomingMemorial | null> => {
118
+    const kakochoList = await this.kakochoService.getKakochoList();
119
+
120
+    const results = await Promise.all(
121
+      kakochoList.map(async (kakocho): Promise<UpcomingMemorial | null> => {
123
         const deathDate = this.parseDate(kakocho.deathDate);
122
         const deathDate = this.parseDate(kakocho.deathDate);
124
-        if (!deathDate) {
125
-          return null;
126
-        }
123
+        if (!deathDate) return null;
127
 
124
 
128
         const eventDate = new Date(this.targetYear, deathDate.getMonth(), deathDate.getDate());
125
         const eventDate = new Date(this.targetYear, deathDate.getMonth(), deathDate.getDate());
129
-        if (eventDate < today || eventDate > endDate) {
130
-          return null;
131
-        }
126
+        if (eventDate < today || eventDate > endDate) return null;
132
 
127
 
133
         const memorialType = this.getMemorialType(deathDate);
128
         const memorialType = this.getMemorialType(deathDate);
129
+
134
         const danka = await this.dankaService.getDankaById(kakocho.dankaId);
130
         const danka = await this.dankaService.getDankaById(kakocho.dankaId);
131
+
135
         const type = memorialType ? '年忌法要' : '命日';
132
         const type = memorialType ? '年忌法要' : '命日';
136
         const status = memorialType ? '準備確認' : '要確認';
133
         const status = memorialType ? '準備確認' : '要確認';
137
 
134
 
145
           type,
142
           type,
146
           status,
143
           status,
147
         };
144
         };
148
-      }),
145
+      })
149
     );
146
     );
150
 
147
 
151
-    this.upcomingMemorials = upcomingMemorials
148
+    this.upcomingMemorials = results
152
       .filter((memorial): memorial is UpcomingMemorial => memorial !== null)
149
       .filter((memorial): memorial is UpcomingMemorial => memorial !== null)
153
       .sort((a, b) => a.date.getTime() - b.date.getTime() || a.title.localeCompare(b.title, 'ja'))
150
       .sort((a, b) => a.date.getTime() - b.date.getTime() || a.title.localeCompare(b.title, 'ja'))
154
       .slice(0, 3);
151
       .slice(0, 3);

+ 23
- 19
src/app/pages/family-edit/family-edit.ts Wyświetl plik

23
   templateUrl: './family-edit.html',
23
   templateUrl: './family-edit.html',
24
   styleUrl: './family-edit.scss',
24
   styleUrl: './family-edit.scss',
25
 })
25
 })
26
-export class FamilyEdit implements OnInit{
26
+export class FamilyEdit implements OnInit {
27
   danka: Danka | undefined;
27
   danka: Danka | undefined;
28
   family: Family | undefined;
28
   family: Family | undefined;
29
   families: Family[] = [];
29
   families: Family[] = [];
135
     return this.families.filter((family) => family.id !== this.familyId);
135
     return this.families.filter((family) => family.id !== this.familyId);
136
   }
136
   }
137
 
137
 
138
-  patchMarriageRelationFields(familyId: string): void {
139
-    const relations = this.marriageRelationService.getMarriageRelationsByFamilyId(familyId);
138
+  async patchMarriageRelationFields(familyId: string): Promise<void> {
139
+    const relations = await this.marriageRelationService.getMarriageRelationsByFamilyId(familyId);
140
+
140
     const relation =
141
     const relation =
141
       relations.find((marriageRelation) => marriageRelation.status === 'current') ?? relations[0];
142
       relations.find((marriageRelation) => marriageRelation.status === 'current') ?? relations[0];
142
 
143
 
143
-    if (!relation) {
144
-      return;
145
-    }
144
+    if (!relation) return;
146
 
145
 
147
     this.familyForm.patchValue({
146
     this.familyForm.patchValue({
148
       spouseId: relation.person1Id === familyId ? relation.person2Id : relation.person1Id,
147
       spouseId: relation.person1Id === familyId ? relation.person2Id : relation.person1Id,
150
     });
149
     });
151
   }
150
   }
152
 
151
 
153
-  findMarriageRelation(person1Id: string, person2Id: string): MarriageRelation | undefined {
154
-    return this.marriageRelationService
155
-      .getMarriageRelationsByFamilyId(person1Id)
156
-      .find(
157
-        (relation) =>
158
-          (relation.person1Id === person1Id && relation.person2Id === person2Id) ||
159
-          (relation.person1Id === person2Id && relation.person2Id === person1Id),
160
-      );
152
+  async findMarriageRelation(
153
+    person1Id: string,
154
+    person2Id: string
155
+  ): Promise<MarriageRelation | undefined> {
156
+
157
+    const relations = await this.marriageRelationService.getMarriageRelationsByFamilyId(person1Id);
158
+
159
+    return relations.find(
160
+      (relation) =>
161
+        (relation.person1Id === person1Id && relation.person2Id === person2Id) ||
162
+        (relation.person1Id === person2Id && relation.person2Id === person1Id),
163
+    );
161
   }
164
   }
162
 
165
 
163
-  saveFamily() {
166
+  async saveFamily() {
164
     if (this.familyForm.invalid) {
167
     if (this.familyForm.invalid) {
165
       return;
168
       return;
166
     }
169
     }
187
     };
190
     };
188
 
191
 
189
     if (spouseId) {
192
     if (spouseId) {
190
-      const existingRelation = this.findMarriageRelation(familyId, spouseId);
191
-      const errors = this.marriageRelationService.saveMarriageRelation({
192
-        id: existingRelation?.id ?? Date.now().toString(),
193
+      const existingRelation = await this.findMarriageRelation(familyId, spouseId);
194
+
195
+      const errors = await this.marriageRelationService.saveMarriageRelation({
196
+        id: existingRelation?.id ?? crypto.randomUUID(),
193
         dankaId,
197
         dankaId,
194
         person1Id: familyId,
198
         person1Id: familyId,
195
         person2Id: spouseId,
199
         person2Id: spouseId,
204
         return;
208
         return;
205
       }
209
       }
206
     } else {
210
     } else {
207
-      const currentMarriage = this.marriageRelationService.getCurrentMarriageByFamilyId(familyId);
211
+      const currentMarriage = await this.marriageRelationService.getCurrentMarriageByFamilyId(familyId);
208
       if (currentMarriage) {
212
       if (currentMarriage) {
209
         this.marriageRelationService.deleteMarriageRelation(currentMarriage.id);
213
         this.marriageRelationService.deleteMarriageRelation(currentMarriage.id);
210
       }
214
       }

+ 1
- 1
src/app/pages/kakocho-edit/kakocho-edit.ts Wyświetl plik

37
   kakocho?: Kakocho;
37
   kakocho?: Kakocho;
38
   sourceFamily?: Family;
38
   sourceFamily?: Family;
39
   kakochoForm: FormGroup;
39
   kakochoForm: FormGroup;
40
-  dankaId: string;
40
+  dankaId: string | undefined;
41
   returnTab: 'family' | 'kakocho' = 'kakocho';
41
   returnTab: 'family' | 'kakocho' = 'kakocho';
42
 
42
 
43
   constructor(
43
   constructor(

Ładowanie…
Anuluj
Zapisz