From c3e6b87430d5a98cf7ed1e12bc087eecab13141d Mon Sep 17 00:00:00 2001 From: Mayura Deshmukh Date: Mon, 29 Jan 2024 15:23:12 +0530 Subject: [PATCH 1/6] MOSIP-30409 added QA report Signed-off-by: Mayura Deshmukh --- src/app/app.constants.ts | 1 + src/app/core/services/data-service.ts | 5 ++++- .../project/view-project/view-project.component.ts | 2 +- .../features/test-run/test-run/test-run.component.ts | 10 +++++++--- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/app/app.constants.ts b/src/app/app.constants.ts index ef623f19..154ef236 100644 --- a/src/app/app.constants.ts +++ b/src/app/app.constants.ts @@ -95,6 +95,7 @@ export const REQUEST_ID = 'requestId'; export const BLANK_STRING = ""; export const UNDERSCORE = "_"; export const COMPLIANCE_COLLECTION = "compliance_collection"; +export const QUALITY_ASSESSMENT_COLLECTION = "quality_assessment_collection"; export const INCOMPLETE_STATUS = "incomplete"; export const COMPLETE_STATUS = "complete"; export const REPORT_STATUS_DRAFT = "draft"; diff --git a/src/app/core/services/data-service.ts b/src/app/core/services/data-service.ts index d2d4ecb5..2f3d5958 100644 --- a/src/app/core/services/data-service.ts +++ b/src/app/core/services/data-service.ts @@ -276,8 +276,11 @@ export class DataService { return this.httpClient.post(url, body); } - generateDraftReport(body: any) { + generateDraftReport(body: any, isComplianceReport: boolean) { let url = `${this.SERVICES_BASE_URL}generateDraftReport`; + if (!isComplianceReport) { + url = `${this.SERVICES_BASE_URL}generateDraftQAReport`; + } return this.httpClient.post(url, body, { responseType: 'blob' }); } diff --git a/src/app/features/project/view-project/view-project.component.ts b/src/app/features/project/view-project/view-project.component.ts index 25191012..01f194e4 100644 --- a/src/app/features/project/view-project/view-project.component.ts +++ b/src/app/features/project/view-project/view-project.component.ts @@ -194,7 +194,7 @@ export class ViewProjectComponent implements OnInit { let tableData = []; for (let item of respArr) { let disableReportBtn = true; - if (appConstants.COMPLIANCE_COLLECTION == item.collectionType) { + if (appConstants.COMPLIANCE_COLLECTION == item.collectionType || appConstants.QUALITY_ASSESSMENT_COLLECTION == item.collectionType ) { try { let check = await Utils.isReportAlreadySubmitted(this.projectType, this.projectId, item.collectionId, this.dataService, this.resourceBundleJson, this.dialog); if (check) { diff --git a/src/app/features/test-run/test-run/test-run.component.ts b/src/app/features/test-run/test-run/test-run.component.ts index 27b75431..979ce125 100644 --- a/src/app/features/test-run/test-run/test-run.component.ts +++ b/src/app/features/test-run/test-run/test-run.component.ts @@ -122,7 +122,7 @@ export class TestRunComponent implements OnInit { this.isAdmin, this.partnerId, this.collectionId, this.resourceBundleJson, this.dialog); await this.getTestRun(); //enable download report button only for compliance collection - if (appConstants.COMPLIANCE_COLLECTION == this.collectionType) { + if (appConstants.COMPLIANCE_COLLECTION == this.collectionType || appConstants.QUALITY_ASSESSMENT_COLLECTION == this.collectionType) { let isReportAlreadySubmitted = await Utils.isReportAlreadySubmitted(this.projectType, this.projectId, this.collectionId, this.dataService, this.resourceBundleJson, this.dialog); if (!isReportAlreadySubmitted) { this.showGenerateReportBtn = true; @@ -359,7 +359,6 @@ export class TestRunComponent implements OnInit { return ""; } } - getProjectName() { let name = ""; if (this.sbiProjectData) @@ -385,7 +384,12 @@ export class TestRunComponent implements OnInit { requesttime: new Date().toISOString(), request: reportRequest }; - const subs = this.dataService.generateDraftReport(request).subscribe( + let isComplianceReport = true; + if (appConstants.QUALITY_ASSESSMENT_COLLECTION == this.collectionType) { + isComplianceReport = false; + + } + const subs = this.dataService.generateDraftReport(request, isComplianceReport).subscribe( (res: any) => { this.dataLoaded = true; if (res) { From 091f694e8569b44a7cd11d617b49b9f1ed5f4a81 Mon Sep 17 00:00:00 2001 From: Mayura Deshmukh Date: Mon, 29 Jan 2024 15:34:50 +0530 Subject: [PATCH 2/6] added chk Signed-off-by: Mayura Deshmukh --- .../test-run/test-run-history/test-run-history.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/features/test-run/test-run-history/test-run-history.component.ts b/src/app/features/test-run/test-run-history/test-run-history.component.ts index f58b9205..4778c1f0 100644 --- a/src/app/features/test-run/test-run-history/test-run-history.component.ts +++ b/src/app/features/test-run/test-run-history/test-run-history.component.ts @@ -70,7 +70,7 @@ export class TestRunHistoryComponent implements OnInit { const collectionRes = await Utils.getCollectionNameAndType(this.subscriptions, this.dataService, this.collectionId, this.resourceBundleJson, this.dialog); this.collectionName = collectionRes.name; const collectionType = collectionRes.type; - if (appConstants.COMPLIANCE_COLLECTION == collectionType) { + if (appConstants.COMPLIANCE_COLLECTION == collectionType|| appConstants.QUALITY_ASSESSMENT_COLLECTION == collectionType) { this.deleteAllowed = false; } if (this.projectType == appConstants.SBI) { From 1ea95cba11aaa9806907518593db604fd5334272 Mon Sep 17 00:00:00 2001 From: Mayura Deshmukh Date: Fri, 2 Feb 2024 13:58:21 +0530 Subject: [PATCH 3/6] MOSIP-31380 updated UI tooltip Signed-off-by: Mayura Deshmukh --- .../project/view-project/view-project.component.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/features/project/view-project/view-project.component.html b/src/app/features/project/view-project/view-project.component.html index 8808bb49..586804fd 100644 --- a/src/app/features/project/view-project/view-project.component.html +++ b/src/app/features/project/view-project/view-project.component.html @@ -651,17 +651,17 @@ From 5bfa9160638a50874236428f2ed4bd4d69479415 Mon Sep 17 00:00:00 2001 From: Mayura Deshmukh Date: Fri, 8 Mar 2024 18:25:42 +0530 Subject: [PATCH 4/6] MOSIP-27524 added Landing Page in UI framework Signed-off-by: Mayura Deshmukh --- src/app/app-config.service.ts | 2 +- src/app/app-routing.module.ts | 57 +++++--------- src/app/app.component.html | 1 - src/app/app.component.ts | 58 +------------- src/app/app.module.ts | 15 +++- .../landing-page/landing-page.component.css | 0 .../landing-page/landing-page.component.html | 10 +++ .../landing-page.component.spec.ts | 25 +++++++ .../landing-page/landing-page.component.ts | 39 ++++++++++ src/app/main-app/main-app-routing.module.ts | 50 +++++++++++++ src/app/main-app/main-app.component.css | 0 src/app/main-app/main-app.component.html | 2 + src/app/main-app/main-app.component.spec.ts | 25 +++++++ src/app/main-app/main-app.component.ts | 75 +++++++++++++++++++ src/app/main-app/main-app.module.ts | 14 ++++ 15 files changed, 270 insertions(+), 103 deletions(-) create mode 100644 src/app/landing-page/landing-page.component.css create mode 100644 src/app/landing-page/landing-page.component.html create mode 100644 src/app/landing-page/landing-page.component.spec.ts create mode 100644 src/app/landing-page/landing-page.component.ts create mode 100644 src/app/main-app/main-app-routing.module.ts create mode 100644 src/app/main-app/main-app.component.css create mode 100644 src/app/main-app/main-app.component.html create mode 100644 src/app/main-app/main-app.component.spec.ts create mode 100644 src/app/main-app/main-app.component.ts create mode 100644 src/app/main-app/main-app.module.ts diff --git a/src/app/app-config.service.ts b/src/app/app-config.service.ts index 9c4de8a9..b76b3876 100644 --- a/src/app/app-config.service.ts +++ b/src/app/app-config.service.ts @@ -11,7 +11,7 @@ export class AppConfigService { constructor(private http: HttpClient) { } async loadAppConfig() { - //console.log('loadAppConfig'); + console.log('loadAppConfig'); this.appConfig = await this.http.get('./assets/config.json').toPromise(); const isAndroidAppMode = environment.isAndroidAppMode == 'yes' ? true : false; if (isAndroidAppMode) { diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 78bf5dc6..6c352075 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -1,47 +1,24 @@ import { NgModule } from '@angular/core'; import { Routes, RouterModule, PreloadAllModules } from '@angular/router'; -import { MainLayoutComponent } from './core/components/main-layout/main-layout.component'; -import { AuthguardService } from './core/services/authguard.service'; - +import { LandingPageComponent } from './landing-page/landing-page.component'; +import { environment } from 'src/environments/environment'; const routes: Routes = [ - { path: '', redirectTo: 'toolkit', pathMatch: 'full' }, { - path: 'toolkit', - component: MainLayoutComponent, - data: { - breadcrumb: { - alias: 'homeBreadCrumb', - }, - }, - children: [ - { path: '', redirectTo: 'dashboard', pathMatch: 'full' }, - { - path: 'dashboard', - data: { breadcrumb: { label: 'dashboard', skip: true } }, - loadChildren: () => - import('./features/dashboard/dashboard.module').then( - (m) => m.DashboardModule - ), - }, - { - path: 'project', - data: { breadcrumb: { label: 'Project', skip: true } }, - loadChildren: () => - import('./features/project/project.module').then( - (m) => m.ProjectModule - ), - }, - { - path: 'biometrics', - data: { breadcrumb: { label: 'Biometrics', skip: true } }, - loadChildren: () => - import('./features/test-data/test-data.module').then( - (m) => m.TestDataModule - ), - }, - ], - canActivateChild: [AuthguardService], + path: '', + redirectTo: environment.isAndroidAppMode == 'yes' ? 'toolkit' : 'landing', pathMatch: 'full', + }, + { + path: 'landing', + component: + LandingPageComponent, pathMatch: 'full', }, + { + path: 'toolkit', + loadChildren: () => + import('./main-app/main-app.module').then( + (m) => m.MainAppModule + ) + } ]; @NgModule({ @@ -55,4 +32,4 @@ const routes: Routes = [ ], exports: [RouterModule], }) -export class AppRoutingModule {} +export class AppRoutingModule { } diff --git a/src/app/app.component.html b/src/app/app.component.html index f7d36943..aedcdf3b 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,3 +1,2 @@ -

Loading...

diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 31aaca0e..3575e4e2 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,16 +1,4 @@ -import { Component, OnInit, OnDestroy, HostListener } from '@angular/core'; -import { - RouterEvent, - NavigationStart, - NavigationEnd, - NavigationCancel, - NavigationError, - Router -} from '@angular/router'; -import { filter } from 'rxjs'; -import { AppConfigService } from './app-config.service'; -import { SessionLogoutService } from './core/services/session-logout.service'; -import { Subscription } from 'rxjs'; +import { Component } from '@angular/core'; @Component({ selector: 'app-root', @@ -21,57 +9,13 @@ export class AppComponent { title = 'mosip-compliance-toolkit-ui'; - loading = true; - - subscribed: any; - - subscriptions: Subscription[] = []; - - constructor( - private router: Router, - private appConfigService: AppConfigService, - private sessionLogoutService: SessionLogoutService ) { - this.subscribed = router.events.subscribe(event => { - this.navigationInterceptor(event); - }); - } ngOnInit() { - this.subscriptions.push(this.sessionLogoutService.currentMessageAutoLogout.subscribe(() => { })); - this.sessionLogoutService.changeMessage({ timerFired: false }); - } - - navigationInterceptor(event: any): void { - if (event instanceof NavigationStart) { - //console.log("NavigationStart"); - this.loading = true; - } - if (event instanceof NavigationEnd) { - //console.log("NavigationEnd"); - this.loading = false; - } - - // Set loading state to false in both of the below events to hide the spinner in case a request fails - if (event instanceof NavigationCancel) { - this.loading = false; - } - if (event instanceof NavigationError) { - this.loading = false; - } } - - @HostListener('keypress') - @HostListener('document:mousedown', ['$event']) - @HostListener('document:keypress', ['$event']) - onMouseClick() { - this.sessionLogoutService.setisActive(true); - } - ngOnDestroy(): void { - this.subscriptions.forEach(subscription => subscription.unsubscribe()); } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 45b995be..c7909edd 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -5,11 +5,15 @@ import { AppRoutingModule } from './app-routing.module'; import { I18nModule } from './i18n.module'; import { AppComponent } from './app.component'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { CoreModule } from './core/core.module'; import { MaterialModule } from './core/material.module'; import { CookieService } from 'ngx-cookie-service'; import { FormsModule, ReactiveFormsModule } from "@angular/forms"; import {MatTabsModule} from '@angular/material/tabs'; +import { LandingPageComponent } from './landing-page/landing-page.component'; +import { HttpClientModule } from '@angular/common/http'; +import { RouterModule } from '@angular/router'; +import { AuthService } from './core/services/authservice.service'; +import { AuthguardService } from './core/services/authguard.service'; const appInitialization = (appConfig: AppConfigService) => { return () => { @@ -18,20 +22,23 @@ const appInitialization = (appConfig: AppConfigService) => { }; @NgModule({ - declarations: [AppComponent], + declarations: [AppComponent, LandingPageComponent], imports: [ BrowserModule, + RouterModule, AppRoutingModule, BrowserAnimationsModule, - CoreModule, MaterialModule, FormsModule, ReactiveFormsModule, I18nModule, - MatTabsModule + MatTabsModule, + HttpClientModule ], providers: [ CookieService, + AuthService, + AuthguardService, AppConfigService, { provide: APP_INITIALIZER, diff --git a/src/app/landing-page/landing-page.component.css b/src/app/landing-page/landing-page.component.css new file mode 100644 index 00000000..e69de29b diff --git a/src/app/landing-page/landing-page.component.html b/src/app/landing-page/landing-page.component.html new file mode 100644 index 00000000..cf5a24f3 --- /dev/null +++ b/src/app/landing-page/landing-page.component.html @@ -0,0 +1,10 @@ + +
+

This is a dummy landing page!

+ +
+
+Loading.. +
diff --git a/src/app/landing-page/landing-page.component.spec.ts b/src/app/landing-page/landing-page.component.spec.ts new file mode 100644 index 00000000..373a2292 --- /dev/null +++ b/src/app/landing-page/landing-page.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { LandingPageComponent } from './landing-page.component'; + +describe('LandingPageComponent', () => { + let component: LandingPageComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ LandingPageComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(LandingPageComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/landing-page/landing-page.component.ts b/src/app/landing-page/landing-page.component.ts new file mode 100644 index 00000000..f10d70a1 --- /dev/null +++ b/src/app/landing-page/landing-page.component.ts @@ -0,0 +1,39 @@ +import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; +import { HttpClient } from '@angular/common/http'; +import { AppConfigService } from '../app-config.service'; + +@Component({ + selector: 'app-landing-page', + templateUrl: './landing-page.component.html', + styleUrls: ['./landing-page.component.css'] +}) +export class LandingPageComponent implements OnInit { + showLandingPage = false; + constructor(private router: Router, private http: HttpClient, private appConfigService: AppConfigService,) { } + + async ngOnInit() { + this.showLandingPage = false; + this.http + .get( + `${this.appConfigService.getConfig().SERVICES_BASE_URL + }authorize/admin/validateToken` + ).subscribe(async (res: any) => { + console.log(res); + if (res && res.errors.length == 0) { + await this.router.navigateByUrl(`toolkit`); + } else { + this.showLandingPage = true; + } + }, + (errors) => { + this.showLandingPage = true; + } + ); + + } + + async doLogin() { + await this.router.navigate([`toolkit`]); + } +} diff --git a/src/app/main-app/main-app-routing.module.ts b/src/app/main-app/main-app-routing.module.ts new file mode 100644 index 00000000..f5cb9d70 --- /dev/null +++ b/src/app/main-app/main-app-routing.module.ts @@ -0,0 +1,50 @@ +import { NgModule } from '@angular/core'; +import { Routes, RouterModule, PreloadAllModules } from '@angular/router'; +import { MainLayoutComponent } from '../core/components/main-layout/main-layout.component'; +import { AuthguardService } from '../core/services/authguard.service'; + +const routes: Routes = [ + { + path: '', + component: MainLayoutComponent, + data: { + breadcrumb: { + alias: 'homeBreadCrumb', + }, + }, + children: [ + { path: '', redirectTo: 'dashboard' }, + { + path: 'dashboard', + data: { breadcrumb: { label: 'dashboard', skip: true } }, + loadChildren: () => + import('../features/dashboard/dashboard.module').then( + (m) => m.DashboardModule + ), + }, + { + path: 'project', + data: { breadcrumb: { label: 'Project', skip: true } }, + loadChildren: () => + import('../features/project/project.module').then( + (m) => m.ProjectModule + ), + }, + { + path: 'biometrics', + data: { breadcrumb: { label: 'Biometrics', skip: true } }, + loadChildren: () => + import('../features/test-data/test-data.module').then( + (m) => m.TestDataModule + ), + }, + ], + canActivateChild: [AuthguardService], + }, +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule], +}) +export class MainAppRoutingModule {} diff --git a/src/app/main-app/main-app.component.css b/src/app/main-app/main-app.component.css new file mode 100644 index 00000000..e69de29b diff --git a/src/app/main-app/main-app.component.html b/src/app/main-app/main-app.component.html new file mode 100644 index 00000000..cd1aafc8 --- /dev/null +++ b/src/app/main-app/main-app.component.html @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/src/app/main-app/main-app.component.spec.ts b/src/app/main-app/main-app.component.spec.ts new file mode 100644 index 00000000..c1d69686 --- /dev/null +++ b/src/app/main-app/main-app.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { MainAppComponent } from './main-app.component'; + +describe('MainAppComponent', () => { + let component: MainAppComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ MainAppComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(MainAppComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/main-app/main-app.component.ts b/src/app/main-app/main-app.component.ts new file mode 100644 index 00000000..c7292bab --- /dev/null +++ b/src/app/main-app/main-app.component.ts @@ -0,0 +1,75 @@ +import { Component, HostListener } from '@angular/core'; +import { + NavigationStart, + NavigationEnd, + NavigationCancel, + NavigationError, + Router +} from '@angular/router'; +import { AppConfigService } from '../app-config.service'; +import { SessionLogoutService } from '../core/services/session-logout.service'; +import { Subscription } from 'rxjs'; + +@Component({ + selector: 'main-app-root', + templateUrl: './main-app.component.html', + styleUrls: ['./main-app.component.css'], +}) +export class MainAppComponent { + + title = 'mosip-compliance-toolkit-ui'; + + loading = true; + + subscribed: any; + + subscriptions: Subscription[] = []; + + + constructor( + private router: Router, + private appConfigService: AppConfigService, + private sessionLogoutService: SessionLogoutService + + ) { + this.subscribed = router.events.subscribe(event => { + this.navigationInterceptor(event); + }); + + } + + ngOnInit() { + this.subscriptions.push(this.sessionLogoutService.currentMessageAutoLogout.subscribe(() => { })); + this.sessionLogoutService.changeMessage({ timerFired: false }); + } + + navigationInterceptor(event: any): void { + if (event instanceof NavigationStart) { + //console.log("NavigationStart"); + this.loading = true; + } + if (event instanceof NavigationEnd) { + //console.log("NavigationEnd"); + this.loading = false; + } + + // Set loading state to false in both of the below events to hide the spinner in case a request fails + if (event instanceof NavigationCancel) { + this.loading = false; + } + if (event instanceof NavigationError) { + this.loading = false; + } + } + + @HostListener('keypress') + @HostListener('document:mousedown', ['$event']) + @HostListener('document:keypress', ['$event']) + onMouseClick() { + this.sessionLogoutService.setisActive(true); + } + + ngOnDestroy(): void { + this.subscriptions.forEach(subscription => subscription.unsubscribe()); + } +} diff --git a/src/app/main-app/main-app.module.ts b/src/app/main-app/main-app.module.ts new file mode 100644 index 00000000..c8c9c3e2 --- /dev/null +++ b/src/app/main-app/main-app.module.ts @@ -0,0 +1,14 @@ +import { NgModule } from '@angular/core'; +import { CoreModule } from '../core/core.module'; +import { MainAppComponent } from './main-app.component'; +import { MainAppRoutingModule } from './main-app-routing.module'; + +@NgModule({ + declarations: [MainAppComponent], + imports: [ + MainAppRoutingModule, + CoreModule, + ], + bootstrap: [MainAppComponent], +}) +export class MainAppModule { } From f74d8a417369805f2540f14aa3f0f856f07c2002 Mon Sep 17 00:00:00 2001 From: Mayura Deshmukh Date: Mon, 11 Mar 2024 12:05:02 +0530 Subject: [PATCH 5/6] added await Signed-off-by: Mayura Deshmukh --- src/app/landing-page/landing-page.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/landing-page/landing-page.component.ts b/src/app/landing-page/landing-page.component.ts index f10d70a1..7d9f060a 100644 --- a/src/app/landing-page/landing-page.component.ts +++ b/src/app/landing-page/landing-page.component.ts @@ -14,7 +14,7 @@ export class LandingPageComponent implements OnInit { async ngOnInit() { this.showLandingPage = false; - this.http + await this.http .get( `${this.appConfigService.getConfig().SERVICES_BASE_URL }authorize/admin/validateToken` From b65966c26dad810ff6ae00dc170d57292351e40e Mon Sep 17 00:00:00 2001 From: Mayura Deshmukh Date: Mon, 11 Mar 2024 12:57:21 +0530 Subject: [PATCH 6/6] await issue Signed-off-by: Mayura Deshmukh --- .../landing-page/landing-page.component.ts | 54 +++++++++++++------ 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/src/app/landing-page/landing-page.component.ts b/src/app/landing-page/landing-page.component.ts index 7d9f060a..2278d3bd 100644 --- a/src/app/landing-page/landing-page.component.ts +++ b/src/app/landing-page/landing-page.component.ts @@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { HttpClient } from '@angular/common/http'; import { AppConfigService } from '../app-config.service'; +import { Subscription } from 'rxjs'; @Component({ selector: 'app-landing-page', @@ -10,30 +11,51 @@ import { AppConfigService } from '../app-config.service'; }) export class LandingPageComponent implements OnInit { showLandingPage = false; + subscriptions: Subscription[] = []; + constructor(private router: Router, private http: HttpClient, private appConfigService: AppConfigService,) { } async ngOnInit() { this.showLandingPage = false; - await this.http - .get( - `${this.appConfigService.getConfig().SERVICES_BASE_URL - }authorize/admin/validateToken` - ).subscribe(async (res: any) => { - console.log(res); - if (res && res.errors.length == 0) { - await this.router.navigateByUrl(`toolkit`); - } else { - this.showLandingPage = true; - } - }, - (errors) => { - this.showLandingPage = true; - } - ); + console.log(`LandingPageComponent: ngOnInit: this.showLandingPage : ${this.showLandingPage}`); + let flag = await this.isUserAuthenticated(); + if (flag) { + await this.router.navigateByUrl(`toolkit`); + } + console.log(`LandingPageComponent: ngOnInit: complete`); + } + async isUserAuthenticated() { + return new Promise((resolve, reject) => { + this.subscriptions.push( + this.http.get(`${this.appConfigService.getConfig().SERVICES_BASE_URL + }authorize/admin/validateToken`).subscribe( + (res: any) => { + console.log(res); + if (res && res.errors && res.errors.length == 0) { + console.log(`LandingPageComponent: redirecting to toolkit`); + resolve(true); + } else { + console.log(`LandingPageComponent: redirecting to landing`); + this.showLandingPage = true; + resolve(false); + } + }, + (errors) => { + this.showLandingPage = true; + console.log(`LandingPageComponent: errors: this.showLandingPage : ${this.showLandingPage}`); + resolve(false); + } + ) + ); + }); } async doLogin() { await this.router.navigate([`toolkit`]); } + + ngOnDestroy(): void { + this.subscriptions.forEach((subscription) => subscription.unsubscribe()); + } }