Fix project selection and add project settings UI
This commit is contained in:
@@ -11,8 +11,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.mchus.pro/mchus/quoteforge/internal/appstate"
|
||||
"git.mchus.pro/mchus/quoteforge/internal/appmeta"
|
||||
"git.mchus.pro/mchus/quoteforge/internal/appstate"
|
||||
"github.com/glebarez/sqlite"
|
||||
mysqlDriver "github.com/go-sql-driver/mysql"
|
||||
uuidpkg "github.com/google/uuid"
|
||||
@@ -434,18 +434,36 @@ func (l *LocalDB) ListConfigurationsWithFilters(status string, search string, of
|
||||
query := l.db.Model(&LocalConfiguration{})
|
||||
switch status {
|
||||
case "active":
|
||||
query = query.Where("is_active = ?", true)
|
||||
query = query.Where("local_configurations.is_active = ?", true)
|
||||
case "archived":
|
||||
query = query.Where("is_active = ?", false)
|
||||
query = query.Where("local_configurations.is_active = ?", false)
|
||||
case "all", "":
|
||||
// no-op
|
||||
default:
|
||||
query = query.Where("is_active = ?", true)
|
||||
query = query.Where("local_configurations.is_active = ?", true)
|
||||
}
|
||||
|
||||
search = strings.TrimSpace(search)
|
||||
if search != "" {
|
||||
query = query.Where("LOWER(name) LIKE ?", "%"+strings.ToLower(search)+"%")
|
||||
needle := "%" + strings.ToLower(search) + "%"
|
||||
hasProjectsTable := l.db.Migrator().HasTable(&LocalProject{})
|
||||
hasServerModel := l.db.Migrator().HasColumn(&LocalConfiguration{}, "server_model")
|
||||
|
||||
conditions := []string{"LOWER(local_configurations.name) LIKE ?"}
|
||||
args := []interface{}{needle}
|
||||
|
||||
if hasProjectsTable {
|
||||
query = query.Joins("LEFT JOIN local_projects lp ON lp.uuid = local_configurations.project_uuid")
|
||||
conditions = append(conditions, "LOWER(COALESCE(lp.name, '')) LIKE ?")
|
||||
args = append(args, needle)
|
||||
}
|
||||
|
||||
if hasServerModel {
|
||||
conditions = append(conditions, "LOWER(COALESCE(local_configurations.server_model, '')) LIKE ?")
|
||||
args = append(args, needle)
|
||||
}
|
||||
|
||||
query = query.Where(strings.Join(conditions, " OR "), args...)
|
||||
}
|
||||
|
||||
var total int64
|
||||
@@ -454,7 +472,7 @@ func (l *LocalDB) ListConfigurationsWithFilters(status string, search string, of
|
||||
}
|
||||
|
||||
var configs []LocalConfiguration
|
||||
if err := query.Order("created_at DESC").Offset(offset).Limit(limit).Find(&configs).Error; err != nil {
|
||||
if err := query.Order("local_configurations.created_at DESC").Offset(offset).Limit(limit).Find(&configs).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return configs, total, nil
|
||||
|
||||
Reference in New Issue
Block a user