File

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

Description

User-centric functions.

Note: functions will be ported over as these are consumed by the apps/

Author: Shilo Banihit

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 getAppConfigForm
getAppConfigForm(appConfigId: string)
Parameters :
Name Type Optional
appConfigId string No
Returns : Promise<AppConfig>
Public Async saveAppConfig
saveAppConfig(appConfigId: string, model: any)
Parameters :
Name Type Optional
appConfigId string No
model any No
Returns : Promise<AppConfig>
Public Async waitForInit
waitForInit()
Inherited from HttpClientService
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

Properties

Private requestOptions
Type : any
Default value : null as any
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 { map, firstValueFrom } from 'rxjs';
import { Inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { APP_BASE_HREF } from '@angular/common';

import { ConfigService } from './config.service';
import { UtilityService } from './utility.service';
import { HttpClientService } from './httpClient.service';
import { LoggerService } from './logger.service';
import { merge as _merge } from 'lodash-es';

export interface AppConfig {
  schema: object;
  model: object;
  fieldOrder:string[];
}


/**
 * User-centric functions. 
 * 
 * Note: functions will be ported over as these are consumed by the apps/
 *
 * Author: <a href='https://github.com/shilob' target='_blank'>Shilo Banihit</a>
 *
 * 
 */
@Injectable()
export class AppConfigService extends HttpClientService {

  private requestOptions:any = null as any;
  
  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);
  }
  
  public override async waitForInit(): Promise<any> {
    await super.waitForInit();
    this.requestOptions = this.reqOptsJsonBodyOnly;
    this.enableCsrfHeader();
    _merge(this.requestOptions, {context: this.httpContext});
    return this;
  }

  

  public async getAppConfigForm(appConfigId:string): Promise<AppConfig> {
    let url = `${this.brandingAndPortalUrl}/appconfig/form/${appConfigId}`;
    const req = this.http.get<AppConfig>(url, {responseType: 'json', observe: 'body', context: this.httpContext});
    req.pipe(
      map((data:any) => {
        return data as AppConfig;
      })
    );
    let result = await firstValueFrom(req);
    return result;
  } 

  public async saveAppConfig(appConfigId:string, model:any): Promise<AppConfig> {
    let url = `${this.brandingAndPortalUrl}/appconfig/form/${appConfigId}`;
    const req = this.http.post<AppConfig>(url, model, {responseType: 'json', observe: 'body', context: this.httpContext});
    req.pipe(
      map((data:any) => {
        return data as AppConfig;
      })
    );
    let result = await firstValueFrom(req);
    return result;
  } 

  
}

results matching ""

    No results matching ""