business done

This commit is contained in:
surendar.m@watermelon.us 2023-03-08 18:04:58 +05:30
parent 40fb087f98
commit bf8cd5f47d
11 changed files with 155 additions and 97 deletions

View File

@ -57,10 +57,7 @@ export class BusinessListComponent implements OnInit {
this._bus.getBusinessListDetails().subscribe(res => {
if (res.status == 200) {
this.businessList = res.data;
}
else{
}
}
}
// , error => {this.errorMessage = <any> error});
,error => {
@ -81,8 +78,8 @@ export class BusinessListComponent implements OnInit {
}
}
confirmBox(name,element){
console.log(name,element)
confirmBox(event,element){
console.log(event,element)
Swal.fire({
title: 'Are you sure want to remove?',
text: 'You will not be able to recover this file!',
@ -92,7 +89,7 @@ export class BusinessListComponent implements OnInit {
cancelButtonText: 'No, keep it'
}).then((result) => {
if (result.value) {
this.deleteRowData(element);
this.formAddUpdateAndDelete(event,element)
Swal.fire(
'Deleted!',
'Your imaginary file has been deleted.',
@ -111,61 +108,91 @@ export class BusinessListComponent implements OnInit {
openDialog(action,obj) {
obj.action = action;
const dialogRef = this.dialog.open(DialogBoxComponent, {
width: '32%',
width: '39%',
height: '100%',
// maxWidth: '38vw',
position: { right: '0' },
data:obj
});
dialogRef.afterClosed().subscribe(result => {
if(result != undefined){
console.log(result)
if(result.event == 'Add'){
this.addRowData(result.data);
}else if(result.event == 'Update'){
this.updateRowData(result.data);
}else if(result.event == 'Delete'){
this.deleteRowData(result.data);
this.formAddUpdateAndDelete(result,result.data)
}
});
}
addRowData(row_obj){
var d = this.dataSource.data.length+1
console.log(this.dataSource)
this.dataSource.data.push
({
id: d,
logo: row_obj.logo,
name: row_obj.name,
email: row_obj.email,
phone: row_obj.phone,
address: row_obj.address,
city: row_obj.city,
state: row_obj.state
});
this.table.renderRows();
}
updateRowData(row_obj){
console.log(row_obj)
this.dataSource = this.dataSource.data.filter((value,key)=>{
if(value.id == row_obj.id){
value.logo = row_obj.logo;
value.name = row_obj.name;
value.email = row_obj.email;
value.phone = row_obj.phone;
value.address = row_obj.address;
value.city = row_obj.city;
value.state = row_obj.state;
formAddUpdateAndDelete(result,row_obj){
console.log(result,row_obj)
let formValue = []
if(result.event == 'Add'){
console.log('add')
let addFormData = {
address: row_obj.address,
// busId: 'abc123',
city: row_obj.city,
busName: row_obj.busName,
email: row_obj.email,
contactNo: row_obj.contactNo,
pincode: row_obj.pincode,
state: row_obj.state ,
workingHrsJson: row_obj.workingHrsJson
};
formValue.push(addFormData);
}else if(result.event == 'Update'){
console.log('Update')
formValue.push(row_obj);
}
else if(result == 'Delete'){
console.log('delete')
let val = {
isActive:0,
id: row_obj.id
}
return true;
formValue.push(val);
}
// var d = this.customersList.length+1
console.log(formValue[0])
this._bus.addFormDetails(formValue[0]).subscribe(res => {
if (res.status == 200) {
// this.customersList = res.data;
this.getBusinessList()
}
else{
// this.customersList=[];
// this.dataSource = null;
// this.recordStatus=true;
}
}
// , error => {this.errorMessage = <any> error});
,error => {
// this.errorMessage.push(error);
// this.notifier.notify('error', 'Something Went Wrong Try Again.! \t\"' + (error.error_type == 2 ? error.error_status + ' ( ' + error.error_text + ' ) ' : ' ( ' + error.error_text + ' ) ') +'\" Error Occur.!');
// alert(error.html_format);
});
}
deleteRowData(row_obj){
console.log(this.dataSource.data,row_obj)
this.dataSource.data = this.dataSource.data.filter((value,key)=>{
return value.id != row_obj.id
});
console.log(this.dataSource)
}
// updateRowData(row_obj){
// console.log(row_obj)
// this.dataSource = this.dataSource.data.filter((value,key)=>{
// if(value.id == row_obj.id){
// value.logo = row_obj.logo;
// value.name = row_obj.name;
// value.email = row_obj.email;
// value.phone = row_obj.phone;
// value.address = row_obj.address;
// value.city = row_obj.city;
// value.state = row_obj.state;
// }
// return true;
// });
// }
// deleteRowData(row_obj){
// console.log(this.dataSource.data,row_obj)
// this.dataSource.data = this.dataSource.data.filter((value,key)=>{
// return value.id != row_obj.id
// });
// console.log(this.dataSource)
// }
}

View File

@ -18,6 +18,13 @@ export class BusinessService {
catchError(this.handleError('role', []))
)
}
addFormDetails(addParams): Observable<any> {
return this._http.post(this.apiUrl + 'createBusinessDetails', addParams)
// .pipe(
// catchError(this.handleError('role', []))
// )
}
private handleError<T>(operation = 'operation', result?: T) {
return (error: any): Observable<T> => {

View File

@ -9,6 +9,7 @@ import { MatFormFieldModule } from '@angular/material/form-field';
import { DialogBoxComponent } from './dialog-box/dialog-box.component';
import { ScrollingModule } from '@angular/cdk/scrolling';
import { DemoMaterialModule } from 'app/shared/demo.module';
import { NgScrollbarModule } from 'ngx-scrollbar';
@ -25,8 +26,8 @@ import { DemoMaterialModule } from 'app/shared/demo.module';
BusinessRoutingModule,
MatSidenavModule,
MatFormFieldModule,
ScrollingModule
ScrollingModule,
NgScrollbarModule
]
})

View File

@ -1,14 +1,15 @@
<mat-card class="settings-panel" >
<!-- <mat-card class="settings-panel" > -->
<h5 mat-dialog-title> <strong>{{action}} Business</strong>
<button mat-icon-button type="button" matTooltip="Close" class="button" matTooltipPosition="above" (click)="close()"
><mat-icon>close</mat-icon></button></h5>
<div mat-dialog-content class="my-table">
<form [formGroup]="form" (ngSubmit)="submit()">
<ng-scrollbar class="scrollHV">
<div mat-dialog-content class="my-table">
<mat-form-field appearance="outline" *ngIf="action != 'Delete'; else elseTemplate" class="mat-pane">
<input placeholder=" Name" matInput formControlName="name">
<mat-error *ngIf="myError('name', 'required')">Name is required</mat-error>
<mat-error *ngIf="myError('name', 'maxlength')">Limit exceed</mat-error>
<input placeholder=" Name" matInput formControlName="busName">
<mat-error *ngIf="myError('busName', 'required')">Name is required</mat-error>
<mat-error *ngIf="myError('busName', 'maxlength')">Limit exceed</mat-error>
</mat-form-field>
<mat-form-field appearance="outline" *ngIf="action != 'Delete'; else elseTemplate" class="mat-pane">
@ -21,9 +22,9 @@
</mat-error>
</mat-form-field>
<mat-form-field appearance="outline" *ngIf="action != 'Delete'; else elseTemplate" class="mat-pane">
<input placeholder=" Phone" matInput [(ngModel)]="local_data.phone" formControlName="contact_no">
<mat-error *ngIf="myError('contact_no', 'required')">Contact No is required</mat-error>
<mat-error *ngIf="myError('contact_no', 'maxlength')">Limit exceed</mat-error>
<input placeholder=" Phone" matInput [(ngModel)]="local_data.contactNo" formControlName="contactNo">
<mat-error *ngIf="myError('contactNo', 'required')">Contact No is required</mat-error>
<mat-error *ngIf="myError('contactNo', 'maxlength')">Limit exceed</mat-error>
</mat-form-field>
<mat-form-field appearance="outline" *ngIf="action != 'Delete'; else elseTemplate" class="mat-pane">
<input placeholder=" Address" matInput [(ngModel)]="local_data.address" formControlName="address">
@ -40,18 +41,25 @@
<mat-error *ngIf="myError('city', 'required')">City is required</mat-error>
<mat-error *ngIf="myError('city', 'maxlength')">Limit exceed</mat-error>
</mat-form-field>
<img class="image" [src]="url" height="50">
<input type='file' (change)="onSelectFile($event)" formControlName="image">
</form>
</div>
<mat-form-field appearance="outline" *ngIf="action != 'Delete'; else elseTemplate" class="mat-pane">
<input placeholder="Working Hrs" matInput formControlName="workingHrsJson">
<mat-error *ngIf="myError('workingHrsJson', 'required')">Working Hrs is required</mat-error>
<mat-error *ngIf="myError('workingHrsJson', 'maxlength')">Limit exceed</mat-error>
</mat-form-field>
<img class="image mb-2" [src]="url" height="50">
<input type='file' (change)="onSelectFile($event)" formControlName="logo">
<ng-template #elseTemplate>
Sure to delete <b>{{local_data.name}}</b>?
</ng-template><br>
<div mat-dialog-actions>
<button mat-button (click)="doAction()" class="mat-green" mat-raised-button >{{action}}</button>
<button mat-button (click)="closeDialog()" >Cancel</button>
</div>
</mat-card>
</ng-scrollbar>
<ng-template #elseTemplate>
Sure to delete <b>{{local_data.name}}</b>?
</ng-template>
<div mat-dialog-actions>
<button mat-button type="submit" class="mat-green" mat-raised-button >{{action}}</button>
<button mat-button (click)="closeDialog()" >Cancel</button>
</div>
</form>
<!-- </mat-card> -->

View File

@ -48,9 +48,15 @@
}
}
::ng-deep .mat-dialog-content {
max-height: 75vh!important;
max-height: 170vh !important;
overflow: hidden!important;
}
::ng-deep .mat-dialog-container{
overflow: hidden!important;
}
.scrollHV {
height: calc(100vh - 150px);
}
:ng-deep .ng-scroll-viewport-wrapper{
right: -25px !important;
}

View File

@ -28,13 +28,9 @@ export class DialogBoxComponent implements OnInit {
get f(){
return this.form.controls;
}
doAction(){
let tmp = this.form.value
tmp.id = this.local_data.id
this.dialogRef.close({event:this.action,data:tmp});
console.log(this.form.value);
console.log(this.action,this.local_data)
}
// doAction(){
// }
closeDialog(){
this.dialogRef.close({event:'Cancel'});
}
@ -52,16 +48,16 @@ export class DialogBoxComponent implements OnInit {
}
ngOnInit() {
this.form = new FormGroup({
businessselect: new FormControl('', [Validators.required]),
image: new FormControl('', null),
name: new FormControl('', [Validators.required, Validators.maxLength(20)]),
workingHrsJson: new FormControl('', [Validators.required]),
logo: new FormControl('', null),
busName: new FormControl('', [Validators.required, Validators.maxLength(20)]),
address: new FormControl('', [Validators.required, Validators.maxLength(50)]),
city: new FormControl('', [Validators.required, Validators.maxLength(10)]),
state: new FormControl('', [Validators.required, Validators.maxLength(10)]),
email: new FormControl('', [Validators.required, Validators.email,Validators.pattern(
'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,63}$',
),]),
contact_no: new FormControl('', [Validators.required, Validators.maxLength(10)]),
contactNo: new FormControl('', [Validators.required, Validators.maxLength(10)]),
});
this.form.patchValue(this.local_data)
}
@ -69,6 +65,10 @@ export class DialogBoxComponent implements OnInit {
return this.form.controls[controlName].hasError(errorName);
}
submit(){
let tmp = this.form.value
tmp.id = this.local_data.id
this.dialogRef.close({event:this.action,data:tmp});
console.log(this.form.value);
console.log(this.action,this.local_data)
}
}

View File

@ -129,15 +129,17 @@ export class CustomersListComponent implements OnInit {
openDialog(action,obj) {
obj.action = action;
const dialogRef = this.dialog.open(DialogBoxComponent, {
// width: '30%',
width: '39%',
height: '100%',
// maxWidth: '38vw',
position: { right: '0' },
data:obj
});
dialogRef.afterClosed().subscribe(result => {
console.log(result)
this.formAddUpdateAndDelete(result,result.data)
if(result != undefined){
console.log(result)
this.formAddUpdateAndDelete(result,result.data)
}
});
}

View File

@ -7,6 +7,7 @@ import { MatSidenavModule } from '@angular/material/sidenav';
import { MatFormFieldModule } from '@angular/material/form-field';
import { DialogBoxComponent } from './dialog-box/dialog-box.component';
import { DemoMaterialModule } from 'app/shared/demo.module';
import { NgScrollbarModule } from 'ngx-scrollbar';
@NgModule({
@ -20,6 +21,7 @@ import { DemoMaterialModule } from 'app/shared/demo.module';
CustomersRoutingModule,
MatSidenavModule,
MatFormFieldModule,
NgScrollbarModule
]
})
export class CustomersModule { }

View File

@ -1,10 +1,11 @@
<mat-card class="settings-panel" >
<!-- <mat-card class="settings-panel" > -->
<h5 mat-dialog-title> <strong>{{action}} Customers</strong>
<button mat-icon-button type="button" matTooltip="Close" class="button" matTooltipPosition="above" (click)="close()"
><mat-icon>close</mat-icon></button></h5>
<div mat-dialog-content class="my-table">
<form [formGroup]="form" (ngSubmit)="submit()">
<ng-scrollbar class="scrollHV">
<div mat-dialog-content class="my-table">
<mat-form-field appearance="outline" *ngIf="action != 'Delete'; else elseTemplate" class="mat-pane">
<input placeholder=" Name" matInput formControlName="cusName">
<mat-error *ngIf="myError('cusName', 'required')">Name is required</mat-error>
@ -49,15 +50,15 @@
<input type='file' (change)="onSelectFile($event)" formControlName="image"> -->
<ng-template #elseTemplate>
Sure to delete <b>{{local_data.cusName}}</b>?
</ng-template><br>
</ng-template>
</div>
</ng-scrollbar>
<div mat-dialog-actions>
<button mat-button type="submit" class="mat-green" mat-raised-button >{{action}}</button>
<button mat-button (click)="closeDialog()" >Cancel</button>
</div>
</form>
</div>
</div>
</form>
</mat-card>
<!-- </mat-card> -->

View File

@ -48,7 +48,10 @@
}
}
::ng-deep .mat-dialog-content {
max-height: 80vh!important;
max-height: 170vh!important;
overflow: hidden!important;
}
.scrollHV {
height: calc(100vh - 150px);
}

View File

@ -218,6 +218,7 @@ users() {
});
}
logout() {
localStorage.clear();
this.router.navigate(['/']);
}