Skip to content

Commit dd12830

Browse files
fix: centers notes tab not displaying notes content (#2877)
1 parent 19359c4 commit dd12830

File tree

3 files changed

+34
-132
lines changed

3 files changed

+34
-132
lines changed
Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,10 @@
1-
<div class="tab-container mat-typography">
2-
<h3>{{ 'labels.heading.Notes' | translate }}</h3>
3-
<div>
4-
<form
5-
#formRef="ngForm"
6-
[formGroup]="noteForm"
7-
class="layout-row align-start-baseline gap-20px"
8-
(ngSubmit)="submit()"
9-
>
10-
<mat-form-field class="flex-90-minus-20px">
11-
<textarea
12-
formControlName="note"
13-
matInput
14-
placeholder="{{ 'labels.text.Write a note' | translate }} ...."
15-
></textarea>
16-
</mat-form-field>
17-
<button
18-
mat-raised-button
19-
class="flex-fill"
20-
color="primary"
21-
[disabled]="!noteForm.valid"
22-
*mifosxHasPermission="'CREATE_GROUPNOTE'"
23-
>
24-
<fa-icon icon="plus" class="m-r-10"></fa-icon> {{ 'labels.buttons.Add' | translate }}
25-
</button>
26-
</form>
27-
</div>
28-
<mat-list>
29-
@for (centerNote of centerNotes; track centerNote; let i = $index) {
30-
<mat-list-item>
31-
<fa-icon icon="sticky-note" matListIcon></fa-icon>
32-
<h3 matLine>{{ centerNote.note }}</h3>
33-
<p matLine>
34-
<span>{{ 'labels.inputs.Created By' | translate }}: {{ centerNote.createdByUsername }}</span
35-
><br />
36-
<span>{{ 'labels.inputs.Date' | translate }}: {{ centerNote.createdOn | dateFormat }}</span>
37-
</p>
38-
<div class="layout-row align-start">
39-
<button mat-button color="primary" (click)="editNote(centerNote.id, centerNote.note, i)">
40-
<fa-icon icon="edit"></fa-icon>
41-
</button>
42-
<button mat-button color="warn" (click)="deleteNote(centerNote.id, i)">
43-
<fa-icon icon="trash"></fa-icon>
44-
</button>
45-
</div>
46-
</mat-list-item>
47-
}
48-
</mat-list>
49-
</div>
1+
<mifosx-entity-notes-tab
2+
[entityId]="entityId"
3+
[entityNotes]="entityNotes"
4+
[username]="username"
5+
[notePermission]="'GROUPNOTE'"
6+
[addNoteCallback]="addNote"
7+
[editNoteCallback]="editNote"
8+
[deleteNoteCallback]="deleteNote"
9+
>
10+
</mifosx-entity-notes-tab>
Lines changed: 23 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
1-
import { Component, OnInit, ViewChild, inject } from '@angular/core';
2-
import { UntypedFormBuilder, UntypedFormGroup, Validators, ReactiveFormsModule } from '@angular/forms';
3-
import { MatDialog } from '@angular/material/dialog';
1+
import { Component, OnInit, inject } from '@angular/core';
42
import { ActivatedRoute } from '@angular/router';
53

6-
/** Custom Components */
7-
import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component';
8-
import { DeleteDialogComponent } from '../../../shared/delete-dialog/delete-dialog.component';
9-
10-
/** Custom Services */
11-
import { TranslateService } from '@ngx-translate/core';
124
import { AuthenticationService } from '../../../core/authentication/authentication.service';
135
import { CentersService } from '../../centers.service';
14-
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
15-
import { MatList, MatListItem } from '@angular/material/list';
16-
import { MatLine } from '@angular/material/grid-list';
17-
import { DateFormatPipe } from '../../../pipes/date-format.pipe';
6+
import { EntityNotesTabComponent } from '../../../shared/tabs/entity-notes-tab/entity-notes-tab.component';
187
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
198

209
@Component({
@@ -23,101 +12,53 @@ import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
2312
styleUrls: ['./notes-tab.component.scss'],
2413
imports: [
2514
...STANDALONE_SHARED_IMPORTS,
26-
FaIconComponent,
27-
MatList,
28-
MatListItem,
29-
MatLine,
30-
DateFormatPipe
15+
EntityNotesTabComponent
3116
]
3217
})
3318
export class NotesTabComponent implements OnInit {
3419
private route = inject(ActivatedRoute);
35-
private formBuilder = inject(UntypedFormBuilder);
36-
private centersService = inject(CentersService);
3720
private authenticationService = inject(AuthenticationService);
38-
private dialog = inject(MatDialog);
39-
private translateService = inject(TranslateService);
21+
private centersService = inject(CentersService);
4022

41-
centerId: string;
23+
entityId: string;
4224
username: string;
43-
centerNotes: any;
44-
noteForm: UntypedFormGroup;
45-
@ViewChild('formRef', { static: true }) formRef: any;
25+
entityNotes: any;
4626

4727
constructor() {
48-
const savedCredentials = this.authenticationService.getCredentials();
49-
this.username = savedCredentials.username;
50-
this.centerId = this.route.parent.snapshot.params['centerId'];
51-
this.route.data.subscribe((data: { centerNotes: any }) => {
52-
this.centerNotes = data.centerNotes;
53-
});
28+
this.entityId = this.route.parent.parent.snapshot.params['centerId'];
29+
this.addNote = this.addNote.bind(this);
30+
this.editNote = this.editNote.bind(this);
31+
this.deleteNote = this.deleteNote.bind(this);
5432
}
5533

5634
ngOnInit() {
57-
this.createNoteForm();
58-
}
59-
60-
createNoteForm() {
61-
this.noteForm = this.formBuilder.group({
62-
note: [
63-
'',
64-
Validators.required
65-
]
35+
const savedCredentials = this.authenticationService.getCredentials();
36+
this.username = savedCredentials.username;
37+
this.route.data.subscribe((data: { centerNotes: any }) => {
38+
this.entityNotes = data.centerNotes;
6639
});
6740
}
6841

69-
submit() {
70-
this.centersService.createCenterNote(this.centerId, this.noteForm.value).subscribe((response: any) => {
71-
this.centerNotes.push({
42+
addNote(noteContent: any) {
43+
this.centersService.createCenterNote(this.entityId, noteContent).subscribe((response: any) => {
44+
this.entityNotes.push({
7245
id: response.resourceId,
7346
createdByUsername: this.username,
7447
createdOn: new Date(),
75-
note: this.noteForm.value.note
48+
note: noteContent.note
7649
});
77-
this.formRef.resetForm();
7850
});
7951
}
8052

81-
editNote(noteId: string, noteContent: string, index: number) {
82-
const editNoteDialogRef = this.dialog.open(FormDialogComponent, {
83-
data: {
84-
formfields: [
85-
{
86-
controlName: 'note',
87-
required: true,
88-
value: noteContent,
89-
controlType: 'input',
90-
label: this.translateService.instant('labels.inputs.Note')
91-
}
92-
],
93-
layout: {
94-
columns: 1,
95-
addButtonText: 'Confirm'
96-
},
97-
title: this.translateService.instant('labels.heading.Edit Note')
98-
}
99-
});
100-
editNoteDialogRef.afterClosed().subscribe((response: any) => {
101-
if (response.data) {
102-
this.centersService.editCenterNote(this.centerId, noteId, response.data.value).subscribe(() => {
103-
this.centerNotes[index].note = response.data.value.note;
104-
});
105-
}
53+
editNote(noteId: string, noteContent: any, index: number) {
54+
this.centersService.editCenterNote(this.entityId, noteId, noteContent).subscribe(() => {
55+
this.entityNotes[index].note = noteContent.note;
10656
});
10757
}
10858

10959
deleteNote(noteId: string, index: number) {
110-
const deleteNoteDialogRef = this.dialog.open(DeleteDialogComponent, {
111-
data: {
112-
deleteContext: `${this.translateService.instant('labels.inputs.Note')} ${this.translateService.instant('labels.inputs.Id')}:${noteId}`
113-
}
114-
});
115-
deleteNoteDialogRef.afterClosed().subscribe((response: any) => {
116-
if (response.delete) {
117-
this.centersService.deleteCenterNote(this.centerId, noteId).subscribe(() => {
118-
this.centerNotes.splice(index, 1);
119-
});
120-
}
60+
this.centersService.deleteCenterNote(this.entityId, noteId).subscribe(() => {
61+
this.entityNotes.splice(index, 1);
12162
});
12263
}
12364
}

src/app/centers/common-resolvers/center-notes.resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class CenterNotesResolver {
2020
* @returns {Observable<any>}
2121
*/
2222
resolve(route: ActivatedRouteSnapshot): Observable<any> {
23-
const centerId = route.parent.paramMap.get('centerId');
23+
const centerId = route.parent.parent.paramMap.get('centerId');
2424
return this.centersService.getCenterNotes(centerId);
2525
}
2626
}

0 commit comments

Comments
 (0)