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 => { this._bus.getBusinessListDetails().subscribe(res => {
if (res.status == 200) { if (res.status == 200) {
this.businessList = res.data; this.businessList = res.data;
} }
else{
}
} }
// , error => {this.errorMessage = <any> error}); // , error => {this.errorMessage = <any> error});
,error => { ,error => {
@ -81,8 +78,8 @@ export class BusinessListComponent implements OnInit {
} }
} }
confirmBox(name,element){ confirmBox(event,element){
console.log(name,element) console.log(event,element)
Swal.fire({ Swal.fire({
title: 'Are you sure want to remove?', title: 'Are you sure want to remove?',
text: 'You will not be able to recover this file!', text: 'You will not be able to recover this file!',
@ -92,7 +89,7 @@ export class BusinessListComponent implements OnInit {
cancelButtonText: 'No, keep it' cancelButtonText: 'No, keep it'
}).then((result) => { }).then((result) => {
if (result.value) { if (result.value) {
this.deleteRowData(element); this.formAddUpdateAndDelete(event,element)
Swal.fire( Swal.fire(
'Deleted!', 'Deleted!',
'Your imaginary file has been deleted.', 'Your imaginary file has been deleted.',
@ -111,61 +108,91 @@ export class BusinessListComponent implements OnInit {
openDialog(action,obj) { openDialog(action,obj) {
obj.action = action; obj.action = action;
const dialogRef = this.dialog.open(DialogBoxComponent, { const dialogRef = this.dialog.open(DialogBoxComponent, {
width: '32%', width: '39%',
height: '100%', height: '100%',
// maxWidth: '38vw', // maxWidth: '38vw',
position: { right: '0' }, position: { right: '0' },
data:obj data:obj
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe(result => {
if(result != undefined){
console.log(result) console.log(result)
if(result.event == 'Add'){ this.formAddUpdateAndDelete(result,result.data)
this.addRowData(result.data);
}else if(result.event == 'Update'){
this.updateRowData(result.data);
}else if(result.event == 'Delete'){
this.deleteRowData(result.data);
} }
}); });
} }
addRowData(row_obj){
var d = this.dataSource.data.length+1 formAddUpdateAndDelete(result,row_obj){
console.log(this.dataSource) console.log(result,row_obj)
this.dataSource.data.push let formValue = []
({ if(result.event == 'Add'){
id: d, console.log('add')
logo: row_obj.logo, let addFormData = {
name: row_obj.name, address: row_obj.address,
email: row_obj.email, // busId: 'abc123',
phone: row_obj.phone, city: row_obj.city,
address: row_obj.address, busName: row_obj.busName,
city: row_obj.city, email: row_obj.email,
state: row_obj.state contactNo: row_obj.contactNo,
pincode: row_obj.pincode,
}); state: row_obj.state ,
this.table.renderRows(); workingHrsJson: row_obj.workingHrsJson
} };
updateRowData(row_obj){ formValue.push(addFormData);
console.log(row_obj) }else if(result.event == 'Update'){
this.dataSource = this.dataSource.data.filter((value,key)=>{ console.log('Update')
if(value.id == row_obj.id){ formValue.push(row_obj);
value.logo = row_obj.logo; }
value.name = row_obj.name; else if(result == 'Delete'){
value.email = row_obj.email; console.log('delete')
value.phone = row_obj.phone; let val = {
value.address = row_obj.address; isActive:0,
value.city = row_obj.city; id: row_obj.id
value.state = row_obj.state;
} }
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){ // updateRowData(row_obj){
console.log(this.dataSource.data,row_obj) // console.log(row_obj)
this.dataSource.data = this.dataSource.data.filter((value,key)=>{ // this.dataSource = this.dataSource.data.filter((value,key)=>{
return value.id != row_obj.id // if(value.id == row_obj.id){
}); // value.logo = row_obj.logo;
console.log(this.dataSource) // 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', [])) 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) { private handleError<T>(operation = 'operation', result?: T) {
return (error: any): Observable<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 { DialogBoxComponent } from './dialog-box/dialog-box.component';
import { ScrollingModule } from '@angular/cdk/scrolling'; import { ScrollingModule } from '@angular/cdk/scrolling';
import { DemoMaterialModule } from 'app/shared/demo.module'; import { DemoMaterialModule } from 'app/shared/demo.module';
import { NgScrollbarModule } from 'ngx-scrollbar';
@ -25,8 +26,8 @@ import { DemoMaterialModule } from 'app/shared/demo.module';
BusinessRoutingModule, BusinessRoutingModule,
MatSidenavModule, MatSidenavModule,
MatFormFieldModule, 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> <h5 mat-dialog-title> <strong>{{action}} Business</strong>
<button mat-icon-button type="button" matTooltip="Close" class="button" matTooltipPosition="above" (click)="close()" <button mat-icon-button type="button" matTooltip="Close" class="button" matTooltipPosition="above" (click)="close()"
><mat-icon>close</mat-icon></button></h5> ><mat-icon>close</mat-icon></button></h5>
<div mat-dialog-content class="my-table">
<form [formGroup]="form" (ngSubmit)="submit()"> <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"> <mat-form-field appearance="outline" *ngIf="action != 'Delete'; else elseTemplate" class="mat-pane">
<input placeholder=" Name" matInput formControlName="name"> <input placeholder=" Name" matInput formControlName="busName">
<mat-error *ngIf="myError('name', 'required')">Name is required</mat-error> <mat-error *ngIf="myError('busName', 'required')">Name is required</mat-error>
<mat-error *ngIf="myError('name', 'maxlength')">Limit exceed</mat-error> <mat-error *ngIf="myError('busName', 'maxlength')">Limit exceed</mat-error>
</mat-form-field> </mat-form-field>
<mat-form-field appearance="outline" *ngIf="action != 'Delete'; else elseTemplate" class="mat-pane"> <mat-form-field appearance="outline" *ngIf="action != 'Delete'; else elseTemplate" class="mat-pane">
@ -21,9 +22,9 @@
</mat-error> </mat-error>
</mat-form-field> </mat-form-field>
<mat-form-field appearance="outline" *ngIf="action != 'Delete'; else elseTemplate" class="mat-pane"> <mat-form-field appearance="outline" *ngIf="action != 'Delete'; else elseTemplate" class="mat-pane">
<input placeholder=" Phone" matInput [(ngModel)]="local_data.phone" formControlName="contact_no"> <input placeholder=" Phone" matInput [(ngModel)]="local_data.contactNo" formControlName="contactNo">
<mat-error *ngIf="myError('contact_no', 'required')">Contact No is required</mat-error> <mat-error *ngIf="myError('contactNo', 'required')">Contact No is required</mat-error>
<mat-error *ngIf="myError('contact_no', 'maxlength')">Limit exceed</mat-error> <mat-error *ngIf="myError('contactNo', 'maxlength')">Limit exceed</mat-error>
</mat-form-field> </mat-form-field>
<mat-form-field appearance="outline" *ngIf="action != 'Delete'; else elseTemplate" class="mat-pane"> <mat-form-field appearance="outline" *ngIf="action != 'Delete'; else elseTemplate" class="mat-pane">
<input placeholder=" Address" matInput [(ngModel)]="local_data.address" formControlName="address"> <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', 'required')">City is required</mat-error>
<mat-error *ngIf="myError('city', 'maxlength')">Limit exceed</mat-error> <mat-error *ngIf="myError('city', 'maxlength')">Limit exceed</mat-error>
</mat-form-field> </mat-form-field>
<img class="image" [src]="url" height="50"> <mat-form-field appearance="outline" *ngIf="action != 'Delete'; else elseTemplate" class="mat-pane">
<input type='file' (change)="onSelectFile($event)" formControlName="image"> <input placeholder="Working Hrs" matInput formControlName="workingHrsJson">
</form> <mat-error *ngIf="myError('workingHrsJson', 'required')">Working Hrs is required</mat-error>
</div> <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> </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 { ::ng-deep .mat-dialog-content {
max-height: 75vh!important; max-height: 170vh !important;
overflow: hidden!important; overflow: hidden!important;
} }
::ng-deep .mat-dialog-container{ ::ng-deep .mat-dialog-container{
overflow: hidden!important; 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(){ get f(){
return this.form.controls; return this.form.controls;
} }
doAction(){ // 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)
}
closeDialog(){ closeDialog(){
this.dialogRef.close({event:'Cancel'}); this.dialogRef.close({event:'Cancel'});
} }
@ -52,16 +48,16 @@ export class DialogBoxComponent implements OnInit {
} }
ngOnInit() { ngOnInit() {
this.form = new FormGroup({ this.form = new FormGroup({
businessselect: new FormControl('', [Validators.required]), workingHrsJson: new FormControl('', [Validators.required]),
image: new FormControl('', null), logo: new FormControl('', null),
name: new FormControl('', [Validators.required, Validators.maxLength(20)]), busName: new FormControl('', [Validators.required, Validators.maxLength(20)]),
address: new FormControl('', [Validators.required, Validators.maxLength(50)]), address: new FormControl('', [Validators.required, Validators.maxLength(50)]),
city: new FormControl('', [Validators.required, Validators.maxLength(10)]), city: new FormControl('', [Validators.required, Validators.maxLength(10)]),
state: new FormControl('', [Validators.required, Validators.maxLength(10)]), state: new FormControl('', [Validators.required, Validators.maxLength(10)]),
email: new FormControl('', [Validators.required, Validators.email,Validators.pattern( email: new FormControl('', [Validators.required, Validators.email,Validators.pattern(
'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,63}$', '[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) this.form.patchValue(this.local_data)
} }
@ -69,6 +65,10 @@ export class DialogBoxComponent implements OnInit {
return this.form.controls[controlName].hasError(errorName); return this.form.controls[controlName].hasError(errorName);
} }
submit(){ 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.form.value);
console.log(this.action,this.local_data)
} }
} }

View File

@ -129,15 +129,17 @@ export class CustomersListComponent implements OnInit {
openDialog(action,obj) { openDialog(action,obj) {
obj.action = action; obj.action = action;
const dialogRef = this.dialog.open(DialogBoxComponent, { const dialogRef = this.dialog.open(DialogBoxComponent, {
// width: '30%', width: '39%',
height: '100%', height: '100%',
// maxWidth: '38vw', // maxWidth: '38vw',
position: { right: '0' }, position: { right: '0' },
data:obj data:obj
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe(result => {
console.log(result) if(result != undefined){
this.formAddUpdateAndDelete(result,result.data) 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 { MatFormFieldModule } from '@angular/material/form-field';
import { DialogBoxComponent } from './dialog-box/dialog-box.component'; import { DialogBoxComponent } from './dialog-box/dialog-box.component';
import { DemoMaterialModule } from 'app/shared/demo.module'; import { DemoMaterialModule } from 'app/shared/demo.module';
import { NgScrollbarModule } from 'ngx-scrollbar';
@NgModule({ @NgModule({
@ -20,6 +21,7 @@ import { DemoMaterialModule } from 'app/shared/demo.module';
CustomersRoutingModule, CustomersRoutingModule,
MatSidenavModule, MatSidenavModule,
MatFormFieldModule, MatFormFieldModule,
NgScrollbarModule
] ]
}) })
export class CustomersModule { } 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> <h5 mat-dialog-title> <strong>{{action}} Customers</strong>
<button mat-icon-button type="button" matTooltip="Close" class="button" matTooltipPosition="above" (click)="close()" <button mat-icon-button type="button" matTooltip="Close" class="button" matTooltipPosition="above" (click)="close()"
><mat-icon>close</mat-icon></button></h5> ><mat-icon>close</mat-icon></button></h5>
<div mat-dialog-content class="my-table">
<form [formGroup]="form" (ngSubmit)="submit()"> <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"> <mat-form-field appearance="outline" *ngIf="action != 'Delete'; else elseTemplate" class="mat-pane">
<input placeholder=" Name" matInput formControlName="cusName"> <input placeholder=" Name" matInput formControlName="cusName">
<mat-error *ngIf="myError('cusName', 'required')">Name is required</mat-error> <mat-error *ngIf="myError('cusName', 'required')">Name is required</mat-error>
@ -49,15 +50,15 @@
<input type='file' (change)="onSelectFile($event)" formControlName="image"> --> <input type='file' (change)="onSelectFile($event)" formControlName="image"> -->
<ng-template #elseTemplate> <ng-template #elseTemplate>
Sure to delete <b>{{local_data.cusName}}</b>? Sure to delete <b>{{local_data.cusName}}</b>?
</ng-template><br> </ng-template>
</div>
</ng-scrollbar>
<div mat-dialog-actions> <div mat-dialog-actions>
<button mat-button type="submit" class="mat-green" mat-raised-button >{{action}}</button> <button mat-button type="submit" class="mat-green" mat-raised-button >{{action}}</button>
<button mat-button (click)="closeDialog()" >Cancel</button> <button mat-button (click)="closeDialog()" >Cancel</button>
</div> </div>
</form> </form>
</div>
</mat-card> <!-- </mat-card> -->

View File

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

View File

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