package apps import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/httpdns/policies" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/maps" ) type CreatePopupAction struct { actionutils.ParentAction } func (this *CreatePopupAction) Init() { this.Nav("", "", "") } func (this *CreatePopupAction) RunGet(params struct{}) { clusters := policies.LoadAvailableDeployClusters() this.Data["clusters"] = clusters defaultPrimaryClusterId := policies.LoadDefaultClusterID() if defaultPrimaryClusterId <= 0 && len(clusters) > 0 { defaultPrimaryClusterId = clusters[0].GetInt64("id") } this.Data["defaultPrimaryClusterId"] = defaultPrimaryClusterId defaultBackupClusterId := int64(0) for _, cluster := range clusters { clusterId := cluster.GetInt64("id") if clusterId > 0 && clusterId != defaultPrimaryClusterId { defaultBackupClusterId = clusterId break } } this.Data["defaultBackupClusterId"] = defaultBackupClusterId // Mock users for dropdown this.Data["users"] = []maps.Map{ {"id": int64(1), "name": "User A", "username": "zhangsan"}, {"id": int64(2), "name": "User B", "username": "lisi"}, {"id": int64(3), "name": "User C", "username": "wangwu"}, } this.Show() } func (this *CreatePopupAction) RunPost(params struct { Name string PrimaryClusterId int64 BackupClusterId int64 UserId int64 Must *actions.Must CSRF *actionutils.CSRF }) { params.Must.Field("name", params.Name).Require("please input app name") params.Must.Field("primaryClusterId", params.PrimaryClusterId).Gt(0, "please select primary cluster") if params.BackupClusterId > 0 && params.BackupClusterId == params.PrimaryClusterId { this.FailField("backupClusterId", "backup cluster must be different from primary cluster") } this.Success() }