|
|
|
@@ -20,6 +20,7 @@ import ( |
|
|
|
issue_indexer "code.gitea.io/gitea/modules/indexer/issues" |
|
|
|
"code.gitea.io/gitea/modules/log" |
|
|
|
"code.gitea.io/gitea/modules/markup/markdown" |
|
|
|
"code.gitea.io/gitea/modules/modelarts" |
|
|
|
"code.gitea.io/gitea/modules/setting" |
|
|
|
"code.gitea.io/gitea/modules/util" |
|
|
|
issue_service "code.gitea.io/gitea/services/issue" |
|
|
|
@@ -31,10 +32,11 @@ import ( |
|
|
|
) |
|
|
|
|
|
|
|
const ( |
|
|
|
tplDashboard base.TplName = "user/dashboard/dashboard" |
|
|
|
tplIssues base.TplName = "user/dashboard/issues" |
|
|
|
tplMilestones base.TplName = "user/dashboard/milestones" |
|
|
|
tplProfile base.TplName = "user/profile" |
|
|
|
tplDashboard base.TplName = "user/dashboard/dashboard" |
|
|
|
tplIssues base.TplName = "user/dashboard/issues" |
|
|
|
tplMilestones base.TplName = "user/dashboard/milestones" |
|
|
|
tplProfile base.TplName = "user/profile" |
|
|
|
tplCloudbrains base.TplName = "user/dashboard/cloudbrains" |
|
|
|
) |
|
|
|
|
|
|
|
// getDashboardContextUser finds out dashboard is viewing as which context user. |
|
|
|
@@ -751,3 +753,117 @@ func Email2User(ctx *context.Context) { |
|
|
|
} |
|
|
|
ctx.Redirect(setting.AppSubURL + "/user/" + u.Name) |
|
|
|
} |
|
|
|
|
|
|
|
func Cloudbrains(ctx *context.Context) { |
|
|
|
ctx.Data["Title"] = ctx.Tr("user.cloudbrains") |
|
|
|
|
|
|
|
listType := ctx.Query("listType") |
|
|
|
jobType := ctx.Query("jobType") |
|
|
|
jobStatus := ctx.Query("jobStatus") |
|
|
|
|
|
|
|
ctx.Data["ListType"] = listType |
|
|
|
ctx.Data["JobType"] = jobType |
|
|
|
ctx.Data["JobStatus"] = jobStatus |
|
|
|
|
|
|
|
page := ctx.QueryInt("page") |
|
|
|
if page <= 0 { |
|
|
|
page = 1 |
|
|
|
} |
|
|
|
debugType := models.TypeCloudBrainAll |
|
|
|
if listType == models.GPUResource { |
|
|
|
debugType = models.TypeCloudBrainOne |
|
|
|
} else if listType == models.NPUResource { |
|
|
|
debugType = models.TypeCloudBrainTwo |
|
|
|
} |
|
|
|
|
|
|
|
var jobTypes []string |
|
|
|
jobTypeNot := false |
|
|
|
if jobType == string(models.JobTypeDebug) { |
|
|
|
jobTypes = append(jobTypes, string(models.JobTypeSnn4imagenet), string(models.JobTypeBrainScore), string(models.JobTypeDebug)) |
|
|
|
} else if jobType != "all" && jobType != "" { |
|
|
|
jobTypes = append(jobTypes, jobType) |
|
|
|
} |
|
|
|
|
|
|
|
var jobStatuses []string |
|
|
|
jobStatusNot := false |
|
|
|
if jobStatus == "other" { |
|
|
|
jobStatusNot = true |
|
|
|
jobStatuses = append(jobStatuses, string(models.ModelArtsTrainJobWaiting), string(models.ModelArtsTrainJobFailed), string(models.ModelArtsRunning), string(models.ModelArtsTrainJobCompleted), |
|
|
|
string(models.ModelArtsStarting), string(models.ModelArtsRestarting), string(models.ModelArtsStartFailed), |
|
|
|
string(models.ModelArtsStopping), string(models.ModelArtsStopped), string(models.JobSucceeded)) |
|
|
|
} else if jobStatus != "all" && jobStatus != "" { |
|
|
|
jobStatuses = append(jobStatuses, jobStatus) |
|
|
|
} |
|
|
|
|
|
|
|
keyword := strings.Trim(ctx.Query("q"), " ") |
|
|
|
|
|
|
|
ctxUser := getDashboardContextUser(ctx) |
|
|
|
if ctx.Written() { |
|
|
|
return |
|
|
|
} |
|
|
|
ciTasks, count, err := models.Cloudbrains(&models.CloudbrainsOptions{ |
|
|
|
ListOptions: models.ListOptions{ |
|
|
|
Page: page, |
|
|
|
PageSize: setting.UI.IssuePagingNum, |
|
|
|
}, |
|
|
|
Keyword: keyword, |
|
|
|
UserID: ctxUser.ID, |
|
|
|
Type: debugType, |
|
|
|
JobTypeNot: jobTypeNot, |
|
|
|
JobStatusNot: jobStatusNot, |
|
|
|
JobStatus: jobStatuses, |
|
|
|
JobTypes: jobTypes, |
|
|
|
NeedRepoInfo: true, |
|
|
|
IsLatestVersion: modelarts.IsLatestVersion, |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
ctx.ServerError("Get job failed:", err) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
for i, task := range ciTasks { |
|
|
|
ciTasks[i].CanDebug = true |
|
|
|
ciTasks[i].CanDel = true |
|
|
|
ciTasks[i].Cloudbrain.ComputeResource = task.ComputeResource |
|
|
|
} |
|
|
|
|
|
|
|
pager := context.NewPagination(int(count), setting.UI.IssuePagingNum, page, getTotalPage(count, setting.UI.IssuePagingNum)) |
|
|
|
pager.SetDefaultParams(ctx) |
|
|
|
pager.AddParam(ctx, "listType", "ListType") |
|
|
|
ctx.Data["Page"] = pager |
|
|
|
ctx.Data["PageIsCloudBrain"] = true |
|
|
|
ctx.Data["Tasks"] = ciTasks |
|
|
|
ctx.Data["CanCreate"] = true |
|
|
|
ctx.Data["Keyword"] = keyword |
|
|
|
|
|
|
|
userCloudbrainCount, err := models.GetUserCloudbrainCount(ctxUser.ID) |
|
|
|
if err != nil { |
|
|
|
ctx.ServerError("GetUserCloudbrainCount failed:", err) |
|
|
|
return |
|
|
|
} |
|
|
|
cloudbrainOneDuration, err := models.GetUserCloudbrainDuration(ctxUser.ID, models.TypeCloudBrainOne) |
|
|
|
if err != nil { |
|
|
|
ctx.ServerError("GetUserCloudbrainOneDuration failed:", err) |
|
|
|
return |
|
|
|
} |
|
|
|
cloudbrainTwoDuration, err := models.GetUserCloudbrainDuration(ctxUser.ID, models.TypeCloudBrainTwo) |
|
|
|
if err != nil { |
|
|
|
ctx.ServerError("GetUserCloudbrainTwoDuration failed:", err) |
|
|
|
return |
|
|
|
} |
|
|
|
ctx.Data["UserCloudbrainCount"] = userCloudbrainCount |
|
|
|
ctx.Data["cloudbrainOneDuration"] = cloudbrainOneDuration |
|
|
|
ctx.Data["cloudbrainTwoDuration"] = cloudbrainTwoDuration |
|
|
|
|
|
|
|
ctx.HTML(200, tplCloudbrains) |
|
|
|
|
|
|
|
} |
|
|
|
func getTotalPage(total int64, pageSize int) int { |
|
|
|
|
|
|
|
another := 0 |
|
|
|
if int(total)%pageSize != 0 { |
|
|
|
another = 1 |
|
|
|
} |
|
|
|
return int(total)/pageSize + another |
|
|
|
|
|
|
|
} |