feat: update ui

This commit is contained in:
2025-08-06 11:12:16 +08:00
parent e034a2e54e
commit c4ad0c1dc9
12 changed files with 4983 additions and 226 deletions

View File

@@ -412,6 +412,14 @@ func (cm *ConnectionManager) isSearchableColumn(columnType string) bool {
return false
}
// GetTableRowCount returns the total number of rows in a table
func (cm *ConnectionManager) GetTableRowCount(tableName string) (int64, error) {
var count int64
query := fmt.Sprintf("SELECT COUNT(*) FROM %s", tableName)
err := cm.db.Raw(query).Scan(&count).Error
return count, err
}
// GetTableDataByID retrieves a single record by ID
func (cm *ConnectionManager) GetTableDataByID(tableName string, id interface{}) (map[string]interface{}, error) {
// Find primary key column

View File

@@ -59,8 +59,10 @@ type TableResponse struct {
// TableInfo represents basic table information
type TableInfo struct {
Name string `json:"name"`
Alias string `json:"alias"`
Name string `json:"name"`
Alias string `json:"alias"`
Description string `json:"description"`
RowCount int64 `json:"row_count"`
}
// DetailResponse represents a single record detail response

View File

@@ -30,9 +30,26 @@ func (r *DataRepository) GetTables() ([]model.TableInfo, error) {
var tables []model.TableInfo
for name, tableConfig := range r.config.Tables {
// Get row count for each table
rowCount, err := r.db.GetTableRowCount(name)
if err != nil {
r.logger.Error("failed to get row count for table", "table", name, "error", err)
rowCount = 0
}
// Use table alias as description if not provided
description := tableConfig.Alias
if desc, ok := tableConfig.Options["description"]; ok {
if descStr, ok := desc.(string); ok {
description = descStr
}
}
tables = append(tables, model.TableInfo{
Name: name,
Alias: tableConfig.Alias,
Name: name,
Alias: tableConfig.Alias,
Description: description,
RowCount: rowCount,
})
}

View File

@@ -184,6 +184,14 @@ func (r *Renderer) RenderList(c fiber.Ctx, tableName string) error {
return c.Status(http.StatusInternalServerError).SendString("Failed to load table configuration")
}
// Calculate record range
startRecord := int64((data.Page-1)*data.PerPage + 1)
endRecord := startRecord + int64(len(data.Data)) - 1
if data.Total == 0 {
startRecord = 0
endRecord = 0
}
// Prepare template data
templateData := map[string]interface{}{
"Table": tableName,
@@ -199,6 +207,9 @@ func (r *Renderer) RenderList(c fiber.Ctx, tableName string) error {
"SortOrder": sortOrder,
"Tables": tables,
"CurrentPath": c.Path(),
"StartRecord": startRecord,
"EndRecord": endRecord,
"LastUpdate": time.Now().Format("2006-01-02 15:04:05"),
}
// set content-type html