mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
prepare sql part for special functions
This commit is contained in:
@@ -78,6 +78,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
|||||||
this.selectMenu = [
|
this.selectMenu = [
|
||||||
{ text: 'Aggregate', value: 'aggregate' },
|
{ text: 'Aggregate', value: 'aggregate' },
|
||||||
{ text: 'Math', value: 'math' },
|
{ text: 'Math', value: 'math' },
|
||||||
|
// { text: 'Special', value: 'special' },
|
||||||
{ text: 'Alias', value: 'alias' },
|
{ text: 'Alias', value: 'alias' },
|
||||||
{ text: 'Column', value: 'column' },
|
{ text: 'Column', value: 'column' },
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -52,6 +52,30 @@ function replaceAggregationAddStrategy(selectParts, partModel) {
|
|||||||
selectParts.splice(1, 0, partModel);
|
selectParts.splice(1, 0, partModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function replaceSpecialAddStrategy(selectParts, partModel) {
|
||||||
|
var hasAlias = false;
|
||||||
|
|
||||||
|
// look for existing aggregation
|
||||||
|
for (var i = 0; i < selectParts.length; i++) {
|
||||||
|
var part = selectParts[i];
|
||||||
|
if (part.def.type === 'special') {
|
||||||
|
selectParts[i] = partModel;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (part.def.type === 'alias') {
|
||||||
|
hasAlias = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add alias if none exists yet
|
||||||
|
if (!hasAlias) {
|
||||||
|
var aliasModel = createPart({ type: 'alias', params: [selectParts[0].params[0]] });
|
||||||
|
selectParts.push(aliasModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
selectParts.splice(1, 0, partModel);
|
||||||
|
}
|
||||||
|
|
||||||
function addMathStrategy(selectParts, partModel) {
|
function addMathStrategy(selectParts, partModel) {
|
||||||
var partCount = selectParts.length;
|
var partCount = selectParts.length;
|
||||||
if (partCount > 0) {
|
if (partCount > 0) {
|
||||||
@@ -184,6 +208,21 @@ register({
|
|||||||
renderer: functionRenderer,
|
renderer: functionRenderer,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
register({
|
||||||
|
type: 'special',
|
||||||
|
style: 'label',
|
||||||
|
params: [
|
||||||
|
{
|
||||||
|
name: 'function',
|
||||||
|
type: 'string',
|
||||||
|
options: ['increase', 'rate'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
defaultParams: ['increase'],
|
||||||
|
addStrategy: replaceSpecialAddStrategy,
|
||||||
|
renderer: aggregateRenderer,
|
||||||
|
});
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
create: createPart,
|
create: createPart,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user