From 45ff3777a7ffb568bcde7f8c11c0716d390162b7 Mon Sep 17 00:00:00 2001 From: josedario87 Date: Tue, 14 Oct 2025 03:51:00 -0600 Subject: [PATCH] =?UTF-8?q?feat:=20agregar=20formulario=20configurable=20d?= =?UTF-8?q?e=20par=C3=A1metros=20en=20queries?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Agregar sección expandible para configurar parámetros antes de ejecutar - Inputs dinámicos según tipo: toggle para boolean, date picker para fechas, text para otros - Inicialización automática con valores por defecto de template-tags - Botón para restablecer parámetros a valores originales - Usar valores del formulario al ejecutar queries - Mejorar UX con labels legibles y estilos consistentes --- .../metabase/MetabaseCardDisplay.vue | 107 ++++++++++++++++-- 1 file changed, 99 insertions(+), 8 deletions(-) diff --git a/nuxt4-app/app/components/metabase/MetabaseCardDisplay.vue b/nuxt4-app/app/components/metabase/MetabaseCardDisplay.vue index 98050ba..be5defa 100644 --- a/nuxt4-app/app/components/metabase/MetabaseCardDisplay.vue +++ b/nuxt4-app/app/components/metabase/MetabaseCardDisplay.vue @@ -45,6 +45,60 @@ + +
+
+ + + Configurar Parámetros + + + +
+
+ + + + + + + + + + +
+ +
+ + Restablecer + +
+
+
+
+
(null) const error = ref(null) const copied = ref(false) +const showParameters = ref(false) +const parameterValues = ref>({}) + +// Initialize parameter values from card template tags +const templateTags = computed(() => props.card.dataset_query?.native?.['template-tags'] || {}) + +const hasParameters = computed(() => Object.keys(templateTags.value).length > 0) + +// Initialize parameters on mount +function initializeParameters() { + const params: Record = {} + for (const [tagName, tagConfig] of Object.entries(templateTags.value)) { + const config = tagConfig as any + if (config.type === 'boolean') { + params[tagName] = config.default?.[0] ?? false + } else { + params[tagName] = config.default ?? '' + } + } + parameterValues.value = params +} + +// Watch for card changes and reinitialize +watch(() => props.card, () => { + initializeParameters() +}, { immediate: true }) const exportItems = [[ { @@ -193,6 +273,20 @@ const exportItems = [[ } ]] +function getParameterType(key: string): string { + const config = templateTags.value[key] as any + return config?.type || 'text' +} + +function getParameterLabel(key: string): string { + const config = templateTags.value[key] as any + return config?.['display-name'] || key +} + +function resetParameters() { + initializeParameters() +} + function getStatusColor(card: any) { if (card.archived) return 'red' if (card.dataset) return 'blue' @@ -214,24 +308,21 @@ 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)) { + // Build parameters from current form values + for (const [tagName, tagConfig] of Object.entries(templateTags.value)) { const config = tagConfig as any let paramType = 'text' - let paramValue = config.default + let paramValue = parameterValues.value[tagName] // Determine parameter type based on tag type if (config.type === 'date') { paramType = 'date/single' - // Use default value if present - paramValue = config.default || null + paramValue = parameterValues.value[tagName] || null } else if (config.type === 'boolean') { paramType = 'category' - paramValue = config.default || [false] + paramValue = [parameterValues.value[tagName]] } parameters.push({