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' ;
42import { 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' ;
124import { AuthenticationService } from '../../../core/authentication/authentication.service' ;
135import { 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' ;
187import { 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} )
3318export 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}
0 commit comments