From a5711131c7c03d34048df9f1279b8418e13c598d Mon Sep 17 00:00:00 2001 From: Karan Takalkar Date: Wed, 20 May 2020 16:17:55 +0530 Subject: [PATCH] feat: add groups view page (notes-tab) (#789) Fixes: #778 --- .../common-resolvers/group-notes.resolver.ts | 32 +++++ src/app/groups/groups-routing.module.ts | 13 +- .../groups-view/groups-view.component.html | 4 + .../notes-tab/notes-tab.component.html | 39 +++++ .../notes-tab/notes-tab.component.scss | 19 +++ .../notes-tab/notes-tab.component.spec.ts | 25 ++++ .../notes-tab/notes-tab.component.ts | 136 ++++++++++++++++++ src/app/groups/groups.module.ts | 4 +- src/app/groups/groups.service.ts | 34 +++++ 9 files changed, 304 insertions(+), 2 deletions(-) create mode 100644 src/app/groups/common-resolvers/group-notes.resolver.ts create mode 100644 src/app/groups/groups-view/notes-tab/notes-tab.component.html create mode 100644 src/app/groups/groups-view/notes-tab/notes-tab.component.scss create mode 100644 src/app/groups/groups-view/notes-tab/notes-tab.component.spec.ts create mode 100644 src/app/groups/groups-view/notes-tab/notes-tab.component.ts diff --git a/src/app/groups/common-resolvers/group-notes.resolver.ts b/src/app/groups/common-resolvers/group-notes.resolver.ts new file mode 100644 index 000000000..9b02c1b79 --- /dev/null +++ b/src/app/groups/common-resolvers/group-notes.resolver.ts @@ -0,0 +1,32 @@ +/** Angular Imports */ +import { Injectable } from '@angular/core'; +import { Resolve, ActivatedRouteSnapshot } from '@angular/router'; + +/** rxjs Imports */ +import { Observable } from 'rxjs'; + +/** Custom Services */ +import { GroupsService } from '../groups.service'; + +/** + * Group Notes data resolver. + */ +@Injectable() +export class GroupNotesResolver implements Resolve { + + /** + * @param {GroupsService} GroupsService Groups service. + */ + constructor(private groupsService: GroupsService) { } + + /** + * Returns the Group's Notes data. + * @param {ActivatedRouteSnapshot} route Route Snapshot. + * @returns {Observable} + */ + resolve(route: ActivatedRouteSnapshot): Observable { + const groupId = route.parent.paramMap.get('groupId'); + return this.groupsService.getGroupNotes(groupId); + } + +} diff --git a/src/app/groups/groups-routing.module.ts b/src/app/groups/groups-routing.module.ts index 52c88b383..a0b432db1 100644 --- a/src/app/groups/groups-routing.module.ts +++ b/src/app/groups/groups-routing.module.ts @@ -12,12 +12,14 @@ import { extract } from '../core/i18n/i18n.service'; import { GroupsComponent } from './groups.component'; import { GroupsViewComponent } from './groups-view/groups-view.component'; import { GeneralTabComponent } from './groups-view/general-tab/general-tab.component'; +import { NotesTabComponent } from './groups-view/notes-tab/notes-tab.component'; /** Custom Resolvers */ import { GroupViewResolver } from './common-resolvers/group-view.resolver'; import { GroupAccountsResolver } from './common-resolvers/group-account.resolver'; import { GroupSummaryResolver } from './common-resolvers/group-summary.resolver'; import { GroupClientMembersResolver } from './common-resolvers/group-client-members.resolver'; +import { GroupNotesResolver } from './common-resolvers/group-notes.resolver'; /** Groups Routes */ const routes: Routes = [ @@ -48,6 +50,14 @@ const routes: Routes = [ groupClientMembers: GroupClientMembersResolver, groupSummary: GroupSummaryResolver } + }, + { + path: 'notes', + component: NotesTabComponent, + data: { title: extract('Notes'), breadcrumb: 'Notes', routeParamBreadcrumb: false }, + resolve: { + groupNotes: GroupNotesResolver + } } ] } @@ -67,6 +77,7 @@ const routes: Routes = [ providers: [GroupViewResolver, GroupAccountsResolver, GroupSummaryResolver, - GroupClientMembersResolver] + GroupClientMembersResolver, + GroupNotesResolver] }) export class GroupsRoutingModule { } diff --git a/src/app/groups/groups-view/groups-view.component.html b/src/app/groups/groups-view/groups-view.component.html index 625635bf3..c53b69851 100644 --- a/src/app/groups/groups-view/groups-view.component.html +++ b/src/app/groups/groups-view/groups-view.component.html @@ -100,6 +100,10 @@ [active]="general.isActive"> General + + Notes + diff --git a/src/app/groups/groups-view/notes-tab/notes-tab.component.html b/src/app/groups/groups-view/notes-tab/notes-tab.component.html new file mode 100644 index 000000000..9ce0613e3 --- /dev/null +++ b/src/app/groups/groups-view/notes-tab/notes-tab.component.html @@ -0,0 +1,39 @@ +
+ +

Notes

+ +
+ + + + + + + +
+ + + + + +

{{groupNote.note}}

+

+ Created by: {{groupNote.createdByUsername}}
+ Date: {{groupNote.createdOn | date}} +

+
+ + +
+
+ +
+ +
diff --git a/src/app/groups/groups-view/notes-tab/notes-tab.component.scss b/src/app/groups/groups-view/notes-tab/notes-tab.component.scss new file mode 100644 index 000000000..566f436e3 --- /dev/null +++ b/src/app/groups/groups-view/notes-tab/notes-tab.component.scss @@ -0,0 +1,19 @@ +.tab-container { + padding: 1%; + margin: 1%; +} + +h3 { + margin-bottom: 0px; +} + +mat-list { + padding-top: 0px; +} + +mat-list-item { + margin-block: 20px; + &:hover{ + background-color: #f5f5f5; + } +} diff --git a/src/app/groups/groups-view/notes-tab/notes-tab.component.spec.ts b/src/app/groups/groups-view/notes-tab/notes-tab.component.spec.ts new file mode 100644 index 000000000..add42af72 --- /dev/null +++ b/src/app/groups/groups-view/notes-tab/notes-tab.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { NotesTabComponent } from './notes-tab.component'; + +describe('NotesTabComponent', () => { + let component: NotesTabComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ NotesTabComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(NotesTabComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/groups/groups-view/notes-tab/notes-tab.component.ts b/src/app/groups/groups-view/notes-tab/notes-tab.component.ts new file mode 100644 index 000000000..dfcb481c2 --- /dev/null +++ b/src/app/groups/groups-view/notes-tab/notes-tab.component.ts @@ -0,0 +1,136 @@ +/** Angular Imports */ +import { Component, OnInit, ViewChild } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { FormGroup, FormBuilder, Validators } from '@angular/forms'; +import { MatDialog } from '@angular/material'; + +/** Custom Services */ +import { AuthenticationService } from '../../../core/authentication/authentication.service'; +import { GroupsService } from '../../groups.service'; + +/** Custom Dialogs */ +import { DeleteDialogComponent } from '../../../shared/delete-dialog/delete-dialog.component'; +import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component'; + +/** Custom Models */ +import { FormfieldBase } from 'app/shared/form-dialog/formfield/model/formfield-base'; +import { InputBase } from 'app/shared/form-dialog/formfield/model/input-base'; + +/** + * Groups Notes Tab Component. + */ +@Component({ + selector: 'mifosx-notes-tab', + templateUrl: './notes-tab.component.html', + styleUrls: ['./notes-tab.component.scss'] +}) +export class NotesTabComponent implements OnInit { + + /** Group Notes */ + groupNotes: any; + /** Group Id */ + groupId: string; + /** User Name */ + username: string; + /** Note form */ + noteForm: FormGroup; + + /** Note Form Reference */ + @ViewChild('formRef') formRef: any; + + /** + * Fetches notes data from `resolve` + * @param {Activated Route} route Activated Route. + * @param {AuthenticationService} authenticationService Authentication Service. + */ + constructor(private route: ActivatedRoute, + private formBuilder: FormBuilder, + private authenticationService: AuthenticationService, + private groupsService: GroupsService, + public dialog: MatDialog) { + const savedCredentials = this.authenticationService.getCredentials(); + this.username = savedCredentials.username; + this.groupId = this.route.parent.snapshot.params['groupId']; + this.route.data.subscribe((data: { groupNotes: any }) => { + this.groupNotes = data.groupNotes; + }); + } + + ngOnInit() { + this.createNoteForm(); + } + + /** + * Creates the note form. + */ + createNoteForm() { + this.noteForm = this.formBuilder.group({ + 'note': ['', Validators.required] + }); + } + + /** + * Adds a new note. + */ + addNote() { + this.groupsService.createGroupNote(this.groupId, this.noteForm.value).subscribe((response: any) => { + this.groupNotes.push({ + id: response.resourceId, + createdByUsername: this.username, + createdOn: new Date(), + note: this.noteForm.value.note + }); + this.formRef.resetForm(); + }); + } + + /** + * Edits selected note. + * @param {string} noteId Note Id. + * @param {string} noteContent Note's content. + * @param {number} index Index of note. + */ + editNote(noteId: string, noteContent: string, index: number) { + const formfields: FormfieldBase[] = [ + new InputBase({ + controlName: 'note', + label: 'Note', + value: noteContent, + type: 'text', + required: true, + }), + ]; + const data = { + title: 'Edit Note', + layout: { addButtonText: 'Confirm' }, + formfields: formfields + }; + const editNoteDialogRef = this.dialog.open(FormDialogComponent, { data }); + editNoteDialogRef.afterClosed().subscribe((response: any) => { + if (response.data) { + this.groupsService.editGroupNote(this.groupId, noteId, response.data.value).subscribe(() => { + this.groupNotes[index].note = response.data.value.note; + }); + } + }); + } + + /** + * Delets the given note. + * @param {string} noteId Note Id. + * @param {number} index Index of Note. + */ + deleteNote(noteId: string, index: number) { + const deleteNoteDialogRef = this.dialog.open(DeleteDialogComponent, { + data: { deleteContext: `Note id:${noteId}` } + }); + deleteNoteDialogRef.afterClosed().subscribe((response: any) => { + if (response.delete) { + this.groupsService.deleteGroupNote(this.groupId, noteId).subscribe(() => { + this.groupNotes.splice(index, 1); + }); + } + }); + } + +} diff --git a/src/app/groups/groups.module.ts b/src/app/groups/groups.module.ts index 799648f06..ed3a3ee38 100644 --- a/src/app/groups/groups.module.ts +++ b/src/app/groups/groups.module.ts @@ -12,6 +12,7 @@ import { DirectivesModule } from '../directives/directives.module'; import { GroupsComponent } from './groups.component'; import { GroupsViewComponent } from './groups-view/groups-view.component'; import { GeneralTabComponent } from './groups-view/general-tab/general-tab.component'; +import { NotesTabComponent } from './groups-view/notes-tab/notes-tab.component'; /** * Groups Module @@ -28,7 +29,8 @@ import { GeneralTabComponent } from './groups-view/general-tab/general-tab.compo declarations: [ GroupsComponent, GroupsViewComponent, - GeneralTabComponent + GeneralTabComponent, + NotesTabComponent ], providers: [DatePipe] }) diff --git a/src/app/groups/groups.service.ts b/src/app/groups/groups.service.ts index 8dfa71bcb..d5e7eb97c 100644 --- a/src/app/groups/groups.service.ts +++ b/src/app/groups/groups.service.ts @@ -89,4 +89,38 @@ export class GroupsService { return this.http.get(`/groups/${groupId}/accounts`); } + /** + * @param groupId Group Id of group to get data for. + * @returns {Observable} Group Notes data. + */ + getGroupNotes(groupId: string): Observable { + return this.http.get(`/groups/${groupId}/notes`); + } + + /** + * @param groupId Group Id of group to create note for. + * @param noteData Note Data. + * @returns {Observable} + */ + createGroupNote(groupId: string, noteData: any): Observable { + return this.http.post(`/groups/${groupId}/notes`, noteData); + } + + /** + * @param groupId Group Id of group to edit note for. + * @param noteId Note Id + * @param noteData Note Data + */ + editGroupNote(groupId: string, noteId: string, noteData: any) { + return this.http.put(`/groups/${groupId}/notes/${noteId}`, noteData); + } + + /** + * @param groupId Group Id of group to delete note for. + * @param noteId Note Id + */ + deleteGroupNote(groupId: string, noteId: string) { + return this.http.delete(`/groups/${groupId}/notes/${noteId}`); + } + }