# All files / src/app/shared/api settings.service.ts

100% Statements 20/20
83.33% Branches 5/6
100% Functions 5/5
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    3594x
    94x

    94x

    94x
    49x

    49x

    94x
    26x

    14x
    8x
    8x

    8x

    94x
    14x

    94x
    5x

    94x
     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}`);
      }
    }