kuni 3 weeks ago
parent
commit
1adc0761ce
5 changed files with 1132 additions and 129 deletions
  1. 998
    5
      package-lock.json
  2. 1
    0
      package.json
  3. 15
    0
      src/app/firebase.ts
  4. 72
    58
      src/app/pages/danka-detail/danka-detail.ts
  5. 46
    66
      src/app/services/dankaService.ts

+ 998
- 5
package-lock.json
File diff suppressed because it is too large
View File


+ 1
- 0
package.json View File

17
     "@angular/forms": "^21.2.0",
17
     "@angular/forms": "^21.2.0",
18
     "@angular/platform-browser": "^21.2.0",
18
     "@angular/platform-browser": "^21.2.0",
19
     "@angular/router": "^21.2.0",
19
     "@angular/router": "^21.2.0",
20
+    "firebase": "^12.14.0",
20
     "rxjs": "~7.8.0",
21
     "rxjs": "~7.8.0",
21
     "svg-pan-zoom": "^3.6.2",
22
     "svg-pan-zoom": "^3.6.2",
22
     "tslib": "^2.3.0"
23
     "tslib": "^2.3.0"

+ 15
- 0
src/app/firebase.ts View File

1
+import { initializeApp } from 'firebase/app';
2
+import { getFirestore } from 'firebase/firestore';
3
+
4
+const firebaseConfig = {
5
+  apiKey: "AIzaSyBdkDfrr2jA33olJSd2Fm5KeneOwpded-o",
6
+  authDomain: "dankamanagement-39a6a.firebaseapp.com",
7
+  projectId: "dankamanagement-39a6a",
8
+  storageBucket: "dankamanagement-39a6a.firebasestorage.app",
9
+  messagingSenderId: "85260511199",
10
+  appId: "1:85260511199:web:27b2c43a0fdb77ad32066a",
11
+  measurementId: "G-Z3PPJZDQ16"
12
+};
13
+
14
+export const app = initializeApp(firebaseConfig);
15
+export const db = getFirestore(app);

+ 72
- 58
src/app/pages/danka-detail/danka-detail.ts View File

4
   ViewChild,
4
   ViewChild,
5
   AfterViewInit
5
   AfterViewInit
6
 } from '@angular/core';
6
 } from '@angular/core';
7
+import { OnInit } from '@angular/core';
7
 import { ActivatedRoute, RouterLink } from '@angular/router';
8
 import { ActivatedRoute, RouterLink } from '@angular/router';
8
 import { DankaService } from '../../services/dankaService';
9
 import { DankaService } from '../../services/dankaService';
9
 import { FamilyService } from '../../services/family-service';
10
 import { FamilyService } from '../../services/family-service';
34
 import { FamilyUnitLayoutService } from '../../services/family-unit-layout';
35
 import { FamilyUnitLayoutService } from '../../services/family-unit-layout';
35
 
36
 
36
 
37
 
38
+
37
 interface NextMemorial {
39
 interface NextMemorial {
38
   name: string;
40
   name: string;
39
   memorialType: string;
41
   memorialType: string;
47
   templateUrl: './danka-detail.html',
49
   templateUrl: './danka-detail.html',
48
   styleUrl: './danka-detail.scss',
50
   styleUrl: './danka-detail.scss',
49
 })
51
 })
50
-export class DankaDetail implements AfterViewInit {
52
+export class DankaDetail implements OnInit, AfterViewInit {
51
   danka: Danka | undefined;
53
   danka: Danka | undefined;
52
   families: Family[] = [];
54
   families: Family[] = [];
53
   kakocholist: Kakocho[] = [];
55
   kakocholist: Kakocho[] = [];
92
     private familyUnitLayout: FamilyUnitLayoutService,
94
     private familyUnitLayout: FamilyUnitLayoutService,
93
     private eventService: EventService,
95
     private eventService: EventService,
94
   ) {
96
   ) {
97
+
95
     const tab = this.route.snapshot.queryParams['tab'];
98
     const tab = this.route.snapshot.queryParams['tab'];
96
     if (tab === 'family') {
99
     if (tab === 'family') {
97
       this.selectedTab = 'family';
100
       this.selectedTab = 'family';
103
       this.selectedTab = 'familyTree';
106
       this.selectedTab = 'familyTree';
104
     }
107
     }
105
 
108
 
109
+  }
110
+  ngOnInit(): void {
111
+    this.init();
112
+  }
113
+  async init(): Promise<void> {
106
     const id = this.route.snapshot.params['id'];
114
     const id = this.route.snapshot.params['id'];
107
-    if (id) {
108
-      this.danka = this.dankaService.getDankaById(id);
109
-      this.marriageRelations = this.marriageRelationService.getMarriageRelationsByDankaId(id);
110
-      this.families = this.sortFamiliesByHouseholder(this.familyService.getFamiliesByDankaId(id));
111
-      this.selectedFamily = this.families[0];
112
-      this.kakocholist = this.kakochoService.getKakochoByDankaId(id);
113
-      this.nextMemorial = this.getNextMemorial();
114
-
115
-      this.treeNodes =
116
-        this.familyTreeBuilder.build(
117
-          this.families,
118
-          this.marriageRelations
119
-        );
115
+    if (!id) return;
120
 
116
 
121
-      const units =
122
-        this.familyTreeBuilder.buildFamilyUnits(
123
-          this.treeNodes
124
-        );
117
+    this.danka = (await this.dankaService.getDankaById(id)) ?? undefined;
118
+    if (!this.danka) return;
125
 
119
 
126
-      const unitTree =
127
-        this.familyTreeBuilder.buildFamilyUnitTree(
128
-          units
129
-        );
120
+    this.marriageRelations = await this.marriageRelationService.getMarriageRelationsByDankaId(id);
121
+    this.families = this.sortFamiliesByHouseholder(
122
+      await this.familyService.getFamiliesByDankaId(id)
123
+    );
130
 
124
 
131
-      const unitRoots =
132
-        this.familyTreeBuilder.getUnitRoots(
133
-          unitTree
134
-        );
125
+    this.selectedFamily = this.families[0];
126
+    this.kakocholist = await this.kakochoService.getKakochoByDankaId(id);
135
 
127
 
136
-      this.unitLayouts =
137
-        this.familyUnitLayout.buildLayout(
138
-          unitRoots
139
-        );
128
+    this.nextMemorial = this.getNextMemorial();
140
 
129
 
141
-      const roots =
142
-        this.familyTreeBuilder.getRoots(
143
-          this.treeNodes
144
-        );
130
+    this.treeNodes =
131
+      this.familyTreeBuilder.build(
132
+        this.families,
133
+        this.marriageRelations
134
+      );
145
 
135
 
146
-      this.layoutNodes =
147
-        this.familyTreeLayout.buildLayout(
148
-          roots
149
-        );
136
+    const units =
137
+      this.familyTreeBuilder.buildFamilyUnits(
138
+        this.treeNodes
139
+      );
150
 
140
 
151
-      this.rebuildLayoutNodeMap();
141
+    const unitTree =
142
+      this.familyTreeBuilder.buildFamilyUnitTree(
143
+        units
144
+      );
152
 
145
 
153
-      this.unitLayouts =
154
-        this.familyUnitLayout.buildLayout(
155
-          unitRoots
156
-        );
146
+    const unitRoots =
147
+      this.familyTreeBuilder.getUnitRoots(
148
+        unitTree
149
+      );
157
 
150
 
158
-      this.rebuildUnitLayoutMap();
151
+    this.unitLayouts =
152
+      this.familyUnitLayout.buildLayout(
153
+        unitRoots
154
+      );
159
 
155
 
160
-      this.calculateViewBox();
156
+    const roots =
157
+      this.familyTreeBuilder.getRoots(
158
+        this.treeNodes
159
+      );
161
 
160
 
162
-      this.kakocholist.forEach(kakocho => {
163
-        if (kakocho.familyId) {
164
-          this.deathDateMap.set(
165
-            kakocho.familyId,
166
-            kakocho
167
-          );
168
-        }
169
-      });
161
+    this.layoutNodes =
162
+      this.familyTreeLayout.buildLayout(
163
+        roots
164
+      );
170
 
165
 
171
-      this.kakocholist.forEach(k => {
172
-        const key = this.normalizeName(k.name) + '_' + k.dankaId;
173
-        this.kakochoByNameMap.set(key, k);
174
-      });
166
+    this.rebuildLayoutNodeMap();
167
+
168
+    this.unitLayouts =
169
+      this.familyUnitLayout.buildLayout(
170
+        unitRoots
171
+      );
172
+
173
+    this.rebuildUnitLayoutMap();
174
+
175
+    this.calculateViewBox();
176
+
177
+    this.kakocholist.forEach(kakocho => {
178
+      if (kakocho.familyId) {
179
+        this.deathDateMap.set(
180
+          kakocho.familyId,
181
+          kakocho
182
+        );
183
+      }
184
+    });
185
+
186
+    this.kakocholist.forEach(k => {
187
+      const key = this.normalizeName(k.name) + '_' + k.dankaId;
188
+      this.kakochoByNameMap.set(key, k);
189
+    });
175
 
190
 
176
-    }
177
   }
191
   }
178
 
192
 
179
   ngAfterViewInit(): void {
193
   ngAfterViewInit(): void {

+ 46
- 66
src/app/services/dankaService.ts View File

1
 import { Injectable } from '@angular/core';
1
 import { Injectable } from '@angular/core';
2
+import {
3
+  collection,
4
+  getDocs,
5
+  doc,
6
+  getDoc,
7
+  setDoc,
8
+  deleteDoc,
9
+  updateDoc
10
+} from 'firebase/firestore';
11
+
12
+import { db } from '../firebase';
2
 import { Danka } from '../models/danka';
13
 import { Danka } from '../models/danka';
3
 
14
 
4
 @Injectable({
15
 @Injectable({
5
   providedIn: 'root',
16
   providedIn: 'root',
6
 })
17
 })
7
 export class DankaService {
18
 export class DankaService {
8
-  private dankaList: Danka[] = [
9
-    {
10
-      id: '1',
11
-      householdName: '鈴木家',
12
-      householdFurigana: 'すずきけ',
13
-      householder: '鈴木 太郎',
14
-      householderFurigana: 'すずき たろう',
15
-      postalCode: '123-4567',
16
-      address: '市内 1-2-3',
17
-      note: '寺報送付あり。年忌法要の案内は施主へ連絡。',
18
-      updatedAt: '2026-05-28',
19
-      phones: [
20
-        {
21
-          tel: '03-4567-8910',
22
-          note: '寺報連絡',
23
-        },
24
-        {
25
-          tel: '090-1234-5678',
26
-          note: '施主',
27
-        },
28
-      ],
29
-    },
30
-    {
31
-      id: '2',
32
-      householdName: '古田家',
33
-      householdFurigana: 'ふるたけ',
34
-      householder: '古田 太郎',
35
-      householderFurigana: 'ふるた たろう',
36
-      postalCode: '234-4567',
37
-      address: '市内 1-2-3',
38
-      note: '電話連絡を優先。',
39
-      updatedAt: '2026-05-28',
40
-      phones: [
41
-        {
42
-          tel: '0-5678-9101',
43
-          note: '寺報連絡',
44
-        },
45
-        {
46
-          tel: '080-7890-4567',
47
-          note: '施主',
48
-        },
49
-      ],
50
-    }
51
-  ];
19
+  private path = 'danka';
20
+
21
+  // 一覧
22
+  async getDankaList(): Promise<Danka[]> {
23
+    const snap = await getDocs(collection(db, this.path));
24
+
25
+    return snap.docs.map(d => ({
26
+      id: d.id,
27
+      ...(d.data() as Omit<Danka, 'id'>)
28
+    }));
29
+  }
30
+
31
+  // 1件
32
+  async getDankaById(id: string): Promise<Danka | undefined> {
33
+    const ref = doc(db, this.path, id);
34
+    const snap = await getDoc(ref);
35
+
36
+    if (!snap.exists()) return undefined;
52
 
37
 
53
-  //サービスの檀家一覧の取得
54
-  getDankaList(): Danka[] {
55
-    return this.dankaList;
38
+    return {
39
+      id: snap.id,
40
+      ...(snap.data() as Omit<Danka, 'id'>)
41
+    };
56
   }
42
   }
57
 
43
 
58
-  //対象の檀家IDを取得
59
-  getDankaById(id: string): Danka | undefined {
60
-    return this.dankaList.find((danka) => danka.id === id);
44
+  // 作成・更新
45
+  async saveDanka(danka: Danka): Promise<void> {
46
+    const ref = doc(db, this.path, danka.id);
47
+    await setDoc(ref, danka);
61
   }
48
   }
62
 
49
 
63
-  //DBへの檀家情報の登録
64
-  saveDanka(updatedDanka: Danka): void {
65
-    const index = this.dankaList.findIndex((danka) => danka.id === updatedDanka.id);
66
-    if (index === -1) {
67
-      this.dankaList.push(updatedDanka);
68
-      return;
69
-    }
70
-    this.dankaList[index] = updatedDanka;
50
+  // 部分更新
51
+  async updateDanka(id: string, data: Partial<Danka>): Promise<void> {
52
+    const ref = doc(db, this.path, id);
53
+    await updateDoc(ref, data as any);
71
   }
54
   }
72
 
55
 
73
-  //DBの檀家情報の削除
74
-  deleteDanka(id: string): void {
75
-    const index = this.dankaList.findIndex((danka) => danka.id === id);
76
-    if (index === -1) {
77
-      return;
78
-    }
79
-    this.dankaList.splice(index, 1);
56
+  // 削除
57
+  async deleteDanka(id: string): Promise<void> {
58
+    const ref = doc(db, this.path, id);
59
+    await deleteDoc(ref);
80
   }
60
   }
81
-}
61
+}

Loading…
Cancel
Save