pdteam editcomponent changes : ps

This commit is contained in:
venbatechnologies@gmail.com 2018-11-23 11:40:13 +05:30
parent 203fcaa72f
commit 5286492952
6 changed files with 131 additions and 97 deletions

View File

@ -6,24 +6,26 @@ import { FormBuilder,
import { MatDialog,
MatDialogRef,
MAT_DIALOG_DATA } from '@angular/material';
/** Service */
import { MastersService } from '../../service/masters/masters.service';
import { PdTeamService } from '../../service/masters/pd-team.service';
import { NotifierService } from 'angular-notifier';
import { Router } from '@angular/router';
import { empty } from 'rxjs';
import { Router } from '@angular/router';
import { empty } from 'rxjs';
/**sweet alert */
import Swal from 'sweetalert2';
@Component({
selector: 'app-pd-team-add',
templateUrl: './pd-team-add.component.html',
styleUrls: ['./pd-team-add.component.scss']
})
export class PdTeamAddComponent implements OnInit {
public _pdTeamForm: FormGroup;
private notifier: NotifierService;
color = 'primary';
errorMessage:string;
@ -42,17 +44,16 @@ selectedProductDatas : any=[];
selectedSegmentDatas : any=[];
constructor(private _formBuilder: FormBuilder,
private _notifier: NotifierService,
private _pdTeamService: PdTeamService,
private _router: Router,
private _masterService: MastersService)
{
this.notifier = _notifier;
}
ngOnInit() {
//console.log(this.notifier);
this.PdTeamFormDatas();
/** For Checking City Validation datas - checking purpose - Already exists are not */
@ -143,15 +144,16 @@ onSubmit() {
this._pdTeamService.addPdTeamDetail(this._pdTeamForm.value).subscribe(
dataresult => {
if(dataresult.dataStatus == true) {
this.notifier.notify('success', 'Record Saved Successfully.!');
Swal('Record Saved Successfully.!','success');
this._router.navigate(['/setting/pdteam/pdteamlist']);
}
else {
this.notifier.notify('warning', 'Something Wents Wrong Try Again.!');
Swal('Wrong.!');
//alert('Some Thing Wents Wrong Try Again !');
//Swal('Wrong.!');
Swal('Some Thing Wents Wrong Try Again !');
//this.errorMessage = "Some Thing Wents Wrong Try Again !";
}
});
@ -225,13 +227,12 @@ onChangeEntityId($event){
}
if($event.isUserInput != false){
//console.log(this.CityValidation,lenderId);
//console.log(this.CityValidation,lenderId);
this._pdTeamService.getLenderData(lenderId).subscribe(
dataresult => {
if(dataresult.dataStatus == true) {
this.CityValidation = dataresult.records;
console.log(this.CityValidation);
//console.log(this.CityValidation);
}
}, error => this.errorMessage = <any> error);
}
@ -263,7 +264,7 @@ onChangeCityDatas($event){
mycheck = 1;
}
}
}
}
if(mycheck == 0){
this.selectedCityDatas.push(cityName.name);

View File

@ -1,4 +1,4 @@
<div style="max-height: 580px;">
<div style="max-height: 580px;" *ngIf="apiFinishLoad">
<form [formGroup]="_pdTeamForm" (submit)="onSubmit()">
<mat-card style="padding: 6px;">
<div class="ml-xs mr-xs" style="width: 100%;" fxLayout="row" fxLayoutAlign="center">

View File

@ -6,9 +6,9 @@ import { FormBuilder,
/** Service */
import { MastersService } from '../../service/masters/masters.service';
import { PdTeamService } from '../../service/masters/pd-team.service';
import { NotifierService } from 'angular-notifier';
/** Here this component is like as a partent component */
import { PdTeamListComponent } from './../pd-team-list/pd-team-list.component';
import { Router,ActivatedRoute } from '@angular/router';
/**sweet alert */
import Swal from 'sweetalert2';
@Component({
@ -22,14 +22,15 @@ export class PdTeamEditComponent implements OnInit {
public _pdTeamForm: FormGroup;
public submitted = false;
public listView: any = true;
private notifier: NotifierService;
color = 'primary';
errorMessage:string;
lenderId:any;
teamID: any;
apiFinishLoad: boolean;
//This "childMessage" to get the function or data from partent component
@Input() public childMessage: any;
//@Input() public childMessage: any;
public childMessage: any[];
//This Type Of Array Declaration for select dropdown to list the datas
citydatas: any[];
lenderdatas: any[];
@ -51,27 +52,33 @@ export class PdTeamEditComponent implements OnInit {
selectedCityDatas : any=[];
selectedProductDatas : any=[];
selectedSegmentDatas : any=[];
//EditDatasforFormGroup: any;
constructor(private _formBuilder: FormBuilder,
private _notifier: NotifierService,
private _router: Router,private route: ActivatedRoute,
private _pdTeamService: PdTeamService,
private _PdTeamListComponent: PdTeamListComponent,
private _masterService: MastersService) {
this.notifier = _notifier;
}
/** Onready function */
ngOnInit() {
//console.log(atob(this.route.snapshot.params['id']));
this.teamID = atob(this.route.snapshot.params['id']);
//console.log(this.teamID);
this._pdTeamForm = this._formBuilder.group({
pdteam_id: ['', Validators.compose([Validators.required])],
team_name: ['', Validators.compose([Validators.required])],
fk_lender: ['', Validators.compose([Validators.required])],
fk_city: ['', Validators.compose([Validators.required])],
fk_customer_segment: ['', Validators.compose([Validators.required])],
fk_product:['', Validators.compose([Validators.required])],
});
this.PdTeamFormDatas();
//console.log('hai I am Child This onready function',this.childMessage);
// this._pdTeamService.getAllPDTeamWithPDTeamID(this.childMessage).subscribe(
// dataresult => {
// console.log(dataresult);
// this.EditDatasforFormGroup = dataresult.records;
// console.log(this.EditDatasforFormGroup);
// });
/** For Checking City Validation datas - checking purpose - Already exists are not */
this._pdTeamService.getAllPdTeamCityMapping().subscribe(
dataresult => {
@ -117,18 +124,30 @@ export class PdTeamEditComponent implements OnInit {
this.customerSegmentdatas = this.customerSegmentdatas.filter(segment=>segment.isactive == 1 );
}
}, error => this.errorMessage = <any> error);
this.lenderId = this._pdTeamForm.value['fk_lender'];
this._pdTeamService.getLenderData(this.lenderId).subscribe(
dataresult => {
if(dataresult.dataStatus == true){
this.CityValidation = dataresult.records;
}
}, error => this.errorMessage = <any> error);
// this.lenderId = this._pdTeamForm.value.fk_lender;
// console.log('form data',this._pdTeamForm);
// console.log('form data Particular Value',this._pdTeamForm.value.fk_lender);
// this._pdTeamService.getLenderData(this.lenderId).subscribe(
// dataresult => {
// if(dataresult.dataStatus == true){
// this.CityValidation = dataresult.records;
// }
// });
}
/** Pd Team Form Datas */
PdTeamFormDatas(){
this._pdTeamService.getAllPDTeamWithPDTeamID(this.teamID).subscribe(
dataresult => {
//console.log('Response Data',dataresult);
if(dataresult.status == 200)
this.childMessage = dataresult.records;
// console.log('Record Data',dataresult.records);
// console.log('sdafd',this.childMessage[0].team_name);
//console.log('Patricular pdteam_id Datas',this.childMessage);
// let PdTeamcity:any = [];
@ -142,7 +161,7 @@ export class PdTeamEditComponent implements OnInit {
let PdTeamCity:any = [];
for(let ptc of this.childMessage[0].CITYMAP){
PdTeamCity.push(ptc.city_id);
}
}
let PdTeamProduct:any = [];
// for(let ptp of this.childMessage[0].PRODUCTS){
@ -173,17 +192,37 @@ export class PdTeamEditComponent implements OnInit {
}
}
}, error => this.errorMessage = <any> error);
this._pdTeamForm.controls['pdteam_id'].setValue(this.childMessage[0].pdteam_id);
this._pdTeamForm.controls['team_name'].setValue(this.childMessage[0].team_name);
this._pdTeamForm.controls['fk_lender'].setValue(this.childMessage[0].fk_lender_id);
this._pdTeamForm.controls['fk_city'].setValue(PdTeamCity);
this._pdTeamForm.controls['fk_customer_segment'].setValue(this.DBCustomerSegmentDatas);
this._pdTeamForm.controls['fk_product'].setValue(this.DBProductDatas);
this.apiFinishLoad = true;
// this.lenderId = this._pdTeamForm.get('fk_customer_segment').value;
// console.log('asf',this.lenderId);
// console.log('form data',this._pdTeamForm);
this._pdTeamService.getLenderData(this.childMessage[0].fk_lender_id).subscribe(
dataresult => {
if(dataresult.dataStatus == true){
this.CityValidation = dataresult.records;
}
});
this._pdTeamForm = this._formBuilder.group({
pdteam_id: [this.childMessage[0].pdteam_id, Validators.compose([Validators.required])],
team_name: [this.childMessage[0].team_name, Validators.compose([Validators.required])],
fk_lender: [this.childMessage[0].fk_lender_id, Validators.compose([Validators.required])],
fk_city: [PdTeamCity, Validators.compose([Validators.required])],
fk_customer_segment: [this.DBCustomerSegmentDatas, Validators.compose([Validators.required])],
fk_product:[this.DBProductDatas, Validators.compose([Validators.required])],
// this._pdTeamForm = this._formBuilder.group({
// pdteam_id: [this.childMessage[0].pdteam_id, Validators.compose([Validators.required])],
// team_name: [this.childMessage[0].team_name, Validators.compose([Validators.required])],
// fk_lender: [this.childMessage[0].fk_lender_id, Validators.compose([Validators.required])],
// fk_city: [PdTeamCity, Validators.compose([Validators.required])],
// fk_customer_segment: [this.DBCustomerSegmentDatas, Validators.compose([Validators.required])],
// fk_product:[this.DBProductDatas, Validators.compose([Validators.required])],
// });
});
}
/** convenience getter for easy access to form fields */
@ -191,9 +230,9 @@ export class PdTeamEditComponent implements OnInit {
/** For Popup Close Button */
onNoClick(): void {
this._PdTeamListComponent.changeListView();
this._router.navigate(['/setting/pdteam/pdteamlist']);
}
/** To Reset Popup Data For Add*/
// onResetForEdit(){
// this.PdTeamFormDatas();
@ -225,9 +264,9 @@ export class PdTeamEditComponent implements OnInit {
this._pdTeamService.editPdTeamchildDetails(ActiveDatas,'PDTEAMCUSTOMERSEGMENT')
.subscribe(dataresult=>{
if (dataresult.dataStatus == true){
//alert('InActive Changes Done in cs');
let index = this.selectedSegmentDatas.indexOf(CustomerSegmentName.name);
this.selectedSegmentDatas.splice(index,1);
// alert('InActive Changes Done in cs');
// let index = this.selectedSegmentDatas.indexOf(CustomerSegmentName.name);
// this.selectedSegmentDatas.splice(index,1);
}else{}
});
@ -326,6 +365,7 @@ export class PdTeamEditComponent implements OnInit {
else if($event.source._selected == false ){
console.log('Return False for city Selection Data');
let index = this.selectedCityDatas.indexOf(cityName.name);
this.selectedCityDatas.splice(index,1);
@ -336,16 +376,20 @@ export class PdTeamEditComponent implements OnInit {
dataresult => {
if (dataresult.dataStatus == true) {
data = dataresult.records;
//console.log('data',data);
data = data.filter(pdteamcity=>pdteamcity.fk_city_id == $event.source.value);
data = data.filter(pdteamcity=>pdteamcity.fk_pdteam_id == this._pdTeamForm.value.pdteam_id)[0];
//console.log(data.pdteam_city_id);
// console.log('cityID',data.pdteam_city_id);
// console.log('Event value',$event.source.value);
this._pdTeamService.deletePDteamCity($event.source.value).subscribe(data=>{
if (dataresult.dataStatus == true) {//alert('Deleted');
let index = this.selectedCityDatas.indexOf(cityName.name);
this.selectedCityDatas.splice(index,1);
//this._PdTeamListComponent.changeListView();
}
// console.log('Response Data',data);
// if (dataresult.dataStatus == true) {
// alert('Deleted');
// // let index = this.selectedCityDatas.indexOf(cityName.name);
// // this.selectedCityDatas.splice(index,1);
// }
});
}
}, error => this.errorMessage = <any> error);
@ -378,17 +422,17 @@ export class PdTeamEditComponent implements OnInit {
dataresult => {
if (dataresult.dataStatus == true) {
data = dataresult.records;
console.log('data',data);
//console.log('data',data);
data = data.filter(pdteamproduct=>pdteamproduct.fk_product_id == $event.source.value && pdteamproduct.isactive == 1);
data = data.filter(pdteamcity=>pdteamcity.fk_pdteam_id == this._pdTeamForm.value.pdteam_id)[0];
console.log(data.pdteam_city_id);
//console.log(data.pdteam_city_id);
let ActiveDatas = { 'pdteam_product_id':data.pdteam_product_id,'isactive': '0'} ;
this._pdTeamService.editPdTeamchildDetails(ActiveDatas,'PDTEAMPRODUCT')
.subscribe(dataresult=>{
if (dataresult.dataStatus == true){
//alert('InActive Changes Done in product');
let index = this.selectedProductDatas.indexOf(productName.name);
this.selectedProductDatas.splice(index,1);
// alert('InActive Changes Done in product');
// let index = this.selectedProductDatas.indexOf(productName.name);
// this.selectedProductDatas.splice(index,1);
}
else{
//alert("Sorry Try Again !");
@ -411,11 +455,13 @@ export class PdTeamEditComponent implements OnInit {
dataresult=>{
if (dataresult.dataStatus == true){
Swal("Data Edited Successfully");
// this.notifier.notify('success', 'Record Edited Successfully.!');
this._router.navigate(['/setting/pdteam/pdteamlist']);
}
else{
Swal("SomeThing Wents Wrong Try Again !");
// this.notifier.notify('warning', 'SomeThing Wents Wrong Try Again !');
}
});

View File

@ -1,4 +1,4 @@
<div *ngIf="listView">
<!-- <div *ngIf="listView"> -->
<mat-card>
<div fxLayout="row" fxLayoutAlign="start center" class="mb-1">
<div class="ml-xs mr-xs" style="width: 30%;">
@ -57,7 +57,7 @@
<mat-header-cell *matHeaderCellDef> Action </mat-header-cell>
<mat-cell *matCellDef="let row">
<button mat-icon-button [color]="color" class="hover-icon" matTooltip="Edit" matTooltipPosition="above" (click)="editPdTeam(row.pdteam_id)"><mat-icon>edit</mat-icon></button>
<button mat-icon-button [color]="color" class="hover-icon" matTooltip="Edit" matTooltipPosition="above" (click)="toEditPdTeam(row.pdteam_id)"><mat-icon>edit</mat-icon></button>
</mat-cell>
</ng-container>
@ -71,8 +71,7 @@
</div>
</mat-card-content>
</mat-card>
</div>
<!-- </div> -->
<!--<div *ngIf="!listView">
<app-pd-team-edit [childMessage]="parentMessage"></app-pd-team-edit>
</div>-->
<notifier-container></notifier-container>

View File

@ -9,8 +9,7 @@ MatTableDataSource } from '@angular/material';
import { MastersService } from '../../service/masters/masters.service';
import { PdTeamService } from '../../service/masters/pd-team.service';
import { NotifierService } from 'angular-notifier';
import { Router } from '@angular/router';
import { Router,ActivatedRoute } from '@angular/router';
/**sweet alert */
import Swal from 'sweetalert2';
@ -38,47 +37,36 @@ export class PdTeamListComponent implements OnInit {
userData = null;
noRecordFound: boolean = false;
private notifier: NotifierService;
public listView: any = true;
public dataLength: number;
public dataSource = new MatTableDataSource();
public parentMessage: any = [];
displayedColumns = ['serialno','team_name','lender_name','actions','isactive'];
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
constructor(notifier: NotifierService,
private router: Router,
constructor(
private router: Router,private route: ActivatedRoute,
private _MasterService: MastersService,
private _PdTeamService: PdTeamService) {
this.getPdTeam();
this.notifier = notifier;
}
ngOnInit() { this.getPdTeam(); }
/** To edit data */
editPdTeam(detail){
this._PdTeamService.getAllPDTeamWithPDTeamID(detail).subscribe(
dataresult => {
this.parentMessage = dataresult;
this.parentMessage = this.parentMessage.records;
this.listView = false;
});
}
/**To Manage Team */
managepdteam(){
this.router.navigate(['/setting/pdteam/pdteammanage']);
}
changeListView(){
this.getPdTeam();
this.listView = true;
toEditPdTeam(pdteam_id){
//this.router.navigate(['/setting/pdteam/editpdteam',pdteam_id]);
console.log(btoa(pdteam_id));
this.router.navigate(['/setting/pdteam/editpdteam',btoa(pdteam_id)]);
}
/**To Manage Team */
managepdteam(){
this.router.navigate(['/setting/pdteam/pdteammanage']);
}
/** To get data for listing */
getPdTeam() {

View File

@ -15,7 +15,7 @@ export const PdTeamRoutes: Routes = [{
path: 'addpdteam',
component: PdTeamAddComponent
},{
path:'editpdteam',
path:'editpdteam/:id',
component:PdTeamEditComponent
},{
path:'pdteammanage',