File

angular/projects/researchdatabox/portal-ng-common/src/lib/report.service.ts

Description

Report Service

Author: Shilo B

Extends

HttpClientService

Index

Properties
Methods

Constructor

constructor(http: HttpClient, rootContext: string, utilService: UtilityService, configService: ConfigService, loggerService: LoggerService)
Parameters :
Name Type Optional
http HttpClient No
rootContext string No
utilService UtilityService No
configService ConfigService No
loggerService LoggerService No

Methods

Public Async getReportConfig
getReportConfig(name: string)

Method to retrieve the report configuration.

Note: this is currently using the /admin endpoint

Parameters :
Name Type Optional
name string No
Returns : Promise<any>
Public Async getReportResult
getReportResult(name: string, pageNum: number, params: any, rows: number)

Retrieves the ReportsResult page

Parameters :
Name Type Optional Default value
name string No
pageNum number No
params any No
rows number No 10
Returns : Promise<any>
Protected enableCsrfHeader
enableCsrfHeader()
Inherited from HttpClientService

Call from extending class to enable CSRF in the header

Returns : void
Public getConfig
getConfig()
Inherited from HttpClientService

Returns the config block

Returns : any
Public getInitSubject
getInitSubject()
Inherited from HttpClientService
Returns : Subject<any>
Public isInitializing
isInitializing()
Inherited from HttpClientService

Default checks if we've loaded the config. Extensions can add more conditions as needed.

Returns : boolean

true if service is ready

Public Async waitForInit
waitForInit()
Inherited from HttpClientService

Returns itself when all dependent services/components/data is/are available.

Returns : Promise<any>

itself

Properties

Public rootContext
Type : string
Decorators :
@Inject(APP_BASE_HREF)
Inherited from HttpClientService
Public baseUrl
Type : string
Inherited from HttpClientService
Public baseUrlWithContext
Type : string
Inherited from HttpClientService
Public brandingAndPortalUrl
Type : string
Inherited from HttpClientService
Protected config
Type : any
Inherited from HttpClientService
Protected httpContext
Type : HttpContext
Default value : null as any
Inherited from HttpClientService
Protected initSubject
Type : any
Inherited from HttpClientService
Protected reqOptsJsonBodyOnly
Type : any
Default value : {responseType: 'json', observe: 'body'}
Inherited from HttpClientService
import { Injectable, Inject } from '@angular/core';
import { APP_BASE_HREF } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import { map, firstValueFrom } from 'rxjs';
import { isEmpty as _isEmpty } from 'lodash-es';
import { HttpClientService } from './httpClient.service';
import { ConfigService } from './config.service';
import { UtilityService } from './utility.service';
import { LoggerService } from './logger.service';
import { ReportDto, ReportResultDto } from '@researchdatabox/sails-ng-common';

/**
 * Report Service
 * 
 * Author: <a href='https://github.com/shilob' target='_blank'>Shilo B</a>
 */
@Injectable()
export class ReportService extends HttpClientService {
  constructor(
    @Inject(HttpClient) protected override http: HttpClient, 
    @Inject(APP_BASE_HREF) public override rootContext: string,
    @Inject(UtilityService) protected override utilService: UtilityService,
    @Inject(ConfigService) protected override configService: ConfigService,
    @Inject(LoggerService) private loggerService: LoggerService
  ) {
    super(http, rootContext, utilService, configService);
  }

  /**
   * Method to retrieve the report configuration. 
   * 
   * Note: this is currently using the `/admin` endpoint
   * 
   * @param name 
   */
  public async getReportConfig(name: string): Promise<any> {
    if (_isEmpty(name)) {
      this.loggerService.error(`getReportConfig() -> Parameter 'name' is empty!`);
      throw new Error('Report Config name is empty!');
    }
    const req = this.http.get(`${this.brandingAndPortalUrl}/admin/getReport?name=${name}`, this.reqOptsJsonBodyOnly);
    req.pipe(
      map((data:any) => {
        return data as ReportDto
      })
    );
    return firstValueFrom(req);
  }
  /**
   * Retrieves the ReportsResult page
   * 
   */
  public async getReportResult(name: string, pageNum:number, params:any, rows:number = 10): Promise<any> {
    if (_isEmpty(name)) {
      this.loggerService.error(`getReportResult() -> Parameter 'name' is empty!`);
      throw new Error('Report name is empty!');
    }
    let start = (pageNum-1) * rows;
    var url = `${this.brandingAndPortalUrl}/admin/getReportResults?name=${name}&start=${start}&rows=${rows}`;
    for(var key in params) {
      url=url+'&'+key+"="+params[key];
    }
    const req = this.http.get(url, this.reqOptsJsonBodyOnly);
    req.pipe(
      map((data:any) => {
        return data as ReportResultDto
      })
    );
    return await firstValueFrom(req);
  }
}

results matching ""

    No results matching ""