Add datatable step when exist entity datatable checks (#1633)
Co-authored-by: Jose Alberto Hernandez <alberto@MacBook-Pro.local>
This commit is contained in:
co-authored by
Jose Alberto Hernandez
parent
cafe8fa73d
commit
3a3d96222e
@@ -1,39 +1,7 @@
|
||||
<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" *mifosxHasPermission="'CREATE_GROUPNOTE'" [disabled]="!noteForm.valid">
|
||||
<fa-icon icon="plus"></fa-icon> 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 | dateFormat}}</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>
|
||||
<mifosx-entity-notes-tab [entityId]="entityId"
|
||||
[entityNotes]="entityNotes"
|
||||
[callbackAdd]="addNote"
|
||||
[callbackEdit]="editNote"
|
||||
[callbackDelete]="deleteNote"
|
||||
>
|
||||
</mifosx-entity-notes-tab>
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
.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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,12 @@
|
||||
/** Angular Imports */
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
|
||||
/** 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.
|
||||
@@ -26,113 +18,66 @@ import { InputBase } from 'app/shared/form-dialog/formfield/model/input-base';
|
||||
})
|
||||
export class NotesTabComponent implements OnInit {
|
||||
|
||||
/** Group Notes */
|
||||
groupNotes: any;
|
||||
/** Group Id */
|
||||
groupId: string;
|
||||
/** User Name */
|
||||
/** Group ID */
|
||||
entityId: string;
|
||||
/** Username */
|
||||
username: string;
|
||||
/** Note form */
|
||||
noteForm: FormGroup;
|
||||
|
||||
/** Note Form Reference */
|
||||
@ViewChild('formRef', { static: true }) formRef: any;
|
||||
/** Client Notes */
|
||||
entityNotes: any;
|
||||
|
||||
/**
|
||||
* Fetches notes data from `resolve`
|
||||
* @param {Activated Route} route Activated Route.
|
||||
* @param {FormBuilder} formBuilder FormBuilder
|
||||
* @param {GroupsService} groupsService Groups Service
|
||||
* @param {MatDialog} dialog MatDialog
|
||||
* @param {AuthenticationService} authenticationService Authentication Service.
|
||||
*/
|
||||
constructor(private route: ActivatedRoute,
|
||||
private formBuilder: FormBuilder,
|
||||
private authenticationService: AuthenticationService,
|
||||
private groupsService: GroupsService,
|
||||
public dialog: MatDialog) {
|
||||
private groupsService: GroupsService) {
|
||||
const savedCredentials = this.authenticationService.getCredentials();
|
||||
this.username = savedCredentials.username;
|
||||
this.groupId = this.route.parent.snapshot.params['groupId'];
|
||||
this.entityId = this.route.parent.snapshot.params['groupId'];
|
||||
this.route.data.subscribe((data: { groupNotes: any }) => {
|
||||
this.groupNotes = data.groupNotes;
|
||||
this.entityNotes = 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({
|
||||
addNote(noteContent: any) {
|
||||
this.groupsService.createGroupNote(this.entityId, noteContent).subscribe((response: any) => {
|
||||
this.entityNotes.push({
|
||||
id: response.resourceId,
|
||||
createdByUsername: this.username,
|
||||
createdOn: new Date(),
|
||||
note: this.noteForm.value.note
|
||||
note: noteContent.note
|
||||
});
|
||||
this.formRef.resetForm();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits selected note.
|
||||
* @param {string} noteId Note Id.
|
||||
* @param {string} noteContent Note's content.
|
||||
* @param {number} index Index of note.
|
||||
* @param {any} noteContent Note's content.
|
||||
*/
|
||||
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;
|
||||
});
|
||||
}
|
||||
editNote(noteId: string, noteContent: any, index: number) {
|
||||
this.groupsService.editGroupNote(this.entityId, noteId, noteContent).subscribe(() => {
|
||||
this.entityNotes[index].note = noteContent.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);
|
||||
});
|
||||
}
|
||||
this.groupsService.deleteGroupNote(this.entityId, noteId)
|
||||
.subscribe(() => {
|
||||
this.entityNotes.splice(index, 1);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user