本文整理汇总了TypeScript中app/features/templating/template_srv.TemplateSrv.init方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TemplateSrv.init方法的具体用法?TypeScript TemplateSrv.init怎么用?TypeScript TemplateSrv.init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app/features/templating/template_srv.TemplateSrv
的用法示例。
在下文中一共展示了TemplateSrv.init方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: init
init(dashboard: DashboardModel) {
this.dashboard = dashboard;
this.dashboard.events.on('time-range-updated', this.onTimeRangeUpdated.bind(this));
this.dashboard.events.on('template-variable-value-updated', this.updateUrlParamsWithCurrentVariables.bind(this));
// create working class models representing variables
this.variables = dashboard.templating.list = dashboard.templating.list.map(this.createVariableFromModel.bind(this));
this.templateSrv.init(this.variables, this.timeSrv.timeRange());
// init variables
for (const variable of this.variables) {
variable.initLock = this.$q.defer();
}
const queryParams = this.$location.search();
return this.$q
.all(
this.variables.map(variable => {
return this.processVariable(variable, queryParams);
})
)
.then(() => {
this.templateSrv.updateIndex();
});
}
示例2: initTemplateSrv
function initTemplateSrv(values: any, multi = false) {
const templateSrv = new TemplateSrv();
templateSrv.init([
new CustomVariable(
{
name: 'test',
current: {
value: values,
},
multi: multi,
},
{}
),
]);
return templateSrv;
}
示例3: beforeEach
beforeEach(() => {
templateSrv.init([
new CustomVariable(
{
name: 'var1',
current: {
value: 'var1-foo',
},
multi: false,
},
{}
),
new CustomVariable(
{
name: 'var2',
current: {
value: 'var2-foo',
},
multi: false,
},
{}
),
new CustomVariable(
{
name: 'var3',
options: [
{ selected: true, value: 'var3-foo' },
{ selected: false, value: 'var3-bar' },
{ selected: true, value: 'var3-baz' },
],
current: {
value: ['var3-foo', 'var3-baz'],
},
multi: true,
},
{}
),
]);
ctx.backendSrv.datasourceRequest = jest.fn(params => {
requestParams = params.data;
return Promise.resolve({ data: {} });
});
});
示例4: it
it('should generate the correct query with interval variable', done => {
templateSrv.init([
new CustomVariable(
{
name: 'period',
current: {
value: '10m',
},
multi: false,
},
{}
),
]);
const query = {
range: { from: 'now-1h', to: 'now' },
rangeRaw: { from: 1483228800, to: 1483232400 },
targets: [
{
refId: 'A',
region: 'us-east-1',
namespace: 'AWS/EC2',
metricName: 'CPUUtilization',
dimensions: {
InstanceId: 'i-12345678',
},
statistics: ['Average'],
period: '[[period]]',
},
],
};
ctx.ds.query(query).then(() => {
const params = requestParams.queries[0];
expect(params.period).toBe('600');
done();
});
});