feat: add groups view page (notes-tab) (#789)

Fixes: #778
This commit is contained in:
Karan Takalkar
2020-05-20 16:17:55 +05:30
committed by GitHub
parent 2e89538432
commit a5711131c7
9 changed files with 304 additions and 2 deletions
@@ -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<Object> {
/**
* @param {GroupsService} GroupsService Groups service.
*/
constructor(private groupsService: GroupsService) { }
/**
* Returns the Group's Notes data.
* @param {ActivatedRouteSnapshot} route Route Snapshot.
* @returns {Observable<any>}
*/
resolve(route: ActivatedRouteSnapshot): Observable<any> {
const groupId = route.parent.paramMap.get('groupId');
return this.groupsService.getGroupNotes(groupId);
}
}
+12 -1
View File
@@ -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 { }
@@ -100,6 +100,10 @@
[active]="general.isActive">
General
</a>
<a mat-tab-link [routerLink]="['./notes']" routerLinkActive #notes="routerLinkActive"
[active]="notes.isActive">
Notes
</a>
</nav>
<router-outlet></router-outlet>
@@ -0,0 +1,39 @@
<div class="tab-container mat-typography">
<h3>Notes</h3>
<form #formRef="ngForm" [formGroup]="noteForm" fxLayout="row" fxLayoutAlign="start baseline" fxLayoutGap="20px"
(ngSubmit)="addNote()">
<mat-form-field fxFlex="calc(90%-20px)">
<textarea formControlName="note" matInput placeholder="Write a note ...."></textarea>
</mat-form-field>
<button mat-raised-button fxFlex color="primary" [disabled]="!noteForm.valid">
<fa-icon icon="plus"></fa-icon>&nbsp;&nbsp; Add
</button>
</form>
<mat-list>
<mat-list-item *ngFor="let groupNote of groupNotes; let i=index;">
<fa-icon icon="sticky-note" matListIcon></fa-icon>
<h3 matLine>{{groupNote.note}} </h3>
<p matLine>
<span>Created by: {{groupNote.createdByUsername}}</span><br />
<span>Date: {{groupNote.createdOn | date}}</span>
</p>
<div fxLayout="row" fxLayoutAlign="flex-start">
<button mat-button color="primary" (click)="editNote(groupNote.id,groupNote.note,i)">
<fa-icon icon="edit"></fa-icon>
</button>
<button mat-button color="warn" (click)="deleteNote(groupNote.id,i)">
<fa-icon icon="trash"></fa-icon>
</button>
</div>
</mat-list-item>
</mat-list>
</div>
@@ -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;
}
}
@@ -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<NotesTabComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ NotesTabComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(NotesTabComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -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);
});
}
});
}
}
+3 -1
View File
@@ -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]
})
+34
View File
@@ -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<any>} Group Notes data.
*/
getGroupNotes(groupId: string): Observable<any> {
return this.http.get(`/groups/${groupId}/notes`);
}
/**
* @param groupId Group Id of group to create note for.
* @param noteData Note Data.
* @returns {Observable<any>}
*/
createGroupNote(groupId: string, noteData: any): Observable<any> {
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}`);
}
}