diff --git a/ng6-seed/salespd_pwa_Test (02-04-2022).zip b/ng6-seed/salesPD_PWA_Test_(13-05-2022).zip similarity index 65% rename from ng6-seed/salespd_pwa_Test (02-04-2022).zip rename to ng6-seed/salesPD_PWA_Test_(13-05-2022).zip index 5337e95..25d7e86 100644 Binary files a/ng6-seed/salespd_pwa_Test (02-04-2022).zip and b/ng6-seed/salesPD_PWA_Test_(13-05-2022).zip differ diff --git a/ng6-seed/salespd_pwa_Production_(13-05-2022).zip b/ng6-seed/salespd_pwa_Production_(13-05-2022).zip new file mode 100644 index 0000000..b3105a7 Binary files /dev/null and b/ng6-seed/salespd_pwa_Production_(13-05-2022).zip differ diff --git a/ng6-seed/src/app/app.routing.ts b/ng6-seed/src/app/app.routing.ts index c13c22a..58c3981 100755 --- a/ng6-seed/src/app/app.routing.ts +++ b/ng6-seed/src/app/app.routing.ts @@ -35,6 +35,10 @@ export const AppRoutes: Routes = [{ path:'sales-pd-list', loadChildren:'./sales-pd/sales-pd.module#SalesPdModule' }, + { + path:'fly-hi', + loadChildren:'./fly-hi/fly-hi.module#FlyHiModule' + }, // { // path:'credit_pd', // loadChildren:'./lender-credit-pd/lender-credit-pd.module#LenderCreditPdModule' diff --git a/ng6-seed/src/app/fly-hi/fly-hi-list/fly-hi-list.component.html b/ng6-seed/src/app/fly-hi/fly-hi-list/fly-hi-list.component.html new file mode 100644 index 0000000..0463cc0 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/fly-hi-list/fly-hi-list.component.html @@ -0,0 +1,140 @@ + +
+
+ + + +
+
+
+ +
+ +
+
+ + + + + + +

Showing data for last {{common}}. To see older records, please use advanced filter

+
+
+ +
+
+ Name Not Given + {{details.applicant_name}}
+ {{details.sales_pd_type == '1' ? 'Physical PD' : 'Telephonic PD'}} +
+
+ + + + {{details.createdon | date:'dd-MM-yy h:mm:ss a'}} +
+ {{details.abbr}} | {{details.status}} + +
+ + +
+ + +
+
+ {{details.sales_pd_id}} +
+
+ {{details.sales_pd_sno}}
+ {{details.sales_pd_type == '1' ? 'Physical PD' : 'Telephonic PD'}} +
+
+ + -- + + + {{details.applicant_name}} +
+ {{details.applicant_id}} +
+
+ {{details.short_name}}
+ {{details.abbr}} +
+
+ + -- + + + {{details.officer_name}} + +
+
+ + + -- + + + {{details.status}} + +
+
+ {{details.createdon | date: 'dd/MM/yyyy'}} +
+
+
+
+ +
+
+ + +
+ +
+ + + + + + + +
+
+ + +
+ +
+ +
+
+
+
+
diff --git a/ng6-seed/src/app/fly-hi/fly-hi-list/fly-hi-list.component.scss b/ng6-seed/src/app/fly-hi/fly-hi-list/fly-hi-list.component.scss new file mode 100644 index 0000000..2d64c11 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/fly-hi-list/fly-hi-list.component.scss @@ -0,0 +1,142 @@ +// .mat-ink-bar{ +// background-color:green; +// } +// .mat-tab-label-active{ +// color: green !important; +// } +// .primary{ +// background-color: #e2412f; + +// } +// .accent{ +// background-color: #0d93a9; + +// } +::ng-deep .mat-tab-group.mat-primary .mat-ink-bar, .mat-tab-nav-bar.mat-primary .mat-ink-bar { + background-color: #0d93a9; +} +.fontTitle{ + font-weight:bold; + text-align: left; +} +.ic-change:hover { + transform: scale(1.1); + color: green; +} +.cell{ + display:inline !important; + // text-align: center !important; +} +.cellhide{ + display: none !important; +} +.center{ + text-align:center; +} +.fontsize{ + font-size:14px; +} +.toolbar-space { + flex: 0.01 0 auto; +} +p.note { + // float: right; + text-align: right; + font-size: 12px; + color: grey; + font-weight: bold; + } + + .ic-change:hover { + transform: scale(1.1); + color: green; + } + + + .center{ + text-align:center; + } + .fontsize{ + font-size:14px; + } + + .toolbar-space { + flex: 0.01 0 auto; + } + p.note { + // float: right; + text-align: right; + font-size: 12px; + color: grey; + font-weight: bold; + } + + // .example-container { + // display: flex; + // flex-direction: column; + // max-height: 500px; + // min-width: 300px; + // } + + // .mat-table { + // overflow: auto; + // max-height: 500px; + // } + + .mobile-label { + display: none; + } + @media(min-width: 600px) { + .webhide{ + display: none !important; + } + } + @media(max-width: 600px) { + .body-container { + padding: 0px !important; + } + .mat-expansion-panel-body { + padding: 0 10px 16px !important; + } + .cell{ + display: none !important; + } + .mat-form-field{ + display: inline !important; + } + // .no-pad{ + // text-align: left !important; + // padding-left: 0px !important; + // } + .mobile-label { + width: 80px; + display: inline-block; + font-weight: bold; + } + + .mat-header-row { + display: none; + } + + .mat-row { + flex-direction: column; + align-items: start; + padding: 8px 24px; + } + .lettericon{ + // background-color: cadetblue; + // padding: 6px 7px 6px 7px; + border-radius: 10px; + color: #e2412f; + font-size: 75%; + font-weight: bold; + min-width: 4.4em; + text-align: center; + margin: 10px 0px 0px 0px !important; + } + .lettertext{ + font-size: 80%; + } + } + + diff --git a/ng6-seed/src/app/fly-hi/fly-hi-list/fly-hi-list.component.spec.ts b/ng6-seed/src/app/fly-hi/fly-hi-list/fly-hi-list.component.spec.ts new file mode 100644 index 0000000..7efc289 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/fly-hi-list/fly-hi-list.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { FlyHiListComponent } from './fly-hi-list.component'; + +describe('FlyHiListComponent', () => { + let component: FlyHiListComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ FlyHiListComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(FlyHiListComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/ng6-seed/src/app/fly-hi/fly-hi-list/fly-hi-list.component.ts b/ng6-seed/src/app/fly-hi/fly-hi-list/fly-hi-list.component.ts new file mode 100644 index 0000000..13f08ad --- /dev/null +++ b/ng6-seed/src/app/fly-hi/fly-hi-list/fly-hi-list.component.ts @@ -0,0 +1,337 @@ +import { Component, OnInit, ViewChild } from '@angular/core'; +import { FlyhiService } from '../services/flyhi.service'; +import { Router, ActivatedRoute } from '@angular/router'; +import { MatDialog, MatTableDataSource, MatPaginator, MatSort } from '@angular/material'; +import { ConstantsProvider } from 'app/providers/constants/constants'; +import { LoaderService } from 'app/shared/loaderService/loader.service'; +import { SalesPdService } from 'app/sales-pd/services/sales-pd.service'; + +@Component({ + selector: 'app-fly-hi-list', + templateUrl: './fly-hi-list.component.html', + styleUrls: ['./fly-hi-list.component.scss'] +}) +export class FlyHiListComponent implements OnInit { + @ViewChild(MatPaginator) paginator: MatPaginator; + @ViewChild(MatSort) sort: MatSort; + public dataLengthTab4: number; + public dataSourceTab4 = new MatTableDataSource(); + is_sales_login:boolean = false + common: any; + roleID: string; + errorMessage:any[]=[]; + flyHiData: any; + recordStatus: boolean; + limitMsg: boolean = false; + finallink: string; + filter_drop_down_data: { product_ids: any[]; lender_ids: any[]; pd_status: any[]; }; + + constructor(private loaderService:LoaderService,private constantProvider:ConstantsProvider,private dialog:MatDialog,private route: ActivatedRoute, private router: Router,private _fly_Hi:FlyhiService,private SalesPDService:SalesPdService) { + this.roleID = localStorage.getItem('user_role'); + setTimeout(()=>{ + let userDetails = localStorage.getItem('user_details'); + console.log('userdetails'); + console.log(userDetails); + + let role= this.constantProvider.takeDecisionRouting(JSON.parse(userDetails)) + console.log(role) + if(role == 'sales'){ + this.is_sales_login = true + this.getListofFlyhi() + } + else { + this.is_sales_login = false + this.getListofFlyhi() + } + },4000) + + setTimeout(()=>{ + this.common = JSON.parse(localStorage.getItem('commonSettings')) + if(this.common){ + this.common = this.common.default_pd_list_count; + this.common = this.common.count+' '+this.common.factor + } + },300) + } + + ngOnInit() { + this.getListofFlyhi() + } + + getListofFlyhi(){ + this._fly_Hi.getFlyHiList(this.is_sales_login).subscribe(res=>{ + if(res['dataStatus']){ + let user1 = localStorage.getItem('user_details'); + let user=(JSON.parse(user1)) + this.roleID = localStorage.getItem('user_role') + + this.flyHiData = res['records']; + this.dataLengthTab4 = res['records'].length; + this.dataSourceTab4.data = this.flyHiData; + this.recordStatus=false + this.limitMsg = true + + if(this.flyHiData.length > 0){ + let products=[] + let lenders=[] + let pd_status=[] + this.flyHiData.map(val=>{ + + // https://gstapp.smcfinance.com/home?saltkey=VQDa79tyBlpu7ZuKt6U&PDID=123&Email=manojsahrawat@smcfinance.com + //let link = "http://gstapp.devopsmcfinance.com/home?saltkey=VQDa79tyBlpu7ZuKt6U" + let link ="https://salesapp.smcfinance.com/app/secure?saltkey=VQDa79tyBlpu7ZuKt6U" + var string:any = { + EmpName:user.user_first_name, + EmpCode:"", + PDID:val.sales_pd_sno, + //PD_NO:val.sales_pd_sno, + } + //console.log(string); + //var encodedString = btoa(JSON.stringify(string)); + //console.log("encode",encodedString); // Outputs: "SGVsbG8gV29ybGQh" + //var decodedString = atob(encodedString); + //console.log("decode",JSON.parse(decodedString)); + //let email="mwisesales1@sine.com"; + let PDID=val.sales_pd_sno; + // let mail="&Email=manojsahrawat@smcfinance.com" + this.finallink=link+"&PDID="+PDID+"&Email="+user.email; + + console.log('this.finallink') + console.log(this.finallink); + val.link = this.finallink; + + if(products.length > 0 ){ + if(products.filter(pro=>pro == val.product_id).length == 0 ){ + products.push(val.product_id) + } + } + else{ + products.push(val.product_id) + } + if(lenders.length > 0 ){ + if(lenders.filter(pro=>pro == val.lender_id).length == 0 ){ + lenders.push(val.lender_id) + } + } + else{ + lenders.push(val.lender_id) + } + if(pd_status.length > 0 ){ + if(pd_status.filter(pro=>pro == val.status).length == 0 ){ + pd_status.push(val.status) + } + } + else{ + pd_status.push(val.status) + } + }) + this.filter_drop_down_data={product_ids:products,lender_ids:lenders,pd_status:pd_status} + // console.log(this.filter_drop_down_data); + } + } + else{ + this.flyHiData=[]; + this.dataLengthTab4= null; + this.recordStatus=true; + this.limitMsg = false + } + } + // , error => this.errorMessage = 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); + }); + } + + editForm(value_obj){ + console.log(value_obj.sales_pd_id,value_obj.rand_string) + // alert('abc'); + console.log('value'); + console.log(value_obj); + let campletedCase = JSON.stringify(value_obj) + localStorage.setItem('completedPD',campletedCase) + // let product= localStorage.getItem('product_id_salesPD') + // storing the sales_pd_id and product id in local storagey + let primary_key= 'sales_pd_id' + if(value_obj.hasOwnProperty('local_pd_id') && value_obj.local_pd_id != null && value_obj.sales_pd_id == null && value_obj.hasOwnProperty('is_pd_synced') && value_obj.is_pd_synced == false) { + primary_key = 'local_pd_id' + } + console.log(value_obj[primary_key]) + localStorage.setItem('sales_pd_id_PRIMARYKEY',value_obj[primary_key]); + localStorage.setItem('sales_rand_string',value_obj.rand_string); + + + // this.salesPDService.insertData_Replace('sales_pd_id_PRIMARYKEY',value_obj[primary_key]).then(()=>{ + //this.salesPDService.insertData_Replace('sales_rand_string',value_obj['rand_string']).then(()=>{ + localStorage.setItem('product_id_salesPD',value_obj.product_id) + if(!value_obj.hasOwnProperty('sales_pd_type')&& !value_obj.sales_pd_type) { + value_obj.sales_pd_type = '2' + } + console.log('value'); + console.log(value_obj); + localStorage.setItem('sales_pd_type',value_obj.sales_pd_type) + // this.router.navigate(['../sectionlist',value_obj.product_id,value_obj.sales_pd_type,value_obj.link],{ relativeTo: this.route }) + this.router.navigate(['../sectionlist'],{ relativeTo: this.route }) + // }) + //}) + } + + + + filteredDataSource(res){ + console.log("From Parent",res); + if(res['dataStatus']){ + + let user1 = localStorage.getItem('user_details'); + let user=(JSON.parse(user1)) + this.roleID = localStorage.getItem('user_role') + + this.flyHiData=res['records'] + this.dataLengthTab4 = res['records'].length; + this.dataSourceTab4.data = this.flyHiData; + this.recordStatus=false + this.limitMsg = false + if(this.flyHiData.length > 0){ + let products=[] + let lenders=[] + let pd_status=[] + this.flyHiData.map(val=>{ + + // https://gstapp.smcfinance.com/home?saltkey=VQDa79tyBlpu7ZuKt6U&PDID=123&Email=manojsahrawat@smcfinance.com + //let link = "http://gstapp.devopsmcfinance.com/home?saltkey=VQDa79tyBlpu7ZuKt6U" + let link ="https://salesapp.smcfinance.com/app/secure?saltkey=VQDa79tyBlpu7ZuKt6U" + var string:any = { + EmpName:user.user_first_name, + EmpCode:"", + PDID:val.sales_pd_sno, + //PD_NO:val.sales_pd_sno, + } + //console.log(string); + //var encodedString = btoa(JSON.stringify(string)); + //console.log("encode",encodedString); // Outputs: "SGVsbG8gV29ybGQh" + //var decodedString = atob(encodedString); + //console.log("decode",JSON.parse(decodedString)); + //let email="mwisesales1@sine.com"; + let PDID=val.sales_pd_sno; + // let mail="&Email=manojsahrawat@smcfinance.com" + this.finallink=link+"&PDID="+PDID+"&Email="+user.email; + + console.log('this.finallink') + console.log(this.finallink); + val.link = this.finallink; + + if(products.length > 0 ){ + if(products.filter(pro=>pro == val.product_id).length == 0 ){ + products.push(val.product_id) + } + } + else{ + products.push(val.product_id) + } + if(lenders.length > 0 ){ + if(lenders.filter(pro=>pro == val.lender_id).length == 0 ){ + lenders.push(val.lender_id) + } + } + else{ + lenders.push(val.lender_id) + } + if(pd_status.length > 0 ){ + if(pd_status.filter(pro=>pro == val.status).length == 0 ){ + pd_status.push(val.status) + } + } + else{ + pd_status.push(val.status) + } + }) + this.filter_drop_down_data={product_ids:products,lender_ids:lenders,pd_status:pd_status} + // console.log(this.filter_drop_down_data); + } + } + else{ + this.flyHiData=[]; + this.dataLengthTab4= null; + this.recordStatus=true; + this.limitMsg = false + } + } + + pageChange(e) { + console.log(e); + } + ngAfterViewInit() { + this.dataSourceTab4.paginator = this.paginator; + this.dataSourceTab4.sort = this.sort; + } + + applyFilter(filterValue: string) { + this.dataSourceTab4.filter = filterValue.trim().toLowerCase(); + } + + newPortal() { + console.log(this.finallink) + window.open(this.finallink); + } + + newForm(){ + // this.salesPDService.getData_fromLocal('sec1').then(result=>{ + // console.log("image",result); + // if(result){ + // this.alertDecision() + // } + // else{ + // this.navCtrl.push(HomePage) + // } + // }); + // this.SalesPDService.clearLocalData() + // this.SalesPDService.clear_local_key('sales_pd_id_PRIMARYKEY'); + // localStorage.removeItem('sales_pd_id_PRIMARYKEY') + // localStorage.removeItem('product_id_salesPD') + // localStorage.removeItem('sales_pd_type') + // // this.navCtrl.push(HomePage) + this.router.navigate([ '../sectionlist'], { relativeTo: this.route }); + + + } + + salesPDpdf(pdfdetail){ + this.loaderService.showMatSpinnerDialog('Processing...') + this.SalesPDService.getSalesPdpdf(pdfdetail) + .subscribe( + data => { + if (data.status == 200) { + // window.location.href=res['records']; + window.open(data.records, '_blank'); + } + this.loaderService.closeMatSpinnerDialog() + + } + // , error => this.errorMessage = error); + ,error => { + this.loaderService.closeMatSpinnerDialog() + 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); + }); + + } + +// regeneratereport(data,option) +// { + +// const dialogRef = this.dialog.open(ReGenerateReportComponent,{ +// data: {pdid: data,option: option}, +// disableClose: true, +// minWidth: '30%', +// maxWidth: '40%', + +// }) +// dialogRef.afterClosed() +// .subscribe(dataresult => { +// // this.viewPdDetails(this.viewID,this.masterRandomString) +// }) +// } + +} diff --git a/ng6-seed/src/app/fly-hi/fly-hi-routing.module.ts b/ng6-seed/src/app/fly-hi/fly-hi-routing.module.ts new file mode 100644 index 0000000..b1fa3ea --- /dev/null +++ b/ng6-seed/src/app/fly-hi/fly-hi-routing.module.ts @@ -0,0 +1,47 @@ +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; +import { FlyHiListComponent } from './fly-hi-list/fly-hi-list.component'; +import { SectionListComponent } from 'app/sales-pd/section-list/section-list.component'; + +const routes: Routes = [ + { + path:'', + redirectTo:'flyhi-list-pd', + pathMatch:'full' + }, + { + path:'flyhi-list-pd', + component:FlyHiListComponent + }, + // { + // path:'add-pd', + // component:HomePage + // }, + // { + // path:'section9', + // component:HomePage + // }, + { + path:'sectionlist', + component:SectionListComponent + }, + // // { + // // path:'sectionlist/:product_id/:sales_pd_type/:link', + // // component:SectionListComponent + // // }, + // { + // path:'', + // component:HomePage + // } + + ]; + + + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule] +}) +export class FlyHiRoutingModule { + static forRoot: any; +} diff --git a/ng6-seed/src/app/fly-hi/fly-hi.module.spec.ts b/ng6-seed/src/app/fly-hi/fly-hi.module.spec.ts new file mode 100644 index 0000000..42ef193 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/fly-hi.module.spec.ts @@ -0,0 +1,13 @@ +import { FlyHiModule } from './fly-hi.module'; + +describe('FlyHiModule', () => { + let flyHiModule: FlyHiModule; + + beforeEach(() => { + flyHiModule = new FlyHiModule(); + }); + + it('should create an instance', () => { + expect(flyHiModule).toBeTruthy(); + }); +}); diff --git a/ng6-seed/src/app/fly-hi/fly-hi.module.ts b/ng6-seed/src/app/fly-hi/fly-hi.module.ts new file mode 100644 index 0000000..e52c8f7 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/fly-hi.module.ts @@ -0,0 +1,91 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; + +import { FlyHiRoutingModule } from './fly-hi-routing.module'; +import { FlyHiListComponent } from './fly-hi-list/fly-hi-list.component'; +import { MatDialogModule, MatMenuModule, MAT_DATE_LOCALE, DateAdapter, MAT_DATE_FORMATS, MatDialogRef, MAT_DIALOG_DATA, MatAutocomplete, MatAutocompleteModule, MatCardModule, MatIconModule, MatRadioModule, MatInputModule, MatTableModule, MatPaginatorModule, MatButtonModule, MatProgressBarModule, MatToolbarModule, MatChipsModule, MatProgressSpinnerModule, MatSlideToggleModule, MatSelectModule, MatListModule, MatGridListModule, MatTabsModule, MatBadgeModule, MatCheckboxModule, MatStepperModule, MatSidenavModule, MatButtonToggleModule, MatBottomSheetModule, MatRippleModule, MatDividerModule, MatNativeDateModule, MatSliderModule, MatSnackBarModule, MatTreeModule, MatDatepickerModule, MatExpansionModule, MatTooltipModule, MatSortModule, MatDialogActions } from '@angular/material'; +import { SharedModule } from 'app/shared/shared.module'; +import { MaterialModule } from 'app/lender-credit-pd/lender-credit-pd.module'; +import { ConstantsProvider } from 'app/providers/constants/constants'; +import { MomentDateAdapter, MAT_MOMENT_DATE_FORMATS } from '@angular/material-moment-adapter'; +import { SalesPdModule } from 'app/sales-pd/sales-pd.module'; +import { StartPd2Component } from './start-pd2/start-pd2.component'; +import { DynamicFormComponent } from './forms-dynamic/dynamic-form/dynamic-form/dynamic-form.component'; +import { DynamicQuestionTemplateComponent } from './forms-dynamic/dynamic-form/dynamic-question-template/dynamic-question-template.component'; +import { CKEditorModule } from 'ng2-ckeditor'; +import { PdfViewerModule } from 'ng2-pdf-viewer'; +import { FlexLayoutModule } from '@angular/flex-layout'; +import { NgxDatatableModule } from '@swimlane/ngx-datatable'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; +import { FileUploadModule } from 'ng2-file-upload'; +import { TreeModule } from 'angular-tree-component'; +import { NgxMatSelectSearchModule } from 'ngx-mat-select-search'; +import { ResizableModule } from 'angular-resizable-element'; +import { OwlDateTimeModule, OwlNativeDateTimeModule } from 'ng-pick-datetime'; +import { AgmCoreModule } from '@agm/core'; +import { environment } from 'environments/environment'; +import { MatVideoModule } from 'mat-video'; +import { AngularSplitModule } from 'angular-split'; +import { FormComponent } from './forms-dynamic/form/form.component'; +import { ImageVideoComponent } from './image-video/image-video.component'; + +@NgModule({ + imports: [ + CommonModule, + FlyHiRoutingModule, + MaterialModule, + MatMenuModule, + SharedModule, + MatDialogModule, + SalesPdModule, + CKEditorModule, + PdfViewerModule, + MatCardModule, + MatIconModule, + MatAutocompleteModule, + MatInputModule, + MatRadioModule, + MatTableModule, + MatPaginatorModule, + MatButtonModule, + MatProgressBarModule, + MatToolbarModule, + FlexLayoutModule, + NgxDatatableModule, + + MatChipsModule,MatProgressSpinnerModule, + FormsModule,MatSlideToggleModule, + + MatSelectModule, MatListModule,MatGridListModule, MatTabsModule, MatBadgeModule, MatCheckboxModule,MatStepperModule,MatSidenavModule ,MatMenuModule, MatButtonToggleModule, + ReactiveFormsModule, + MatBottomSheetModule, + + MatDividerModule, + + MatNativeDateModule, + + MatRippleModule, + + MatSliderModule, + + MatSnackBarModule, + MatTreeModule, + FileUploadModule, + TreeModule, + MatDatepickerModule, + MatDialogModule,MatSortModule, + NgxMatSelectSearchModule,MatTooltipModule, MatExpansionModule,ResizableModule, + OwlDateTimeModule, + OwlNativeDateTimeModule, + AngularSplitModule, + MatVideoModule + + ], + declarations:[StartPd2Component,DynamicFormComponent,DynamicQuestionTemplateComponent,FormComponent], + exports:[StartPd2Component], + entryComponents:[FlyHiListComponent,DynamicFormComponent,DynamicQuestionTemplateComponent,FormComponent], + providers:[ConstantsProvider,{ provide: MAT_DATE_LOCALE, useValue: 'en-GB' },{provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE]}, + {provide: MAT_DATE_FORMATS, useValue: MAT_MOMENT_DATE_FORMATS},{ provide: MatDialogRef, useValue: {} },{ provide: MAT_DIALOG_DATA, useValue: [] }], + bootstrap: [FlyHiListComponent], +}) +export class FlyHiModule { } diff --git a/ng6-seed/src/app/fly-hi/forms-dynamic/answer-option-create-dialog/answer-option-create-dialog.component.html b/ng6-seed/src/app/fly-hi/forms-dynamic/answer-option-create-dialog/answer-option-create-dialog.component.html new file mode 100644 index 0000000..2f2479e --- /dev/null +++ b/ng6-seed/src/app/fly-hi/forms-dynamic/answer-option-create-dialog/answer-option-create-dialog.component.html @@ -0,0 +1,75 @@ +

+
+ Add New Address +
+
+ + + +
+ +

+ + +
+
+ + Address + + Required + + + State + + + + + + {{SL.name}} + + + Required + + + City + + + + + + + {{CL.city_name}} + + + Required + + + Pincode + + + + + {{PL.pincode}} + + Required + +
+
+
+ + +
+

{{errormsg}}

+
+
+ + +
+ +
\ No newline at end of file diff --git a/ng6-seed/src/app/fly-hi/forms-dynamic/answer-option-create-dialog/answer-option-create-dialog.component.scss b/ng6-seed/src/app/fly-hi/forms-dynamic/answer-option-create-dialog/answer-option-create-dialog.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/ng6-seed/src/app/fly-hi/forms-dynamic/answer-option-create-dialog/answer-option-create-dialog.component.spec.ts b/ng6-seed/src/app/fly-hi/forms-dynamic/answer-option-create-dialog/answer-option-create-dialog.component.spec.ts new file mode 100644 index 0000000..ee8ead3 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/forms-dynamic/answer-option-create-dialog/answer-option-create-dialog.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { AnswerOptionCreateDialogComponent } from './answer-option-create-dialog.component'; + +describe('AnswerOptionCreateDialogComponent', () => { + let component: AnswerOptionCreateDialogComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ AnswerOptionCreateDialogComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(AnswerOptionCreateDialogComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/ng6-seed/src/app/fly-hi/forms-dynamic/answer-option-create-dialog/answer-option-create-dialog.component.ts b/ng6-seed/src/app/fly-hi/forms-dynamic/answer-option-create-dialog/answer-option-create-dialog.component.ts new file mode 100644 index 0000000..7caafe6 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/forms-dynamic/answer-option-create-dialog/answer-option-create-dialog.component.ts @@ -0,0 +1,183 @@ +import { Component, Inject, OnInit } from '@angular/core'; +import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; +import { PdTrigerService } from 'app/personal-discussion/pd-service/pd-triger.service'; +import { ReplaySubject } from 'rxjs'; +import { QuesFormService } from '../dynamic-form/ques-form/ques-form.service'; + +@Component({ + selector: 'app-answer-option-create-dialog', + templateUrl: './answer-option-create-dialog.component.html', + styleUrls: ['./answer-option-create-dialog.component.scss'] +}) +export class AnswerOptionCreateDialogComponent implements OnInit { + stateList:any = [] + cityList:any = [] + pincodeList:any = [] + + filteredstateList:ReplaySubject= new ReplaySubject(1) + filteredcityList:ReplaySubject = new ReplaySubject(1) + filteredpincodeList:ReplaySubject = new ReplaySubject(1) + + stateSearch:FormControl = new FormControl('') + citySearch:FormControl = new FormControl('') + pinSearch:FormControl = new FormControl('') + newAddressForm:FormGroup; + + field_appearance="outline" + errormsg: string = null; + + constructor(@Inject(MAT_DIALOG_DATA) public data:any, private _pdService:PdTrigerService, private _fb:FormBuilder, + private dialogRef:MatDialogRef, private quesService:QuesFormService) { + this.newAddressForm = this._fb.group({ + address:['',Validators.required], + state:['',Validators.required], + city:['',Validators.required], + pincode:['',Validators.required] + }) + console.log(this.data) + } + + ngOnInit() { + this._pdService.getAllMasterDatas('STATE').subscribe( + data => { + if (data.status == 200) { + this.stateList = data.records.filter(item => item.isactive == 1); + this.filteredstateList.next(this.stateList); + } + }); + this.filterList() + } + filterList() { + this.stateSearch.valueChanges.pipe().subscribe(()=>{ + this.applyFilter(this.stateSearch.value,this.filteredstateList,this.stateList,'name') + }) + this.citySearch.valueChanges.pipe().subscribe(()=>{ + this.applyFilter(this.citySearch.value,this.filteredcityList,this.cityList,'city_name') + }) + this.pinSearch.valueChanges.pipe().subscribe(()=>{ + this.applyFilter(this.pinSearch.value,this.filteredpincodeList,this.pincodeList,'pincode') + }) + + + } + applyFilter(filtered_text,filter_list,raw_list,obj_name) { + if (!raw_list) { + return; + } + // get the search keyword + let search = filtered_text; + if (!search) { + filter_list.next(raw_list.slice()); + return; + } else { + search = search.toLowerCase(); + } + // filter the banks + filter_list.next( + raw_list.filter(bank => bank[obj_name].toLowerCase().indexOf(search) > -1) + ); + } + + //get city list details based on state id + getCityList(stateID: string) { + this._pdService.getStateWiseCities(stateID).subscribe(data => { + if (data.status == 200) { + this.cityList = data.records.cities; + this.pincodeList = data.records.pincode; + this.filteredcityList.next(this.cityList) + this.filteredpincodeList.next(this.pincodeList) + } + }); + } + addNewAddress() { + console.log(this.newAddressForm.getRawValue()) + if(this.newAddressForm.invalid) { + this.showMsg("Please Fill all the fields") + // this.findInvalidControls() + return; + } + let formValue=this.newAddressForm.getRawValue() + let params = {pd_id:this.data.pd_all_details.pdmaster_details.pd_id,file_id:null, addressline:formValue.address, state:formValue.state.state_id, city:formValue.city.city_id, pincode:formValue.pincode.pincode_id} + let display_address= formValue.address+ ', '+formValue.state.name+', '+formValue.city.city_name+', '+formValue.pincode.pincode + console.log(this.newAddressForm.getRawValue(),display_address) + this._pdService.saveNewSMCTempAddresses(params).subscribe(res=>{ + if(res['dataStatus']) { + this._pdService.getSMCTempAddresses(this.data.pd_all_details.pdmaster_details.pd_id).subscribe(rr=>{ + if(rr && rr['dataStatus'] && rr['records']) { + let address_data = this.quesService.convertArrayNames(["display","display"],rr['records']) + this.dialogRef.close({update:true, address_for_display:address_data}) + } + else { + this.dialogRef.close({update:false, error_msg:"Unable to get the address"}) + } + },err=> { + this.dialogRef.close({update:false, error_msg:"Network error. Unable to get the address"}) + }) + // this.dialogRef.close({update:true, address_for_display:display_address}) + } + else { + this.showMsg("Something went wrong") + } + },err=>{ + this.showMsg("Network Error") + }) + + } + showMsg(msg) { + this.errormsg = msg + setTimeout(()=>{ + this.errormsg = null + }, 3000) + } + public findInvalidControls() { + const invalid = []; + + for (const name in (this.newAddressForm.controls)) { + console.log(this.newAddressForm.controls[name],name) + if (this.newAddressForm.controls[name].invalid) { + invalid.push(name); + let invalidFields = [].slice.call(document.getElementsByClassName('ng-invalid')); + let firstInvalidField; + for(let val in invalidFields){ + if( invalidFields[val].nodeName == 'MAT-FORM-FIELD' || invalidFields[val].nodeName == 'MAT-SELECT' || invalidFields[val].nodeName == 'TEXTAREA' || invalidFields[val].nodeName == 'MAT-RADIO-GROUP' ){ //INPUT FOR INPUT FIELD + firstInvalidField=invalidFields[val] + + break; + } + } + + if(firstInvalidField != undefined){ + // firstInvalidField.scrollIntoView({behavior: "smooth", block: "end", inline: "nearest"}) + + setTimeout(()=>{ + firstInvalidField.scrollIntoView({block: "start", inline: "nearest"}) + setTimeout(()=>{ + firstInvalidField.focus() + },0) + // firstInvalidField.style.background = 'red' + firstInvalidField.classList.remove('field_highlight') + setTimeout(()=>{ + firstInvalidField.classList.add('field_highlight') + },300) + },300) + + } + break + } + } + + // } + // } + // let business_group_ctrl = formArray.at(2).get('business_group') as FormArray + // const controls = this.getQuestionControl().at(1)['controls'] + // for (const name in controls) { + // if (controls[name].invalid) { + // invalid.push(name); + // } + // } + return invalid; + } + + +} diff --git a/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-form/dynamic-form.component.html b/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-form/dynamic-form.component.html new file mode 100644 index 0000000..3a53109 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-form/dynamic-form.component.html @@ -0,0 +1,167 @@ +
+
+ + + + + + +
+ + + + +
+ + +
+
+ +
+ + + +
+ + + + {{parent_ques.group_title}} {{g_i+1}} +
+
{{singleQues.group_key | json}}
+
+
+ +
+ +
+ + +
+ +
+ + +
+ + + +
+ + + + + {{singleQues | json}} +
+ {{group_ques_child.value | json}} + + + + {{singleQues.group_title}} {{g_c_i+1}} + + + + +
+ + + {{singleQues_child | json}} + + + +
+
+
+
+ + +
+
+ + +
+
+
+
+
+ +
+ +
+ + + + + + + + +
+
+
+
+ + +
+
+ + +
+
+
+
+
+ +
+ +
+ + +
+
+
+ \ No newline at end of file diff --git a/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-form/dynamic-form.component.scss b/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-form/dynamic-form.component.scss new file mode 100644 index 0000000..1f1770e --- /dev/null +++ b/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-form/dynamic-form.component.scss @@ -0,0 +1,15 @@ +::ng-deep { + .mat-expansion-panel-body{ + flex-flow: wrap; + + } +form{ + flex-flow: row wrap; + box-sizing: border-box; + display: flex; + /* place-content: stretch space-between; */ + align-items: stretch; + flex: 1 1 100%; + max-width: 100%; +} +} \ No newline at end of file diff --git a/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-form/dynamic-form.component.spec.ts b/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-form/dynamic-form.component.spec.ts new file mode 100644 index 0000000..1d3b4a4 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-form/dynamic-form.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { DynamicFormComponent } from './dynamic-form.component'; + +describe('DynamicFormComponent', () => { + let component: DynamicFormComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ DynamicFormComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(DynamicFormComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-form/dynamic-form.component.ts b/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-form/dynamic-form.component.ts new file mode 100644 index 0000000..41bb621 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-form/dynamic-form.component.ts @@ -0,0 +1,294 @@ +import { Component, OnInit, Input, ViewChild } from '@angular/core'; +import { FormBuilder, FormArray, FormGroup } from '@angular/forms'; +import { MatExpansionPanel,MatAccordion } from '@angular/material'; +import { QuesFormService } from '../ques-form/ques-form.service'; + +import {SelectionModel} from '@angular/cdk/collections'; +import {FlatTreeControl} from '@angular/cdk/tree'; +import {Injectable} from '@angular/core'; +import {MatTreeFlatDataSource, MatTreeFlattener} from '@angular/material/tree'; +import {BehaviorSubject} from 'rxjs'; +import { PdTrigerService } from 'app/personal-discussion/pd-service/pd-triger.service'; + + +@Component({ + selector: 'app-dynamic-form', + templateUrl: './dynamic-form.component.html', + styleUrls: ['./dynamic-form.component.scss'], + +}) +export class DynamicFormComponent { + + @Input() form_group_name:FormGroup; + @Input() questions_JSON:any; + @Input() json_answers:any; + length:any; + step: number=0; + isDefaultGenerated:boolean = false + step_child:number = 0 + @ViewChild('mapanel') matExpansionPanel:MatExpansionPanel + @ViewChild('accordion') Accordion: MatAccordion + vr: boolean = false; + constructor(private _fb:FormBuilder,private questionService:QuesFormService ) { + + + this.questionService.currentMessageSubscriber.subscribe((data : any)=>{ + console.log(data) + + }) + } + + ngOnInit() { + console.log(this.form_group_name) + console.log(this.questions_JSON.questions) + this.form_group_name=this.questionService.assignFormControl_array(this.form_group_name,this.questions_JSON.questions) + + this.generateGroupControls(); + console.log( this.questions_JSON.questions) + this.questionService.notify(this.questions_JSON) + if(this.questions_JSON.questions){ + this.questions_JSON.questions.forEach(element => { + if(element.question instanceof Array){ + element.question.forEach(e => { + console.log(e.question) + }); + }else{ + console.log(this.questions_JSON.questions) + } + }); + + } + + + + } + + generateGroupControls() { + + + if(this.json_answers && this.json_answers != null){ + this.isDefaultGenerated = true; + console.log( this.questions_JSON.questions) + this.questions_JSON.questions.forEach(parent_ques=>{ + + + // debugger; + // FOR ADDING THE GROUP QUES TO DISPLAY WITHOUT CONSIDERING INDEX 0 + if(parent_ques.is_repeatable == '1'){ + if(this.json_answers[parent_ques.group_key] && this.json_answers[parent_ques.group_key].length > this.form_group_name.value[parent_ques.group_key].length) { + + // this.json_answers[parent_ques.group_key].mobile_numbers= [{mobile_no:93299},{mobile_no:948392}] + this.json_answers[parent_ques.group_key].forEach((group_ques,g_i)=>{ + + + // debugger; + + if(g_i != 0){ + // let parent_control=this.form_group_name + + // if(parent_control.value.hasOwnProperty('questions_group')){ + this.addData(g_i,parent_ques) + // } + } + // FOR CHILD REPEATABLE + let keys= Object.keys(group_ques) + keys.forEach((vv,key_index)=>{ + if(typeof(group_ques[vv]) != 'string') { + + if(group_ques[vv] && group_ques[vv].length > 0) { + // + group_ques[vv].forEach((child_val,child_index)=>{ + if(child_index != 0) { + + let find_json = parent_ques.group_questions[g_i].filter(val=>val.hasOwnProperty('group_key') && val.group_key == vv) + if(find_json.length > 0) { + find_json = find_json[0] + + this.addSecondLevelChild(g_i,find_json,this.form_group_name.get(parent_ques.group_key)['controls'][g_i]) + } + + } + }) + } + } + }) +}) +} + } + }) + } + } + ngOnChanges() { + // console.log(this.questions_JSON,this.json_answers,this.questionService); + // debugger +// if(this.json_answers && this.json_answers != null ){ +// this.questions_JSON.questions.forEach(parent_ques=>{ +// console.log(parent_ques); +// // debugger; +// // FOR ADDING THE GROUP QUES TO DISPLAY WITHOUT CONSIDERING INDEX 0 +// if(parent_ques.is_repeatable == '1'){ +// console.log(this.json_answers[parent_ques.group_key]); +// debugger; +// this.json_answers[parent_ques.group_key].forEach((group_ques,g_i)=>{ +// console.log(parent_ques,g_i) +// debugger; +// if(g_i != 0){ +// // let parent_control=this.form_group_name + +// // if(parent_control.value.hasOwnProperty('questions_group')){ +// this.addData(g_i,parent_ques) +// // } +// } +// }) +// } +// }) +// } + // this.form_group_name=new FormGroup({questions:this._fb.array([])}) + + + // this.form_group_name.valueChanges.subscribe(()=>{ + // this.form_group_name.updateValueAndValidity(); + // }) + // debugger; + // this.form_group_name.patchValue(this.json_answers) + } + addData(index,json_obj) { + let control_names:any= {} + let control = this.form_group_name.get(json_obj.group_key) as FormArray + json_obj.question.map(val=>{ + // FOR CHILD REPEATABLE + if(val.is_repeatable == '2') { + val.question.map(rr=>{ + control_names[val.group_key]=this._fb.array([this._fb.group({[rr.question_key]:''})]) + // control_names[val.group_key].push({[rr.question_key]:''}) + }) + } + else { + control_names[val.question_key] = '' + } + }) + + // debugger; + + json_obj.group_questions.push(json_obj.question); + control.push(this._fb.group(control_names)) + + json_obj.question.forEach((group_indi,arr_index)=>{ + + + if(group_indi.is_repeatable == '2' && group_indi.hasOwnProperty('questions_level_two') && group_indi.questions_level_two.length > 0) { + group_indi.questions_level_two[0].forEach((child_val,child_index)=> { + // console.log("sd",group_indi,arr_index,control.at(control.length-1),control) + // debugger; + let child_control = control.at(control.length-1).get(group_indi.group_key) as FormArray + + this.questionService.addAdditionalControl(child_val, child_control.controls[child_control.length-1], child_index) + }) + } + else{ + this.questionService.addAdditionalControl(group_indi, control.controls[control.length-1], arr_index) + } + }) + json_obj.question = JSON.parse(JSON.stringify(json_obj.question)) + control.updateValueAndValidity(); + control.controls[control.length-1].updateValueAndValidity(); + this.form_group_name.updateValueAndValidity(); + this.step = control.length-1 + + // debugger; + } + // ADDING A CHILD REPEATABLE OBJ IN A EXISTING FORM ARRYA + addSecondLevelChild(index,json_obj,parent_group) { + + let control_names:any= {} + let control = parent_group.get(json_obj.group_key) as FormArray + json_obj.question.map(val=>{ + control_names[val.question_key] = '' + }) + + + json_obj.questions_level_two.push(json_obj.question); + control.push(this._fb.group(control_names)) + + json_obj.question.forEach((group_indi,arr_index)=>{ + // console.log("sd",childControl) + this.questionService.addAdditionalControl(group_indi, control.controls[control.length-1], arr_index) + }) + json_obj.question = JSON.parse(JSON.stringify(json_obj.question)) + control.updateValueAndValidity(); + control.controls[control.length-1].updateValueAndValidity(); + parent_group.updateValueAndValidity(); + this.step_child = control.length-1 + + // debugger; + } + // REMOVE OF CHILD REPEATABLE OBJ + removeSecondLevelChild(index,json_obj,parent_group) { + + // debugger; + let control = parent_group.get(json_obj.group_key) + control.removeAt(index) + json_obj.questions_level_two.splice(index,1) + this.step_child = control.length-1 + + } + + removeData(index,json_obj) { + + // debugger; + let control = this.form_group_name.get(json_obj.group_key) as FormArray + control.removeAt(index) + if(this.json_answers[json_obj.group_key] ){ + + + if(this.json_answers[json_obj.group_key] != null && this.json_answers[json_obj.group_key] instanceof Array){ + this.json_answers[json_obj.group_key].splice(index,1) + } + } + json_obj.group_questions.splice(index,1) + this.step = control.length-1 + + } + openMatExpansionPanel() { + + if(this.matExpansionPanel!= undefined){ + this.matExpansionPanel.open() + } + } + openAllPanels(){ + this.Accordion.openAll(); + + return; +} +updateAllComplete(a,b){ + console.log(a) + console.log(b.checked) + + if(b.checked){ + + + this.vr = true + }else{ + + this.vr = false + + + +} +} + + + + + + + + + + + + + + + +} diff --git a/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-question-template/dynamic-question-template.component.html b/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-question-template/dynamic-question-template.component.html new file mode 100644 index 0000000..ac466df --- /dev/null +++ b/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-question-template/dynamic-question-template.component.html @@ -0,0 +1,230 @@ +
+ +
+ + {{parent_ques.title}} + + +
+
+
+
+ + {{parent_ques.sub_title}} + + +
+ + + + + {{parent_ques.question}} + + + {{"₹"}} {{formGroupN.value[parent_ques.question_key] | numberToWords}} + + + + + + {{validation.message}} + + + + + {{parent_ques.question}} + + + + {{val.answer}} + + + {{"₹"}} {{formGroupN.value[parent_ques.question_key] | numberToWords}} + + + + + {{validation.message}} + + + + +
+ {{parent_ques.question}}
+ + {{val.answer}}

+
+ + + {{validation.message}} + +
+ + + {{parent_ques.question}} + + Select + add_circle_outline {{val.answer}} + + + + {{validation.message}} + + + +
+ {{parent_ques.question}} + {{val.answer}}
+ + + {{validation.message}} + + +
+
+ {{parent_ques.question}}   + + + + {{validation.message}} + +
+ + + + {{parent_ques.question}}   + + + + + + {{validation.message}} + + + + + + + {{parent_ques.question}} + + + {{val.answer}} + + + + + {{validation.message}} + + + + + + + {{parent_ques.question}} + + + + + {{validation.message}} + + + + + {{parent_ques.question}} + + + + close + + + Select + + add_circle_outline {{val.answer}} + + + + {{validation.message}} + + +
+ +
+ + + + + + + diff --git a/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-question-template/dynamic-question-template.component.scss b/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-question-template/dynamic-question-template.component.scss new file mode 100644 index 0000000..c1d7cf2 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-question-template/dynamic-question-template.component.scss @@ -0,0 +1,90 @@ +mat-radio-button,mat-checkbox{ + margin-top: 13px; + } + mat-form-field { + width: 100%; + } + .radio-gap{ + margin-top: 10px; + margin-bottom: 10px; + } + .radio-btn-gap{ + margin:10px; + } + + ::ng-deep .mat-radio-button.mat-accent.mat-radio-checked .mat-radio-outer-circle{ + border-color:rgb(212, 15, 15); + } + + ::ng-deep .mat-radio-button.mat-accent .mat-radio-inner-circle{ + color:rgb(212, 15, 15); + background-color:rgb(212, 15, 15); + } + + ::ng-deep .mat-radio-button.mat-accent .mat-radio-ripple .mat-ripple-element { + background-color:rgba(224, 22, 22, 0.308); + } + input { + // width: 100px; + // border-radius: 4px; + // border-color: gray; + // font-size: 12px; + height: 31px; + + } + .mat-select, .text-area { + margin-top: 8px; + } + + @-webkit-keyframes highlight-fade { + 0% { + background: orange; + } + 100% { + background: white; + } + } + @-moz-keyframes highlight-fade { + 0% { + background: orange; + } + 100% { + background: white; + } + } + @-ms-keyframes highlight-fade { + 0% { + background: orange; + } + 100% { + background: white; + } + } + @keyframes highlight-fade { + 0% { + background: orange; + } + 100% { + background: white; + } + } + .field_highlight { + -webkit-animation: highlight-fade 4s ease-out; + -moz-animation: highlight-fade 4s ease-out; + -o-animation: highlight-fade 4s ease-out; + animation: highlight-fade 4s ease-out; + // background: blue; + } + + ::ng-deep .mat-form-field-label{ + white-space: pre-wrap; + } + .large-select-option { + height: unset !important; + line-height: 1.2em !important; + padding-top: 0.9em !important; + padding-bottom: 0.9em !important; + span { + white-space: normal; + } + } \ No newline at end of file diff --git a/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-question-template/dynamic-question-template.component.spec.ts b/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-question-template/dynamic-question-template.component.spec.ts new file mode 100644 index 0000000..6303295 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-question-template/dynamic-question-template.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { DynamicQuestionTemplateComponent } from './dynamic-question-template.component'; + +describe('DynamicQuestionTemplateComponent', () => { + let component: DynamicQuestionTemplateComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ DynamicQuestionTemplateComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(DynamicQuestionTemplateComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-question-template/dynamic-question-template.component.ts b/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-question-template/dynamic-question-template.component.ts new file mode 100644 index 0000000..1e6e722 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/dynamic-question-template/dynamic-question-template.component.ts @@ -0,0 +1,1058 @@ +import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; +import { FormGroup, FormArray, FormControl, FormBuilder } from '@angular/forms'; +import { QuesFormService } from '../ques-form/ques-form.service'; +import { startWith, map } from 'rxjs/operators'; +import { Observable, ReplaySubject } from 'rxjs'; +import { MatDialog } from '@angular/material'; +import { AnswerOptionCreateDialogComponent } from '../../answer-option-create-dialog/answer-option-create-dialog.component'; +import { LoaderService } from 'app/shared/loaderService/loader.service'; + +@Component({ + selector: 'app-dynamic-question-template', + templateUrl: './dynamic-question-template.component.html', + styleUrls: ['./dynamic-question-template.component.scss'], +}) +export class DynamicQuestionTemplateComponent implements OnInit { + @Input() formGroupN : FormGroup; + @Input() currFormArrayObj; + + + parent_ques: any; + fileredSearchValue: any=[]; + @Input() whole_json:any; + @Input() json_index:any; + @Input() whole_form:FormGroup; + @Input() json_answers:any; + @Input()group_key:any; + length:any; + @Output() generateGroupControls= new EventEmitter() + local_city: any; + local_pincode: any; + local_city1: any; + local_pincode1: any; + json_answers1:any; + isChecked:any=[]; + autoCompleteAns:Observable + public commonFilterCtrl:FormControl = new FormControl(); + public ngxFilteredValue:ReplaySubject = new ReplaySubject(1); + vr: boolean; + check: any = "Letter of Credit"; + role_id: string; + + + constructor(private quesService:QuesFormService,private _fb:FormBuilder, private matDialog:MatDialog, private loaderService:LoaderService) { + this.role_id = localStorage.getItem('LenderRoleID') + } + + ngOnInit() { + this.quesService.currentMessageSubscriber.subscribe((data : any)=>{ + console.log(data) + if(data){ + this.check = true + }else{ + this.check = false + } + + // output : {msg : 'do something'} + }) + localStorage.setItem('use',"0"); + console.log( this.whole_json) + this.parent_ques = this.currFormArrayObj + + + if(this.parent_ques.type == '9' && this.parent_ques.answers && this.parent_ques.answers.length > 0) { + this.autoCompleteAns =this.formGroupN.get(this.parent_ques.question_key).valueChanges.pipe( + startWith(''), + map(value => this.autoCompleteFilter(value)) + ) + } + //let length=this.quesService.ans_length() + + } + checkCat(data,w){ + console.log(this.isChecked) + if( this.isChecked.length == 0){ + this.isChecked = this.json_answers[w.question_key] + let ref = this.isChecked.find(x => x == data); // this checks the cat[] array + if(ref == data){ + return true; + } else { + return false; + } + }else{ + let ref = this.isChecked.find(x => x == data); // this checks the cat[] array + if(ref == data){ + return true; + } else { + return false; + } + } + + } + ngOnChanges() { + //alert('ans'); + this.parent_ques = this.currFormArrayObj + + this.json_answers1=[{ + stakeholder_name0: "SUMIT KHANDELWAL", + share_holding0: 10, + vintage_in_current_biz0: 5, + total_work_exp0: 10, + started_biz0: "", + + stakeholder_name1: "RAM", + share_holding1: 10.5, + vintage_in_current_biz1: 8, + total_work_exp1: 5, + started_biz1: "", + + stakeholder_name2: "VIGNESH", + share_holding2: 55, + vintage_in_current_biz2: 6, + total_work_exp2: 0, + started_biz2: "", + stakeholder_length:'2', + company_name: 3}, + { + stakeholder_name0: "SUMIT KHANDELWAL", + share_holding0: 15, + vintage_in_current_biz0: 6, + total_work_exp0: 11, + started_biz0: "", + + + + stakeholder_name1: "RAM", + share_holding1: 0, + vintage_in_current_biz1: 10, + total_work_exp1: 9, + started_biz1: "", + + + + stakeholder_name2: "VIGNESH", + share_holding2: 25, + vintage_in_current_biz2: 12, + total_work_exp2: 8, + started_biz2: "", + + stakeholder_length:'2', + company_name: 2},{ + stakeholder_name0: "SUMIT KHANDELWAL", + share_holding0: 25, + vintage_in_current_biz0: 7, + total_work_exp0: 12, + started_biz0: "", + + + + stakeholder_name1: "RAM", + share_holding1: 25.5, + vintage_in_current_biz1: 15, + total_work_exp1: 0, + started_biz1: "", + + + + stakeholder_name2: "VIGNESH", + share_holding2: 0, + vintage_in_current_biz2: 10, + total_work_exp2: 9, + started_biz2: "", + + stakeholder_length:'2', + company_name: 1} + + ] + + setTimeout(()=>{ + console.log(this.parent_ques); + if( this.parent_ques.answers && this.parent_ques.answers instanceof Array){ + + console.log(this.parent_ques.answers.length) + console.log( this.formGroupN.get(this.parent_ques.question_key)) + if(this.parent_ques.type == '3' && this.parent_ques.answers.length == 1){ + console.log(this.parent_ques.answers.answer_id) + this.formGroupN.get(this.parent_ques.question_key).patchValue(this.parent_ques.answers[0].answer_id || '') + }else if(this.parent_ques.type == '3' && this.parent_ques.answers.length == 0){ + console.log(this.parent_ques.answers.answer_id) + this.formGroupN.get(this.parent_ques.question_key).patchValue(this.parent_ques.answers[0].answer_id || '') + } + } + }, 1000); + + if(this.json_answers!=null && this.json_answers != undefined && this.json_answers) { + + // setTimeout(()=>{ + // console.clear() + + if(this.json_answers!=null && this.json_answers!= undefined && this.json_answers&& !this.group_key) { + this.formGroupN.get(this.parent_ques.question_key).patchValue((this.json_answers[this.parent_ques.question_key] || '')) + if(this.parent_ques.question_key == '5'){ + + this.isChecked = this.json_answers[this.parent_ques.question_key] + console.log( this.isChecked) + } + + this.onChangeProperty({value:this.json_answers[this.parent_ques.question_key]},this.parent_ques,'','','','TS') + console.log( this.json_answers[this.parent_ques.question_key]) + } + else if(this.json_answers!=null && this.json_answers != undefined && this.json_answers){ + // this.formGroupN.patchValue((this.json_answers[this.group_key] || '')) + + // debugger; + + this.formGroupN.get(this.parent_ques.question_key) + + this.whole_form.get(this.group_key).patchValue(this.json_answers) + if(this.json_answers.length > 1) { + this.generateGroupControls.emit() + } + + + this.json_answers.forEach((value,index)=>{ + + + let keys= Object.keys(value) + keys.forEach(vv=>{ + + // debugger; + if(typeof(value[vv])== 'string') { + + + + if(this.whole_form.get(this.group_key) && this.whole_json.length > 0) { + + let curr_obj=this.whole_json.filter(vl=>vl.question_key == vv)[0] + this.onChangeProperty({value:value[vv]},curr_obj,'','','','TS') + } + + } + }) + + }) + // debugger; + + } + // this.formGroupN.get(this.parent_ques.question_key).patchValue((this.json_answers[this.parent_ques.question_key] || '')) + // setTimeout(()=>{ + // console.log("last on change fun",this.json_answers[this.parent_ques.question_key],this.parent_ques.question_key) + // debugger; + // this.onChangeProperty({value:this.json_answers[this.parent_ques.question_key]},this.parent_ques,'') + // },1000) + // this.formGroupN.patchValue(this.json_answers) + // }) + this.loaderService.closeMatSpinnerDialog(); + // this.formGroupN.get(this.parent_ques.question_key).patchValue(this.json_answers[this.parent_ques.question_key]) + // this.onChangeProperty({value:this.json_answers[this.parent_ques.question_key]},this.parent_ques,'') + // setTimeout(()=>{ + // this.json_answers = null + // },700) + // if(this.json_answers == ) + // console.log("KEY TO BE FIND",this.json_index,this.whole_json) + setTimeout(() => { + // this.quesService.formanswers=null; + this.loaderService.closeMatSpinnerDialog(); + },0) + } + + // console.log(this.parent_ques,this.formGroupN,this.whole_json ,this.json_answers); + // debugger; + + if(this.parent_ques.type == '8') { + + if(this.parent_ques.answers && this.parent_ques.answers.length > 0){ + this.ngxFilteredValue.next(this.parent_ques.answers.slice()) + // this.filterList() + } + else{ + setTimeout(()=>{ + + if(this.parent_ques.answers && this.parent_ques.answers.length > 0){ + this.ngxFilteredValue.next(this.parent_ques.answers.slice()) + // this.filterList() + } + },1600) + } + this.filterList() + } + } + filterList() { + this.commonFilterCtrl.valueChanges.pipe().subscribe(()=>{ + + if(this.parent_ques.type == '8' && this.parent_ques.answers && this.parent_ques.answers.length > 0) { + this.applyFilter(this.commonFilterCtrl.value,this.ngxFilteredValue,this.parent_ques.answers,'answer') + } + }) + + } + applyFilter(filtered_text,filter_list,raw_list,obj_name) { + if (!raw_list) { + return; + } + // get the search keyword + let search = filtered_text; + if (!search) { + filter_list.next(raw_list.slice()); + return; + } else { + search = search.toLowerCase(); + } + // filter the banks + filter_list.next( + raw_list.filter(bank => bank[obj_name].toLowerCase().indexOf(search) > -1) + ); + } + autoCompleteFilter(value:string): string[] { + if(value) { + const filterValue = value.toLowerCase(); + + return this.parent_ques.answers.filter(option => option.answer.toLowerCase().indexOf(filterValue) === 0); + } + else { + return this.parent_ques.answers + } + } + onChange_checkbox(event,sec_control){ + console.log(this.isChecked) + // this.isChecked =[]; + console.log( this.formGroupN.get(sec_control.question_key).value) + + const control=this.formGroupN.get(sec_control.question_key) as FormArray + + if(event.checked) { + control.push(new FormControl(event.source.value)) + } else { + const i = control.controls.findIndex(x => x.value === event.source.value); + control.removeAt(i); + } + + // this.isChecked = this.formGroupN.get(sec_control.question_key).value + + } + onChangeProperty(event,sec_control,question_key,options?,sec_index?,from?){ + // alert('datatamil'); + if(!from && from != 'TS' && this.quesService.formanswers != null) { + console.log("Value changes",from); + this.quesService.formanswers = null + } + + // this.fileredSearchValue=[] + + if(sec_control && sec_control.answers!= null && sec_control.answers.length > 0){ + // this.creatSubField(sec_control,event.value) + } + //FOR API CALLS + // console.log(sec_control.value); + if(sec_control && sec_control.onchange_properties != null && sec_control.onchange_properties.length >0){ + + let onChangeProperties_value=sec_control.onchange_properties + +// let new_name=`{ +// "purpose":"FORM_CTRL", +// "form_controls":[ +// { +// "insert_index":"total_work_exp", +// "expression":"(total_work_exp > vintage_in_current_biz)", +// "value_keys":[ +// "total_work_exp", +// "vintage_in_current_biz"], +// "questions":[ +// { +// "question_key":"previous_experience_details2", +// "question":"Previous Experience2", +// "type":"1", +// "api_properties":null, +// "answers":null, +// "onchange_properties":null, +// "is_repeatable":null, +// "field_type":"string", +// "validations":[{ +// "isactive": "1", +// "message": "Name Required", +// "name": "required", +// "validator": "Validators.required", +// "value": null +// }] + +// }] + +// }, +// { +// "insert_index":"vintage_in_current_biz", +// "expression":"(total_work_exp > vintage_in_current_biz)", +// "value_keys":[ +// "total_work_exp", +// "vintage_in_current_biz"], +// "questions":[{ +// "question_key":"vintage1", +// "question":"Vintage check", +// "type":"1", +// "api_properties":null, +// "answers":null, +// "onchange_properties":null, +// "is_repeatable":null, +// "field_type":"string", +// "validations":[] + +// }] + +// } +// ] + +// }` +// onChangeProperties_value.push(JSON.parse(new_name)) + + onChangeProperties_value.forEach(onChangeProperty=>{ + console.log(onChangeProperty) + if(onChangeProperty.purpose == 'api2'){ + console.log(event.value,onChangeProperty.params) + if(onChangeProperty.api == 'getListOfStatesAndCities'){ + console.log(event.value,onChangeProperty.params) + // onChangeProperty.params = JSON.stringify(onChangeProperty.params); + // let updatedParams =JSON.stringify(onChangeProperty.params); + // updatedParams = updatedParams.replace('value_of_answer',event.value); + // // updatedParams = JSON.parse(updatedParams) + // console.log(JSON.parse(updatedParams),updatedParams,JSON.parse(JSON.stringify(updatedParams))) + // debugger; + let params={records:{state_id:event.value}} + + this.quesService.apiCall(onChangeProperty.api,params,onChangeProperty.api_method).subscribe(res=>{ + + if(res['dataStatus']){ + + this.local_city1=res['records'].cities + this.local_pincode1=res['records'].pincode + + this.whole_json.forEach((val,index)=>{ + + + if(val.api_properties == 'local_city1' ){ + + this.local_city1=this.quesService.convertArrayNames(['city_id','city_name'],this.local_city1) + console.log( this.local_city1) + val.answers = (this.local_city1) + } + else if(val.api_properties == 'local_pincode1'){ + this.local_pincode1=this.quesService.convertArrayNames(['pincode_id','pincode'],this.local_pincode1) + val.answers = (this.local_pincode1) + } + + }) + + } + }) + } + } + if(onChangeProperty.purpose == 'api'){ + if(onChangeProperty.api == 'getListOfStatesAndCities'){ + // console.log(event.value,onChangeProperty.params) + // onChangeProperty.params = JSON.stringify(onChangeProperty.params); + // let updatedParams =JSON.stringify(onChangeProperty.params); + // updatedParams = updatedParams.replace('value_of_answer',event.value); + // // updatedParams = JSON.parse(updatedParams) + // console.log(JSON.parse(updatedParams),updatedParams,JSON.parse(JSON.stringify(updatedParams))) + // debugger; + let params={records:{state_id:event.value}} + + this.quesService.apiCall(onChangeProperty.api,params,onChangeProperty.api_method).subscribe(res=>{ + + if(res['dataStatus']){ + this.local_city=res['records'].cities + this.local_pincode=res['records'].pincode + + + this.whole_json.forEach((val,index)=>{ + + if(val.api_properties == 'local_city' ){ + + this.local_city=this.quesService.convertArrayNames(['city_id','city_name'],this.local_city) + console.log( this.local_city) + val.answers = (this.local_city) + } + else if(val.api_properties == 'local_pincode'){ + this.local_pincode=this.quesService.convertArrayNames(['pincode_id','pincode'],this.local_pincode) + val.answers = (this.local_pincode) + } + // if(val.api_properties == 'local_city1' ){ + + // this.local_city1=this.quesService.convertArrayNames(['city_id','city_name'],this.local_city1) + // console.log( this.local_city1) + // val.answers = (this.local_city1) + // } + // else if(val.api_properties == 'local_pincode1'){ + // this.local_pincode1=this.quesService.convertArrayNames(['pincode_id','pincode'],this.local_pincode1) + // val.answers = (this.local_pincode1) + // } + + }) + + } + }) + }else if(onChangeProperty.purpose == 'api2'){ + console.log(event.value,onChangeProperty.params) + if(onChangeProperty.api == 'getListOfStatesAndCities'){ + console.log(event.value,onChangeProperty.params) + // onChangeProperty.params = JSON.stringify(onChangeProperty.params); + // let updatedParams =JSON.stringify(onChangeProperty.params); + // updatedParams = updatedParams.replace('value_of_answer',event.value); + // // updatedParams = JSON.parse(updatedParams) + // console.log(JSON.parse(updatedParams),updatedParams,JSON.parse(JSON.stringify(updatedParams))) + // debugger; + let params={records:{state_id:event.value}} + + this.quesService.apiCall(onChangeProperty.api,params,onChangeProperty.api_method).subscribe(res=>{ + + if(res['dataStatus']){ + + this.local_city1=res['records'].cities + this.local_pincode1=res['records'].pincode + + this.whole_json.forEach((val,index)=>{ + + + if(val.api_properties == 'local_city1' ){ + + this.local_city1=this.quesService.convertArrayNames(['city_id','city_name'],this.local_city1) + console.log( this.local_city1) + val.answers = (this.local_city1) + } + else if(val.api_properties == 'local_pincode1'){ + this.local_pincode1=this.quesService.convertArrayNames(['pincode_id','pincode'],this.local_pincode1) + val.answers = (this.local_pincode1) + } + + }) + + } + }) + } + } + else{ + + this.quesService.apiCall(onChangeProperty.api,onChangeProperty.params,onChangeProperty.api_method).subscribe((result:any)=>{ + + if(result['dataStatus']){ + if(result.hasOwnProperty('records')){ + result=result['records'] + } + // let ques_control= this.quesAnsForm.controls.questions['controls'] + // if(options == 2){ + // ques_control=group_ques.controls.questions['controls'] + // } + if(onChangeProperty.hasOwnProperty('filter_properties') && onChangeProperty.filter_properties && result.length > 0) { + let filter_properties = onChangeProperty.filter_properties + result = result.filter(vv=>vv[filter_properties.key_name] == filter_properties.value) + } + + this.whole_json.forEach((val,index)=>{ + + if(val.api_properties == onChangeProperty.local_variable){ + let values1=this.quesService.convertArrayNames(onChangeProperty.fields,result) + val.answers = (values1) + } + + }) + } + }) + } + } + if(onChangeProperty.purpose == 'validations'){ + + // if(options == 2){ + this.setValidations_onChange(onChangeProperty,this.formGroupN,sec_control,sec_index) + // } + // else{ + // this.setValidations_onChange(onChangeProperty,this.quesAnsForm,sec_control,sec_index) + // } + } + if(onChangeProperty.purpose == 'FORM_CTRL'){ + console.log(onChangeProperty) + // if(options == 2){ + + // debugger; + this.creteNewField(onChangeProperty,this.formGroupN,sec_control,sec_index) + // } + // else{ + // this.creteNewField(onChangeProperty,this.quesAnsForm,sec_control,sec_index) + // } + } + if(onChangeProperty.purpose == 'answer_value' || onChangeProperty.purpose == 'question_label') { + this.setModifiedValuetoControl(onChangeProperty,this.formGroupN,sec_index) + } + // for calculation field from multiple arr values + if(onChangeProperty.purpose == 'answer_value_arr') { + let index = JSON.parse(JSON.stringify(this.json_index)) + this.setModifiedValuetoControl_frommultiple(onChangeProperty,this.whole_form.get(this.group_key),index,sec_control) + } + }) + } + } + setModifiedValuetoControl_frommultiple(curr_obj,formArray,curr_index ?,sec_control?) { + + if(curr_obj && curr_obj.value_keys.length > 0 && curr_obj.arr_include.length > 0 ) { + let expression_value=curr_obj.expression + for(let index_str of curr_obj.arr_include) { + let value_index; + if(index_str == 'py') { + if(curr_index == 0) { + formArray.controls[curr_index].controls[curr_obj.insert_control].setValue(0) + // curr_obj.is_hidden = true; + + this.whole_json.filter(vv=>{ + if(vv.question_key == curr_obj.insert_control) { + vv.is_hidden = true + }}) + + } + if(formArray.value.length < 2) { + + return; + } + value_index = curr_index-1 + } + if(index_str == 'now'){ + value_index = curr_index + } + for(let value of curr_obj.value_keys) { + + let control_value = formArray.getRawValue()[value_index] ? formArray.getRawValue()[value_index][value] : '' + if(control_value) { + + if(sec_control.type == '1' && sec_control.field_type == 'num' || sec_control.field_type == 'numtoword') { + let val = Number(control_value) + + if(val == undefined || isNaN(val)) { + control_value = 0 + } + } + expression_value = expression_value.split(value+'['+index_str+']').join(control_value) + } + else{ + if(formArray.value.length > curr_index+1) { + + this.setModifiedValuetoControl_frommultiple(curr_obj,formArray,curr_index+1,sec_control) + } + + return + } + } + } + if(expression_value) { + + let calc_exp=eval(expression_value) + + if(calc_exp){ + if(typeof(calc_exp) == 'number'){ + calc_exp = calc_exp.toFixed(2) + } + if(curr_obj.insert_control) { + formArray.controls[curr_index].controls[curr_obj.insert_control].setValue(calc_exp) + if(formArray.value.length > curr_index+1) { + + this.setModifiedValuetoControl_frommultiple(curr_obj,formArray,curr_index+1,sec_control) + } + } + } + } + } + + } + // for setting the modified value to another or same control while field change + setModifiedValuetoControl(curr_obj,form_control_obj,curr_index) { + + if(curr_obj && curr_obj.value_keys.length > 0){ + let expression_value=curr_obj.expression + // curr_obj.value_keys.forEach(val=>{ + for(let val of curr_obj.value_keys) { + let control_value + control_value =form_control_obj.getRawValue()[val] + if(control_value) { + expression_value = expression_value.split(val).join(control_value) + } + else{ + return; + } + } + // }) + + let calc_exp=eval(expression_value) + + if( (typeof(calc_exp) == 'string' || typeof(calc_exp) == 'number' ) ){ + // if(typeof(calc_exp) == 'number'){ + // calc_exp = calc_exp.toFixed(2) + // } + if(curr_obj.insert_control) { + // FOR SETTING THE ANSWER TO OTHER OR SAME FIELD + if(curr_obj.purpose == 'answer_value') { + form_control_obj.controls[curr_obj.insert_control].setValue(calc_exp) + } + // FOR SETTING THE Question Label TO OTHER OR SAME Question + if(curr_obj.purpose == 'question_label') { + let curr_question_obj + let curr_json = this.whole_json + if(curr_obj.hasOwnProperty('insert_group_key') && curr_obj.insert_group_key != null) { + curr_json = curr_json.filter(val=>val.group_key == curr_obj.insert_group_key) + curr_json = curr_json[0] + if(curr_json && curr_json.group_questions && curr_json.group_questions.length > 0) { + curr_json.group_questions.forEach(rr=>{ + let temp_curr = rr.filter(val=>val.question_key == curr_obj.insert_control) + if(temp_curr && temp_curr.length > 0) { + temp_curr[0].question = calc_exp + } + }) + curr_json = curr_json.question + } + } + + if(curr_json) { + curr_question_obj = curr_json.filter(val=>val.question_key == curr_obj.insert_control) + if(curr_question_obj && curr_question_obj.length > 0) { + curr_question_obj[0].question = calc_exp + } + } + } + } + } + } + + } + + creteNewField(form_control_obj_raw,group_ques,sec_control,sec_index,purpose?){ + + if(form_control_obj_raw.form_controls.length > 0){ + form_control_obj_raw.form_controls.forEach(form_control_obj=>{ + if(form_control_obj.value_keys != null && form_control_obj.value_keys.length > 0 ){ + let expression_value=form_control_obj.expression + form_control_obj.value_keys.forEach(res=>{ + let control_value_obj + if(purpose != 'edit'){ + control_value_obj =group_ques.value[res] + } + else{ + control_value_obj = sec_index.questions.filter(val=>val.question_key == res)[0] + } + if(control_value_obj){ + // if(control_value_obj.answer_value == ''){ + // control_value_obj.answer_value =0 + // } + expression_value=expression_value.split(res).join(control_value_obj) + } + }) + + let calc_exp=eval(expression_value) + + if(calc_exp != false){ + if(form_control_obj.questions.length > 0){ + let question_index_after + this.whole_json.forEach((val,index,arr)=>{ + + if(val.question_key == form_control_obj.insert_index){ + question_index_after= arr.indexOf(val) + } + }) + + this.createControl(form_control_obj,group_ques,question_index_after,1) //FOR ADD CONTOL + } + } + else{ + this.createControl(form_control_obj,group_ques,'',2) //FOR REMOVE CONTROL + } + } + }) + } + } + createControl(form_control_obj,group_ques,question_index_after,options){ + + let ques_control=this.whole_json + let inserted_control_obj=form_control_obj + // inserted_control_obj.questions.sort() + // inserted_control_obj.questions.reverse() + + inserted_control_obj.questions.forEach((val,index)=>{ + if(val.hasOwnProperty('is_repeatable') && val.is_repeatable == '1') { + if(options == 1) { + let check_dup=ques_control.filter(control_key=>control_key.group_key == val.group_key) + + if(check_dup.length == 0){ + this.formGroupN.addControl(val.group_key,this._fb.array([])) + // val.question.reverse() + let childControl: any = this.formGroupN.get(val.group_key) as FormArray + let control_names:any={} + inserted_control_obj.questions[index].group_questions = [] + inserted_control_obj.questions[index].group_questions.push(val.question) + this.whole_json.splice(question_index_after+1,0,val); + val.question.forEach(group_val=>{ + control_names[group_val.question_key] = '' + // console.log("check ffffff",inserted_control_obj.questions.reverse(),inserted_control_obj.questions,group_val) + this.addOrRemoveControl(group_val,ques_control,question_index_after,options,val) + }) + const question_temp:any = JSON.parse(JSON.stringify(val.question)); + inserted_control_obj.questions[index].question = question_temp + console.log(control_names) + childControl.push(this._fb.group(control_names)) + val.group_questions[0].forEach((group_indi,arr_index)=>{ + + this.quesService.addAdditionalControl(group_indi, childControl.controls[0], arr_index) + }) + } + } + else{ + // let childControl: any = this.formGroupN.get(val.group_key) as FormArray + val.question.forEach(group_val=>{ + // control_names[group_val.question_key] = '' + // console.log("check ffffff",inserted_control_obj.questions.reverse(),inserted_control_obj.questions,group_val) + this.addOrRemoveControl(group_val,ques_control,question_index_after,options,val) + }) + } + } + else{ + this.addOrRemoveControl(val,ques_control,question_index_after,options,val) + } + }) + } + addOrRemoveControl(val,ques_control,question_index_after,options,paren_ques) { + console.log(val); + console.log(ques_control); + console.log(question_index_after); + console.log(paren_ques); + if(options == 1){ + let check_dup=ques_control.filter(control_key=>control_key.question_key == val.question_key) + + + // let check_dup = [] + if(check_dup.length == 0){ + val.raw_validations=val.validations + // ques_control.insert(question_index_after+1,this.questionService.createValue(val)) + if(paren_ques.hasOwnProperty('is_repeatable') && paren_ques.is_repeatable == '1') { + + // this.formGroupN.addControl(val.question_key,new FormControl('')) + } + else{ + this.whole_json.splice(question_index_after+1,0,val); + this.formGroupN.addControl(val.question_key,new FormControl('')) + this.quesService.addAdditionalControl(val, this.formGroupN, question_index_after+1,"") + } + + } + } + else{ + + ques_control.forEach((control_key,index)=>{ + if(paren_ques.hasOwnProperty('is_repeatable') && paren_ques.is_repeatable == '1') { + if(control_key.group_key == paren_ques.group_key){ + this.whole_json.splice(index,1) + // this.formGroupN.controls[val.question_key].reset() + this.formGroupN.removeControl(paren_ques.group_key); + } + + } + else{ + if(control_key.question_key == val.question_key){ + this.whole_json.splice(index,1) + this.formGroupN.controls[val.question_key].reset() + this.formGroupN.removeControl(val.question_key); + this.checkAndRemoveSubQuestion(control_key,ques_control) + // let getSubQuestion = this.whole_json.filter(vv=>vv.parent_question_key == control_key.question_key) + // console.log(getSubQuestion,control_key,this.whole_json) + } + } + }) + } + } + checkAndRemoveSubQuestion(question_obj,ques_control) { + + let getSubQuestion = this.whole_json.filter(vv=>vv.parent_question_key == question_obj.question_key) + if(getSubQuestion.length > 0) { + getSubQuestion.forEach(val=>{ + this.addOrRemoveControl(val,ques_control,'',2,val) + }) + } + + } + setValidations_onChange(validation_obj_raw,group_ques,sec_control,sec_index){ + + + if(validation_obj_raw.validations.length > 0){ + validation_obj_raw.validations.forEach(validation_obj=>{ + + //FOR CHECKING THE EXPRESSION OR NORMAL VALIDATION + if(validation_obj.hasOwnProperty('value_keys')){ + + if( validation_obj.value_keys != null){ + + + let expression_value=validation_obj.value + validation_obj.value_keys.forEach(res=>{ + let validator_value_obj=group_ques.value[res] + // if(validator_value_obj){ + expression_value=expression_value.split(res).join(validator_value_obj) + // } + }) + + // validation_obj.value=expression_value + validation_obj.validator=eval(expression_value) + + if(validation_obj.validator == false){ + validation_obj.isactive='0' + // // MAKING THE DECISION FOR SETTING THE VALIDATOR FOR CURRENT CONTROL OR OTHERS + this.proceedValidationSet(validation_obj,group_ques,sec_control,'') + } + else{ + validation_obj.isactive='1' + let validator_single=this.quesService.setValueForValidator(validation_obj) + + // // MAKING THE DECISION FOR SETTING THE VALIDATOR FOR CURRENT CONTROL OR OTHERS + this.proceedValidationSet(validation_obj,group_ques,sec_control,validator_single) + } + //END OF EXPRESSION CHECK + } + else{ + // STARTING VALUE VALIDATION + let validator_value_obj + + + + validator_value_obj=this.formGroupN.value[ validation_obj.value] + + + validation_obj.validator=validator_value_obj + + // let validator_single=this.questionService.setValueForValidator(validation_obj) + // console.log(validator_single) + // MAKING THE DECISION FOR SETTING THE VALIDATOR FOR CURRENT CONTROL OR OTHERS + this.proceedValidationSet(validation_obj,group_ques,sec_control,'') + + // END OF VALUE VALIDATION + } + + // + + // } + // else{ + + // } + + } + }) + } + } + + proceedValidationSet(validation_obj,group_ques,sec_control,validator_single?){ + + let ques_control; + if(validation_obj.validation_to == null){ + + ques_control=this.whole_json[this.json_index] + + + // if(validation_obj.isactive == '1'){ + // ques_control.controls.answer_value.setValidators(validator_single) + // ques_control.controls.answer_value.updateValueAndValidity() + // } + // else{ + // ques_control.controls.answer_value.clearValidators() + // ques_control.controls.answer_value.updateValueAndValidity() + // } + // validation_obj.validator=validator_single + let new_validation_obj=this.updateValidationMsg(ques_control,validation_obj) + + this.quesService.settingArrayofValidators({validations:new_validation_obj,question_key:sec_control.question_key},this.formGroupN,'') + } + else{ + ques_control=this.whole_json[this.json_index] + + let other_control = ques_control + if(ques_control.hasOwnProperty('is_repeatable') && ques_control.is_repeatable == '2') { + return; + } + // =ques_control.filter(val=>{ + // if(val.question_key == validation_obj.validation_to){ + // return val + // } + // })[0] + // let updateMsg=other_control.value.validations.filter(val=>val.name != validation_obj.name) + // updateMsg.push(validation_obj) + + // other_control.controls.answer_value.setValidators(validator_single) + // if(validation_obj.isactive == '1'){ + // other_control.controls.answer_value.setValidators(validator_single) + // other_control.controls.answer_value.updateValueAndValidity() + // } + // else{ + // other_control.controls.answer_value.clearValidators() + // other_control.controls.answer_value.updateValueAndValidity() + // } + + // other_control.controls.validations.setValue(updateMsg); + // validation_obj.validator=validator_single + let new_validations_obj=this.updateValidationMsg(other_control,validation_obj) + + this.quesService.settingArrayofValidators({validations:new_validations_obj,question_key:validation_obj.validation_to},this.formGroupN,'') + } + } + newAnswerCreateDialog(choosed_answer_obj,curr_ques_obj) { + // console.log('aa'); + // console.log(choosed_answer_obj); + // console.log(curr_ques_obj); + // console.log('abx'); + // console.log(choosed_answer_obj.answer) + // if(choosed_answer_obj.answer!='') + // { + // console.log('changed'); + + // let company=this.quesService.companynamechanged(choosed_answer_obj,curr_ques_obj) + // } + if(choosed_answer_obj.is_others == '-1') { + this.formGroupN.get(curr_ques_obj.question_key).setValue('') + let dialog = this.matDialog.open(AnswerOptionCreateDialogComponent,{ + data:{pd_all_details:this.quesService.pd_all_details}, + disableClose: true, + width: '80vw', + maxHeight: '100vh', + panelClass:'min-padding' + }) + dialog.afterClosed().subscribe(rr=>{ + if(rr.update && rr.address_for_display && rr.address_for_display.length > 0) { + // curr_ques_obj.answers.splice(curr_ques_obj.answers.length -1,0,{answer:rr.address_for_display,answer_id:rr.address_for_display}) + curr_ques_obj.answers = rr.address_for_display + + let lastAddress = curr_ques_obj.answers[curr_ques_obj.answers.length-1].answer_id && curr_ques_obj.answers[curr_ques_obj.answers.length-1].answer_id != null && curr_ques_obj.answers[curr_ques_obj.answers.length-1].is_others != -1 ? curr_ques_obj.answers[curr_ques_obj.answers.length-1].answer_id : curr_ques_obj.answers[curr_ques_obj.answers.length-2].answer_id + this.formGroupN.get(curr_ques_obj.question_key).patchValue(lastAddress) + } + else if(rr.hasOwnProperty('update') && rr.update == false){ + alert(rr.error_msg ? rr.error_msg : "Something went wrong while getting address") + } + }) + } + } + updateValidationMsg(ques_control,validation_obj){ + if(!ques_control) { + return; + } + let updateMsg=ques_control.validations.filter(val=>val.name != validation_obj.name) + updateMsg.push(validation_obj) + // ques_control.controls.validations.setValue(updateMsg); + ques_control.validations = updateMsg + return updateMsg; + } + updateAllComplete(a,b){ + console.log(a) + console.log(b.checked) + if(b.checked){ + console.log( this.whole_json) + this.formGroupN.get(a).disable() + this.parent_ques.disable =true + + this.vr = true + }else{ + console.log( this.whole_json) + this.formGroupN.get(a).enable() + this.parent_ques.disable = false + this.vr = false + console.log(this.parent_ques.disable) + + + } +} +} diff --git a/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/ques-form/ques-form.service.spec.ts b/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/ques-form/ques-form.service.spec.ts new file mode 100644 index 0000000..56b5b15 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/ques-form/ques-form.service.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing'; + +import { QuesFormService } from './ques-form.service'; + +describe('QuesFormService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: QuesFormService = TestBed.get(QuesFormService); + expect(service).toBeTruthy(); + }); +}); diff --git a/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/ques-form/ques-form.service.ts b/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/ques-form/ques-form.service.ts new file mode 100644 index 0000000..36afdf3 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/forms-dynamic/dynamic-form/ques-form/ques-form.service.ts @@ -0,0 +1,1320 @@ +import { Injectable, Testability } from '@angular/core'; +import { FormGroup, FormArray, FormBuilder, FormControl, Validators } from '@angular/forms'; +import { HttpClient, HttpParams } from '@angular/common/http'; +import { environment } from 'environments/environment'; +import { DatePipe } from '@angular/common'; + +import { BehaviorSubject } from 'rxjs'; +const apiUrl = environment.apiEndpoint + +@Injectable({ + providedIn: 'root' +}) +export class QuesFormService { + formgroup_company:FormGroup; + ques_data_company:any; + company_name:any; + length:any; + + len:any; + formanswers=null; + pd_all_details:any= {} ; + datepipe: DatePipe; + tmp: any[]; + //length: any; + constructor(private _fb:FormBuilder,private http:HttpClient) { + this.datepipe=new DatePipe('en-US') + // this.apiUrl = constantProvider.environment().url + } + // FOR CREATING A FORM CONTROL DYNAMICALLY + // companynamechanged(choosed_answer_obj,curr_ques_obj) { + // alert('new'); + // console.log('aa'); + // console.log(choosed_answer_obj); + // console.log(curr_ques_obj); + // console.log('abx'); + // console.log(choosed_answer_obj.answer) + // if(choosed_answer_obj.answer!='') + // { + // console.log(hanged'); + // this.company_name=choosed_answer_obj.answer + // } + + // } + private messageSource = new BehaviorSubject('default message'); + public currentMessageSubscriber = this.messageSource.asObservable(); + notify(message: any) { + this.messageSource.next(message) + } + + ques_length(length1: any) + { + this.len=length1; + + } + assignFormControl_array(formgroup: FormGroup, ques_data: any) { + + const control: any = formgroup + + ques_data.forEach((val, index) => { + + if (val.hasOwnProperty('is_repeatable') && val.is_repeatable == '1') { + + // control.push(this._fb.group({ + // "is_repeatable": [val.is_repeatable || null], + // "group_title": [val.group_title || null], "group_type": [val.group_type || null] + // ,"question_key":[val.question[0].question_key] + // })) + + control.addControl(val.group_key, this._fb.array([])) + + let childControl: any = control.get(val.group_key) as FormArray + + + + + // childControl.push(this._fb.group({ 'questions': this._fb.array([]) })) + + + if(this.len=='3' && val.form_name=='Key Stakeholders in Business') + { + + val.question.push({ + "question":"", + "question_key":"stakeholder_name1", + "place_holder":"Enter text", + "type":"1", + "field_width":"19", + "api_properties":null, + "answers":null, + "onchange_properties":null, + "is_repeatable":null, + "field_type":"string", + "validations":[ + { + "name":"required", + "isactive":"1", + "validator":"Validators.required", + "message":"Name Required", + "value":null + } + ] + + }, + { + "question":"", + "question_key":"share_holding1", + "place_holder":"Enter number", + "type":"1", + "field_width":"19", + "api_properties":null, + "answers":null, + "onchange_properties":null, + "is_repeatable":null, + "field_type":"num", + "validations":[ + { + "name":"required", + "isactive":"1", + "validator":"Validators.required", + "message":"Share value Required", + "value":null + }, + { + "name":"max", + "validator":"100", + "isactive":"1", + "message":"Number must be less than 100", + "value":null + } + ] + }, + { + "question":"", + "question_key":"vintage_in_current_biz1", + "place_holder":"Enter in years", + "type":"1", + "field_width":"19", + "api_properties":null, + "answers":null, + "is_repeatable":null, + "field_type":"num", + "validations":[ + { + "name":"required", + "isactive":"1", + "validator":"Validators.required", + "message":"Current vintage Required", + "value":null + } + ], + "onchange_properties":[ + { + "purpose":"FORM_CTRL", + "form_controls":[ + { + "insert_index":"started_biz1", + "expression":"(total_work_exp1 > vintage_in_current_biz1)", + "value_keys":[ + "total_work_exp1", + "vintage_in_current_biz1" + ], + "questions":[ + { + "question_key":"previous_experience_details1", + "question":"Previous Experience Details", + "place_holder":"Enter text", + "type":"1", + + "api_properties":null, + "answers":null, + "onchange_properties":null, + "is_repeatable":null, + "field_type":"string", + "parent_question_key":"vintage_in_current_biz1", + "validations":[ + { + "name":"required", + "isactive":"1", + "validator":"Validators.required", + "message":"Previous Experience Required", + "value":null + } + ] + } + ] + } + ] + } + ] + }, + { + "question":"", + "question_key":"total_work_exp1", + "place_holder":"Enter in years", + "type":"1", + "field_width":"19", + "api_properties":null, + "answers":null, + "is_repeatable":null, + "field_type":"num", + "validations":[ + { + "name":"required", + "isactive":"1", + "validator":"Validators.required", + "message":"Total experience Required", + "value":null + } + ], + "onchange_properties":[ + { + "purpose":"FORM_CTRL", + "form_controls":[ + { + "insert_index":"started_biz1", + "expression":"(total_work_exp1 > vintage_in_current_biz1)", + "value_keys":[ + "total_work_exp1", + "vintage_in_current_biz1" + ], + "questions":[ + { + "question":"Previous Experience Details", + "question_key":"previous_experience_details1", + "place_holder":"Enter text", + "type":"1", + + "api_properties":null, + "answers":null, + "onchange_properties":null, + "is_repeatable":null, + "field_type":"string", + "parent_question_key":"total_work_exp1", + "validations":[ + { + "name":"required", + "isactive":"1", + "validator":"Validators.required", + "message":"Previous Experience Required", + "value":null + } + ] + } + ] + } + ] + } + ] + }, + { + "question":"", + "question_key":"started_biz1", + "type":"2", + "field_width":"19", + "api_properties":null, + "onchange_properties":null, + "is_repeatable":null, + "answers":[ + { + "answer_id":"Yes", + "answer":"Yes" + }, + { + "answer_id":"No", + "answer":"No" + } + ], + "validations":[ + { + "name":"required", + "isactive":"1", + "validator":"Validators.required", + "message":"Started Business Required", + "value":null + } + ] + + },{ + "question":"", + "question_key":"stakeholder_name2", + "place_holder":"Enter text", + "type":"1", + "field_width":"19", + "api_properties":null, + "answers":null, + "onchange_properties":null, + "is_repeatable":null, + "field_type":"string", + "validations":[ + { + "name":"required", + "isactive":"1", + "validator":"Validators.required", + "message":"Name Required", + "value":null + } + ] + + }, + { + "question":"", + "question_key":"share_holding2", + "place_holder":"Enter number", + "type":"1", + "field_width":"19", + "api_properties":null, + "answers":null, + "onchange_properties":null, + "is_repeatable":null, + "field_type":"num", + "validations":[ + { + "name":"required", + "isactive":"1", + "validator":"Validators.required", + "message":"Share value Required", + "value":null + }, + { + "name":"max", + "validator":"100", + "isactive":"1", + "message":"Number must be less than 100", + "value":null + } + ] + }, + { + "question":"", + "question_key":"vintage_in_current_biz2", + "place_holder":"Enter in years", + "type":"1", + "field_width":"19", + "api_properties":null, + "answers":null, + "is_repeatable":null, + "field_type":"num", + "validations":[ + { + "name":"required", + "isactive":"1", + "validator":"Validators.required", + "message":"Current vintage Required", + "value":null + } + ], + "onchange_properties":[ + { + "purpose":"FORM_CTRL", + "form_controls":[ + { + "insert_index":"started_biz2", + "expression":"(total_work_exp2 > vintage_in_current_biz2)", + "value_keys":[ + "total_work_exp2", + "vintage_in_current_biz2" + ], + "questions":[ + { + "question_key":"previous_experience_details2", + "question":"Previous Experience Details", + "place_holder":"Enter text", + "type":"1", + + "api_properties":null, + "answers":null, + "onchange_properties":null, + "is_repeatable":null, + "field_type":"string", + "parent_question_key":"vintage_in_current_biz2", + "validations":[ + { + "name":"required", + "isactive":"1", + "validator":"Validators.required", + "message":"Previous Experience Required", + "value":null + } + ] + } + ] + } + ] + } + ] + }, + { + "question":"", + "question_key":"total_work_exp2", + "place_holder":"Enter in years", + "type":"1", + "field_width":"19", + "api_properties":null, + "answers":null, + "is_repeatable":null, + "field_type":"num", + "validations":[ + { + "name":"required", + "isactive":"1", + "validator":"Validators.required", + "message":"Total experience Required", + "value":null + } + ], + "onchange_properties":[ + { + "purpose":"FORM_CTRL", + "form_controls":[ + { + "insert_index":"started_biz2", + "expression":"(total_work_exp2 > vintage_in_current_biz2)", + "value_keys":[ + "total_work_exp2", + "vintage_in_current_biz2" + ], + "questions":[ + { + "question":"Previous Experience Details", + "question_key":"previous_experience_details2", + "place_holder":"Enter text", + "type":"1", + + "api_properties":null, + "answers":null, + "onchange_properties":null, + "is_repeatable":null, + "field_type":"string", + "parent_question_key":"total_work_exp2", + "validations":[ + { + "name":"required", + "isactive":"1", + "validator":"Validators.required", + "message":"Previous Experience Required", + "value":null + } + ] + } + ] + } + ] + } + ] + }, + { + "question":"", + "question_key":"started_biz2", + "type":"2", + "field_width":"19", + "api_properties":null, + "onchange_properties":null, + "is_repeatable":null, + "answers":[ + { + "answer_id":"Yes", + "answer":"Yes" + }, + { + "answer_id":"No", + "answer":"No" + } + ], + "validations":[ + { + "name":"required", + "isactive":"1", + "validator":"Validators.required", + "message":"Started Business Required", + "value":null + } + ] + + } + ) + } + else if(this.len=='2' && val.form_name=='Key Stakeholders in Business') + { + + val.question.push({ + "question":"", + "question_key":"stakeholder_name1", + "place_holder":"Enter text", + "type":"1", + "field_width":"19", + "api_properties":null, + "answers":null, + "onchange_properties":null, + "is_repeatable":null, + "field_type":"string", + "validations":[ + { + "name":"required", + "isactive":"1", + "validator":"Validators.required", + "message":"Name Required", + "value":null + } + ] + + }, + { + "question":"", + "question_key":"share_holding1", + "place_holder":"Enter number", + "type":"1", + "field_width":"19", + "api_properties":null, + "answers":null, + "onchange_properties":null, + "is_repeatable":null, + "field_type":"num", + "validations":[ + { + "name":"required", + "isactive":"1", + "validator":"Validators.required", + "message":"Share value Required", + "value":null + }, + { + "name":"max", + "validator":"100", + "isactive":"1", + "message":"Number must be less than 100", + "value":null + } + ] + }, + { + "question":"", + "question_key":"vintage_in_current_biz1", + "place_holder":"Enter in years", + "type":"1", + "field_width":"19", + "api_properties":null, + "answers":null, + "is_repeatable":null, + "field_type":"num", + "validations":[ + { + "name":"required", + "isactive":"1", + "validator":"Validators.required", + "message":"Current vintage Required", + "value":null + } + ], + "onchange_properties":[ + { + "purpose":"FORM_CTRL", + "form_controls":[ + { + "insert_index":"started_biz1", + "expression":"(total_work_exp1 > vintage_in_current_biz1)", + "value_keys":[ + "total_work_exp1", + "vintage_in_current_biz1" + ], + "questions":[ + { + "question_key":"previous_experience_details1", + "question":"Previous Experience Details", + "place_holder":"Enter text", + "type":"1", + "api_properties":null, + "answers":null, + "onchange_properties":null, + "is_repeatable":null, + "field_type":"string", + "parent_question_key":"vintage_in_current_biz1", + "validations":[ + { + "name":"required", + "isactive":"1", + "validator":"Validators.required", + "message":"Previous Experience Required", + "value":null + } + ] + } + ] + } + ] + } + ] + }, + { + "question":"", + "question_key":"total_work_exp1", + "place_holder":"Enter in years", + "type":"1", + "field_width":"19", + "api_properties":null, + "answers":null, + "is_repeatable":null, + "field_type":"num", + "validations":[ + { + "name":"required", + "isactive":"1", + "validator":"Validators.required", + "message":"Total experience Required", + "value":null + } + ], + "onchange_properties":[ + { + "purpose":"FORM_CTRL", + "form_controls":[ + { + "insert_index":"started_biz1", + "expression":"(total_work_exp1 > vintage_in_current_biz1)", + "value_keys":[ + "total_work_exp1", + "vintage_in_current_biz1" + ], + "questions":[ + { + "question":"Previous Experience Details", + "question_key":"previous_experience_details1", + "place_holder":"Enter text", + "type":"1", + "api_properties":null, + "answers":null, + "onchange_properties":null, + "is_repeatable":null, + "field_type":"string", + "parent_question_key":"total_work_exp1", + "validations":[ + { + "name":"required", + "isactive":"1", + "validator":"Validators.required", + "message":"Previous Experience Required", + "value":null + } + ] + } + ] + } + ] + } + ] + }, + { + "question":"", + "question_key":"started_biz1", + "type":"2", + "field_width":"19", + "api_properties":null, + "onchange_properties":null, + "is_repeatable":null, + "answers":[ + { + "answer_id":"Yes", + "answer":"Yes" + }, + { + "answer_id":"No", + "answer":"No" + } + ], + "validations":[ + { + "name":"required", + "isactive":"1", + "validator":"Validators.required", + "message":"Started Business Required", + "value":null + } + ] + + }) + } + + + + // let sub_childControl: any = childControl.controls[0].get('questions') as FormArray + let control_names:any={} + ques_data[index].group_questions = [] + console.log(childControl) + //ques_data[index].group_questions1 = [] + ques_data[index].group_questions.push(val.question) + + val.group_questions[0].forEach((group_indi, arr_index) => { + // CREATING A FORMARRAY AND CONTROL FOR CHILD REPEATABLE + console.log(group_indi) //mobile number + console.log(childControl) // form array + console.log(val.group_questions[0]) // all data group + console.log(val.question) // single data + if(group_indi.is_repeatable == '2') { + this.addLevelTwoControls(group_indi,childControl,val.group_questions[0],val.question,arr_index) + } + else { + group_indi.raw_validations = group_indi.validations + + control_names[group_indi.question_key] = '' + + + if (group_indi.api_properties != null) { + if(group_indi.api_properties.hasOwnProperty('purpose') && group_indi.api_properties.purpose == 'answer_options_local') { + if(group_indi.api_properties.master_name == 'pd_applicants') { + group_indi.answers = (this.convertArrayNames( group_indi.api_properties.fields,this.pd_all_details.pdapplicants_detials)) + val.question[arr_index].answers = group_indi.answers + } + } + else{ + this.apiPropertiesCall(group_indi).then(res => { + if (res != false) { + group_indi.answers = [] + // group_indi.answers=this.convertArrayNames(val.api_properties.fields,res) + group_indi.answers = (this.convertArrayNames(group_indi.api_properties.fields, res)) + val.question[arr_index].answers = group_indi.answers + + } + }) + } + } + + const question_temp:any = JSON.parse(JSON.stringify(val.question)); + ques_data[index].question = question_temp + } + // else{ + // setTimeout(()=>{ + // sub_childControl.push(this.createValue(group_indi)) + // },200) + // } + // sub_childControl.push(this.createValue(group_indi)) + }) + + // debugger + // val.questions[0]=val.question; + if(childControl.value.length == 0) { + + childControl.push(this._fb.group(control_names)) + } + else{ + // MERGINE THE 0 INDEX ARRAY WITH CHILD REPEATABLE + // control_names[childControl.at(0)] ='' + let previous_added_controls = childControl.at(0).controls + control_names = Object.assign(previous_added_controls,control_names) + + // debugger; + childControl.setControl(0,this._fb.group(control_names)) + } + + // debugger; + val.group_questions[0].forEach((group_indi,arr_index)=>{ + + if(group_indi.is_repeatable == '2' && group_indi.hasOwnProperty('questions_level_two') && group_indi.questions_level_two.length > 0) { + group_indi.questions_level_two[0].forEach((child_val,child_index)=> { + console.log( childControl.at(0).get(group_indi.group_key).controls[0]) + this.addAdditionalControl(child_val, childControl.at(0).get(group_indi.group_key).controls[0], child_index) + }) + } + else{ + this.addAdditionalControl(group_indi, childControl.controls[0], arr_index) + } + }) + + // } + // else{ + // sub_childControl.push(this.createValue(group_indi)) + // } + // setTimeout(()=>{ + + // },500) + + + // let key_list=Object.keys(val) + // console.log(Object.keys(val)) + // key_list.forEach(key=>{ + // childControl.controls + // }) + } + else { + console.log(formgroup) + // console.log("con",control) + // let key_list=Object.keys(val) + // console.log(Object.keys(val)) + // let curr_object + // console.log("apikd",typeof(val.api_properties)) + // if(val.api_properties != null && typeof(val.api_properties) == 'object'){ + val.raw_validations = val.validations + console.log(val) + // control.push(this.createValue(val)) + formgroup.addControl(val.question_key,new FormControl('')) + // for checkbox remove the form control and add the formarray for multiple values + this.addAdditionalControl(val, formgroup, index) + // if(val.type == '5'){ + // control.controls[index].removeControl('answer_value'); + // console.log("loop",index,control); + // control.controls[index].addControl('answer_value',this._fb.array([])) + // } + // if(val.type == '1'){ + // control.controls[index].addControl('field_type',new FormControl(val.field_type)) + // } + // if(val.type == '8'){ + // control.controls[index].addControl('select_search',new FormControl(val.field_type)) + // } + if (val.api_properties != null) { + if(val.api_properties.hasOwnProperty('purpose') && val.api_properties.purpose == 'answer_options_local') { + if(val.api_properties.master_name == 'pd_applicants') { + val.answers = (this.convertArrayNames( val.api_properties.fields,this.pd_all_details.pdapplicants_detials)) + } + } + else{ + this.apiPropertiesCall(val).then(res => { + + if (res != false) { + // val.answers=[] + // val.answers=this.convertArrayNames(val.api_properties.fields,res) + val.answers = this.convertArrayNames(val.api_properties.fields, res) + + } + }, err => console.log(err)) + } + } + // else{ + // setTimeout(()=>{ + // control.push(this.createValue(val)) + // },200) + // } + + // } + // else{ + // control.push(this.createValue(val)) + // } + console.log(formgroup,ques_data) + // debugger; + + } + }, err => console.log(err)) + return formgroup + } + // END OF FORM CREATION + + // FUNCTIONAL TO HANDLE THE CREATION OF CHILD REPEABLE 2 + addLevelTwoControls(curr_obj:any,child_control,group_ques,valQues,group_index) { + console.log(group_ques) + console.log(valQues) + console.log(curr_obj.questions_level_two) + // CURR VALUE(MULTI ARRAY) + const question_temp:any = JSON.parse(JSON.stringify(curr_obj.questions_level_two)); + group_ques[group_index].questions_level_two = [] + group_ques[group_index].questions_level_two.push(question_temp) + group_ques[group_index].question = question_temp + + // RAW VALUES(SINGLE ARRAY) + valQues[group_index].question = question_temp + valQues[group_index].questions_level_two = [] + console.log( valQues[group_index].questions_level_two) + valQues[group_index].questions_level_two.push(question_temp) + console.log( valQues[group_index].questions_level_two) + // debugger; + let group_key:any = {} + group_key[curr_obj.group_key] = this._fb.array([]) + child_control.push(this._fb.group(group_key)) + + // debugger; + let levelTwoChildCtrl: any = child_control.at(0).get(curr_obj.group_key) as FormArray + let control_names:any={} + curr_obj.questions_level_two[0].forEach((val,arr_index)=>{ + + val.raw_validations = val.validations + control_names[val.question_key] = '' + + if (val.api_properties != null) { + if(val.api_properties.hasOwnProperty('purpose') && val.api_properties.purpose == 'answer_options_local') { + if(val.api_properties.master_name == 'pd_applicants') { + val.answers = (this.convertArrayNames( val.api_properties.fields,this.pd_all_details.pdapplicants_detials)) + // val.question[arr_index].answers = val.answers + } + } + else{ + this.apiPropertiesCall(val).then(res => { + if (res != false) { + val.answers = [] + // group_indi.answers=this.convertArrayNames(val.api_properties.fields,res) + val.answers = (this.convertArrayNames(val.api_properties.fields, res)) + // val.question[arr_index].answers = val.answers + + } + }) + } + } + + }) + + + levelTwoChildCtrl.push(this._fb.group(control_names)) + // console.log(formgroup.value); + } + addLevelTwoControls2(curr_obj:any,child_control,group_ques,valQues,group_index) { + console.log(group_ques) + console.log(valQues) + console.log(curr_obj.questions_level_two) + + + + // CURR VALUE(MULTI ARRAY) + const question_temp:any = JSON.parse(JSON.stringify(curr_obj.questions_level_two)); + + group_ques[group_index].questions_level_two = [] + group_ques[group_index].questions_level_two.push(question_temp) + group_ques[group_index].question = question_temp + + // RAW VALUES(SINGLE ARRAY) + valQues[group_index].question = question_temp + valQues[group_index].questions_level_two = [] + + valQues[group_index].questions_level_two.push(question_temp) + console.log(curr_obj.questions_level_two) + + //debugger; + // let group_key:any = {} + // group_key[curr_obj.group_key] = this._fb.array([]) + // child_control.push(this._fb.group(group_key)) + + // debugger; + //let levelTwoChildCtrl: any = child_control.at(0).get(curr_obj.group_key) as FormArray + console.log(this.tmp) + let control_names:any={} + curr_obj.questions_level_two[0].forEach((val,arr_index)=>{ + + // val.raw_validations = val.validations + // control_names[val.question_key] = '' + + if (val.api_properties != null) { + if(val.api_properties.hasOwnProperty('purpose') && val.api_properties.purpose == 'answer_options_local') { + if(val.api_properties.master_name == 'pd_applicants') { + val.answers = (this.convertArrayNames( val.api_properties.fields,this.pd_all_details.pdapplicants_detials)) + // val.question[arr_index].answers = val.answers + } + } + else{ + this.apiPropertiesCall(val).then(res => { + if (res != false) { + val.answers = [] + // group_indi.answers=this.convertArrayNames(val.api_properties.fields,res) + val.answers = (this.convertArrayNames(val.api_properties.fields, res)) + // val.question[arr_index].answers = val.answers + + } + }) + } + } + + }) + + + //levelTwoChildCtrl.push(this._fb.group(control_names)) + // console.log(formgroup.value); + } + // FOR CREATING THE FORM CONTROL FOR SPECIFIC FORM ARRAY + createValue(data){ + let is_amt_in_words=false + let answer_value_loc=''; + let answers_from_client=[] + // if(data.hasOwnProperty('answer_value') && data.answer_value != '' || null){ + // let values_for_cli:any = this.getAnswerValue(data) + // if(values_for_cli.flag == 1){ + // answer_value_loc=values_for_cli.values + // } + // else{ + // answers_from_client=values_for_cli.values + // } + // } + // if(data.hasOwnProperty('field_type')){ + // if(data.field_type == 'num'){ + // is_amt_in_words=true + // } + // } + return this._fb.group({ + "answer_value":[{value:answer_value_loc,disabled:answer_value_loc != '' ? true : false}], // OLD VALIDATION >>>> data.type != '6' ? Validators.compose([Validators.required]) : '' + "question":[data.question], + "question_key":[data.question_key], + "type":[data.type], + "raw_validations":[data.raw_validations], + "validations":[data.raw_validations], + "api_properties":[data.api_properties], + "onchange_properties":[data.onchange_properties], + "answers":[answers_from_client.length != 0 ? answers_from_client: data.answers], + "is_repeatable":[data.is_repeatable || null], + "group_title":[data.group_title || null] + }) + } + // END OF CREATEVALUE FUN + + // FOR REQUESTING THE API AUTOMATICALLY FROM JSON + apiPropertiesCall(val){ + return new Promise((resolve,reject)=>{ + if(val.api_properties != null && typeof(val.api_properties) == 'object'){ + this.apiCall(val.api_properties.api,val.api_properties.params,val.api_properties.api_method).subscribe((res:any)=>{ + if(res['dataStatus']){ + if(res.hasOwnProperty('records')){ + res=res['records'] + // res.push({display:"Add New", id:"00",is_others:"-1"}) + } + if(val.api_properties.hasOwnProperty('filter_properties') && val.api_properties.filter_properties && res.length > 0) { + let filter_properties = val.api_properties.filter_properties + res = res.filter(vv=>vv[filter_properties.key_name] == filter_properties.value) + } + resolve(res) + + // val.answers=res + } + else{ + resolve(false) + } + }) + } + else{ + resolve(false) + } + }) + } + apiCall(api_name:string,params,api_method?){ + + if(api_method.toUpperCase() == 'POST'){ + //let param = params; + let temp=params; + if(temp.hasOwnProperty("records")) { + temp=temp.records + + } + let keysList = Object.keys(temp) + if(keysList.length > 0) { + keysList.forEach(val=>{ + if(temp[val] == 'VAR_PD_ID') { + console.log(this.pd_all_details.pdmaster_details.pd_id) + temp[val] = this.pd_all_details.pdmaster_details.pd_id + } + if(temp[val]=='VAR_RANDOM_STRING') + { + temp[val] = this.pd_all_details.pdmaster_details.random_string + } + + //param = param.set(val,params[val]) + }) + // console.log('13may'); + // console.log(temp); + // console.log('13may'); + if(params.hasOwnProperty("records")) + { + params.records=temp + } + else + { + params=temp; + } + } + + return this.http.post(apiUrl+api_name,params) + + } + else{ + let httpParams = new HttpParams() + if(params) { + let keysList = Object.keys(params) + if(keysList.length > 0) { + keysList.forEach(val=>{ + if(params[val] == 'VAR_PD_ID') { + params[val] = this.pd_all_details.pdmaster_details.pd_id + } + + httpParams = httpParams.set(val,params[val]) + }) + } + } + return this.http.get(apiUrl+api_name,{params:httpParams}) + } + + } + // END OF API PROPERTIES CALL + + // ---FOR CONVERTING THE ANSWER KEYS UNIQUE + convertArrayNames(fieldName,data_from_api){ + let val1=[] + let modified_json = data_from_api.map( + obj => { + return { + "answer_id" : obj[fieldName[0]], + "answer":obj[fieldName[1]], + "is_others":obj.is_others ? obj.is_others : '0' + } + }); + return modified_json + } + // END OF CONVERTARRAYNAMES FUN-- + + setAnswerOptionsorValue(data_json,control) { + + let answer_value_loc=''; + let answers_from_client=[] + if(data_json.hasOwnProperty('answer_value') && data_json.answer_value != '' || null){ + + let values_for_cli:any = this.getAnswerValue(data_json) + if(values_for_cli.flag == 1){ + answer_value_loc=values_for_cli.values + } + else{ + answers_from_client=values_for_cli.values + } + data_json.answers = answers_from_client; + if(answer_value_loc){ + control.setValue(answer_value_loc) + } + } + } + + // --- FOR SETTING THE VALUE DEFAULT WITH DISABLED AND GENERATE THE ANSWERS FOR FIELDS(EX. refer 'GET_FY_YEARS' switch) + getAnswerValue(value_obj) { + if (value_obj != null && value_obj.hasOwnProperty('answer_value')) { + let return_value = { flag: 1, values: '' }; + let user_det: any = localStorage.getItem("user_details") + user_det = JSON.parse(user_det); + switch (value_obj.answer_value) { + case 'CURRENT_USER': + + return_value.values = user_det.user_first_name + ' ' + user_det.user_last_name + break; + case "CURRENT_DESIGNATION": + return_value.values = user_det.designation_name != null ? user_det.designation_name : '' + break; + case "CURRENT_DATE": + let date = new Date() + return_value.values = this.datepipe.transform(date, 'dd-MM-yyyy, h:mm:ss a') + break; + case "GET_FY_YEARS": + return_value.values = this.getCurrentFyYears() + return_value.flag = 2 + break; + default: + return_value.values = '' + break + } + return return_value + } + return '' + } + // --END OF GETANSWERVALUE FUN + + addAdditionalControl(data,curr_control,curr_index,purpose?){ + + //FOR CHECKBOX CHANGE THE VALUE STORAGE AS ARRAY + if(data.type == '5'){ + // curr_control.controls[curr_index].removeControl('answer_value'); + // curr_control.controls[curr_index].addControl('answer_value',this._fb.array([])) + curr_control.removeControl(data.question_key) + curr_control.addControl(data.question_key,this._fb.array([])) + } + + //FOR numeric of string field + if(data.type == '1'){ + // curr_control.controls[curr_index].addControl('field_type',new FormControl(data.field_type)) + // curr_control.controls[curr_index].addControl('place_holder',new FormControl(data.place_holder)) + } + + //FOR SEARCHABLE FIELD VALUE KEY () + if(data.type == '8'){ + // curr_control.controls[curr_index].addControl('select_search',new FormControl(data.field_type)) + curr_control.addControl(data.question_key+'_searchControl',new FormControl(data.field_type)) + } + if(purpose == 'additional_field'){ + curr_control.controls[curr_index].addControl('additional_field',new FormControl(1)) + } + + // FOR IMAGE STATUS + if(data.type == '6'){ + curr_control.controls[curr_index].addControl('is_loader',new FormControl('')) + curr_control.controls[curr_index].addControl('is_saved',new FormControl('')) + curr_control.controls[curr_index].addControl('is_image_status',new FormControl(false)) + } + if (data.api_properties != null) { + if(data.api_properties.hasOwnProperty('purpose') && data.api_properties.purpose == 'answer_options_local') { + if(data.api_properties.master_name == 'pd_applicants') { + data.answers = (this.convertArrayNames( data.api_properties.fields,this.pd_all_details.pdapplicants_detials)) + // val.question[arr_index].answers = group_indi.answers + } + } + else{ + this.apiPropertiesCall(data).then(res => { + if (res != false) { + data.answers = [] + // group_indi.answers=this.convertArrayNames(val.api_properties.fields,res) + data.answers = (this.convertArrayNames(data.api_properties.fields, res)) + // val.question[arr_index].answers = group_indi.answers + + } + }) + } + } + + // FOR DISABLE THE CONTROL + if(data.hasOwnProperty('is_disabled') && data.is_disabled == '1') { + curr_control.controls[data.question_key].disable(); + } + + //FOR SETTING THE VALIDATORS + this.settingArrayofValidators(data,curr_control,curr_index) + this.setAnswerOptionsorValue(data,curr_control) + } + + // FOR SETTING THE ARRAY OF VALIDATORS COMING FROM JSON Temp, + settingArrayofValidators(data,curr_control,curr_index){ + + if(data.hasOwnProperty('validations') && data.validations.length > 0 ){ + const validList :any= []; + let validator_value + data.validations=data.validations.filter(val=>val.isactive != '0') + data.validations.forEach(valid => { + if(valid.value != null && !valid.hasOwnProperty('validation_to')){ + validator_value= this.getvalidatorValue(valid) + } + else{ + validator_value=this.setValueForValidator(valid) + + + } + validList.push(validator_value); + }); + // console.log("valid",validList,curr_control) + // let val="Validators.required" + // console.log(typeof(Validators)) + // console.log(typeof(`${val}`)) + + // let val1=`${val}` + // console.log(typeof(eval(val))) + // console.log(eval(val)) + + // curr_control.controls[curr_index].controls.answer_value.setValidators(validList) + if(curr_control.controls[data.question_key]) { + curr_control.controls[data.question_key].setValidators(validList) + + curr_control.controls[data.question_key].updateValueAndValidity() + } + + // debugger; + } + } + // END OF SETTINGARRAYOFVALIDATORS FUN + + // FOR GETTING THE VALIDATION VALUE + getvalidatorValue(value_obj){ + if(value_obj != null && value_obj.hasOwnProperty('value')){ + let value_of_validator + switch(value_obj.value){ + case 'CURRENT_YEAR': + value_of_validator=new Date().getFullYear() + break; + default: + value_of_validator='' + break; + } + value_obj.validator=String(value_of_validator) + return this.setValueForValidator(value_obj) + } + } + // END OF GETVALIDATORVALUE FUN + + + // FOR GENERATING THE FY YEAR FIELD ANSWERS + getCurrentFyYears(){ + let month=new Date().getMonth() + let year=new Date().getFullYear() + let fy:any=[]; + if(month >=3){ + fy.push({fy_year:year-1+'-'+(year),curr:year}) + } + else{ + fy.push({fy_year:year-2+'-'+(year-1),curr:year-1}) + } + + for(let i=0;i<=2;i++){ + fy.push({fy_year:(fy[i].curr-2)+'-'+(fy[i].curr-1),curr:fy[i].curr-1}) + } + fy.reverse(); + return fy.map(val=>({answer:val.fy_year,answer_id:val.fy_year})) + } + // END OF GETCURRFYYEARS FUN + + // FOR CREATING THE CORRECT VALIDATION + setValueForValidator(value_obj){ + + let return_value + if(value_obj != null && value_obj.hasOwnProperty('validator')){ + switch(value_obj.name) + { + case 'required': + return_value=Validators.required + break; + case 'minLength': + return_value=Validators.minLength(value_obj.validator) + break; + case 'maxLength': + return_value=Validators.maxLength(value_obj.validator) + break; + case 'min': + return_value=Validators.min(value_obj.validator) + break; + case 'max': + return_value=Validators.max(value_obj.validator) + break; + case 'pattern': + return_value=Validators.pattern(value_obj.validator) + break; + default: + return_value='' + break; + } + return return_value + } + else{ + return false + } + } + // END OF SETVALUEFORVALIDATOR FUN +} diff --git a/ng6-seed/src/app/fly-hi/forms-dynamic/form/form.component.html b/ng6-seed/src/app/fly-hi/forms-dynamic/form/form.component.html new file mode 100644 index 0000000..a572feb --- /dev/null +++ b/ng6-seed/src/app/fly-hi/forms-dynamic/form/form.component.html @@ -0,0 +1,59 @@ +

+
+ + {{questions_JSON.section_name}} +
+
+ +
+

+ + +
No Templates Found
+
Loading...
+ + + + + + + +
+ + + +
+ +
+
+ +
+
+ \ No newline at end of file diff --git a/ng6-seed/src/app/fly-hi/forms-dynamic/form/form.component.scss b/ng6-seed/src/app/fly-hi/forms-dynamic/form/form.component.scss new file mode 100644 index 0000000..2f902f1 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/forms-dynamic/form/form.component.scss @@ -0,0 +1,43 @@ +.float{ + float: right; +} +.paragraph_change { + color: #fff !important; + background-color: #e00201 !important; + } + ::ng-deep { .no-padding > mat-dialog-container { + // background: black; + padding: 0; + overflow-y: scroll !important; + } +} + +::ng-deep .mat-dialog-content { + margin: inherit !important; + +} +.mat-dialog-content{ + // margin:0px !important; + margin: inherit !important; +} + // mat-placeholder{ + // margin-top: 20px; + // word-wrap: break-word; + // } +// input{ +// height:40px; +// } + + .mat-form-field-label { + white-space: normal; + } + + textarea.mat-input-element { + padding: 0px 0; + margin: 5px 0; + } + + .mat-input-placeholder { + white-space: normal; + } + \ No newline at end of file diff --git a/ng6-seed/src/app/fly-hi/forms-dynamic/form/form.component.spec.ts b/ng6-seed/src/app/fly-hi/forms-dynamic/form/form.component.spec.ts new file mode 100644 index 0000000..0ace80a --- /dev/null +++ b/ng6-seed/src/app/fly-hi/forms-dynamic/form/form.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { FormComponent } from './form.component'; + +describe('FormComponent', () => { + let component: FormComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ FormComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(FormComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/ng6-seed/src/app/fly-hi/forms-dynamic/form/form.component.ts b/ng6-seed/src/app/fly-hi/forms-dynamic/form/form.component.ts new file mode 100644 index 0000000..dc622df --- /dev/null +++ b/ng6-seed/src/app/fly-hi/forms-dynamic/form/form.component.ts @@ -0,0 +1,638 @@ +import { Component, Inject, OnInit, ViewChild, Input } from '@angular/core'; +import { MatDialogRef, MatDialog, MAT_DIALOG_DATA } from '@angular/material'; +import { ActivatedRoute, Router } from '@angular/router'; +import { AwsService } from 'app/AwsService/aws.service'; +import { PdTrigerService } from 'app/personal-discussion/pd-service/pd-triger.service'; +import { LoaderService } from 'app/shared/loaderService/loader.service'; +import { environment } from 'environments/environment'; +// import { environment } from 'environments/environment'; +import { DynamicFormComponent } from '../dynamic-form/dynamic-form/dynamic-form.component'; +import { QuesFormService } from '../dynamic-form/ques-form/ques-form.service'; +import { FlyhiService } from 'app/fly-hi/services/flyhi.service'; +import { FormGroup, FormBuilder } from '@angular/forms'; +import { NotifierService } from 'angular-notifier'; + +@Component({ + selector: 'app-form', + templateUrl: './form.component.html', + styleUrls: ['./form.component.scss'], +}) +export class FormComponent implements OnInit { + anslength:any; + form_id: number; + parent_pdid: any; + pdid: any; + private notifier: NotifierService; + main_applicant: any; + lender_applicant_id: any; + subproduct_abbr: any; + customer_segment_abbr: any; + lenderShortName: any; + fk_pd_type: any; + image_doc_params: { pdid: any; form_id: any; company_id: string; }; + questions_JSON: any = {questions:[],section_name:''}; + commonFormGroup:FormGroup; + + @Input() json_answers:any; + @ViewChild(DynamicFormComponent) formComponent:DynamicFormComponent + is_loading: boolean = false; + pd_all_details: any=[]; + pdMasterList:any=[]; + template_id: any; + sales_pd_id: any; + completeStatus: any; + role_id: string; + constructor(notifier: NotifierService, + private fb: FormBuilder, + private route: ActivatedRoute, + private router: Router, + private _pd: PdTrigerService, + private questionService:QuesFormService, + private dialogRef: MatDialogRef, + private dialog: MatDialog, public quesService:QuesFormService, + @Inject(MAT_DIALOG_DATA) public jsonData: any,private _flyhi:FlyhiService, + private awsService:AwsService,private loaderService:LoaderService) { + this.role_id = localStorage.getItem('LenderRoleID') + console.log(jsonData) + this.questions_JSON = this.jsonData.Json['sections'][0]; + // this.questions_JSON = this.jsonData.Json['sections'][0]; + this.notifier = notifier; + } + + ngOnInit() { + this.loadTemplate() + // this.getSectionData() + let key_value = localStorage.getItem('sales_pd_id_PRIMARYKEY') + + let resultData=null; + // let key_value='43'; + this.sales_pd_id = key_value + console.log('key value',key_value,this.sales_pd_id); + + if(key_value != null){ + this.loaderService.showMatSpinnerDialog('Please wait') + console.log('key value',key_value,this.sales_pd_id); + this._flyhi.getPDSectionData(this.sales_pd_id,this.questions_JSON.section_id,'').subscribe(result=>{ + + if(result['dataStatus']) { + + + let records = result['records'][0].section_data + console.log(JSON.parse(records)) + let values = JSON.parse(records) + console.log(values) + + + let formValues:any ={}; + // console.log(records.hasOwnProperty('json')) + // if(records && records.hasOwnProperty('json') && records.json) { + formValues = values.json + console.log(formValues) + + this.quesService.formanswers= formValues + this.loaderService.closeMatSpinnerDialog() + // if(formValues.key_stakeholders[0].stakeholder_length=='2') + // { + // let controlcount='2'; + // this.quesService.ques_length(controlcount) + // this.loadTemplate() + // } + // else + // { + // let controlcount1='3'; + // this.quesService.ques_length(controlcount1) + // this.loadTemplate() + // } + // if(formValues.key_stakeholders[0].stakeholder_length=="undefined") + // { + + // } + // } + } + // else + // { + + // let params = {"pd_id":this.pdMasterList.pd_id,"random_string":this.pdMasterList.random_string,"form_id":this.pd_all_details.form_id} + // this._flyhi.loadDataFromExcel(params).subscribe(result=>{ + // if(result['dataStatus']) { + // let records = result['records'] + // let formValues1:any ={}; + // if(records ) { + // formValues1 = records + // if(formValues1.key_stakeholders[0].stakeholder_length=='2') + // { + // let controlcount='2'; + // this.quesService.ques_length(controlcount) + // this.loadTemplate() + // } + // else + // { + // let controlcount1='3'; + // this.quesService.ques_length(controlcount1) + // this.loadTemplate() + // } + // } + // } + // }) + // } + }) + } + else{ + this.loaderService.closeMatSpinnerDialog() + } + + // if(this.pd_all_details.form_id=='5' && this.pdMasterList.product_abbr=='LFMP') +// { + + + +// let params = {"fk_pd_id":this.pdMasterList.pd_id,"fk_form_id":this.pd_all_details.form_id} + +// this._flyhi.getPDSectionData(params,params,params).subscribe(result=>{ + +// if(result['dataStatus']) { + + +// let records = result['records'] +// let formValues:any ={}; + +// if(records && records.hasOwnProperty('json') && records.json) { +// formValues = JSON.parse(records.json) +// if(formValues.key_stakeholders[0].stakeholder_length=='2') +// { +// let controlcount='2'; +// this.quesService.ques_length(controlcount) +// this.loadTemplate() +// } +// else +// { +// let controlcount1='3'; +// this.quesService.ques_length(controlcount1) +// this.loadTemplate() +// } +// // if(formValues.key_stakeholders[0].stakeholder_length=="undefined") +// // { + +// // } +// } +// } +// // else +// // { + +// // let params = {"pd_id":this.pdMasterList.pd_id,"random_string":this.pdMasterList.random_string,"form_id":this.pd_all_details.form_id} +// // this._flyhi.loadDataFromExcel(params).subscribe(result=>{ +// // if(result['dataStatus']) { +// // let records = result['records'] +// // let formValues1:any ={}; +// // if(records ) { +// // formValues1 = records +// // if(formValues1.key_stakeholders[0].stakeholder_length=='2') +// // { +// // let controlcount='2'; +// // this.quesService.ques_length(controlcount) +// // this.loadTemplate() +// // } +// // else +// // { +// // let controlcount1='3'; +// // this.quesService.ques_length(controlcount1) +// // this.loadTemplate() +// // } +// // } +// // } +// // }) +// // } +// }) + +// if(this.pd_all_details.is_answered == '1') { +// this.getSectionData() +// } +// else{ +// this.getExcelData(); +// } + + +// } +// else +// { + +// this.loadTemplate() +// if(this.pd_all_details.is_answered == '1') { +// this.getSectionData() +// } +// else{ +// this.getExcelData(); +// } +// } + } + loadTemplate() { + this.commonFormGroup = new FormGroup({}) + + this.questions_JSON = this.jsonData.Json['sections'][0]; + console.log(this.questions_JSON) + + } + getSectionData() { + // let params = {"fk_pd_id":this.pdMasterList.pd_id,"fk_form_id":this.pd_all_details.form_id} + // let params = { "pd_id":this.pdMasterList.pd_id,"pd_form_id":this.jsonData.FormData.form_id} + + // console.log(params) + console.log(this.jsonData) + let form_group = this.jsonData.FormData.is_group_form + //let params :any = {"pdid":this.pdMasterList.pd_id,"parent_pdid":this.pdMasterList.pd_id,formid:this.jsonData.FormData.form_id,"json":this.commonFormGroup.getRawValue(),fk_createdby:''} + this._flyhi.getPDSectionData(this.pdMasterList,this.jsonData.FormData.form_id,form_group).subscribe(result=>{ + console.log(result) + if(result['dataStatus']) { + let records = result['records'] + let formValues:any ={}; + if(records && records.hasOwnProperty('json') && records.json) { + + //formValues = JSON.parse(records.json) + formValues = records.json + + this.quesService.formanswers= formValues + this.loaderService.showMatSpinnerDialog("") + // setTimeout(()=>{ + // this.quesService.formanswers = null + // },2000) + // this.commonFormGroup.patchValue(formValues) + } + } + if(this.pdMasterList.re_uploaded == '1' && this.pd_all_details.is_reupload_data_fetched != '1') { + // console.log("Reuploaded excel") + // let data = {"permanant_employees_person_met":"1","temporary_employees_person_met":"2","permanant_employees_cm":"3","temporary_employees_cm":"45","permanant_employees_salary":"55","temporary_employees_salary":"55","common_remarks":"dummy datas"} + // setTimeout(()=>{ + // this.commonFormGroup.patchValue(data) + // },1000) + this.getExcelData(1) + } + }) + } + getExcelData(re_uploaded?) { + // let params = {"pd_id":this.pdMasterList.pd_id,"random_string":this.pdMasterList.random_string,"form_id":this.pd_all_details.form_id} + // this._flyhi.loadDataFromExcel(params).subscribe(result=>{ + // if(result['dataStatus']) { + // let records = result['records'] + // let formValues:any ={}; + // if(records ) { + // formValues = records + + + // // records.forEach(val=>{ + // // if(val) { + // // formValues[val.key_name] = val.value + // // } + // // }) + // // console.log(formValues) + // // debugger; + // if(re_uploaded && re_uploaded == '1') { + // this.commonFormGroup.patchValue(formValues) + // } + // else { + // this.loaderService.showMatSpinnerDialog("") + // this.quesService.formanswers= formValues + // // setTimeout(()=>{ + // // this.quesService.formanswers = null + // // },2500) + // } + // // this.commonFormGroup.patchValue(formValues) + // } + // } + // }) + } + getLocalFormId() { + // console.log(this.pd_all_details) + switch(this.pd_all_details.form_id) { + case '5': + return 2 + break + case '18': + return 1 + break; + case '10': + return 3 + break; + } + + } + private markFormGroupTouched(formGroup: FormGroup) { + (Object).values(formGroup.controls).forEach(control => { + control.markAsTouched(); + + if (control.controls) { + this.markFormGroupTouched(control); + } + }); + } + public findInvalidControls() { + const invalid = []; + let msg='' + // let formArray:any = this.commonFormGroup ; + // console.log(formArray); + // for( const group in (this.commonFormGroup.controls)) { + // if(group.invalid) { + // console.log(group,group.value.form_name,this.commonFormGroup.controls); + // debugger; + // msg= group.value.form_name+" are not complete" + // let index = this.stepperInfo.findIndex(vv=>vv.form_id == group.value.form_id); + // console.log("Index",index); + // if(index != -1) { + // msg = this.stepperInfo[index].form_name+" are not complete" + // this.myStepper.selectedIndex = this.stepperInfo[index].stepper_index + // } + for (const name in (this.commonFormGroup.controls)) { + // console.log(this.commonFormGroup.controls[name],name) + if (this.commonFormGroup.controls[name].invalid) { + invalid.push(name); + let invalidFields = [].slice.call(document.getElementsByClassName('ng-invalid')); + let firstInvalidField; + for(let val in invalidFields){ + if( invalidFields[val].nodeName == 'MAT-FORM-FIELD' || invalidFields[val].nodeName == 'MAT-SELECT' || invalidFields[val].nodeName == 'TEXTAREA' || invalidFields[val].nodeName == 'MAT-RADIO-GROUP' ){ //INPUT FOR INPUT FIELD + firstInvalidField=invalidFields[val] + + break; + } + } + + if(firstInvalidField != undefined){ + // firstInvalidField.scrollIntoView({behavior: "smooth", block: "end", inline: "nearest"}) + this.formComponent.openMatExpansionPanel() + + setTimeout(()=>{ + firstInvalidField.scrollIntoView({block: "start", inline: "nearest"}) + setTimeout(()=>{ + firstInvalidField.focus() + },0) + // firstInvalidField.style.background = 'red' + firstInvalidField.classList.remove('field_highlight') + setTimeout(()=>{ + firstInvalidField.classList.add('field_highlight') + },300) + },300) + // this.myStepper.selectedIndex = 0; + + } + else { + // msg = this.stepperInfo[index].form_name+" images are not taken" + } + + // console.log("kkdd",group['controls'][name],firstInvalidField) + + // if(typeof(group['controls'][name].value) == 'string') { + // return name+' field is not ' + // } + break + } + } + + // } + // } + // let business_group_ctrl = formArray.at(2).get('business_group') as FormArray + // const controls = this.getQuestionControl().at(1)['controls'] + // for (const name in controls) { + // if (controls[name].invalid) { + // invalid.push(name); + // } + // } + return invalid; + } + saveForm(flag) { + + console.log(this.commonFormGroup.getRawValue()) + let jsonParamData = this.commonFormGroup.getRawValue() + + + this.completeStatus = flag + console.log(this.jsonData) + //console.log("values",this.commonFormGroup.getRawValue(),this.questions_JSON) + if(this.commonFormGroup.invalid) { + this.commonFormGroup.markAsDirty(); + this.commonFormGroup.markAsTouched() + this.markFormGroupTouched(this.commonFormGroup) + let invalidfield = this.findInvalidControls() + console.log("Invalid field",invalidfield) + this.notifier.notify("info","Please fill all the required fields"); + this.formComponent.openAllPanels() + return + } + let checkProperty=this.onSubmitProperty() + console.log("check rp",checkProperty) + if(checkProperty == false){ + return; + } + this.loaderService.showMatSpinnerDialog('') + // "pdid":"2888","parent_pdid":"2888","formid":"5","fk_createdby":"165" + // let params:any ; + console.log(this.jsonData) + + + // if(this.jsonData.hasOwnProperty("Form_parent")){ + // console.log(this.jsonData) + // let form_group = this.jsonData.Form_parent.is_group_form + // let company_id = this.jsonData.Form_parent.is_business_form + // if(company_id == 1){ + // params = {"pdid":this.pdMasterList.pd_id,"parent_pdid":this.pdMasterList.pd_id,formid:this.jsonData.FormData.form_id,"json":this.commonFormGroup.getRawValue(),fk_createdby:'',"company_id":company_id,"template_id": this.template_id} + // } + + // }else{ + // params = {"pdid":this.pdMasterList.pd_id,"parent_pdid":this.pdMasterList.pd_id,formid:this.jsonData.FormData.form_id,"json":this.commonFormGroup.getRawValue(),fk_createdby:'',"template_id": this.template_id} + + // } + + // if(this.pdMasterList.re_uploaded == '1') { + // params.is_reupload_data_fetched = '1' + // } + // console.log(params) + this._flyhi.get_Pd_Id(jsonParamData).subscribe(result=>{ + console.log(result) + if(result['dataStatus']) { + console.log(result) + this.sales_pd_id = result['records'] + if(result['records'] != true && typeof(result['records']) != 'object'){ + console.log('1710') + this.sales_pd_id = result['records'] + localStorage.setItem('sales_pd_id_PRIMARYKEY',String(result['records'])) + // this.SalesPdService.insertData_Replace('sales_pd_id_PRIMARYKEY',String(apiresult['records'])).then(local_result=>{ + localStorage.setItem('sales_rand_string',String(result['rand_string'])) + // this.SalesPdService.insertData_Replace('sales_rand_string',String(apiresult['rand_string'])).then(()=>{ + // console.log(this.submit_btn) + this.sendSectionData(this.jsonData,this.completeStatus) + // if(!this.submit_btn){ + // console.log('1718') + // this.sendSectiontoApi(section_data) + }else{ + this.sendSectionData(this.jsonData,this.completeStatus) + } + + + // this.notifier.notify("success","Saved successfully..") + // setTimeout(()=>{ + // this.dialogRef.close('refresh') + // },1500) + } + // else { + // this.notifier.notify("warning","Something went wrong"); + // } + // this.loaderService.closeMatSpinnerDialog() + },err=>{ + // this.loaderService.closeMatSpinnerDialog() + // this.notifier.notify("warning","Network Error"); + }) + + } + sendSectionData(JSONData,completeStatus){ + console.log(JSONData) + let userid:any=localStorage.getItem("user_details") + userid=JSON.parse(userid).userid; + console.log(userid) + let key_value = localStorage.getItem('sales_pd_id_PRIMARYKEY') + let orderid + if(this.questions_JSON.section_id == 1){ + orderid = 1 + }else{ + orderid = 2 + } + + let params:any + params = {"fk_createdby":userid,"order_id":orderid,"is_complete":completeStatus,'onsubmit': null,"json":this.commonFormGroup.getRawValue(),"sales_pd_id":key_value,"section_id":this.questions_JSON.section_id,"section_name":this.questions_JSON.section_name} + console.log(params) + this._flyhi.saveForm(params).subscribe(result=>{ + if(result['dataStatus']) { + this.loaderService.closeMatSpinnerDialog() + // this.notifier.notify("success","Saved Successfully"); + setTimeout(()=>{ + this.dialogRef.close('refresh') + },1500) + } + else { + this.notifier.notify("warning","Something went wrong"); + } + this.loaderService.closeMatSpinnerDialog() + },err=>{ + this.loaderService.closeMatSpinnerDialog() + this.notifier.notify("warning","Network Error"); + }) + } + onSubmitProperty(){ + let return_val=[] + let send_val:boolean=true + // this.local_ques_JSON.onsubmit=[ + // { + // "expression": "(function () {let sum_val=null;let ques_key=[];control.questions_group.forEach(ques_obj=>{ques_obj.questions.map(ques=>{if(ques.question_key == submitProperty.key_name){ques_key.push(ques)}})});if(ques_key.length >=3){return true}else{return false}return sum_val}())", + // "key_name": "approach_to_pd_location", + // "msg": "Minimum 3 image required in approach" + // }, + // { + // "expression": "(function () {let sum_val=null;let ques_key=[];if(control.question_key == submitProperty.key_name && control.answer_value == ''){return false}else{return true}return sum_val}())", + // "key_name": "selfie_with_person_met", + // "msg": "Selfie Person met pic is required" + // } + // { + // "expression": "(function () {let sum_val=null;let ques_key=[];if(control.question_key == submitProperty.key_name){return control.answer_value.length >= 100}}())", + // "key_name": "brief_business_service", + // "msg": "Please enter more details" + // } + // ] + // console.log(this.local_ques_JSON); + if(this.questions_JSON.hasOwnProperty('onsubmit') && this.questions_JSON.onsubmit != null){ + for(let i=0; i{ + // let parent_ques + // for( parent_ques of this.commonFormGroup.getRawValue()){ + // this.local_ques_JSON.onsubmit.forEach(submitProperty=>{ + + let submitProperty=this.questions_JSON.onsubmit[i] + + + if((submitProperty.hasOwnProperty('group_key') && submitProperty.group_key)){ + + + return_val.length = 0 + let val=this.calculation(this.commonFormGroup.getRawValue()[submitProperty.group_key],submitProperty) + + if(val != true && val != 100){ + this.notifier.notify("info",submitProperty.msg) + return_val.push(false) ; + break; + } + else { + return_val.push(true) ; + } + } + else{ + send_val =true + } + // }) + // }) + // } + // console.log(return_val.filter(val=>val == false).length > 0) + if(return_val.filter(val=>val == false).length > 0){ + break; + } + } + console.log(return_val) + if(return_val.length > 0){ + if(return_val.filter(res=>res == false).length > 0){ + send_val = false + } + else{ + send_val =true + } + } + } + return send_val + } + calculation(control,submitProperty){ + console.log("control",control) + let exp=` + (function () {let sum_val=null + let ques_key=[] + control.questions_group.forEach(ques_obj=>{ + ques_obj.questions.map(ques=>{ + // console.log(ques) + if(ques.question_key == 'share_holding'){ + ques_key.push(ques) + } + }) + }) + if(ques_key.length > 0){ + console.log(ques_key) + sum_val= ques_key.map(val=>val.answer_value).reduce((tot,val)=>{ + console.log(">>>>",tot,val) + return parseInt(tot)+parseInt(val) + }) + } + return sum_val == 100}());` + let exp1 = `(function (){let sum_val=null;let ques_key=[]; + control.forEach(ques_obj=>{ques_key.push(ques_obj[submitProperty.key_name])});console.log('none',ques_key);return new Set(ques_key).size === ques_key.length}())` + let exp2 = `(function (){let sum_val=null;let ques_key=[]; + control.forEach(ques_obj=>{ques_key.push(ques_obj[submitProperty.key_name])});console.log('none',ques_key);return new Set(ques_key).size === ques_key.length}())` + + //for image total check + // let exp=` + // (function () {let sum_val=null + // let ques_key=[] + // control.questions_group.forEach(ques_obj=>{ + // ques_obj.questions.map(ques=>{ + // // console.log(ques) + // if(ques.question_key == 'name_board_seen'){ + // ques_key.push(ques) + // } + // }) + // }) + // if(ques_key.length >= 3){ + // sum_val=true + // } + // else{ + // sum_val=false + // } + // return sum_val }());` + + + let val= eval(submitProperty.expression); + // let val= eval(exp1); + console.log(val) + return val + } + +} diff --git a/ng6-seed/src/app/fly-hi/image-video/image-video.component.html b/ng6-seed/src/app/fly-hi/image-video/image-video.component.html new file mode 100644 index 0000000..c194146 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/image-video/image-video.component.html @@ -0,0 +1,137 @@ + + +
+

+
+ Image Capture URL +
+
+ + +
+ +

+ +
+
+ {{details.Link}} +
+
+ +
+
+ +
+
+
+ +
+

This link will be sent as SMS to ({{details.applicantNo}}). Please proceed if this number is correct, else close this window and edit the applicant mobile number

+
+
+ +
+
+
+
+ + +
+ + +

+
+ VIDEO CALL +
+
+ + + + + +
+ +

+
+
+
+

PDGenie Chat :

+
+
+ +
+
+ + +
+
+ + +
+
+ {{pdGenie_GMeet_Link}} +
+ +
+
+
+ +
+

This link will be sent as SMS to ({{details.applicantNo}}). Please proceed if this number is correct, else close this window and edit the applicant mobile number

+
+
+ +
+
+
+
+ + +
+

+
+ VIDEO CALL +
+
+ +
+ +

+
+
+ + +
+
+
+ + \ No newline at end of file diff --git a/ng6-seed/src/app/fly-hi/image-video/image-video.component.scss b/ng6-seed/src/app/fly-hi/image-video/image-video.component.scss new file mode 100644 index 0000000..414c142 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/image-video/image-video.component.scss @@ -0,0 +1,12 @@ +.linkStyle{ + width: 100% !important; + padding: 15px !important; + letter-spacing: .00625em !important; + font-family: Roboto,Arial,sans-serif !important; + font-size: 1rem !important; + font-weight: 400 !important; + line-height: 1.5rem !important; + color: #202124 !important; + box-flex: 1 !important; + background-color: #8080803b !important; +} \ No newline at end of file diff --git a/ng6-seed/src/app/fly-hi/image-video/image-video.component.spec.ts b/ng6-seed/src/app/fly-hi/image-video/image-video.component.spec.ts new file mode 100644 index 0000000..1f390e5 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/image-video/image-video.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ImageVideoComponent } from './image-video.component'; + +describe('ImageVideoComponent', () => { + let component: ImageVideoComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ImageVideoComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ImageVideoComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/ng6-seed/src/app/fly-hi/image-video/image-video.component.ts b/ng6-seed/src/app/fly-hi/image-video/image-video.component.ts new file mode 100644 index 0000000..f33e874 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/image-video/image-video.component.ts @@ -0,0 +1,192 @@ +import { Component, OnInit, Inject } from '@angular/core'; +import { FormBuilder } from '@angular/forms'; +import { MatDialogRef, MatDialog, MAT_DIALOG_DATA } from '@angular/material'; +import { SectionListComponent } from 'app/sales-pd/section-list/section-list.component'; +import { FlyhiService } from '../services/flyhi.service'; +import { VideoPlayerComponent } from 'app/video-player/video-player.component'; +import { NotifierService } from 'angular-notifier'; + +@Component({ + selector: 'app-image-video', + templateUrl: './image-video.component.html', + styleUrls: ['./image-video.component.scss'] +}) +export class ImageVideoComponent implements OnInit { + + private notifier: NotifierService; + hideDetails: boolean = false; + details: any; + master: any; + g_code: Object | any[]; + google_Meet_Link: string; + pdGenie_GMeet_Link: any; + showLinkCard: boolean = false; + videoplayback: any = {enableBtn:true,url:null}; + g_meet_hide_button: boolean = false; + pdgenie_hide_button: boolean = false; + roleID: string; + constructor(notifier: NotifierService, + private _fb: FormBuilder, + private dialogRef: MatDialogRef, + private _flyhi: FlyhiService, private dialog: MatDialog, + @Inject(MAT_DIALOG_DATA) public data: any) { + this.details =data + this.notifier = notifier; + console.log(this.details) + this.roleID = localStorage.getItem('user_role') + // if(this.details.flag == 1){ + // let masterDetailsData = this.details.masterDetails + // if(masterDetailsData.gmeet_code == '' || masterDetailsData.gmeet_code == null){ + // console.log('711 createG_Meet') + // this.createG_Meet() + // // cus_link = 'http://meet.google.com/'+this.pdMasterData[0].gmeet_code; + // } else { + // let g_link = this.details.masterDetails.gmeet_code + // let cus_link = 'http://meet.google.com/'+g_link; + // this.google_Meet_Link = cus_link + + // } + // } + // this.master = this.details.masterDetails + this.master = localStorage.getItem('completedPD') + console.log(this.master) + this.master = JSON.parse(this.master) + } + + ngOnInit() { + } + + /** For Popup Close Button */ + closeComponent(): void { + this.dialogRef.close(); + } + + copyToClipBoard(linkData,iconDetails){ + + if(iconDetails == 'imageURL'){ + this._flyhi.copyToClipBoard(linkData); + this.notifier.notify('info','Image Capture Customer link copied'); + + }else if(iconDetails == 'videoChat'){ + this.g_meet_hide_button = true + this.showLinkCard = true + this._flyhi.copyToClipBoard(linkData); + this.pdGenie_GMeet_Link = this.details.videoChatLink + this.notifier.notify('info','Video Chat Customer link copied'); + + }else if(iconDetails == 'G_Meet'){ + this.pdgenie_hide_button = true + this.showLinkCard = true + this._flyhi.copyToClipBoard(linkData); + this.pdGenie_GMeet_Link = this.google_Meet_Link + this.notifier.notify('info','Google Meet Customer link copied'); + + } + + } + + createG_Meet(){ + console.log('727 createG_Meet') + let pdid = this.details.masterDetails.pd_id + console.log(pdid) + this._flyhi.create_G_Video_Status(pdid).subscribe(data => { + console.log(data) + if (data['status'] == 200) { + console.log('732') + // console.log('create_G_Video_Status',data) + this.g_code = data + console.log(this.g_code) + if(data['dataStatus'] == true){ + let cus_link_Gmeet = 'http://meet.google.com/'+this.g_code['data'].gmeet_code + console.log(cus_link_Gmeet) + this.google_Meet_Link = cus_link_Gmeet + } + } else { + console.log('743') + let msg_G_meet = data['msg'] + console.log(msg_G_meet) + this.notifier.notify('info',msg_G_meet); + } + }, error => { + console.log('%c Something Went Wrong Try Again.! \t\"' + (error.error_type == 2 ? error.error_status + ' ( ' + error.error_text + ' ) ' : ' ( ' + error.error_text + ' ) ') +'\" Error Occur.!', 'font-weight: bold; font-size: 50px;color: red; '); + }); + } + + smsCheck(event){ + if(event == 1){ + this.hideDetails = true + } + } + + onClickSmsLink(){ + + let param={ + pd_id: this.master.pd_id, + mobile_no: this.details.applicantNo, + random_string: this.master.random_string, + sms_flag:'1' + // pd_type:master.fk_pd_type + } + // sms_flag options + // 1 - Image Capture for Telepd and smart pd + // 2 - Image Recapture for Telepd and smart pd + this._flyhi.smsLink(param).subscribe(res=>{ + if(res['dataStatus']){ + this.notifier.notify("info","SMS Sent Successfully") + this.hideDetails = false + } + }) + } + + open_PDGenie_GMeet(event){ + // let dialogRef = this.dialog.open(VideoChatComponent,{ + // data:{type:'init',random_string:this.pdMasterData[0].random_string,pd_id:this.viewID}, + // maxWidth: '100vw', + // maxHeight: '100vh', + // height: '100%', + // width: '100%', + // disableClose: true, + // panelClass:'video-chat' + // }) + if(event == 'PDGenie'){ + let url = window.location.origin+'/vchat/#/chat/'+this.master.rand_string+';id='+this.master.sales_pd_id+';type=2' + window.open(url,'_blank') + } else if(event == 'G_Meet'){ + let url = this.google_Meet_Link + window.open(url,'_blank') + } + } + openPlayer(){ + // if(this.videoplayback.url == null) { + // this.notifier.notify('info',"No Videos Found"); + // return; + // } + let params = {"pd_id":this.master.sales_pd_id,"random_string":this.master.rand_string,"pd_category":2} + this._flyhi.getRecordedPlaybackUrl(params).subscribe(result=>{ + if(result && result['dataStatus'] && result['records'] && result['records'].length > 0) { + let dialogRef = this.dialog.open(VideoPlayerComponent,{ + data:{videoUrl:result['records'],masterData:this.master}, + maxWidth: '100vw', + maxHeight: '100vh', + height: '90%', + width: '70%', + disableClose: false, + panelClass:'video-player' + }) + } + else { + this.notifier.notify('info',"No Videos Found"); + } + }) + } + + // uploadRecordedVideo() { + // const dialogRef = this.dialog.open(UploadVideoComponent,{ + // minWidth:'50vw', + // disableClose:true, + // data:{pd_id:this.master.pd_id,random_string:this.master.random_string} + // // maxWidth:'75vw' + // }) + // } + +} diff --git a/ng6-seed/src/app/fly-hi/services/flyhi.service.spec.ts b/ng6-seed/src/app/fly-hi/services/flyhi.service.spec.ts new file mode 100644 index 0000000..a68f08a --- /dev/null +++ b/ng6-seed/src/app/fly-hi/services/flyhi.service.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing'; + +import { FlyhiService } from './flyhi.service'; + +describe('FlyhiService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: FlyhiService = TestBed.get(FlyhiService); + expect(service).toBeTruthy(); + }); +}); diff --git a/ng6-seed/src/app/fly-hi/services/flyhi.service.ts b/ng6-seed/src/app/fly-hi/services/flyhi.service.ts new file mode 100644 index 0000000..3f50d97 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/services/flyhi.service.ts @@ -0,0 +1,233 @@ +import { Injectable } from '@angular/core'; +import { environment } from 'environments/environment'; +import { Observable, of, forkJoin } from 'rxjs'; +import { HttpClient, HttpParams } from '@angular/common/http'; +import { catchError, map } from 'rxjs/operators'; +import { Observer } from 'rxjs'; + +const api_url = environment.apiEndpoint; + +@Injectable({ + providedIn: 'root' +}) + +export class FlyhiService { + + constructor(private _http:HttpClient) { } + + getFlyHiList(is_sales_login){ + // let params = new HttpParams().set("paramName",paramValue) + + // console.log("Api Stauts ",this.networkProvider.getCurrentNetworkStatus()) + let det:any=localStorage.getItem('user_details') + console.log('494',det,localStorage.getItem('user_details')) + det=JSON.parse(det) + console.log('494',det) + // let params = {'fk_entity_id':det.fk_entity_id,userid:det.userid} + // if(this.networkProvider.getCurrentNetworkStatus() == ConnectionStatus.online) { + let complete_url = api_url+'listFlyhiPD' + if(is_sales_login) { + complete_url = complete_url + } + return this._http.get(complete_url).map(res=>{ + // this.ionicStorageProvider.checkAndInsertApiDataLocally(res,params,'listSalesPD'); + return res; + + }) + // } + // else{ + // return this.ionicStorageProvider.getApiDataFromLocally(params,'listSalesPD'); + // } + } + loadPDTemplates2(pdId: string,randomString): Observable { + + let httpParams = new HttpParams().set('pd_id', pdId); + httpParams = httpParams.append('random_string',randomString); + // console.log('loadFullTemplate api load httpParams are',httpParams); + const options = pdId ? { params: httpParams } : {}; + console.log(options) + //return this._http.get(this.apiUrl + "loadFullTemplate", options) + return this._http.get(api_url + "loadFullTemplateV2", options) + // .pipe( + // catchError(this.handleError('operation', [])) + // ) +} +getPDSectionData(sales_pd_id,section_id,form_group) { + let params = { + "sales_pd_id":sales_pd_id, + "section_id":section_id + } + console.log(params) + // if(form_group == 1){ + // return this._http.post(api_url+'getPDFormDetails',{ "pd_id":pd_id,"pd_form_id":pd_form_id,"company_id":1}) + // }else{ + return this._http.post(api_url+'getFlyhiPDSectionData',{"records":params}) + // } + + +} + +loadCreditPDTemplate2(form_id,mapid,Formname,template_id):Observable { + + //return this._http.get(this.apiUrl + "formWiseJSONTemplateV2?form_id=5&map_id=7").map(result) + + // return this._http.get(this.apiUrl + "formWiseJSONTemplateV2?form_id=5&map_id=7").map(result=>{ + // console.log(result) + // let apivalue ={dataStatus:true,records:{template:JSON.stringify(result)}} + // console.log(apivalue) + // return apivalue + // }) + // if( Formname == 'Business Information'){ + // return this._http.get('assets/data/SMC_CREDIT_TEMPLATES/LFMP/2.json').map(rr=>{ + // let returnValue ={dataStatus:true,status:200,records:{template:JSON.stringify(rr)}} + // // this.raw_credit_pd_template= returnValue.records.template + // return returnValue + // }) + + // }else{ + if(template_id != null){ + return this._http.get(api_url + "formWiseJSONTemplateV2?form_id="+form_id+"&map_id="+mapid+"&template_id="+template_id+"").map(result=>{ + console.log(result) + let apivalue ={dataStatus:true,status:200,records:{template:JSON.stringify(result)}} + console.log(apivalue) + return apivalue + }) + }else{ + return this._http.get(api_url + "formWiseJSONTemplateV2?form_id="+form_id+"&map_id="+mapid+"").map(result=>{ + console.log(result) + let apivalue ={dataStatus:true,status:200,records:{template:JSON.stringify(result)}} + console.log(apivalue) + return apivalue + }) + } + + // } + + + +} + +loadTemplate(form_id,mapid,Formname) { + console.log( Formname) + // return this._http.get('assets/data/SMC_CREDIT_TEMPLATES/'+form_id+'.json').map(rr=>{ + // return this._http.get('assets/data/SMC_CREDIT_TEMPLATES/LFMP/16.json').map(rr=>{ + if( Formname == 'Business Information'){ + return this._http.get('assets/data/SMC_CREDIT_TEMPLATES/LFMP/1.json').map(rr=>{ + // return this._http.get('assets/data/SMC_CREDIT_TEMPLATES/LFMP/'+form_id+'.json').map(rr=>{ + let returnValue ={dataStatus:true,status:200,records:{template:JSON.stringify(rr)}} + // this.raw_credit_pd_template= returnValue.records.template + return returnValue + }) + + }else{ + // return this._http.get(this.apiUrl + "formWiseJSONTemplateV2?form_id="+form_id+"&map_id="+mapid+"").map(result=>{ + // console.log(result) + // let apivalue ={dataStatus:true,status:200,records:{template:JSON.stringify(result)}} + // console.log(apivalue) + // return apivalue + // }) + //return this._http.get('assets/data/SMC_CREDIT_TEMPLATES/all/'+form_id+'.json').map(rr=>{ + return this._http.get('assets/data/SMC_CREDIT_TEMPLATES/DONE/6.json').map(rr=>{ + let returnValue ={dataStatus:true,status:200,records:{template:JSON.stringify(rr)}} + // this.raw_credit_pd_template= returnValue.records.template + console.log("12345") + return returnValue + }) + } + +} + + saveForm(records: any): Observable { + // records.fk_createdby = this._aws.getlocale(); + let params = records + console.log(params) + return this._http.post(api_url + 'saveFlyhiPDsection',{"records":params} + ).map(res=>{ + // console.log(res,curr_vendor_ans_fetch_status,res['dataStatus'],curr_vendor_ans_fetch_status == '0'); + // // for UPDATING THE VENDOR FORM STATUS (SMART PD ONLY) + // if (curr_vendor_ans_fetch_status == '0') { + // if (res['dataStatus']) { + // console.log("inside") + // this.updateVendorFormStatus({"fk_pd_id":records.pdid,"fk_form_id":records.formid}).subscribe(re=>{ + + // }) + // } + // } + // end of UPDATING THE VENDOR FORM STATUS (SMART PD ONLY) + return res + }) + // .pipe( + // catchError(this.handleError('role', [])) + // ) + } + + get_Pd_Id(jsonParamsData){ + let userid:any=localStorage.getItem("user_details") + userid=JSON.parse(userid).userid; + let lender_id = localStorage.getItem("LocalSetEntity") + console.log(lender_id) + let key_value = localStorage.getItem('sales_pd_id_PRIMARYKEY') + console.log(key_value) + let sales_pd_type + if(jsonParamsData.verification_type == 'Residence verification'){ + sales_pd_type = 4 + } + if(jsonParamsData.verification_type == 'Office verification'){ + sales_pd_type = 3 + } + + let createdby = userid + let params = { + "createdby" : createdby, + "sales_pd_id" : key_value, + "lender_id": lender_id, + "product_id":jsonParamsData.product_name, + "sales_pd_type":sales_pd_type, + } + console.log(params) + // let params = { records } + return this._http.post(api_url + 'saveFlyhiPD', {"records":params}).map(res=>{ + return res + }) + + + } + copyToClipBoard(message) { + const selBox = document.createElement('textarea'); + selBox.style.position = 'fixed'; + selBox.style.left = '0'; + selBox.style.top = '0'; + selBox.style.opacity = '0'; + selBox.value = message; + document.body.appendChild(selBox); + selBox.focus(); + selBox.select(); + document.execCommand('copy'); + document.body.removeChild(selBox); + } + create_G_Video_Status(pdid: any){ + return this._http.get(api_url+'createGmeetLink?pdid='+pdid) + // .pipe( + // catchError(this.handleError('role', [])) + // ) + } + getRecordedPlaybackUrl(params){ + return this._http.post(api_url+'getVideoURL',params) + } + + /** To get SMS Link + * List PD + */ + smsLink(params): Observable { + return this._http.post(api_url + 'sendCusLinkViaSMS', params) + // .pipe( + // catchError(this.handleError('role', [])) + // ) + } + + // getSalesPdpdf(pdfdetail){ + // return this._http.get(api_url + "downloadFlyhiPDReport/" + pdfdetail) + // } + + +} diff --git a/ng6-seed/src/app/fly-hi/start-pd2/start-pd2.component.html b/ng6-seed/src/app/fly-hi/start-pd2/start-pd2.component.html new file mode 100644 index 0000000..e69de29 diff --git a/ng6-seed/src/app/fly-hi/start-pd2/start-pd2.component.scss b/ng6-seed/src/app/fly-hi/start-pd2/start-pd2.component.scss new file mode 100644 index 0000000..ac59721 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/start-pd2/start-pd2.component.scss @@ -0,0 +1,84 @@ +// .child_mat_card mat-card { +// margin: 2 0%; +// } +::ng-deep .mat-dialog-container{ + overflow: hidden !important; +} + ::ng-deep .mat-card-header-text{ + margin:0px !important; + } + .mat-purple{ + background-color: gray !important; + } + .cdk-global-overlay-wrapper{ + justify-content: center !important; +} +mat-card.parent_mat_card > { + mat-card-header { + display: flex; + flex-direction: column; + } + mat-card-content { + min-height:auto; + max-height:52vh; + overflow:auto; + } + + + .user-thumb { + position: absolute; + bottom: -35%; + // img { + // border: 5px solid $white; + // border-radius: 100%; + // height: 75px; + // width: 75px; + // } +} + // @media only screen and (max-width:319px) { + // mat-card-content { + // max-height: 350px; + // overflow: auto; + // } + // } + // @media only screen and (min-width:320px) and (max-width:767px) { + // mat-card-content { + // max-height: 350px; + // overflow: auto; + // } + // } + // @media only screen and (min-width:768px) and (max-width:1023px) { + // mat-card-content { + // max-height: 350px; + // overflow: auto; + // } + // } + // @media only screen and (min-width:1024px) and (max-width:1899px) { + // mat-card-content { + // max-height: 400px; + // overflow: auto; + // } + // } + // @media only screen and (min-width:1900px) { + // mat-card-content { + // max-height: 500px; + // overflow: auto; + // } + // } +} +$base-card-box-shadow:1.5px 2.6px 24px 0 rgba(0, 35, 136, 0.08) !important; +mat-card .child_mat_card > mat-card { + border-radius: 0px 0px 0px 15px; + box-shadow: $base-card-box-shadow; + transform: scale(0.95); + transition: box-shadow 0.5s, transform 0.5s; + border: 1px solid lavender; + &:hover { + cursor: pointer; + // background-color: #e00201 !important; + transform: scale(1); + box-shadow: 5px 20px 30px rgba(0, 0, 0, 0.2); + } + + } + diff --git a/ng6-seed/src/app/fly-hi/start-pd2/start-pd2.component.spec.ts b/ng6-seed/src/app/fly-hi/start-pd2/start-pd2.component.spec.ts new file mode 100644 index 0000000..682ff86 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/start-pd2/start-pd2.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { StartPd2Component } from './start-pd2.component'; + +describe('StartPd2Component', () => { + let component: StartPd2Component; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ StartPd2Component ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(StartPd2Component); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/ng6-seed/src/app/fly-hi/start-pd2/start-pd2.component.ts b/ng6-seed/src/app/fly-hi/start-pd2/start-pd2.component.ts new file mode 100644 index 0000000..b2818c3 --- /dev/null +++ b/ng6-seed/src/app/fly-hi/start-pd2/start-pd2.component.ts @@ -0,0 +1,300 @@ +import {Component, ViewChild, OnInit, ViewEncapsulation, OnDestroy} from '@angular/core'; +import {FormBuilder, FormGroup, Validators, FormControl, FormArray, AbstractControl} from '@angular/forms'; +import {ActivatedRoute, Router} from '@angular/router'; +import {MatDialog } from '@angular/material'; +import {NotifierService} from 'angular-notifier'; +// import {ListPdComponent} from './../../list-pd.component'; + +// import {PdTrigerService} from '../../../../pd-service/pd-triger.service'; + +// import {GeneralInfoComponent} from './../forms/general-info/general-info.component'; + +// import {PdStatusChangeDialogueComponent } from './../../pd-status-change-dialogue/pd-status-change-dialogue.component'; + +// import { ImagesAllComponent } from './../forms/images-all/images-all.component'; + +import { FormComponent } from './../forms-dynamic/form/form.component'; + +// import { ImageCaptureComponent } from './Form-Dynamic/image-capture/image-capture.component'; +import { LoaderService } from 'app/shared/loaderService/loader.service'; +import { PdTrigerService } from 'app/personal-discussion/pd-service/pd-triger.service'; +import { FlyhiService } from '../services/flyhi.service'; + + + +@Component({ + selector: 'app-start-pd2', + templateUrl: './start-pd2.component.html', + styleUrls: ['./start-pd2.component.scss'] +}) +export class StartPd2Component implements OnInit, OnDestroy { + public startPD: string; + public mainApplicantName: string; + public randomString: string; +//public remarks: string; + errorMessage: any; + selectedCategory: any = []; + categoryList: any = []; + pdMasterList: any = []; + pdFullDetails:any=[]; + +// category static form buttons + categoryFormButtons: any; + formsCategoryEnable: boolean = false; + selectedFormsCategory: any; +// create values for status check + pdStatusCheck: any = { + "DRAFT": 'DRAFT', + "TRIGGERED": 'TRIGGERED', + "ALLOCATED": 'ALLOCATED', + "SCHEDULED": 'SCHEDULED', + "INPROGRESS": 'INPROGRESS', + "COMPLETED": 'COMPLETED', + "QC_COMPLETED": 'QC_COMPLETED', + }; + currentPDStatus: boolean; + actualQuestions: number; + answeredQuestions: number; + private notifier: NotifierService; + vendor_status_arr: any = []; + photographButtons: any[]; + + constructor(notifier: NotifierService, private dialog: MatDialog, private fb: FormBuilder, private route: ActivatedRoute, + private router: Router,private _flyhi:FlyhiService, + private loaderService:LoaderService) { + this.startPD = this.route.snapshot.params['pdid']; + this.randomString = this.route.snapshot.params['rdmstr']; + // console.log(this.route.snapshot.params['pdid'],this.route.snapshot.params['rdmstr']); + this.notifier = notifier; + this.currentPDStatus = false; + } + + ngOnInit() { + + // this.listPDComponent.showListView(false); + // const elemSidebar = document.querySelector('.app-inner .mail-sidebar'); + // const elemContent = document.querySelector('.app-inner .main-content'); + + // if (window.matchMedia(`(min-width: 960px)`).matches && !this.isMac()) { + // // Ps.initialize(elemSidebar, { wheelSpeed: 2, suppressScrollX: true }); + // // Ps.initialize(elemContent, { wheelSpeed: 2, suppressScrollX: true }); + // } + this.loadTemplates(this.startPD,1,this.randomString); + + // this.getCreditPDTemplate(); + + + } + // getCreditPDTemplate() { + // // let params = { "fk_entity_id":this.pddetails.fk_lender_id,"fk_product_id":this.pddetails.fk_product_id,"pd_form_id":this.pddetails.pd_id } + // let params = { "fk_entity_id":"","fk_product_id":"","pd_form_id":"24","fk_pd_id": this.startPD } + // this._flyhi.loadCreditPDTemplate(params).subscribe(result=> { + // let creditTemplate:any = null; + // if(result['dataStatus']) { + // if(result.hasOwnProperty('records') && result['records']) { + // creditTemplate = result['records']; + // } + // } + // localStorage.setItem("dynamicQuesTemplate",JSON.stringify(creditTemplate)); + // }) + // } + + isMac(): boolean { + let bool = false; + if (navigator.platform.toUpperCase().indexOf('MAC') >= 0 || navigator.platform.toUpperCase().indexOf('IPAD') >= 0) { + bool = true; + } + return bool; + } + + isOver(): boolean { + return window.matchMedia(`(max-width: 960px)`).matches; + } + + + // load templates details + loadTemplates(startID:string,type:number,randomString:string){ + // console.log('start pd component inside - loadTemplates params are,',startID,type,randomString); + this._flyhi.loadPDTemplates2(startID,randomString).subscribe( + data => { + console.log("after reponse = ", data); + console.log("after reponse = ", data.records.pdmaster_details); + + + if (data.status == 200) { + this.pdMasterList=data.records.pdmaster_details; + // this.categoryList=data.records.question_answers; + let filterApplicantName= data.records.pdapplicants_detials.filter(item => item.applicant_type == 1); + this.mainApplicantName = filterApplicantName.length > 0 ? filterApplicantName[0].applicant_name : ''; + this.currentPDStatus = data.records.pdmaster_details.pd_status=='INPROGRESS' ? true : data.records.pdmaster_details.pd_status=='SCHEDULED' ? true :data.records.pdmaster_details.pd_status=='ALLOCATED' ? true : false; + //let categoryFormButtons1 = Object.keys(data.records.template_forms).map((item)=>data.records.template_forms[item]).filter(item=>item.isAnswerable===true); + //this.categoryFormButtons =categoryFormButtons1.filter(item=>item.form_id!=26); + this.categoryFormButtons = data.records.template_forms + + + this.categoryFormButtons.sort((a,b) => a.pd_form_order - b.pd_form_order ) + // let s = this.categoryFormButtons.sort((a,b) => a.pd_form_order < b.pd_form_order); + console.log( this.categoryFormButtons); + // this.photographButtons=categoryFormButtons1.filter(item=>item.form_id==26); + // console.log(this.photographButtons); + this.categoryFormButtons = this.categoryFormButtons.filter(item=>item.isAnswerable===true); + this.actualQuestions = this.categoryFormButtons.length; + let getAnsweredFormsCount = this.categoryFormButtons.filter(item=>item.isAnswered===true); + this.answeredQuestions = getAnsweredFormsCount.length; + console.log("ans",this.answeredQuestions,this.actualQuestions) + this.pdFullDetails = data.records; + // VENDOR FORM ANSWER FETCH STATUS START(SMART PD ONLY) + // if(this.pdMasterList.fk_pd_type == '2') { + // if(data.records.vendor_form_status && data.records.vendor_form_status.length > 0) { + // this.vendor_form_status_arr = JSON.stringify(data.records.vendor_form_status) + // localStorage.setItem("vendorFormStatus_arr",this.vendor_form_status_arr) + // } + // } + console.log(this.pdMasterList) + console.log(this.pdMasterList.fk_pd_type) + if(this.pdMasterList.fk_pd_type == '2') { + // let temp_vendor_status = localStorage.getItem("vendorFormStatus_arr") + if(data.records.hasOwnProperty('vendor_form_status') && data.records.vendor_form_status && data.records.vendor_form_status.length > 0) { + // temp_vendor_status = JSON.parse(temp_vendor_status) + // if(temp_vendor_status && temp_vendor_status.length > 0 ) { + this.vendor_status_arr = data.records.vendor_form_status + + // } + } + } + // END OF VENDOR FORM ANSWER FETCH + // if(type==1 && (data.records.pdmaster_details.pd_status=='SCHEDULED' || data.records.pdmaster_details.pd_status=='ALLOCATED')) { + // this.pdStatusDialogue(this.pdStatusCheck.INPROGRESS,1) + // } + } + else{ + this.pdMasterList = ""; + this.mainApplicantName = ""; + this.categoryList = []; + this.currentPDStatus = false; + } + // this.getAnswers(serachQuestions); + + }); + } + + // load pd status change dialogue +// pdStatusDialogue(status: string, checkType: number): void { + +// const dialogRef = this.dialog.open(PdStatusChangeDialogueComponent, { +// data: { pdid: this.startPD, pd_status: status ,random_string:this.randomString,pd_type:this.pdMasterList.fk_pd_type }, +// disableClose: true, +// minWidth:'30%', +// maxWidth:'40%', +// }); +// dialogRef.afterClosed() +// .subscribe(dataresult => { +// if(dataresult.update_status==true){ +// setTimeout(()=>{ +// checkType==2 ? this.router.navigate(['../../viewpd', this.pdMasterList.parent_pd_id], {relativeTo: this.route}) : this.loadTemplates(this.startPD,2,this.randomString); +// let data = { +// "pd_id": this.startPD, +// "regenerate":0, +// "random_string":this.randomString +// }; +// },2000) +// // this._flyhi.archivePDImages(data).subscribe(data => { + +// // }) +// let data1 = { +// "pd_id": this.startPD, +// "regenerate":0, +// "random_string":this.randomString +// }; +// this._flyhi.photoPDFDownload(data1).subscribe(data => { + +// }) + +// } +// else { +// checkType==1 ? this.router.navigate(['../../viewpd', this.pdMasterList.parent_pd_id], {relativeTo: this.route}) : this.loadTemplates(this.startPD,2,this.randomString); +// } +// if(checkType == 2){ +// // this.loadTemplates(this.startPD,2,this.randomString); +// } +// }); +// } + + // start + // direct form based questions + OnSelectDirectForms(details: any,id:any) { + + console.log(details.form_name) + console.log( this.vendor_status_arr ) + // this.formsCategoryEnable = true; + this.selectedFormsCategory = details; + + let curr_vendor_ans_fetch_status = null + if(this.pdMasterList.fk_pd_type == '2') { + if(this.vendor_status_arr && this.vendor_status_arr.length > 0 && this.selectedFormsCategory.form_id != 13) { + console.log(this.vendor_status_arr,this.selectedFormsCategory) + curr_vendor_ans_fetch_status =this.vendor_status_arr.filter(val=>val.fk_form_id == String(this.selectedFormsCategory.form_id)) + if(curr_vendor_ans_fetch_status.length > 0) { + curr_vendor_ans_fetch_status = curr_vendor_ans_fetch_status[0].form_status + } + else { + curr_vendor_ans_fetch_status = null + } + } + } + this.pdFullDetails.pdmaster_details.curr_vendor_ans_fetch_status = curr_vendor_ans_fetch_status + // this.pdFullDetails.form_id= this.selectedFormsCategory.fk_form_id + // this.pdFullDetails.is_answered = this.selectedFormsCategory.is_answered + this.pdFullDetails.pdmaster_details = this.pdMasterList + + console.log(this.pdFullDetails); + console.log(this.pdMasterList); + console.log(details); + console.log(this.startPD,2,this.randomString) + let data:any; + data = {pd_FullDetails:this.pdFullDetails,pdMasterList:this.pdMasterList,FormData:details,Formname:details.form_name,pdmaster_details:this.pdMasterList}; + let componen_name:any = FormComponent + // if(details.is_business_form == 1) { + // componen_name = FormGroupComponent + + // }else if(details.form_id == '26'){ + // componen_name = ImagesAllComponent + + // }else if(details.form_id == '18'){ + // componen_name = GeneralInfoComponent + // data = this.pdFullDetails; + // } + const dialogRef = this.dialog.open(componen_name, { + + data: data, + + position: { right: '0'}, + maxWidth: '100vw', + maxHeight: '100vh', + height: '100%', + width: '100%', + disableClose: true, + closeOnNavigation:true, + panelClass:'no-padding' + }); + dialogRef.afterClosed() + .subscribe(dataresult => { + // this.notifier.notify('success', 'Successfully allocated.!'); + // if(dataresult == 'refresh') { + this.loadTemplates(this.startPD,2,this.randomString); + // } + }); + + + } + + ngOnDestroy(): void { + // this.listPDComponent.showListView(true); + } + // load pd view component + loadPdViewCompoent() { + this.router.navigate(['../../../viewpd', this.pdMasterList.parent_pd_id,this.randomString], {relativeTo: this.route}); + } + + } + diff --git a/ng6-seed/src/app/layouts/admin/admin-layout.component.html b/ng6-seed/src/app/layouts/admin/admin-layout.component.html index 99f6263..a973418 100755 --- a/ng6-seed/src/app/layouts/admin/admin-layout.component.html +++ b/ng6-seed/src/app/layouts/admin/admin-layout.component.html @@ -95,7 +95,7 @@
- +
--> -
-
- -
-
- -
- -
-
- -
+ + +
+
+
+ +
+
+ +
+ +
+
+
\ No newline at end of file diff --git a/ng6-seed/src/app/sales-pd/components/ques-template/ques-template.ts b/ng6-seed/src/app/sales-pd/components/ques-template/ques-template.ts index e6e67ba..6700f60 100755 --- a/ng6-seed/src/app/sales-pd/components/ques-template/ques-template.ts +++ b/ng6-seed/src/app/sales-pd/components/ques-template/ques-template.ts @@ -82,6 +82,8 @@ export class QuesTemplateComponent { tmp:any =[]; roleID: string; pdstatus: string; + local_city1: any; + local_pincode1: any; constructor( private cameraService: CameraService,public dialogRef: MatDialogRef,private route: ActivatedRoute,private router: Router,private dialog:MatDialog,private _fb:FormBuilder,private questionService:QuestionServiceService,private SalesPdService:SalesPdService,notifier: NotifierService,private loaderService:LoaderService) { console.log('Hello QuesTemplateComponent Component'); this.text = 'Hello World'; @@ -89,6 +91,8 @@ export class QuesTemplateComponent { //this.cameraProvider.checkGPSPermission(); //alert('abi1'); //this.ngOnChanges() + this.roleID = localStorage.getItem('user_role') + console.log(this.roleID) } ngOnChanges(){ @@ -1072,18 +1076,93 @@ this.proceedonChangeProperty(modified) onChangeProperties_value.forEach(onChangeProperty=>{ console.log("api",onChangeProperty) + if(onChangeProperty.purpose == 'api2'){ + if(onChangeProperty.api == 'getListOfStatesAndCities'){ + this.SalesPdService.getCityPincode(event.value).subscribe(res=>{ + console.log('1082') + if(res['dataStatus']){ + console.log('1084') + this.local_city1=res['records'].cities + this.local_pincode1=res['records'].pincode + console.log(this.quesAnsForm.controls.questions['controls']) + this.quesAnsForm.controls.questions['controls'].forEach((val,index)=>{ + console.log(val) + // if(val.value.hasOwnProperty('questions_group')){ + // console.log('1089',val.value.questions_group[0]['questions']) + // console.log('1089',val.value.questions_group) + + // val.value.questions_group[0]['questions'].forEach((getCity2,index)=>{ + // console.log(getCity2) + // if(getCity2.api_properties == 'local_city1'){ + // console.log('1091',getCity2.controls) + // this.local_city1=this.questionService.convertArrayNames(['city_id','city_name'],this.local_city1) + // console.log('1096',getCity2) + // getCity2.answers =(this.local_city1) + // console.log(getCity2.answer) + // } + // else if(getCity2.api_properties == 'local_pincode1'){ + // this.local_pincode1=this.questionService.convertArrayNames(['pincode_id','pincode'],this.local_pincode1) + // getCity2.answers=(this.local_pincode1) + // } + + // }) + + // // }) + // } + + // console.log('1089',val.value.hasOwnProperty('questions_group')) + if(val.value.api_properties == 'local_city1'){ + console.log('1091') + this.local_city1=this.questionService.convertArrayNames(['city_id','city_name'],this.local_city1) + val.controls.answers.setValue(this.local_city1) + } + else if(val.value.api_properties == 'local_pincode1'){ + this.local_pincode1=this.questionService.convertArrayNames(['pincode_id','pincode'],this.local_pincode1) + val.controls.answers.setValue(this.local_pincode1) + } + + }) + + } + }) + } + else{ + this.SalesPdService.api_post_method(onChangeProperty.api,onChangeProperty.params,onChangeProperty.api_method).subscribe(result=>{ + if(result['dataStatus']){ + if(result.hasOwnProperty('records')){ + result=result['records'] + } + let ques_control= this.quesAnsForm.controls.questions['controls'] + if(options == 2){ + ques_control=group_ques.controls.questions['controls'] + } + + ques_control.forEach((val,index)=>{ + + if(val.value.api_properties == onChangeProperty.local_variable){ + let values1=this.questionService.convertArrayNames(onChangeProperty.fields,result) + val.controls.answers.setValue(values1) + } + + }) + } + }) + } + } if(onChangeProperty.purpose == 'api'){ if(onChangeProperty.api == 'getListOfStatesAndCities'){ this.SalesPdService.getCityPincode(event.value).subscribe(res=>{ if(res['dataStatus']){ this.local_city=res['records'].cities this.local_pincode=res['records'].pincode - + console.log(this.quesAnsForm.controls.questions['controls']) this.quesAnsForm.controls.questions['controls'].forEach((val,index)=>{ - + console.log(val) if(val.value.api_properties == 'local_city'){ this.local_city=this.questionService.convertArrayNames(['city_id','city_name'],this.local_city) + console.log(this.local_city) + console.log(val.controls) val.controls.answers.setValue(this.local_city) } else if(val.value.api_properties == 'local_pincode'){ @@ -1699,7 +1778,7 @@ this.proceedonChangeProperty(modified) // alert('b'); const dialogRef = this.dialog.open(AlertDialogComponent, { width: '500px', - data: {buttons:[{name:"Complete",visible:true,id:'Complete'},{name:'Cancel',visible:'true',id:'cancel'}],title:'Complete sales PD', + data: {buttons:[{name:"Complete",visible:true,id:'Complete'},{name:'Cancel',visible:'true',id:'cancel'}],title:'Complete PD', msg:'You are completing this PD, once completed you will not be able to make changes'} }); diff --git a/ng6-seed/src/app/sales-pd/components/ques-template/single-capture-btn/single-capture-btn.component.html b/ng6-seed/src/app/sales-pd/components/ques-template/single-capture-btn/single-capture-btn.component.html index 2c203d7..09f13ab 100644 --- a/ng6-seed/src/app/sales-pd/components/ques-template/single-capture-btn/single-capture-btn.component.html +++ b/ng6-seed/src/app/sales-pd/components/ques-template/single-capture-btn/single-capture-btn.component.html @@ -1,4 +1,4 @@ - diff --git a/ng6-seed/src/app/sales-pd/components/ques-template/single-capture-btn/single-capture-btn.component.ts b/ng6-seed/src/app/sales-pd/components/ques-template/single-capture-btn/single-capture-btn.component.ts index 3f30d62..885a043 100644 --- a/ng6-seed/src/app/sales-pd/components/ques-template/single-capture-btn/single-capture-btn.component.ts +++ b/ng6-seed/src/app/sales-pd/components/ques-template/single-capture-btn/single-capture-btn.component.ts @@ -14,8 +14,10 @@ export class SingleCaptureBtnComponent implements OnInit { @Output() singleDataEmitter = new EventEmitter sales_pd_type: string; + role_id: string; constructor(private ng2ImgMax:Ng2ImgMaxService,private loaderService:LoaderService) { + this.role_id = localStorage.getItem('user_role') this.sales_pd_type = localStorage.getItem('sales_pd_type') console.log(this.sales_pd_type) } diff --git a/ng6-seed/src/app/sales-pd/home/home.html b/ng6-seed/src/app/sales-pd/home/home.html index 5ec0804..cce38af 100755 --- a/ng6-seed/src/app/sales-pd/home/home.html +++ b/ng6-seed/src/app/sales-pd/home/home.html @@ -1,4 +1,4 @@ -
+
{{question_data.section_name}}
diff --git a/ng6-seed/src/app/sales-pd/home/home.ts b/ng6-seed/src/app/sales-pd/home/home.ts index 39a4956..dac8d93 100755 --- a/ng6-seed/src/app/sales-pd/home/home.ts +++ b/ng6-seed/src/app/sales-pd/home/home.ts @@ -683,9 +683,11 @@ export class Section9 { all_sections:any; formGroupValue: any=null; sec_id: any; + role_id: string; //network_status: ConnectionStatus constructor(public dialogRef: MatDialogRef,notifier: NotifierService,private route: ActivatedRoute,private router: Router,private dialog: MatDialog,private MatDialogModule:MatDialogModule,@Inject(MAT_DIALOG_DATA) public data: any) { + this.role_id = localStorage.getItem('user_role') // alert('section9') console.log('data',data) this.notifier = notifier; diff --git a/ng6-seed/src/app/sales-pd/providers/sales-pd/sales-pd.ts b/ng6-seed/src/app/sales-pd/providers/sales-pd/sales-pd.ts index aeee63a..0ef1bf4 100755 --- a/ng6-seed/src/app/sales-pd/providers/sales-pd/sales-pd.ts +++ b/ng6-seed/src/app/sales-pd/providers/sales-pd/sales-pd.ts @@ -167,7 +167,14 @@ current_section:any; } saveSalesPDSection(params){ let users:any=localStorage.getItem('user_details') - users=JSON.parse(users) + users=JSON.parse(users) + let apiName + if(users.user_role != '20'){ + apiName = 'saveSalesPDsection' + }else if(users.user_role == '20'){ + apiName = 'getFlyhiPDSectionData' + } + params.fk_createdby=users.userid return Observable.create((observer:Observer)=>{ this.getData_fromLocal('sales_pd_id_PRIMARYKEY').then(key_value=>{ @@ -177,7 +184,7 @@ current_section:any; let modified_params = params console.log("###################$%%",(key_value != null ? (typeof(key_value) == 'string' ? !key_value.includes('local') : true ) : true)); if(key_value != null ? (typeof(key_value) == 'string' ? !key_value.includes('local') : true ) : true) { - return this.http.post(this.apiUrl+'saveSalesPDsection',{records:params}).pipe().subscribe(response=>{ + return this.http.post(this.apiUrl+apiName,{records:params}).pipe().subscribe(response=>{ // delete modified_params.questions modified_params.is_synced = true; modified_params.section_data = section_data @@ -196,7 +203,7 @@ current_section:any; else if(modified_params.section_id != '9'){ // console.log("#######params",modified_params) let offline_params = modified_params - offline_params.request_items={url:this.apiUrl+'saveSalesPDsection', + offline_params.request_items={url:this.apiUrl+apiName, params:JSON.stringify({records:params}),method:'POST'} offline_params.is_synced = false offline_params.section_data = section_data diff --git a/ng6-seed/src/app/sales-pd/sales-pd-routing.module.ts b/ng6-seed/src/app/sales-pd/sales-pd-routing.module.ts index 3102398..718e411 100755 --- a/ng6-seed/src/app/sales-pd/sales-pd-routing.module.ts +++ b/ng6-seed/src/app/sales-pd/sales-pd-routing.module.ts @@ -4,6 +4,7 @@ import { Routes, RouterModule } from '@angular/router'; import { SectionListComponent } from './section-list/section-list.component'; import { SalesPdComponent } from './sales-pd-list/sales-pd.component'; import { HomePage } from './home/home'; +import { FlyHiListComponent } from 'app/fly-hi/fly-hi-list/fly-hi-list.component'; //import {Section9} from './home/home' const routes: Routes = [ @@ -28,10 +29,10 @@ const routes: Routes = [ path:'sectionlist/:product_id/:sales_pd_type', component:SectionListComponent }, - // { - // path:'sectionlist/:product_id/:sales_pd_type/:link', - // component:SectionListComponent - // }, + { + path:'flyhi-list-pd', + component:FlyHiListComponent + }, { path:'', component:HomePage diff --git a/ng6-seed/src/app/sales-pd/sales-pd.module.ts b/ng6-seed/src/app/sales-pd/sales-pd.module.ts index d2db924..449bc29 100755 --- a/ng6-seed/src/app/sales-pd/sales-pd.module.ts +++ b/ng6-seed/src/app/sales-pd/sales-pd.module.ts @@ -21,6 +21,8 @@ import { SingleCaptureBtnComponent } from './components/ques-template/single-cap import { HomePageModule } from './home/home.module'; import { CommonModule } from '@angular/common'; import { ReGenerateReportComponent } from './sales-pd-list/re-generate-report/re-generate-report.component'; +import { FlyHiListComponent } from 'app/fly-hi/fly-hi-list/fly-hi-list.component'; +import { ImageVideoComponent } from 'app/fly-hi/image-video/image-video.component'; @NgModule({ imports: [ SalesPdRoutingModule, @@ -30,10 +32,11 @@ import { ReGenerateReportComponent } from './sales-pd-list/re-generate-report/re StartPdModule, HomePageModule, CommonModule, - MatDialogModule + MatDialogModule, + MatTooltipModule ], - declarations: [AlertDialogComponent,SalesPdComponent,AdvanceFilterComponent, ReGenerateReportComponent], - entryComponents:[AlertDialogComponent,SalesPdComponent,ReGenerateReportComponent], + declarations: [ImageVideoComponent,AlertDialogComponent,FlyHiListComponent,SalesPdComponent,AdvanceFilterComponent, ReGenerateReportComponent], + entryComponents:[ImageVideoComponent,AlertDialogComponent,SalesPdComponent,ReGenerateReportComponent], providers:[ConstantsProvider,{ provide: MAT_DATE_LOCALE, useValue: 'en-GB' },{provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE]}, {provide: MAT_DATE_FORMATS, useValue: MAT_MOMENT_DATE_FORMATS},{ provide: MatDialogRef, useValue: {} },{ provide: MAT_DIALOG_DATA, useValue: [] }], bootstrap: [SalesPdComponent], diff --git a/ng6-seed/src/app/sales-pd/section-list/section-list.component.html b/ng6-seed/src/app/sales-pd/section-list/section-list.component.html index 96cca85..478dcc1 100644 --- a/ng6-seed/src/app/sales-pd/section-list/section-list.component.html +++ b/ng6-seed/src/app/sales-pd/section-list/section-list.component.html @@ -1,11 +1,19 @@ - +
-

Section List

+

Section List

-
+ +
+ + +    +    @@ -19,7 +27,7 @@ - @@ -27,13 +35,14 @@ + -
+
@@ -67,6 +76,19 @@ pd_completed.pd_complete_request_items != null"> -->
+
+ + +
+
+
{{sec.section_name}}
+
+
+ check_circle_outline +
+
+
+