1 import { HttpClient } from '@angular/common/http';
2 import { Injectable } from '@angular/core';
4 import * as _ from 'lodash';
5 import { ApiModule } from './api.module';
10 export class SettingsService {
11 constructor(private http: HttpClient) {}
13 private settings: { [url: string]: string } = {};
15 ifSettingConfigured(url: string, fn: (value?: string) => void, elseFn?: () => void): void {
16 const setting = this.settings[url];
17 if (setting === undefined) {
18 this.http.get(url).subscribe(
20 this.settings[url] = this.getSettingsValue(data);
21 this.ifSettingConfigured(url, fn, elseFn);
24 if (resp.status !== 401) {
25 this.settings[url] = '';
29 } else if (setting !== '') {
38 // Easiest way to stop reloading external content that can't be reached
40 this.settings[url] = '';
43 private getSettingsValue(data: any): string {
44 return data.value || data.instance || '';
47 validateGrafanaDashboardUrl(uid) {
48 return this.http.get(`api/grafana/validation/${uid}`);