| @@ -46,3 +46,6 @@ | |||
| - 点击[这里](https://git.openi.org.cn/OpenI/aiforge/issues)在线提交问题(点击页面右上角绿色按钮**创建任务**) | |||
| - 加入微信群实时交流,获得进一步的支持 | |||
| <img src="https://git.openi.org.cn/OpenI/aiforge/wiki/raw/img/wechatgroup.jpg" width=200px /> | |||
| ## 启智社区小白训练营: | |||
| - 结合案例给大家详细讲解如何使用社区平台,帮助无技术背景的小白成长为启智社区达人 (https://git.openi.org.cn/zeizei/OpenI_Learning) | |||
| @@ -6,8 +6,6 @@ import ( | |||
| "fmt" | |||
| ) | |||
| const DefaultOrgTagLimit = -1 | |||
| type OfficialTag struct { | |||
| ID int64 `xorm:"pk autoincr"` | |||
| Name string `xorm:"NOT NULL"` | |||
| @@ -156,7 +154,7 @@ func GetOfficialTagDetail(orgID, tagId int64) ([]Repository, error) { | |||
| func GetAllOfficialTags() ([]OfficialTag, error) { | |||
| //todo redis? | |||
| o := make([]OfficialTag, 0) | |||
| err := x.Where("status = ?", 0).Find(&o) | |||
| err := x.Where("status = ?", 0).OrderBy("updated_unix desc").Find(&o) | |||
| if err != nil { | |||
| log.Error("GetAllOfficialTags error,%v", err) | |||
| return nil, err | |||
| @@ -7,7 +7,6 @@ package repo | |||
| import ( | |||
| "net/http" | |||
| "os" | |||
| "strconv" | |||
| "strings" | |||
| @@ -15,8 +14,8 @@ import ( | |||
| "code.gitea.io/gitea/modules/context" | |||
| "code.gitea.io/gitea/modules/log" | |||
| "code.gitea.io/gitea/modules/modelarts" | |||
| "code.gitea.io/gitea/modules/setting" | |||
| "code.gitea.io/gitea/modules/storage" | |||
| routerRepo "code.gitea.io/gitea/routers/repo" | |||
| ) | |||
| func GetModelArtsNotebook(ctx *context.APIContext) { | |||
| @@ -258,7 +257,7 @@ func DelTrainJobVersion(ctx *context.APIContext) { | |||
| } | |||
| } | |||
| } else { //已删除该任务下的所有版本 | |||
| deleteJobStorage(task.JobName) | |||
| routerRepo.DeleteJobStorage(task.JobName) | |||
| } | |||
| ctx.JSON(http.StatusOK, map[string]interface{}{ | |||
| @@ -325,21 +324,3 @@ func ModelList(ctx *context.APIContext) { | |||
| "PageIsCloudBrain": true, | |||
| }) | |||
| } | |||
| func deleteJobStorage(jobName string) error { | |||
| //delete local | |||
| localJobPath := setting.JobPath + jobName | |||
| err := os.RemoveAll(localJobPath) | |||
| if err != nil { | |||
| log.Error("RemoveAll(%s) failed:%v", localJobPath, err) | |||
| } | |||
| //delete oss | |||
| dirPath := setting.CodePathPrefix + jobName + "/" | |||
| err = storage.ObsRemoveObject(setting.Bucket, dirPath) | |||
| if err != nil { | |||
| log.Error("ObsRemoveObject(%s) failed:%v", localJobPath, err) | |||
| } | |||
| return nil | |||
| } | |||
| @@ -13,14 +13,23 @@ import ( | |||
| "strconv" | |||
| ) | |||
| const DefaultOrgTagLimit = -1 | |||
| // SubmitTags submit repos of org tag | |||
| func SubmitTags(ctx *context.Context, form auth.SubmitReposOfTagForm) { | |||
| org, tag := getOrgAndTagFromContext(ctx) | |||
| if !ctx.Org.IsOwner { | |||
| ctx.ServerError("UpdateTagReposByID", errors.New("no access to submit tags")) | |||
| return | |||
| } | |||
| tag := getTagFromContext(ctx) | |||
| if ctx.Written() { | |||
| return | |||
| } | |||
| err := models.UpdateTagReposByID(tag.ID, org.ID, form.RepoList) | |||
| if tag.Limit != DefaultOrgTagLimit && len(form.RepoList) > tag.Limit { | |||
| ctx.ServerError("UpdateTagReposByID", errors.New("tags size over limit")) | |||
| return | |||
| } | |||
| err := models.UpdateTagReposByID(tag.ID, ctx.Org.Organization.ID, form.RepoList) | |||
| if err != nil { | |||
| ctx.ServerError("UpdateTagReposByID", err) | |||
| return | |||
| @@ -34,12 +43,16 @@ func SubmitTags(ctx *context.Context, form auth.SubmitReposOfTagForm) { | |||
| // GetTagRepos get repos under org tag | |||
| func GetTagRepos(ctx *context.Context) { | |||
| org, tag := getOrgAndTagFromContext(ctx) | |||
| if !ctx.Org.IsOwner { | |||
| ctx.ServerError("GetTagRepos", errors.New("no access to get tags")) | |||
| return | |||
| } | |||
| tag := getTagFromContext(ctx) | |||
| if ctx.Written() { | |||
| return | |||
| } | |||
| r, err := models.GetTagRepos(tag.ID, org.ID) | |||
| r, err := models.GetTagRepos(tag.ID, ctx.Org.Organization.ID) | |||
| if err != nil { | |||
| ctx.ServerError("GetTagRepos", err) | |||
| return | |||
| @@ -52,36 +65,15 @@ func GetTagRepos(ctx *context.Context) { | |||
| }) | |||
| } | |||
| // getDashboardContextUser finds out dashboard is viewing as which context user. | |||
| func getOrgAndTagFromContext(ctx *context.Context) (*models.User, *models.OfficialTag) { | |||
| var org *models.User | |||
| // getTagFromContext finds out tag info From context. | |||
| func getTagFromContext(ctx *context.Context) *models.OfficialTag { | |||
| var tag *models.OfficialTag | |||
| var err error | |||
| orgName := ctx.Params(":org") | |||
| if len(orgName) > 0 { | |||
| // Organization. | |||
| org, err = models.GetUserByName(orgName) | |||
| if err != nil { | |||
| if models.IsErrUserNotExist(err) { | |||
| ctx.NotFound("GetUserByName", err) | |||
| } else { | |||
| ctx.ServerError("GetUserByName", err) | |||
| } | |||
| return nil, nil | |||
| } | |||
| if !org.IsOrganization() { | |||
| ctx.ServerError("GetUserByName", errors.New("it is not an organization")) | |||
| return nil, nil | |||
| } | |||
| } | |||
| tagIdStr := ctx.Query("tagId") | |||
| if len(tagIdStr) == 0 { | |||
| ctx.ServerError("GetTagInfo", errors.New("tag is not exist")) | |||
| return nil, nil | |||
| return nil | |||
| } | |||
| tagId, _ := strconv.ParseInt(tagIdStr, 10, 32) | |||
| tag, err = models.GetTagByID(tagId) | |||
| @@ -91,8 +83,8 @@ func getOrgAndTagFromContext(ctx *context.Context) (*models.User, *models.Offici | |||
| } else { | |||
| ctx.ServerError("GetTagInfo", err) | |||
| } | |||
| return nil, nil | |||
| return nil | |||
| } | |||
| return org, tag | |||
| return tag | |||
| } | |||
| @@ -294,7 +294,7 @@ func CloudBrainRestart(ctx *context.Context) { | |||
| if count >= 1 { | |||
| log.Error("the user already has running or waiting task", ctx.Data["MsgID"]) | |||
| resultCode = "-1" | |||
| errorMsg = "the user already has running or waiting task" | |||
| errorMsg = "you have already a running or waiting task, can not create more" | |||
| break | |||
| } | |||
| } | |||
| @@ -11,11 +11,10 @@ import ( | |||
| "strings" | |||
| "time" | |||
| "code.gitea.io/gitea/modules/cloudbrain" | |||
| "code.gitea.io/gitea/models" | |||
| "code.gitea.io/gitea/modules/auth" | |||
| "code.gitea.io/gitea/modules/base" | |||
| "code.gitea.io/gitea/modules/cloudbrain" | |||
| "code.gitea.io/gitea/modules/context" | |||
| "code.gitea.io/gitea/modules/git" | |||
| "code.gitea.io/gitea/modules/log" | |||
| @@ -249,7 +248,7 @@ func NotebookManage(ctx *context.Context) { | |||
| break | |||
| } | |||
| if !ctx.IsSigned || (ctx.User.ID != task.UserID && !ctx.IsUserSiteAdmin() && !ctx.IsUserRepoOwner()){ | |||
| if !ctx.IsSigned || (ctx.User.ID != task.UserID && !ctx.IsUserSiteAdmin() && !ctx.IsUserRepoOwner()) { | |||
| log.Error("the user has no right ro stop the job", task.JobName, ctx.Data["MsgID"]) | |||
| resultCode = "-1" | |||
| errorMsg = "you have no right to stop the job" | |||
| @@ -263,7 +262,7 @@ func NotebookManage(ctx *context.Context) { | |||
| break | |||
| } | |||
| if !ctx.IsSigned || (ctx.User.ID != task.UserID && !ctx.IsUserSiteAdmin()){ | |||
| if !ctx.IsSigned || (ctx.User.ID != task.UserID && !ctx.IsUserSiteAdmin()) { | |||
| log.Error("the user has no right ro restart the job", task.JobName, ctx.Data["MsgID"]) | |||
| resultCode = "-1" | |||
| errorMsg = "you have no right to restart the job" | |||
| @@ -1413,6 +1412,11 @@ func TrainJobDel(ctx *context.Context) { | |||
| } | |||
| } | |||
| //删除存储 | |||
| if len(VersionListTasks) > 0 { | |||
| DeleteJobStorage(VersionListTasks[0].JobName) | |||
| } | |||
| ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/modelarts/train-job") | |||
| } | |||
| @@ -1538,3 +1542,21 @@ func ModelDownload(ctx *context.Context) { | |||
| } | |||
| http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusMovedPermanently) | |||
| } | |||
| func DeleteJobStorage(jobName string) error { | |||
| //delete local | |||
| localJobPath := setting.JobPath + jobName | |||
| err := os.RemoveAll(localJobPath) | |||
| if err != nil { | |||
| log.Error("RemoveAll(%s) failed:%v", localJobPath, err) | |||
| } | |||
| //delete oss | |||
| dirPath := setting.CodePathPrefix + jobName + "/" | |||
| err = storage.ObsRemoveObject(setting.Bucket, dirPath) | |||
| if err != nil { | |||
| log.Error("ObsRemoveObject(%s) failed:%v", localJobPath, err) | |||
| } | |||
| return nil | |||
| } | |||
| @@ -20,7 +20,7 @@ | |||
| } | |||
| .content_list{ | |||
| max-height: 200px; | |||
| max-height: 130px; | |||
| overflow: auto; | |||
| } | |||
| .Relist{ | |||
| @@ -152,11 +152,12 @@ | |||
| var num=0; | |||
| function showcreate(obj){ | |||
| document.getElementById("search_selectPro").value='' | |||
| $('.ui.modal') | |||
| .modal({ | |||
| centered: false, | |||
| onShow:function(){ | |||
| $("#org_list").empty() | |||
| $("#org_list").empty() | |||
| getPro(1) | |||
| }, | |||
| @@ -179,7 +180,7 @@ | |||
| pro_html = getHTML(data) | |||
| $("#org_list").append(pro_html) | |||
| console.log('原始',data) | |||
| checkedNum() | |||
| checkedNum(0) | |||
| } | |||
| }); | |||
| } | |||
| @@ -188,11 +189,11 @@ | |||
| for (let i=0;i<data.length;i++){ | |||
| if (data[i].Selected==true){ | |||
| console.log("data[i]:",data[i]) | |||
| pro_html += `<div class="ui checkbox" style="width: 33%;margin-bottom:10px" > <input type="checkbox" checked="" onclick="checkedNum()" class="Relist" name ='select_pro_name' data-repoid="${data[i].RepoID}" data-reponame="${data[i].RepoName}" data-selected=${data[i].Selected} > <label> ${data[i].RepoName} </label></div>` | |||
| pro_html += `<div class="ui checkbox" style="width: 33%;margin-bottom:10px" > <input type="checkbox" id = " ${i}" checked="" onclick="checkedNum(${i})" class="Relist" name ='select_pro_name' data-repoid="${data[i].RepoID}" data-reponame="${data[i].RepoName}" data-selected=${data[i].Selected} > <label> ${data[i].RepoName} </label></div>` | |||
| pro_html += '</div>' | |||
| } | |||
| else{ | |||
| pro_html += `<div class="ui checkbox" style="width: 33%;margin-bottom:10px" > <input type="checkbox" onclick="checkedNum()" class="Relist" name ='select_pro_name' data-repoid="${data[i].RepoID}" data-reponame="${data[i].RepoName}" data-selected= ${data[i].Selected}> <label> ${data[i].RepoName} </label></div>` | |||
| pro_html += `<div class="ui checkbox" style="width: 33%;margin-bottom:10px" > <input type="checkbox" id = "${i}" onclick="checkedNum(${i})" class="Relist" name ='select_pro_name' data-repoid="${data[i].RepoID}" data-reponame="${data[i].RepoName}" data-selected= ${data[i].Selected}> <label> ${data[i].RepoName} </label></div>` | |||
| pro_html += '</div>' | |||
| } | |||
| } | |||
| @@ -205,6 +206,10 @@ | |||
| saveData.push(parseInt(this.dataset.repoid)); | |||
| }) | |||
| if(saveData.length>9){ | |||
| alert("最多可选9个,保存失败") | |||
| return | |||
| } | |||
| // saveData = getSelecteDataID(); | |||
| // console.log("数据:",saveData) | |||
| $.ajax({ | |||
| @@ -227,7 +232,7 @@ | |||
| var selectedData=[]; | |||
| $('input[name="select_pro_name"]:checked').each(function(){ | |||
| // console.log(this) | |||
| console.log('值',this.dataset.selected) | |||
| // console.log('值',this.dataset.selected) | |||
| selectedData.push({"RepoID":parseInt(this.dataset.repoid),"RepoName":this.dataset.reponame,"Selected":JSON.parse(this.dataset.selected)}); | |||
| }) | |||
| @@ -272,14 +277,22 @@ | |||
| } | |||
| } | |||
| function checkedNum(){ | |||
| function checkedNum(id){ | |||
| num=0; | |||
| var inputs = document.getElementsByName("select_pro_name") | |||
| for (var i=0;i<inputs.length;i++){ | |||
| if(inputs[i].checked){ | |||
| num++ | |||
| if(num>9){ | |||
| document.getElementById(id).checked=false | |||
| alert("选择超过9个,请重新选择!") | |||
| return | |||
| } | |||
| } | |||
| } | |||
| var show_num = 9-num; | |||
| document.getElementById("recommend").innerHTML="还能推荐"+show_num+"个" | |||