fix: coolify_configs table missing + miniwebs real status
- Add coolify_config.go model (missing from worktree branch) - Add CoolifyConfig to normal-startup AutoMigrate → creates table on next start - Fix miniwebs tab: m.activo is not in API response; fallback to vcard.estado (true/false) to show real status instead of always Inactiva - Improve miniwebs row: show url, user name, vcard status badge Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Copilot
parent
661e02ef9c
commit
5373cebf9c
@@ -79,6 +79,8 @@ func main() {
|
|||||||
&models.PortalPasswordResetToken{},
|
&models.PortalPasswordResetToken{},
|
||||||
// Integración VCard API Admin
|
// Integración VCard API Admin
|
||||||
&models.VcardApiConfig{},
|
&models.VcardApiConfig{},
|
||||||
|
// Integración Coolify
|
||||||
|
&models.CoolifyConfig{},
|
||||||
// Servidores: nuevos campos de agente + tabla join de integraciones
|
// Servidores: nuevos campos de agente + tabla join de integraciones
|
||||||
&models.Servidor{},
|
&models.Servidor{},
|
||||||
&models.ConxDb{},
|
&models.ConxDb{},
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/sujit-baniya/fiber-boilerplate/app"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CoolifyConfig almacena las credenciales para la API REST de Coolify.
|
||||||
|
// Coolify expone su API en {base_url}/api/v1 con Bearer token.
|
||||||
|
type CoolifyConfig struct {
|
||||||
|
gorm.Model
|
||||||
|
Nombre string `json:"nombre" gorm:"column:nombre;not null"`
|
||||||
|
BaseURL string `json:"base_url" gorm:"column:base_url;type:text;not null"`
|
||||||
|
ApiToken string `json:"api_token" gorm:"column:api_token;type:text;not null"`
|
||||||
|
Activo bool `json:"activo" gorm:"column:activo;default:true"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (CoolifyConfig) TableName() string { return "coolify_configs" }
|
||||||
|
|
||||||
|
func GetCoolifyConfig() (*CoolifyConfig, error) {
|
||||||
|
var cfg CoolifyConfig
|
||||||
|
if err := app.Http.Database.DB.First(&cfg).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &cfg, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpsertCoolifyConfig(nombre, baseURL, apiToken string, activo bool) (*CoolifyConfig, error) {
|
||||||
|
var cfg CoolifyConfig
|
||||||
|
err := app.Http.Database.DB.First(&cfg).Error
|
||||||
|
if err != nil {
|
||||||
|
// No existe → crear
|
||||||
|
cfg = CoolifyConfig{
|
||||||
|
Nombre: nombre,
|
||||||
|
BaseURL: baseURL,
|
||||||
|
ApiToken: apiToken,
|
||||||
|
Activo: activo,
|
||||||
|
}
|
||||||
|
if createErr := app.Http.Database.DB.Create(&cfg).Error; createErr != nil {
|
||||||
|
return nil, createErr
|
||||||
|
}
|
||||||
|
return &cfg, nil
|
||||||
|
}
|
||||||
|
cfg.Nombre = nombre
|
||||||
|
cfg.BaseURL = baseURL
|
||||||
|
if apiToken != "" {
|
||||||
|
cfg.ApiToken = apiToken
|
||||||
|
}
|
||||||
|
cfg.Activo = activo
|
||||||
|
if err := app.Http.Database.DB.Save(&cfg).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &cfg, nil
|
||||||
|
}
|
||||||
@@ -440,12 +440,31 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<template x-for="m in items" :key="m.id || m._id">
|
<template x-for="m in items" :key="m.id || m._id">
|
||||||
<tr class="hover:bg-gray-50 border-b border-gray-100">
|
<tr class="hover:bg-gray-50 border-b border-gray-100">
|
||||||
<td class="py-2 px-3 font-medium" x-text="m.titulo || m.title || '—'"></td>
|
|
||||||
<td class="py-2 px-3 text-xs text-gray-500" x-text="(m.user && m.user.email) ? m.user.email : (m.user_id || '—')"></td>
|
|
||||||
<td class="py-2 px-3 text-xs text-gray-500" x-text="(m.vcard && m.vcard.nombre) ? m.vcard.nombre : '—'"></td>
|
|
||||||
<td class="py-2 px-3">
|
<td class="py-2 px-3">
|
||||||
<span :class="m.activo ? 'bg-green-100 text-green-700' : 'bg-red-100 text-red-700'"
|
<div class="font-medium" x-text="m.titulo || m.title || '—'"></div>
|
||||||
class="text-xs px-2 py-0.5 rounded-full" x-text="m.activo ? 'Activa' : 'Inactiva'"></span>
|
<a x-show="m.url || m.unico" :href="m.url || ('https://web.u-site.app/w/' + m.unico)" target="_blank"
|
||||||
|
class="text-xs text-blue-500 hover:underline font-mono" x-text="m.unico || m.url || ''"></a>
|
||||||
|
</td>
|
||||||
|
<td class="py-2 px-3 text-xs text-gray-500">
|
||||||
|
<div x-text="(m.user && m.user.name) ? m.user.name : '—'"></div>
|
||||||
|
<div class="text-gray-400" x-text="(m.user && m.user.email) ? m.user.email : ''"></div>
|
||||||
|
</td>
|
||||||
|
<td class="py-2 px-3 text-xs text-gray-500">
|
||||||
|
<div x-text="(m.vcard && m.vcard.nombre) ? m.vcard.nombre : '—'"></div>
|
||||||
|
<span x-show="m.vcard" :class="(m.vcard && (m.vcard.estado === true || m.vcard.estado === 'true')) ? 'bg-green-100 text-green-700' : 'bg-gray-100 text-gray-400'"
|
||||||
|
class="text-xs px-1.5 py-0.5 rounded-full"
|
||||||
|
x-text="(m.vcard && (m.vcard.estado === true || m.vcard.estado === 'true')) ? 'VCard activa' : 'VCard inactiva'"></span>
|
||||||
|
</td>
|
||||||
|
<td class="py-2 px-3">
|
||||||
|
<template x-if="m.activo !== undefined && m.activo !== null">
|
||||||
|
<span :class="m.activo ? 'bg-green-100 text-green-700' : 'bg-red-100 text-red-700'"
|
||||||
|
class="text-xs px-2 py-0.5 rounded-full" x-text="m.activo ? 'Activa' : 'Inactiva'"></span>
|
||||||
|
</template>
|
||||||
|
<template x-if="m.activo === undefined || m.activo === null">
|
||||||
|
<span :class="(m.vcard && (m.vcard.estado === true || m.vcard.estado === 'true')) ? 'bg-green-100 text-green-700' : 'bg-gray-100 text-gray-500'"
|
||||||
|
class="text-xs px-2 py-0.5 rounded-full"
|
||||||
|
x-text="(m.vcard && (m.vcard.estado === true || m.vcard.estado === 'true')) ? 'Activa' : 'Sin estado'"></span>
|
||||||
|
</template>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user