fix: usar valores por defecto de template-tags al ejecutar queries
- Extraer valores por defecto de template-tags de la card - Construir parámetros dinámicamente basados en la configuración - Soportar tipos: date, boolean, text - Resolver error de parámetros faltantes en queries con fechas
This commit is contained in:
@@ -214,15 +214,36 @@ async function executeQuery() {
|
||||
queryResult.value = null
|
||||
|
||||
try {
|
||||
// Extract template tags and their defaults from the card
|
||||
const templateTags = props.card.dataset_query?.native?.['template-tags'] || {}
|
||||
const parameters = []
|
||||
|
||||
// Build parameters from template tags
|
||||
for (const [tagName, tagConfig] of Object.entries(templateTags)) {
|
||||
const config = tagConfig as any
|
||||
let paramType = 'text'
|
||||
let paramValue = config.default
|
||||
|
||||
// Determine parameter type based on tag type
|
||||
if (config.type === 'date') {
|
||||
paramType = 'date/single'
|
||||
// Use default value if present
|
||||
paramValue = config.default || null
|
||||
} else if (config.type === 'boolean') {
|
||||
paramType = 'category'
|
||||
paramValue = config.default || [false]
|
||||
}
|
||||
|
||||
parameters.push({
|
||||
type: paramType,
|
||||
target: ['variable', ['template-tag', tagName]],
|
||||
value: paramValue
|
||||
})
|
||||
}
|
||||
|
||||
const result = await $fetch(`/api/metabase/cards/${props.card.id}/query`, {
|
||||
method: 'POST',
|
||||
body: {
|
||||
parameters: [
|
||||
{ type: 'category', target: ['variable', ['template-tag', 'incluir_anulados']], value: [false] },
|
||||
{ type: 'date/single', target: ['variable', ['template-tag', 'fecha_desde']], value: null },
|
||||
{ type: 'date/single', target: ['variable', ['template-tag', 'fecha_hasta']], value: null }
|
||||
]
|
||||
}
|
||||
body: { parameters }
|
||||
})
|
||||
queryResult.value = result
|
||||
} catch (e: any) {
|
||||
|
||||
Reference in New Issue
Block a user