diff --git a/Mohem/src/app/app.component.ts b/Mohem/src/app/app.component.ts index 01c88780..fd62f41e 100644 --- a/Mohem/src/app/app.component.ts +++ b/Mohem/src/app/app.component.ts @@ -10,6 +10,9 @@ import { SMSCheckResponse } from "src/app/hmg-common/services/authentication/mod import { PushService } from '../../src/app/hmg-common/services/push/push.service'; import { LazyLoadingService } from "./hmg-common/services/lazy-loading/lazy-loading.service"; import { DomSanitizer } from '@angular/platform-browser'; +// import { SplashScreen } from '@ionic-native/splash-screen'; +import { SplashScreen } from '@ionic-native/splash-screen/ngx'; + @Component({ selector: "app-root", @@ -29,10 +32,12 @@ export class AppComponent implements OnInit, AfterViewInit { companyDesc: string = "Powered By Cloud Solutions"; public direction = "ltr"; User_Job_name: string; + public logoutFlage: any =false; requestGetLoginInfo: { DeviceType: string; DeviceToken: string; //this.deviceToken }; user: boolean; + deviceToken: string; constructor( public ts: TranslatorService, private cs: CommonService, @@ -43,7 +48,9 @@ export class AppComponent implements OnInit, AfterViewInit { private menu: MenuController, private authService: AuthenticationService, private sanitizer: DomSanitizer, - public pushService: PushService + public pushService: PushService, + private splashScreen: SplashScreen + ) { this.events.subscribe("img-change", displayImg => { console.log("app compont: "+displayImg); @@ -78,6 +85,11 @@ export class AppComponent implements OnInit, AfterViewInit { private startReceivingPushService() { console.log("platform.ready") this.pushService.startReceiving(); + setTimeout(() => { + + this.getLastLoginInfo(); + },5000); + } subscribeEvents() { this.events.subscribe("setMenu", () => { @@ -128,8 +140,14 @@ export class AppComponent implements OnInit, AfterViewInit { } logout() { this.cs.sharedService.clearAll(); - this.menu.toggle(); - this.cs.openLogin(); + //this.menu.toggle(); + this.menu.enable(false); + this.logoutFlage=true; + this.events.publish('logoutFlage', this.logoutFlage); + + this.getLastLoginInfo(); + // this.cs.openLogin(); + } // profile() { @@ -166,6 +184,70 @@ export class AppComponent implements OnInit, AfterViewInit { this.menu.toggle(); } + getLastLoginInfo(){ + this.deviceToken= localStorage.getItem('devicyeToken'); + console.log("let deviceToken app" + this.deviceToken); + + if (this.deviceToken) { + console.log('login enabled first time: ' + this.deviceToken); + } else { + console.log("no deviceToken" ); + + this.pushService.startReceiving(); + setTimeout(() => { + this.deviceToken= localStorage.getItem('deviceToken'); + console.log('login enabled second time: ' + this.deviceToken); + + }, 1000); + } + + + this.requestGetLoginInfo= { + DeviceType:this.cs.getDeviceType(),//'Android', + DeviceToken:this.deviceToken//"5ca8a69cf1804db55264c349edffb99b9d63acd9fa9b6b18956bcb2ad3f2ba36"//this.deviceToken + } + this.authService.getLoginInfo(this.requestGetLoginInfo,() => {}, this.ts.trPK('general', 'ok')).subscribe(res => { + + if (this.cs.validResponse(res)) { + + if(res.Mohemm_GetMobileLoginInfoList.length > 0){ + + this.cs.sharedService.setSharedData( + // res.Patient_SELECTDeviceIMEIbyIMEIList[0], + res.Mohemm_GetMobileLoginInfoList[0], + AuthenticationService.IMEI_USER_DATA + ); + this.user = true; + this.events.publish('user', this.user); + + this.splashScreen.hide(); + if(this.logoutFlage){ + this.cs.openLogin(); + + } + + } + else{ + this.user = false; + this.events.publish('user', this.user); + this.splashScreen.hide(); + if(this.logoutFlage){ + this.cs.openLogin(); + + } + + } + + + }else{ + // this.user = false; + // this.splashScreen.hide(); + // if(this.logoutFlage){ + // this.cs.openLogin(); + // } + } + }); + } } diff --git a/Mohem/src/app/authentication/login/login.component.ts b/Mohem/src/app/authentication/login/login.component.ts index 7442330d..aa8ad0a2 100644 --- a/Mohem/src/app/authentication/login/login.component.ts +++ b/Mohem/src/app/authentication/login/login.component.ts @@ -2,7 +2,7 @@ import { Component, OnInit, NgZone, OnDestroy } from "@angular/core"; import { CommonService } from "src/app/hmg-common/services/common/common.service"; import { AuthenticationService } from "src/app/hmg-common/services/authentication/authentication.service"; import { Router } from "@angular/router"; -import { AlertController, Platform } from "@ionic/angular"; +import { AlertController, Platform, Events } from "@ionic/angular"; import { TranslatorService } from "src/app/hmg-common/services/translator/translator.service"; import { CheckUserAuthenticationResponse } from "src/app/hmg-common/services/authentication/models/check-user-auth.response"; import { SmsReaderService } from "src/app/hmg-common/services/sms/sms-reader.service"; @@ -49,6 +49,8 @@ export class LoginComponent implements OnInit, OnDestroy { user: boolean =false; DeviceType: string; requestGetLoginInfo:any; + logoutFlage: boolean ; + getuser:any=""; constructor( public cs: CommonService, @@ -58,40 +60,89 @@ export class LoginComponent implements OnInit, OnDestroy { public ts: TranslatorService, public smsService: SmsReaderService, private faio: FingerprintAIO, + public events:Events, public ngZone: NgZone, public device: Device, public splash: SplashScreen, public sharedData: SharedDataService, public plt: Platform, public pushService: PushService - ) { } + ) { + this.events.subscribe("logoutFlage", logoutFlage => { + console.log("login compont logoutFlage: "+logoutFlage); + if(logoutFlage == true){ + console.log(" subscribe check logoutFlage: "+logoutFlage); + this.logoutFlage = logoutFlage; + localStorage.setItem('logoutFlage',logoutFlage); + } + }); + + this.getuser = this.cs.sharedService.getSharedData( + AuthenticationService.IMEI_USER_DATA, + false + ); + // alert(" this.getuser "+this.getuser); + if(this.getuser){ + this.user = true; + + } + else{ + this.user = false; + + } + } ngOnInit() { // this.deviceToken= this.cs.sharedService.getSharedData(AuthenticationService.DEVICE_TOKEN, false); // console.log("get deviceToken login"+ this.deviceToken) + + + // this.getuser = this.cs.sharedService.getSharedData( + // AuthenticationService.IMEI_USER_DATA, + // false + // ); + + // if(this.getuser){ + // console.log("this.getuser"+this.getuser); + // this.logoutFlage = true; + + // } + + this.events.subscribe("user", user => { + console.log("login compont: "+user); + this.user = user; + + }); + + + this.deviceToken= localStorage.getItem('devicyeToken'); - console.log("let deviceToken" + this.deviceToken); + console.log("let deviceToken" + this.deviceToken); if (this.deviceToken) { - console.log('login enabled first time: ' + this.deviceToken); + console.log('login enabled first time: ' + this.deviceToken); } else { console.log("no deviceToken" ); this.pushService.startReceiving(); setTimeout(() => { - this.deviceToken= localStorage.getItem('deviceToken'); - console.log('login enabled second time: ' + this.deviceToken); + // alert('login enabled second time: ' + this.deviceToken); }, 1000); } - setTimeout(() => { + // setTimeout(() => { + // alert("this.logoutFlage in setTime" +localStorage.getItem('logoutFlage')); + // alert("this.this.user in setTime" + this.user); + + // if(localStorage.getItem('logoutFlage')== "true"){ + // this.getLastLoginInfo(); - this.getLastLoginInfo(); - },5000); + // } + // },1000); @@ -355,12 +406,14 @@ export class LoginComponent implements OnInit, OnDestroy { getLastLoginInfo(){ this.requestGetLoginInfo= { - DeviceType:this.cs.getDeviceType(), + DeviceType:this.cs.getDeviceType(),//"Android",//this.cs.getDeviceType(), DeviceToken:this.deviceToken//"5ca8a69cf1804db55264c349edffb99b9d63acd9fa9b6b18956bcb2ad3f2ba36"//this.deviceToken } this.authService.getLoginInfo(this.requestGetLoginInfo,() => {}, this.ts.trPK('general', 'ok')).subscribe(res => { if (this.cs.validResponse(res)) { + if(res.Mohemm_GetMobileLoginInfoList.length > 0){ + this.cs.sharedService.setSharedData( // res.Patient_SELECTDeviceIMEIbyIMEIList[0], res.Mohemm_GetMobileLoginInfoList[0], diff --git a/Mohem/src/app/hmg-common/ui/welcome-login/welcome.component.ts b/Mohem/src/app/hmg-common/ui/welcome-login/welcome.component.ts index 31d50324..aa5abdec 100644 --- a/Mohem/src/app/hmg-common/ui/welcome-login/welcome.component.ts +++ b/Mohem/src/app/hmg-common/ui/welcome-login/welcome.component.ts @@ -87,7 +87,7 @@ export class WelcomeComponent implements OnInit, AfterViewInit, OnDestroy { false ); - console.log( this.user); + console.log( "this.user in welcome login"+ this.user); this.userName = localStorage.getItem("user"); this.password = localStorage.getItem("password"); diff --git a/Mohem/src/app/pipes/pipes.module.ts b/Mohem/src/app/pipes/pipes.module.ts index c754645c..3a3a580a 100644 --- a/Mohem/src/app/pipes/pipes.module.ts +++ b/Mohem/src/app/pipes/pipes.module.ts @@ -2,12 +2,13 @@ import { NgModule } from '@angular/core'; import { DateStringPipe } from './date-string/date-string'; import { FilterLangPipe } from './filter-lang/filter-lang'; import { TurncatePipe } from './turncate/turncate.pipe'; +import{ JsonDatePipe} from './json-date/json-date' @NgModule({ - declarations: [DateStringPipe, + declarations: [DateStringPipe,JsonDatePipe, FilterLangPipe, TurncatePipe], imports: [], exports: [DateStringPipe, - FilterLangPipe,TurncatePipe] + FilterLangPipe,TurncatePipe,JsonDatePipe] }) export class PipesModule {}