diff --git a/models/cloudbrain_static.go b/models/cloudbrain_static.go index 371b30f66..58a93d476 100644 --- a/models/cloudbrain_static.go +++ b/models/cloudbrain_static.go @@ -34,6 +34,7 @@ type TaskDetail struct { CardDuration string `json:"CardDuration"` AiCenter string `json:"AiCenter"` FlavorName string `json:"FlavorName"` + Spec *Specification `json:"Spec"` } func GetTodayCreatorCount(beginTime time.Time, endTime time.Time) (int64, error) { diff --git a/models/task_config.go b/models/task_config.go index 204cbaf95..baa8c9adb 100644 --- a/models/task_config.go +++ b/models/task_config.go @@ -65,6 +65,19 @@ type TaskAndLimiterConfig struct { LimitConfig LimitConfig `xorm:"extends"` } +type PointRule struct { + UserDailyLimit int64 + TaskRules []TaskRule +} + +type TaskRule struct { + TaskCode string + AwardType string + AwardAmount int64 + RefreshRate string + LimitNum int64 +} + func (TaskAndLimiterConfig) TableName() string { return "task_config" } diff --git a/routers/api/v1/repo/cloudbrain_dashboard.go b/routers/api/v1/repo/cloudbrain_dashboard.go index 55d7400b7..9d237d8e3 100755 --- a/routers/api/v1/repo/cloudbrain_dashboard.go +++ b/routers/api/v1/repo/cloudbrain_dashboard.go @@ -733,6 +733,7 @@ func GetCloudbrainsDetailData(ctx *context.Context) { ctx.ServerError("Get job failed:", err) return } + models.LoadSpecs4CloudbrainInfo(ciTasks) nilTime := time.Time{} tasks := []models.TaskDetail{} for i, task := range ciTasks { @@ -769,6 +770,7 @@ func GetCloudbrainsDetailData(ctx *context.Context) { } else { taskDetail.IsDelete = false } + taskDetail.Spec = ciTasks[i].Spec tasks = append(tasks, taskDetail) } diff --git a/routers/reward/point/point.go b/routers/reward/point/point.go index 7b3e0fe49..88cd8b22a 100644 --- a/routers/reward/point/point.go +++ b/routers/reward/point/point.go @@ -8,6 +8,7 @@ import ( "code.gitea.io/gitea/routers/response" "code.gitea.io/gitea/services/reward" "code.gitea.io/gitea/services/reward/point/account" + "code.gitea.io/gitea/services/task" "errors" "net/http" ) @@ -92,6 +93,17 @@ func GetRulePage(ctx *context.Context) { ctx.HTML(200, tplPointRule) } +func GetRuleConfig(ctx *context.Context) { + r, err := task.GetPointRule() + if err != nil { + log.Error("GetRuleConfig error.%v", err) + ctx.JSON(http.StatusOK, response.ServerError(err.Error())) + return + } + + ctx.JSON(http.StatusOK, response.SuccessWithData(r)) +} + func GetAdminRewardList(ctx *context.Context) { opts, err := buildAdminRewardRecordListOpts(ctx) if err != nil { diff --git a/routers/routes/routes.go b/routers/routes/routes.go index d19a307e3..afb7f3187 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -1432,6 +1432,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Group("/reward/point", func() { m.Get("", point.GetPointPage) m.Get("/rule", point.GetRulePage) + m.Get("/rule/config", point.GetRuleConfig) m.Get("/account", point.GetPointAccount) m.Get("/record/list", point.GetPointRecordList) }, reqSignIn) diff --git a/services/task/task_config.go b/services/task/task_config.go index 424151098..87f66e00a 100644 --- a/services/task/task_config.go +++ b/services/task/task_config.go @@ -6,8 +6,10 @@ import ( "code.gitea.io/gitea/modules/redis/redis_client" "code.gitea.io/gitea/modules/redis/redis_key" "code.gitea.io/gitea/modules/redis/redis_lock" + "code.gitea.io/gitea/services/reward/limiter" "encoding/json" "errors" + "fmt" "time" ) @@ -181,3 +183,46 @@ func DelTaskConfig(id int64, doer *models.User) error { redis_client.Del(redis_key.TaskConfigList()) return nil } + +func GetPointRule() (*models.PointRule, error) { + r, err := limiter.GetSingleDailyPointLimitConfig() + if err != nil { + return nil, err + } + limiters, err := limiter.GetLimitersByLimitType(models.LimitTypeTask) + if err != nil { + return nil, err + } + limiterMap := make(map[string]*models.LimitConfig, 0) + for i := 0; i < len(limiters); i++ { + limiterMap[limiters[i].LimitCode] = &limiters[i] + } + + taskConfigs, err := GetTaskConfigList() + if err != nil { + return nil, err + } + taskRules := make([]models.TaskRule, len(taskConfigs)) + + for i, taskConfig := range taskConfigs { + rule := models.TaskRule{ + TaskCode: taskConfig.TaskCode, + AwardType: taskConfig.AwardType, + AwardAmount: taskConfig.AwardAmount, + } + limiter := limiterMap[fmt.Sprint(taskConfig.TaskCode)] + if limiter != nil { + rule.RefreshRate = limiter.RefreshRate + rule.LimitNum = limiter.LimitNum + } + taskRules[i] = rule + } + + pointRule := &models.PointRule{ + TaskRules: taskRules, + } + if r != nil { + pointRule.UserDailyLimit = r.LimitNum + } + return pointRule, nil +} diff --git a/templates/reward/point/rule.tmpl b/templates/reward/point/rule.tmpl index c7eee3370..3d81fd0f7 100644 --- a/templates/reward/point/rule.tmpl +++ b/templates/reward/point/rule.tmpl @@ -16,10 +16,10 @@ text-align: center; } -