From 64bf9a582b639ea8b563de6542a32d5bc3dbcec1 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Thu, 11 Apr 2024 12:52:07 +0300 Subject: [PATCH 1/2] add report service --- ui/src/app/app-routing.module.ts | 4 +++ ui/src/app/report/report.component.html | 7 ++++ ui/src/app/report/report.component.spec.ts | 40 ++++++++++++++++++++++ ui/src/app/report/report.component.ts | 38 ++++++++++++++++++++ ui/src/app/report/report.module.ts | 11 ++++++ ui/src/app/report/report.route.ts | 24 +++++++++++++ ui/src/app/report/report.scss | 4 +++ ui/src/app/report/report.service.ts | 14 ++++++++ 8 files changed, 142 insertions(+) create mode 100644 ui/src/app/report/report.component.html create mode 100644 ui/src/app/report/report.component.spec.ts create mode 100644 ui/src/app/report/report.component.ts create mode 100644 ui/src/app/report/report.module.ts create mode 100644 ui/src/app/report/report.route.ts create mode 100644 ui/src/app/report/report.scss create mode 100644 ui/src/app/report/report.service.ts diff --git a/ui/src/app/app-routing.module.ts b/ui/src/app/app-routing.module.ts index 5d6b04edd..9d6e2cd24 100644 --- a/ui/src/app/app-routing.module.ts +++ b/ui/src/app/app-routing.module.ts @@ -28,6 +28,10 @@ const routes: Routes = [ path: 'members', loadChildren: () => import('./member/member.module').then((m) => m.MemberModule), }, + { + path: 'report', + loadChildren: () => import('./report/report.module').then((m) => m.ReportModule), + }, ] @NgModule({ diff --git a/ui/src/app/report/report.component.html b/ui/src/app/report/report.component.html new file mode 100644 index 000000000..cabd3e285 --- /dev/null +++ b/ui/src/app/report/report.component.html @@ -0,0 +1,7 @@ +
+
+
+ +
+
+
diff --git a/ui/src/app/report/report.component.spec.ts b/ui/src/app/report/report.component.spec.ts new file mode 100644 index 000000000..02e806831 --- /dev/null +++ b/ui/src/app/report/report.component.spec.ts @@ -0,0 +1,40 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing' +import { ReportComponent } from './report.component' +import { ReportService } from './report.service' +import { ActivatedRoute } from '@angular/router' +import { of } from 'rxjs' +import { RouterTestingModule } from '@angular/router/testing' + +describe('ReportComponent', () => { + let component: ReportComponent + let fixture: ComponentFixture + let activatedRoute: jasmine.SpyObj + let reportService: jasmine.SpyObj + + beforeEach(async () => { + let reportServiceSpy = jasmine.createSpyObj('ReportService', ['getDashboardInfo']) + + await TestBed.configureTestingModule({ + declarations: [ReportComponent], + imports: [RouterTestingModule], + providers: [{ provide: ReportService, useValue: reportServiceSpy }], + }).compileComponents() + + activatedRoute = TestBed.inject(ActivatedRoute) as jasmine.SpyObj + reportService = TestBed.inject(ReportService) as jasmine.SpyObj + fixture = TestBed.createComponent(ReportComponent) + component = fixture.componentInstance + }) + + it('should create the component', () => { + expect(component).toBeTruthy() + }) + + it('should call reportService to get report data', () => { + activatedRoute.data = of({ reportType: 'test' }) + reportService.getDashboardInfo.and.returnValue(of({ url: 'url', jwt: 'jwt' })) + fixture.detectChanges() + + expect(reportService.getDashboardInfo).toHaveBeenCalled() + }) +}) diff --git a/ui/src/app/report/report.component.ts b/ui/src/app/report/report.component.ts new file mode 100644 index 000000000..2e2758208 --- /dev/null +++ b/ui/src/app/report/report.component.ts @@ -0,0 +1,38 @@ +import { Component, OnInit } from '@angular/core' +import { ReportService } from './report.service' +import { DomSanitizer } from '@angular/platform-browser' +import { ActivatedRoute } from '@angular/router' + +@Component({ + selector: 'app-report', + templateUrl: './report.component.html', + styleUrls: ['report.scss'], +}) +export class ReportComponent implements OnInit { + reportSrc: any + reportType: string | undefined + + constructor( + private reportService: ReportService, + private sanitizer: DomSanitizer, + private activatedRoute: ActivatedRoute + ) {} + + ngOnInit() { + this.activatedRoute.data.subscribe((data) => { + this.reportType = data['reportType'] + + if (this.reportType) { + this.reportService.getDashboardInfo(this.reportType).subscribe((res) => { + const url = res.url + const token = res.jwt + this.reportSrc = this.safeUrl(url + '?_token=' + token) + }) + } + }) + } + + safeUrl(url: string) { + return this.sanitizer.bypassSecurityTrustResourceUrl(url) + } +} diff --git a/ui/src/app/report/report.module.ts b/ui/src/app/report/report.module.ts new file mode 100644 index 000000000..9ca2654c0 --- /dev/null +++ b/ui/src/app/report/report.module.ts @@ -0,0 +1,11 @@ +import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core' +import { RouterModule } from '@angular/router' +import { ReportComponent } from './report.component' +import { REPORT_ROUTE } from './report.route' + +@NgModule({ + imports: [RouterModule.forChild([REPORT_ROUTE])], + declarations: [ReportComponent], + schemas: [CUSTOM_ELEMENTS_SCHEMA], +}) +export class ReportModule {} diff --git a/ui/src/app/report/report.route.ts b/ui/src/app/report/report.route.ts new file mode 100644 index 000000000..cc0dbe25f --- /dev/null +++ b/ui/src/app/report/report.route.ts @@ -0,0 +1,24 @@ +import { Injectable } from '@angular/core' +import { Resolve, ActivatedRouteSnapshot, Route, ResolveFn, RouterStateSnapshot } from '@angular/router' +import { Observable, of } from 'rxjs' +import { ReportComponent } from './report.component' + +export const ReportResolver: ResolveFn = ( + route: ActivatedRouteSnapshot, + state: RouterStateSnapshot +): Observable => { + const reportType = route.params['reportType'] ? route.params['reportType'] : null + return of(reportType) +} + +export const REPORT_ROUTE: Route = { + path: ':reportType', + component: ReportComponent, + resolve: { + reportType: ReportResolver, + }, + data: { + authorities: [], + pageTitle: 'gatewayApp.report.member.title.string', + }, +} diff --git a/ui/src/app/report/report.scss b/ui/src/app/report/report.scss new file mode 100644 index 000000000..74ba78f8c --- /dev/null +++ b/ui/src/app/report/report.scss @@ -0,0 +1,4 @@ +iframe { + width: 100%; + height: 1000px; +} diff --git a/ui/src/app/report/report.service.ts b/ui/src/app/report/report.service.ts new file mode 100644 index 000000000..435814b22 --- /dev/null +++ b/ui/src/app/report/report.service.ts @@ -0,0 +1,14 @@ +import { Injectable } from '@angular/core' +import { HttpClient, HttpResponse } from '@angular/common/http' +import { Observable } from 'rxjs' + +@Injectable({ providedIn: 'root' }) +export class ReportService { + public resourceUrl = '/services/memberservice/api/reports' + + constructor(protected http: HttpClient) {} + + getDashboardInfo(reportType: string): Observable<{ url: any; jwt: any }> { + return this.http.get<{ url: any; jwt: any }>(`${this.resourceUrl}/` + reportType) + } +} From 9b6350d3be7ae3ed5bc9dcce2e58d4d862d850fd Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Thu, 11 Apr 2024 12:53:09 +0300 Subject: [PATCH 2/2] lint --- ui/src/app/report/report.component.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/app/report/report.component.spec.ts b/ui/src/app/report/report.component.spec.ts index 02e806831..93134e30b 100644 --- a/ui/src/app/report/report.component.spec.ts +++ b/ui/src/app/report/report.component.spec.ts @@ -12,7 +12,7 @@ describe('ReportComponent', () => { let reportService: jasmine.SpyObj beforeEach(async () => { - let reportServiceSpy = jasmine.createSpyObj('ReportService', ['getDashboardInfo']) + const reportServiceSpy = jasmine.createSpyObj('ReportService', ['getDashboardInfo']) await TestBed.configureTestingModule({ declarations: [ReportComponent],