feat: update ui
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user