Fairoj : Notification issues for both foreground and background resolved and turnover validated section introduced in fin info form for clix housing

This commit is contained in:
venbatechnologies@gmail.com 2020-02-04 19:15:50 +05:30
parent 034bb1c16a
commit b704269471
12 changed files with 472 additions and 21 deletions

View File

@ -692,9 +692,9 @@
}
},
"@angular/fire": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/@angular/fire/-/fire-5.3.0.tgz",
"integrity": "sha512-Z/dywnrQiuz6Hfq0MncDvwB0obirWdCetrd//OkHsWKLKi1deFrb6ChuTBTGj+kN/cjHUEwI9pD4uoDvU7jyAg=="
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/@angular/fire/-/fire-5.4.0.tgz",
"integrity": "sha512-067oatMtDbNKEWNdZoMWqKOzPpp0r8XZvpL1bcH6PO+q62ceJ2ig46ne1UqJP2nHRyXNAtIyJp7VhVoG4gRPiA=="
},
"@angular/flex-layout": {
"version": "6.0.0-beta.18",

View File

@ -20,7 +20,7 @@
"@angular/common": "^6.1.10",
"@angular/compiler": "^6.1.10",
"@angular/core": "^6.1.10",
"@angular/fire": "^5.3.0",
"@angular/fire": "^5.4.0",
"@angular/flex-layout": "^6.0.0-beta.18",
"@angular/forms": "^6.1.10",
"@angular/http": "^6.0.0-rc.6",

View File

@ -5,6 +5,7 @@ import { AwsService } from './AwsService/aws.service';
import { DashboardService } from './dashboard/dashboard.service';
import 'rxjs/add/observable/interval';
import { Observable,interval, Subscription } from 'rxjs';
import { PushNotifyService } from './shared/push-notify.service';
@Component({
selector: 'app-root',
@ -16,7 +17,7 @@ export class AppComponent {
// public timer
constructor(translate: TranslateService,
private messagingService: MessagingService,
public aws: AwsService,private dashBoardService:DashboardService) {
public aws: AwsService,private dashBoardService:DashboardService,private pushNotify:PushNotifyService) {
translate.addLangs(['en', 'fr']);
translate.setDefaultLang('en');
@ -30,6 +31,7 @@ export class AppComponent {
this.messagingService.receiveMessage()
this.message = this.messagingService.currentMessage
// this.alertForTAT()
this.pushNotify.requestPermission();
}
// alertForTAT(){

View File

@ -14,6 +14,7 @@ import { DashboardService } from '../../dashboard/dashboard.service';
import { AwsService } from '../../AwsService/aws.service';
import { RoleMenuItemsPipe } from './../role-menu-items.pipe';
import 'rxjs/add/observable/interval';
import { MessagingService } from 'app/shared/messaging.service';
@ -59,7 +60,7 @@ export class AdminLayoutComponent implements OnInit, OnDestroy {
alertTAT: any;
countTAT: number;
constructor(private router: Router, public menuItems: MenuItems, public horizontalMenuItems : HorizontalMenuItems, public translate: TranslateService,public aws:AwsService,public users:UserService,private _dashboardService: DashboardService) {
constructor(private router: Router, public menuItems: MenuItems, public horizontalMenuItems : HorizontalMenuItems, public translate: TranslateService,public aws:AwsService,public users:UserService,private _dashboardService: DashboardService,private messagingService:MessagingService) {
const browserLang: string = translate.getBrowserLang();
translate.use(browserLang.match(/en|fr/) ? browserLang : 'en');
@ -292,7 +293,10 @@ export class AdminLayoutComponent implements OnInit, OnDestroy {
this.aws.logout().subscribe(res=>{
//alert("res");
localStorage.removeItem('user_role');
this.messagingService.unsubscribeNotification()
setTimeout(()=>{
this.router.navigate(['/authentication/login']);
})
})
}
menunav(active){

View File

@ -518,6 +518,256 @@
<!-- </mat-form-field> -->
</div><br/>
</mat-card>
<mat-card *ngIf="lender_short_name == 'CHFPL'">
<mat-card-header><mat-card-title>Turnover validated during PD</mat-card-title></mat-card-header>
<mat-card-content>
<mat-form-field style="width:35%">
<mat-select placeholder="Is Turnover validated?" formControlName="is_turnover_validated"
(selectionChange)="turnoverValidatedValues($event.value)">
<mat-option value="yes">Yes</mat-option>
<mat-option value="no">No</mat-option>
</mat-select>
<mat-error align="end" *ngIf="financialForm.controls['is_turnover_validated'].hasError('required')">Is Turnover validated is required</mat-error>
</mat-form-field>
<div formArrayName="turnover_values">
<div *ngFor="let details of financialForm.controls.turnover_values['controls']; let i=index"
[formGroupName]="i">
<mat-card-content class="matcard">
<div style="width:100%">
<mat-form-field style="width:25%">
<input matInput autocomplete="off" placeholder="Annual Sales From"
formControlName="estimate_sales_from" (change)="calculateSalesAverage(i, details);"
OnlyNumber type="text">
<mat-hint align="start" style="font-size:90%" *ngIf="details.get('estimate_sales_from').value != ''">{{"&#8377;"}}
{{details.get('estimate_sales_from').value | numberToWords}}
Only</mat-hint>
</mat-form-field>
<mat-form-field style="width:25%">
<input matInput autocomplete="off" placeholder="Annual Sales To"
formControlName="estimate_sales_to" (change)="confirmAlert(i, details);"
OnlyNumber type="text">
<mat-hint align="start" style="font-size:90%" *ngIf="details.get('estimate_sales_to').value != ''">{{"&#8377;"}}
{{details.get('estimate_sales_to').value | numberToWords}} Only</mat-hint>
<!-- <input matInput autocomplete="off" placeholder="Annual Sales To"
formControlName="estimate_sales_to" (change)="confirmAlert(i, details);"
(keyup)="inWords($event,i,12)">
<mat-hint align="start" style="font-size:70%" *ngIf="details.get('estimate_sales_to').value != ''">{{"&#8377;"}}
{{AV_SalesToInwords[i]}} Only</mat-hint> -->
</mat-form-field>
<mat-form-field style="width:25%">
<input matInput autocomplete="off" placeholder="Considered Sales Average"
formControlName="estimate_sales_average" readonly>
<mat-hint align="start" style="font-size:90%" *ngIf="details.get('estimate_sales_average').value != ''">{{"&#8377;"}}
{{details.get('estimate_sales_average').value | numberToWords}}
Only</mat-hint>
<!-- <input matInput autocomplete="off" placeholder="Considered Sales Average"
formControlName="estimate_sales_average" readonly>
<mat-hint align="start" style="font-size:70%" *ngIf="details.get('estimate_sales_average').value != ''">{{"&#8377;"}}
{{AV_SalesInwords[i]}} Only</mat-hint> -->
</mat-form-field>
</div>
<div style="width:100%">
<mat-form-field style="width:39%">
<mat-select placeholder="Was there Net Profit or Net Loss?"
formControlName="estimate_profit_or_loss">
<mat-option value="1">Net Profit</mat-option>
<mat-option value="2">Net Loss</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field style="width:40%" *ngIf="details.get('estimate_profit_or_loss').value != '' ">
<mat-select placeholder="Is there Net Margin information Available?"
formControlName="estimate_net_margin_availablity">
<mat-option value="yes">Yes</mat-option>
<mat-option value="no">No</mat-option>
</mat-select>
</mat-form-field>
<div style="width:100%" *ngIf="details.get('estimate_profit_or_loss').value == 1 && details.get('estimate_net_margin_availablity').value == 'yes' ">
<mat-form-field style="width:25%">
<input matInput autocomplete="off" placeholder="Net Profit % From"
formControlName="estimate_profit_range_from" OnlyNumber
type="text" min='0' max='100' (change)="calculateMarginProfit( i, details);">
</mat-form-field>
<mat-form-field style="width:25%">
<input matInput autocomplete="off" placeholder="Net Profit % To"
formControlName="estimate_profit_range_to" OnlyNumber type="text"
min='0' max='100' (change)="calculateMarginProfit( i, details);">
</mat-form-field>
<mat-form-field style="width:25%">
<input matInput autocomplete="off" placeholder="Net Profit % Considered"
formControlName="estimate_profit_margin_percent" OnlyNumber
type="text" readonly>
<!-- <mat-hint align="start" style="font-size:70%" *ngIf="details.get('estimate_profit_margin').value != ''"> {{"&#8377;"}} {{AV_marginProfitAmtInwords[i]}} Only ( {{"&#8377;"}} {{details.get('estimate_profit_margin').value}} ) </mat-hint> -->
</mat-form-field>
<mat-form-field style="width:25%">
<input matInput placeholder="Net Profit Amount Considered"
formControlName="estimate_profit_margin" readonly>
<mat-hint align="start" style="font-size:90%" *ngIf="details.get('estimate_profit_margin').value != ''">{{"&#8377;"}}
{{details.get('estimate_profit_margin').value |
numberToWords}} Only</mat-hint>
<!-- <input matInput placeholder="Net Profit Amount Considered"
formControlName="estimate_profit_margin" readonly>
<mat-hint align="start" style="font-size:70%" *ngIf="details.get('estimate_profit_margin').value != ''">
{{"&#8377;"}} {{AV_marginProfitAmtInwords[i]}} Only
</mat-hint> -->
</mat-form-field>
</div>
<div style="width:100%" *ngIf="details.get('estimate_profit_or_loss').value == 1 && details.get('estimate_net_margin_availablity').value == 'no' ">
<mat-form-field style="width:25%">
<input matInput autocomplete="off" placeholder="Net Profit Amount From"
formControlName="estimate_net_profit_from" OnlyNumber type="text"
(change)="calculateProfitAmount(i, details);">
<mat-hint align="start" style="font-size:90%" *ngIf="details.get('estimate_net_profit_from').value != ''">{{"&#8377;"}}
{{details.get('estimate_net_profit_from').value |
numberToWords}} Only</mat-hint>
<!-- <input matInput autocomplete="off" placeholder="Net Profit Amount From"
formControlName="estimate_net_profit_from" OnlyNumber type="text"
(change)="calculateProfitAmount(i, details);" (keyup)="inWords($event,i,7)">
<mat-hint align="start" style="font-size:70%" *ngIf="details.get('estimate_net_profit_from').value != ''">{{"&#8377;"}}
{{AV_netProfitAmtFrmInwords[i]}} Only </mat-hint> -->
</mat-form-field>
<mat-form-field style="width:25%">
<input matInput autocomplete="off" placeholder="Net Profit Amount To"
formControlName="estimate_net_profit_to" OnlyNumber type="text"
(change)="calculateProfitAmount(i, details);">
<mat-hint align="start" style="font-size:90%" *ngIf="details.get('estimate_net_profit_to').value != ''">{{"&#8377;"}}
{{details.get('estimate_net_profit_to').value |
numberToWords}} Only</mat-hint>
<!-- <input matInput autocomplete="off" placeholder="Net Profit Amount To"
formControlName="estimate_net_profit_to" OnlyNumber type="text"
(change)="calculateProfitAmount(i, details);" (keyup)="inWords($event,i,8)">
<mat-hint align="start" style="font-size:70%" *ngIf="details.get('estimate_net_profit_to').value != ''">{{"&#8377;"}}
{{AV_netProfitAmtToInwords[i]}} Only </mat-hint> -->
</mat-form-field>
<mat-form-field style="width:25%">
<input matInput autocomplete="off" placeholder="Considered Net Profit % "
formControlName="estimate_net_profit_percent" readonly>
</mat-form-field>
<mat-form-field style="width:25%">
<input matInput placeholder="Considered Profit Amount"
formControlName="estimate_net_profit" readonly>
<mat-hint align="start" style="font-size:90%" *ngIf="details.get('estimate_net_profit').value != ''">{{"&#8377;"}}
{{details.get('estimate_net_profit').value |
numberToWords}} Only</mat-hint>
<!-- <input matInput autocomplete="off" placeholder="Considered Profit Amount"
formControlName="estimate_net_profit" OnlyNumber type="text"
readonly>
<mat-hint align="start" style="font-size:70%" *ngIf="details.get('estimate_net_profit').value != ''">{{"&#8377;"}}
{{AV_netProfitAmtInwords[i]}} Only </mat-hint> -->
</mat-form-field>
</div>
<div style="width:100%" *ngIf="details.get('estimate_profit_or_loss').value == 2 && details.get('estimate_net_margin_availablity').value == 'yes' ">
<mat-form-field style="width:25%">
<input matInput autocomplete="off" placeholder="Net Loss % From"
formControlName="estimate_loss_range_from" min='0' max='100'
OnlyNumber type="text" (change)="calculateMarginLoss( i, details);">
</mat-form-field>
<mat-form-field style="width:25%">
<input matInput autocomplete="off" placeholder="Net Loss % To"
formControlName="estimate_loss_range_to" min='0' max='100'
OnlyNumber type="text" (change)="calculateMarginLoss( i, details);">
</mat-form-field>
<mat-form-field style="width:25%">
<input matInput autocomplete="off" placeholder="Net Loss % Considered"
formControlName="estimate_loss_margin_percent" OnlyNumber
type="text" readonly>
</mat-form-field>
<mat-form-field style="width:25%">
<input matInput placeholder="Net Loss Amount Considered"
formControlName="estimate_loss_margin" readonly>
<mat-hint align="start" style="font-size:90%" *ngIf="details.get('estimate_loss_margin').value != ''">{{"&#8377;"}}
{{details.get('estimate_loss_margin').value |
numberToWords}} Only</mat-hint>
<!-- <input matInput placeholder="Net Loss Amount Considered"
formControlName="estimate_loss_margin" readonly>
<mat-hint align="start" style="font-size:70%" *ngIf="details.get('estimate_loss_margin').value != ''">{{"&#8377;"}}
{{AV_marginLossAmtInwords[i]}} Only </mat-hint> -->
</mat-form-field>
</div>
<div style="width:100%" *ngIf="details.get('estimate_profit_or_loss').value == 2 && details.get('estimate_net_margin_availablity').value == 'no' ">
<mat-form-field style="width:25%">
<input matInput autocomplete="off" placeholder="Net Loss Amount From"
formControlName="estimate_net_loss_from" OnlyNumber type="text"
(change)="calculateLossAmount(i, details);">
<mat-hint align="start" style="font-size:90%" *ngIf="details.get('estimate_net_loss_from').value != ''">{{"&#8377;"}}
{{details.get('estimate_net_loss_from').value |
numberToWords}} Only</mat-hint>
</mat-form-field>
<mat-form-field style="width:25%">
<input matInput autocomplete="off" placeholder="Net Loss Amount To"
formControlName="estimate_net_loss_to" OnlyNumber type="text"
(change)="calculateLossAmount(i, details);">
<mat-hint align="start" style="font-size:90%" *ngIf="details.get('estimate_net_loss_to').value != ''">{{"&#8377;"}}
{{details.get('estimate_net_loss_to').value |
numberToWords}} Only</mat-hint>
</mat-form-field>
<!-- <mat-form-field style="width:25%">
<mat-hint align="start" style="font-size:90%" *ngIf="details.get('estimate_net_loss_to').value != ''">{{"&#8377;"}}
{{details.get('estimate_net_loss_to').value |
numberToWords}} Only</mat-hint>
</mat-form-field> -->
<mat-form-field style="width:25%">
<input matInput autocomplete="off" placeholder="Considered Net Loss %"
formControlName="estimate_net_loss_percent" readonly>
</mat-form-field>
<mat-form-field style="width:25%">
<input matInput autocomplete="off" platurnover_validatedceholder="Considered Loss Amount"
formControlName="estimate_net_loss" OnlyNumber type="text">
<mat-hint align="start" style="font-size:90%" *ngIf="details.get('estimate_net_loss').value != ''">{{"&#8377;"}}
{{details.get('estimate_net_loss').value | numberToWords}}
Only</mat-hint>
<!-- <input matInput autocomplete="off" placeholder="Considered Loss Amount"
formControlName="estimate_net_loss" OnlyNumber type="text" readonly>
<mat-hint align="start" style="font-size:70%" *ngIf="details.get('estimate_net_loss').value != ''">{{"&#8377;"}}
{{AV_netLossAmtInwords[i]}} Only</mat-hint> -->
</mat-form-field>
</div>
<div style="width:100%" *ngIf="details.get('estimate_profit_or_loss').value == 2">
<mat-form-field style="width:83%">
<input matInput autocomplete="off" placeholder="What is the reason for the Loss?"
formControlName="estimate_reason_for_loss">
</mat-form-field>
</div>
<!-- <mat-form-field style="width:54%" *ngIf="lender_short_name == 'CLIX' && prod_catagory =='LAEP'">
<input matInput placeholder="Annual Sales through Credit Card / POS machines"
formControlName="estimate_posmachine_or_cc_annual_sales">
<mat-hint align="start" style="font-size:90%" *ngIf="details.get('estimate_posmachine_or_cc_annual_sales').value != ''">{{"&#8377;"}}
{{details.get('estimate_posmachine_or_cc_annual_sales').value | numberToWords}} Only</mat-hint>
</mat-form-field> -->
</div>
</mat-card-content>
</div>
</div>
<div *ngIf="financialForm.value.is_turnover_validated == 'yes'">
<mat-form-field style="width: 40%">
<mat-select placeholder="How was the turnover validated" formControlName="how_turnover_validated">
<mat-option>Select</mat-option>
<mat-option *ngFor="let val of turnover_validate_list" [value]="val.name">{{val.name}}</mat-option>
</mat-select>
<mat-error align="end" *ngIf="financialForm.controls['how_turnover_validated'].hasError('required')">How was the Turnover validated is required</mat-error>
</mat-form-field>
<mat-form-field style="width: 40%" *ngIf="financialForm.value.how_turnover_validated == 'Others'">
<input matInput type="text" autocomplete="off" placeholder="Please specify the turnover validated (Others)" formControlName="turnover_validated_others">
</mat-form-field>
</div>
</mat-card-content>
</mat-card>
</div>
</div>
<div fxLayout="row wrap">

View File

@ -31,6 +31,7 @@ import { ImageCropComponent } from '../dialogue/image-crop/image-crop.component'
styleUrls: ['./financial-info.component.scss']
})
export class FinancialInfoComponent implements OnInit {
customer_segment_abbr: any;
subproduct_abbr: any;
product_abbr: any;
@ -85,6 +86,20 @@ export class FinancialInfoComponent implements OnInit {
documentsAndFilesList: any = [];
image_doc_params: { pdid: string; form_id: number; company_id: string; };
prod_catagory: any;
turnover_validate_list:any=[{
id:2,
name:'Validated from Bills/Records'
},{
id:3,
name:'Validated from Business activities seen'
},{
id:4,
name:'Validated from Stock/Inventory seen'
},{
id:1,
name:'Others'
},
]
constructor(notifier: NotifierService,
private fb: FormBuilder,
@ -148,6 +163,13 @@ export class FinancialInfoComponent implements OnInit {
this.financialForm.addControl('customer_declared_turnover',new FormControl())
this.financialForm.addControl('kuccha_bill_allowed',new FormControl())
}
if(this.lender_short_name == 'CHFPL'){
this.financialForm.addControl('is_turnover_validated',new FormControl('yes',Validators.compose([Validators.required])))
this.financialForm.addControl('how_turnover_validated',new FormControl('',Validators.compose([Validators.required])))
this.financialForm.addControl('turnover_validated_others',new FormControl(''))
this.financialForm.addControl('turnover_values',this.fb.array([]))
this.turnoverValidatedValues('yes')
}
this._pd.getTypeofActivityForSuppliedInfoForm(this.pdid, this.company_id).subscribe(data => {
if (data.dataStatus) {
@ -299,6 +321,9 @@ export class FinancialInfoComponent implements OnInit {
retriveData.formid = this.form_id;
retriveData.company_id = this.company_id;
retriveData.fk_createdby = this.pdid;
if(this.lender_short_name == 'CHFPL'){
this.turnoverValidatedValues(retriveData.is_turnover_validated);
}
retriveData.hasOwnProperty('latest_year_financials_as_per_applicant_met') ? retriveData.latest_year_financials_as_per_applicant_met : retriveData.latest_year_financials_as_per_applicant_met=''
if(this.lender_short_name == "IIB"){
@ -312,7 +337,7 @@ export class FinancialInfoComponent implements OnInit {
retriveData.hasOwnProperty('customer_declared_turnover') ? retriveData.customer_declared_turnover : retriveData.customer_declared_turnover=''
retriveData.hasOwnProperty('kuccha_bill_allowed') ? retriveData.kuccha_bill_allowed : retriveData.kuccha_bill_allowed=''
}
this.financialForm.setValue(retriveData);
this.financialForm.patchValue(retriveData);
if(this.ServiceDataAvailability == false && retriveData.unsold_stock_lies_in_days == 'NA'){
this.financialForm.controls['unsold_stock_lies_in_days'].setValue('');
@ -412,11 +437,11 @@ export class FinancialInfoComponent implements OnInit {
/** CREATING financial Statement ( financial_year AutoGenerate ) */
createDate(date) {
return this.fb.group({
financial_year: [date, Validators.compose([Validators.pattern(/^[0-9]{4}-[0-9]{2}$/)])],
financial_year: [date],
financial_annual_sale: ['', Validators.compose([Validators.pattern(/^[0-9\(\)]+$/)])],
finanical_profit_or_loss:[''],
financial_net_profit: ['', Validators.compose([Validators.pattern(/^-?[1-9]\d*|0$/)])],
financial_net_loss: ['', Validators.compose([Validators.pattern(/^-?[1-9]\d*|0$/)])],
financial_net_profit: [''],//, Validators.compose([Validators.pattern(/^-?[1-9]\d*|0$/)])
financial_net_loss: [''],//, Validators.compose([Validators.pattern(/^-?[1-9]\d*|0$/)])
financial_margin_of_profit: [''],
financial_margin_of_loss: [''],
financial_variation: [''],
@ -735,6 +760,21 @@ export class FinancialInfoComponent implements OnInit {
control.push(this.createValue(''));
}
}
turnoverValidatedValues(e:string){
const control = <FormArray>this.financialForm.controls['turnover_values'];
if(e == 'no'){
while (control.length !== 0) {
control.removeAt(0);
}
this.financialForm.controls['how_turnover_validated'].clearValidators()
}
else if (e == 'yes' && control.length === 0){
control.push(this.createValue(''));
this.financialForm.controls['how_turnover_validated'].setValidators(Validators.required)
}
this.financialForm.controls['how_turnover_validated'].updateValueAndValidity();
}
/** old code Without foreach loop
* calculating Annual Sale for financial Statement
@ -1968,10 +2008,10 @@ export class FinancialInfoComponent implements OnInit {
this.financialForm.value.date_per_financial['financial_margin_of_loss'].updateValueAndValidity();
}
// if (!this.financialForm.valid) {
// this.notifier.notify('warning', 'Please Fill All Mandatory Fields.!');
// return;
// }
if (!this.financialForm.valid) {
this.notifier.notify('warning', 'Please Fill All Mandatory Fields.!');
return;
}
let records = this.financialForm.value;

View File

@ -13,6 +13,7 @@ import { CustomValidators } from 'ng2-validation';
import { MatDialog, MatDialogRef, MatDialogConfig } from '@angular/material';
import { CognitoService } from '../../AwsService/cognito.service';
import { MessagingService } from 'app/shared/messaging.service';
@Component({
selector: 'ms-login-session',
@ -41,7 +42,7 @@ export class LoginComponent implements OnInit{
};
constructor(
private router: Router, public aws: AwsService, public dialog: MatDialog,
public shared:CognitoService,) {
public shared:CognitoService,private messagingService:MessagingService) {
}
ngOnInit(){
@ -59,6 +60,7 @@ export class LoginComponent implements OnInit{
if (res !== undefined) {
// local storage for validate user access
localStorage.setItem('user_role',res.idToken.payload["custom:role_id"]);
this.initializeNotification()
this.router.navigate(['/home']);
}
}, err => {
@ -82,6 +84,7 @@ export class LoginComponent implements OnInit{
let auth = { 'Username': this.email, 'Password': this.password, 'newpassword': result };
this.aws.dologin(auth).subscribe(res => {
localStorage.setItem('user_role',res.idToken.payload["custom:role_id"]);
this.initializeNotification()
this.router.navigate(['/home']);
}, err => {
alert(err.message);
@ -113,6 +116,13 @@ export class LoginComponent implements OnInit{
return true;
}
}
initializeNotification(){
const userId = this.aws.getlocale();
this.messagingService.requestPermission(userId)
this.messagingService.receiveMessage()
let msg = this.messagingService.currentMessage
console.log("From Login",msg)
}
}

View File

@ -1,8 +1,8 @@
import { Injectable } from '@angular/core';
import { AngularFireDatabase } from '@angular/fire/database';
import { AngularFireDatabase, AngularFireList } from '@angular/fire/database';
import { AngularFireAuth } from '@angular/fire/auth';
import { AngularFireMessaging } from '@angular/fire/messaging';
import { mergeMapTo,catchError } from 'rxjs/operators';
import { mergeMapTo,catchError, mergeMap } from 'rxjs/operators';
import { take } from 'rxjs/operators';
import { BehaviorSubject, Observable, of } from 'rxjs'
import { HttpClient } from '@angular/common/http';
@ -10,18 +10,20 @@ import { HttpClient } from '@angular/common/http';
/** Environment */
import { environment } from 'environments/environment'
import { Router } from '@angular/router';
import { PushNotifyService } from './push-notify.service';
@Injectable()
export class MessagingService {
currentMessage = new BehaviorSubject(null);
public curr: AngularFireList<any>;
constructor(
private angularFireDB: AngularFireDatabase,
private angularFireAuth: AngularFireAuth,
private angularFireMessaging: AngularFireMessaging,
private http: HttpClient,
private router:Router) {
private router:Router,
private notify_service:PushNotifyService) {
this.angularFireMessaging.messaging.subscribe(
(_messaging) => {
_messaging.onMessage = _messaging.onMessage.bind(_messaging);
@ -85,8 +87,51 @@ export class MessagingService {
this.angularFireMessaging.messages.subscribe(
(payload) => {
console.log("new message received. ", payload);
let notify_param:any=[]
notify_param.push(payload['notification'])
this.notify_service.generateNotification(notify_param)
this.currentMessage.next(payload);
//this.router.navigate([''])
})
}
unsubscribeNotification1() {
this.angularFireMessaging.getToken.subscribe(res=>{
console.log("Deleting Token",res);
// console.log(this.angularFireDB.object('fcmTokens/'));
// console.log( this.angularFireDB.object('fcmTokens/'+res).remove())
// this.angularFireDB.object('fcmTokens/').remove().then(res=>{
// console.log("Token del",res)
// },err=>{
// console.log("new error",err);
// })
let subscribe=this.angularFireDB.object('/fcmTokens').snapshotChanges().subscribe()
subscribe.unsubscribe()
// this.curr=this.angularFireDB.list('/groups/');
// this.curr.snapshotChanges().subscribe(data=>{
// console.log(data);
// })
// // this.curr.unsubscribe();
// })
// const ll=this.angularFireDB.object('fcmTokens/')
// ll.unsubscribe
this.angularFireMessaging.deleteToken(res).subscribe(del=>{
console.log("Token Deleted",del)
},err=>{
console.log("Error Deleting the FCM Token",err)
})
},err=>{
console.log("Error getting the Token from FCM",err)
})
}
unsubscribeNotification() {
this.angularFireMessaging.getToken
.pipe(mergeMap(token => this.angularFireMessaging.deleteToken(token)))
.subscribe(
(token) => { console.log('Deleted!',token); },err=>{
console.log("Error while deleting token",err)
window.location.reload()
}
);
}
}

View File

@ -0,0 +1,12 @@
import { TestBed } from '@angular/core/testing';
import { PushNotifyService } from './push-notify.service';
describe('PushNotifyService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: PushNotifyService = TestBed.get(PushNotifyService);
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,87 @@
import { Injectable } from '@angular/core';
import {
Observable
} from 'rxjs/Observable';
@Injectable({
providedIn: 'root'
})
export class PushNotifyService {
public permission: Permission;
constructor() {
this.permission = this.isSupported() ? 'default' : 'denied';
}
public isSupported(): boolean {
return 'Notification' in window;
}
requestPermission(): void {
let self = this;
if ('Notification' in window) {
Notification.requestPermission(function(status) {
return self.permission = status;
});
}
}
create(title: string, options ? : PushNotification): any {
let self = this;
return new Observable(function(obs) {
if (!('Notification' in window)) {
console.log('Notifications are not available in this environment');
obs.complete();
}
if (self.permission !== 'granted') {
console.log("The user hasn't granted you permission to send push notifications");
obs.complete();
}
let _notify = new Notification(title, options);
_notify.onshow = function(e) {
return obs.next({
notification: _notify,
event: e
});
};
_notify.onclick = function(e) {
return obs.next({
notification: _notify,
event: e
});
};
_notify.onerror = function(e) {
return obs.error({
notification: _notify,
event: e
});
};
_notify.onclose = function() {
return obs.complete();
};
});
}
generateNotification(source: Array < any > ): void {
let self = this;
source.forEach((item) => {
let options = {
body: item.body,
icon: item.icon
};
let notify = self.create('', options).subscribe();
})
}
}
export declare type Permission = 'denied' | 'granted' | 'default';
export interface PushNotification {
body ? : string;
icon ? : string;
tag ? : string;
data ? : any;
renotify ? : boolean;
silent ? : boolean;
sound ? : string;
noscreen ? : boolean;
sticky ? : boolean;
dir ? : 'auto' | 'ltr' | 'rtl';
lang ? : string;
vibrate ? : number[];
}

View File

@ -3,7 +3,7 @@ export const environment = {
map_api_key:'AIzaSyA3lYDYxwtn5vLSl45SOKbtK7G6cEyXGr0',
environmentName: 'Testing Environment',//Test Environment.
apiEndpoint: 'https://demo.pdgenie.com/sparqtest/api/',
apiEndpoint: 'https://apitest.pdgenie.com/sparqtest/api/',
authorization: 'sparqvenba2018',
login_string: "cognito-idp.ap-south-1.amazonaws.com/ap-south-1_qQ85yQZJO",

View File

@ -11,7 +11,8 @@ export const environment = {
environmentName: 'Development Environment',//Localhost Environment.
// apiEndpoint: 'https://demo.pdgenie.com/sparqtest/api/',
apiEndpoint: 'https://demo.pdgenie.com/sparqapi/api/',
// apiEndpoint: 'https://demo.pdgenie.com/sparqapi/api/',
apiEndpoint:'https://apitest.pdgenie.com/sparqapi/api/',
authorization: 'sparqvenba2018',