From 9d5e2dbfe28b3372b9e6abdc07dae65340981248 Mon Sep 17 00:00:00 2001 From: josedario87 Date: Tue, 14 Oct 2025 03:47:37 -0600 Subject: [PATCH] fix: usar valores por defecto de template-tags al ejecutar queries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- .../metabase/MetabaseCardDisplay.vue | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/nuxt4-app/app/components/metabase/MetabaseCardDisplay.vue b/nuxt4-app/app/components/metabase/MetabaseCardDisplay.vue index 56e6907..98050ba 100644 --- a/nuxt4-app/app/components/metabase/MetabaseCardDisplay.vue +++ b/nuxt4-app/app/components/metabase/MetabaseCardDisplay.vue @@ -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) {