Skip to content

Commit

Permalink
Merge pull request #1155 from ORCID/reports
Browse files Browse the repository at this point in the history
Reports
  • Loading branch information
bobcaprice authored Apr 11, 2024
2 parents 33928ff + 9b6350d commit 966e123
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ui/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
7 changes: 7 additions & 0 deletions ui/src/app/report/report.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="row">
<div class="col-md-12">
<div>
<iframe *ngIf="reportSrc" [src]="reportSrc"></iframe>
</div>
</div>
</div>
40 changes: 40 additions & 0 deletions ui/src/app/report/report.component.spec.ts
Original file line number Diff line number Diff line change
@@ -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<ReportComponent>
let activatedRoute: jasmine.SpyObj<ActivatedRoute>
let reportService: jasmine.SpyObj<ReportService>

beforeEach(async () => {
const 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<ActivatedRoute>
reportService = TestBed.inject(ReportService) as jasmine.SpyObj<ReportService>
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()
})
})
38 changes: 38 additions & 0 deletions ui/src/app/report/report.component.ts
Original file line number Diff line number Diff line change
@@ -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)
}
}
11 changes: 11 additions & 0 deletions ui/src/app/report/report.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}
24 changes: 24 additions & 0 deletions ui/src/app/report/report.route.ts
Original file line number Diff line number Diff line change
@@ -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<string | null> = (
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<string | null> => {
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',
},
}
4 changes: 4 additions & 0 deletions ui/src/app/report/report.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
iframe {
width: 100%;
height: 1000px;
}
14 changes: 14 additions & 0 deletions ui/src/app/report/report.service.ts
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 966e123

Please sign in to comment.