File

src/app/shared/api/settings.service.ts

Index

Properties
Methods

Constructor

constructor(http: HttpClient)
Parameters :
Name Type Optional
http HttpClient No

Methods

Private getSettingsValue
getSettingsValue(data: any)
Parameters :
Name Type Optional
data any No
Returns : string
ifSettingConfigured
ifSettingConfigured(url: string, fn: (value: string) => void)
Parameters :
Name Type Optional
url string No
fn function No
Returns : void
validateGrafanaDashboardUrl
validateGrafanaDashboardUrl(uid)
Parameters :
Name Optional
uid No
Returns : any

Properties

Private settings
Type : literal type
Default value : {}
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

import * as _ from 'lodash';
import { ApiModule } from './api.module';

@Injectable({
  providedIn: ApiModule
})
export class SettingsService {
  constructor(private http: HttpClient) {}

  private settings: { [url: string]: string } = {};

  ifSettingConfigured(url: string, fn: (value?: string) => void): void {
    const setting = this.settings[url];
    if (setting === undefined) {
      this.http.get(url).subscribe((data: any) => {
        this.settings[url] = this.getSettingsValue(data);
        this.ifSettingConfigured(url, fn);
      });
    } else if (setting !== '') {
      fn(setting);
    }
  }

  private getSettingsValue(data: any): string {
    return data.value || data.instance || '';
  }

  validateGrafanaDashboardUrl(uid) {
    return this.http.get(`api/grafana/validation/${uid}`);
  }
}

result-matching ""

    No results matching ""