mirror of https://github.com/grafana/grafana
@grafana/runtime: expose config and loadPluginCss (#17655)
* move config to grafana runtime * set defaults * defaults in constructor * use @types/systemjs * rename Settings to GrafanaBootConfigpull/17674/head
parent
c9ad411d8e
commit
428134482d
@ -0,0 +1,78 @@ |
||||
import extend from 'lodash/extend'; |
||||
import { GrafanaTheme, getTheme, GrafanaThemeType, PanelPluginMeta, DataSourceInstanceSettings } from '@grafana/ui'; |
||||
|
||||
export interface BuildInfo { |
||||
version: string; |
||||
commit: string; |
||||
isEnterprise: boolean; |
||||
env: string; |
||||
latestVersion: string; |
||||
hasUpdate: boolean; |
||||
} |
||||
|
||||
export class GrafanaBootConfig { |
||||
datasources: { [str: string]: DataSourceInstanceSettings } = {}; |
||||
panels: { [key: string]: PanelPluginMeta } = {}; |
||||
appSubUrl = ''; |
||||
windowTitlePrefix = ''; |
||||
buildInfo: BuildInfo = {} as BuildInfo; |
||||
newPanelTitle = ''; |
||||
bootData: any; |
||||
externalUserMngLinkUrl = ''; |
||||
externalUserMngLinkName = ''; |
||||
externalUserMngInfo = ''; |
||||
allowOrgCreate = false; |
||||
disableLoginForm = false; |
||||
defaultDatasource = ''; |
||||
alertingEnabled = false; |
||||
alertingErrorOrTimeout = ''; |
||||
alertingNoDataOrNullValues = ''; |
||||
authProxyEnabled = false; |
||||
exploreEnabled = false; |
||||
ldapEnabled = false; |
||||
oauth: any; |
||||
disableUserSignUp = false; |
||||
loginHint: any; |
||||
passwordHint: any; |
||||
loginError: any; |
||||
viewersCanEdit = false; |
||||
editorsCanAdmin = false; |
||||
disableSanitizeHtml = false; |
||||
theme: GrafanaTheme; |
||||
pluginsToPreload: string[] = []; |
||||
|
||||
constructor(options: GrafanaBootConfig) { |
||||
this.theme = options.bootData.user.lightTheme ? getTheme(GrafanaThemeType.Light) : getTheme(GrafanaThemeType.Dark); |
||||
|
||||
const defaults = { |
||||
datasources: {}, |
||||
windowTitlePrefix: 'Grafana - ', |
||||
panels: {}, |
||||
newPanelTitle: 'Panel Title', |
||||
playlist_timespan: '1m', |
||||
unsaved_changes_warning: true, |
||||
appSubUrl: '', |
||||
buildInfo: { |
||||
version: 'v1.0', |
||||
commit: '1', |
||||
env: 'production', |
||||
isEnterprise: false, |
||||
}, |
||||
viewersCanEdit: false, |
||||
editorsCanAdmin: false, |
||||
disableSanitizeHtml: false, |
||||
}; |
||||
|
||||
extend(this, defaults, options); |
||||
} |
||||
} |
||||
|
||||
const bootData = (window as any).grafanaBootData || { |
||||
settings: {}, |
||||
user: {}, |
||||
}; |
||||
|
||||
const options = bootData.settings; |
||||
options.bootData = bootData; |
||||
|
||||
export const config = new GrafanaBootConfig(options); |
@ -1 +1,3 @@ |
||||
export * from './services'; |
||||
export * from './config'; |
||||
export { loadPluginCss } from './utils/plugin'; |
||||
|
@ -0,0 +1,17 @@ |
||||
import { config } from '../config'; |
||||
|
||||
/* tslint:disable:import-blacklist */ |
||||
import System from 'systemjs'; |
||||
|
||||
export interface PluginCssOptions { |
||||
light: string; |
||||
dark: string; |
||||
} |
||||
|
||||
export function loadPluginCss(options: PluginCssOptions) { |
||||
if (config.bootData.user.lightTheme) { |
||||
System.import(options.light + '!css'); |
||||
} else { |
||||
System.import(options.dark + '!css'); |
||||
} |
||||
} |
@ -1,79 +1,5 @@ |
||||
import _ from 'lodash'; |
||||
import { GrafanaTheme, getTheme, GrafanaThemeType, PanelPluginMeta, DataSourceInstanceSettings } from '@grafana/ui'; |
||||
import { config, GrafanaBootConfig } from '@grafana/runtime'; |
||||
|
||||
export interface BuildInfo { |
||||
version: string; |
||||
commit: string; |
||||
isEnterprise: boolean; |
||||
env: string; |
||||
latestVersion: string; |
||||
hasUpdate: boolean; |
||||
} |
||||
|
||||
export class Settings { |
||||
datasources: { [str: string]: DataSourceInstanceSettings }; |
||||
panels: { [key: string]: PanelPluginMeta }; |
||||
appSubUrl: string; |
||||
windowTitlePrefix: string; |
||||
buildInfo: BuildInfo; |
||||
newPanelTitle: string; |
||||
bootData: any; |
||||
externalUserMngLinkUrl: string; |
||||
externalUserMngLinkName: string; |
||||
externalUserMngInfo: string; |
||||
allowOrgCreate: boolean; |
||||
disableLoginForm: boolean; |
||||
defaultDatasource: string; |
||||
alertingEnabled: boolean; |
||||
alertingErrorOrTimeout: string; |
||||
alertingNoDataOrNullValues: string; |
||||
authProxyEnabled: boolean; |
||||
exploreEnabled: boolean; |
||||
ldapEnabled: boolean; |
||||
oauth: any; |
||||
disableUserSignUp: boolean; |
||||
loginHint: any; |
||||
passwordHint: any; |
||||
loginError: any; |
||||
viewersCanEdit: boolean; |
||||
editorsCanAdmin: boolean; |
||||
disableSanitizeHtml: boolean; |
||||
theme: GrafanaTheme; |
||||
pluginsToPreload: string[]; |
||||
|
||||
constructor(options: Settings) { |
||||
this.theme = options.bootData.user.lightTheme ? getTheme(GrafanaThemeType.Light) : getTheme(GrafanaThemeType.Dark); |
||||
|
||||
const defaults = { |
||||
datasources: {}, |
||||
windowTitlePrefix: 'Grafana - ', |
||||
panels: {}, |
||||
newPanelTitle: 'Panel Title', |
||||
playlist_timespan: '1m', |
||||
unsaved_changes_warning: true, |
||||
appSubUrl: '', |
||||
buildInfo: { |
||||
version: 'v1.0', |
||||
commit: '1', |
||||
env: 'production', |
||||
isEnterprise: false, |
||||
}, |
||||
viewersCanEdit: false, |
||||
editorsCanAdmin: false, |
||||
disableSanitizeHtml: false, |
||||
}; |
||||
|
||||
_.extend(this, defaults, options); |
||||
} |
||||
} |
||||
|
||||
const bootData = (window as any).grafanaBootData || { |
||||
settings: {}, |
||||
user: {}, |
||||
}; |
||||
|
||||
const options = bootData.settings; |
||||
options.bootData = bootData; |
||||
|
||||
export const config = new Settings(options); |
||||
// Legacy binding paths
|
||||
export { config, GrafanaBootConfig as Settings }; |
||||
export default config; |
||||
|
Loading…
Reference in new issue