diff --git a/routers/admin/cloudbrains.go b/routers/admin/cloudbrains.go index 5f42c8a51..c4e0e827a 100755 --- a/routers/admin/cloudbrains.go +++ b/routers/admin/cloudbrains.go @@ -70,7 +70,7 @@ func CloudBrains(ctx *context.Context) { keyword := strings.Trim(ctx.Query("q"), " ") - ciTasks, _, err := models.Cloudbrains(&models.CloudbrainsOptions{ + ciTasks, count, err := models.Cloudbrains(&models.CloudbrainsOptions{ ListOptions: models.ListOptions{ Page: page, PageSize: setting.UI.IssuePagingNum, @@ -84,6 +84,7 @@ func CloudBrains(ctx *context.Context) { IsLatestVersion: modelarts.IsLatestVersion, ComputeResource: listType, Type: models.TypeCloudBrainAll, + AiCenter: aiCenter, Cluster: cluster, }) if err != nil { @@ -92,24 +93,25 @@ func CloudBrains(ctx *context.Context) { } models.LoadSpecs4CloudbrainInfo(ciTasks) - tasks := []*models.CloudbrainInfo{} - - for _, task := range ciTasks { - if aiCenter == "" || aiCenter == task.Cloudbrain.Spec.AiCenterCode { - task.CanDebug = true - task.CanDel = true - task.Cloudbrain.ComputeResource = task.ComputeResource - tasks = append(tasks, task) + + for i, task := range ciTasks { + ciTasks[i].CanDebug = true + ciTasks[i].CanDel = true + ciTasks[i].Cloudbrain.ComputeResource = task.ComputeResource + + if ciTasks[i].Cloudbrain.Type == models.TypeC2Net { + ciTasks[i].Cloudbrain.Spec.Cluster = models.C2NetCluster + } else { + ciTasks[i].Cloudbrain.Spec.Cluster = models.OpenICluster } } - count := int64(len(tasks)) 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"] = tasks + ctx.Data["Tasks"] = ciTasks ctx.Data["CanCreate"] = true ctx.Data["Keyword"] = keyword diff --git a/routers/user/home.go b/routers/user/home.go index 345b9d296..1ec6e4e3e 100755 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -812,7 +812,7 @@ func Cloudbrains(ctx *context.Context) { for i, _ := range repos { repoIDList = append(repoIDList, repos[i].ID) } - ciTasks, _, err := models.Cloudbrains(&models.CloudbrainsOptions{ + ciTasks, count, err := models.Cloudbrains(&models.CloudbrainsOptions{ ListOptions: models.ListOptions{ Page: page, PageSize: setting.UI.IssuePagingNum, @@ -828,29 +828,30 @@ func Cloudbrains(ctx *context.Context) { RepoIDList: repoIDList, ComputeResource: listType, Type: models.TypeCloudBrainAll, + AiCenter: aiCenter, Cluster: cluster, }) if err != nil { ctx.ServerError("Get job failed:", err) return } - models.LoadSpecs4CloudbrainInfo(ciTasks) - tasks := []*models.CloudbrainInfo{} - for _, task := range ciTasks { - if aiCenter == "" || aiCenter == task.Cloudbrain.Spec.AiCenterCode { - task.CanDebug = true - task.CanDel = true - task.Cloudbrain.ComputeResource = task.ComputeResource - tasks = append(tasks, task) + for i, _ := range ciTasks { + ciTasks[i].CanDebug = true + ciTasks[i].CanDel = true + ciTasks[i].Cloudbrain.ComputeResource = ciTasks[i].ComputeResource + + if ciTasks[i].Cloudbrain.Type == models.TypeC2Net { + ciTasks[i].Cloudbrain.Spec.Cluster = models.C2NetCluster + } else { + ciTasks[i].Cloudbrain.Spec.Cluster = models.OpenICluster } } - count := int64(len(tasks)) 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["PageIsUserCloudBrain"] = true - ctx.Data["Tasks"] = tasks + ctx.Data["Tasks"] = ciTasks ctx.Data["CanCreate"] = true ctx.Data["Keyword"] = keyword diff --git a/templates/admin/cloudbrain/search.tmpl b/templates/admin/cloudbrain/search.tmpl index 5d250db29..12e8a7515 100644 --- a/templates/admin/cloudbrain/search.tmpl +++ b/templates/admin/cloudbrain/search.tmpl @@ -71,33 +71,36 @@ document.addEventListener('DOMContentLoaded', function() { $.ajax({ type: "GET", - url: "/admin/resources/queue/centers", + url: "/api/v1/cloudbrain/get_center_info", dataType: "json", data: {}, success: function (res) { - if (res && res.Code === 0) { - var data = res.Data; - var aiCenterSelEl = $('#aiCenter-sel'); - var itemEl = aiCenterSelEl.find('.menu .item').eq(0); - var selectAiCenterCode = aiCenterSelEl.find('.default').attr('aicenter'); - var selectAiCenterName = ''; - for (var i = 0, iLen = data.length; i < iLen; i++) { - var dataI = data[i]; - var itemClone = itemEl.clone(); - var oHref = itemClone.attr('href'); - var oId = itemClone.attr('id'); - itemClone.attr('data-value', dataI.AiCenterCode); - itemClone.removeAttr('id'); - itemClone.attr('href', oHref + dataI.AiCenterCode); - itemClone.text(dataI.AiCenterName); - aiCenterSelEl.find('.menu').append(itemClone); - if (selectAiCenterCode === dataI.AiCenterCode) { - selectAiCenterName = dataI.AiCenterName; - } + var data = res || []; + var aiCenterSelEl = $('#aiCenter-sel'); + var itemEl = aiCenterSelEl.find('.menu .item').eq(0); + var selectAiCenterCode = aiCenterSelEl.find('.default').attr('aicenter'); + var selectAiCenterName = ''; + var lang = document.querySelector('html').getAttribute('lang') || 'en-US'; + var except = ['', 'more']; + for (var i = 0, iLen = data.length; i < iLen; i++) { + var dataI = data[i]; + var aiCenterCode = dataI.name; + if (except.indexOf(aiCenterCode) >= 0) continue; + var aiCenterName = lang === 'en-US' ? dataI.content_en : dataI.content; + var itemClone = itemEl.clone(); + var oHref = itemClone.attr('href'); + var oId = itemClone.attr('id'); + itemClone.attr('data-value', aiCenterCode); + itemClone.removeAttr('id'); + itemClone.attr('href', oHref + aiCenterCode); + itemClone.text(aiCenterName); + aiCenterSelEl.find('.menu').append(itemClone); + if (selectAiCenterCode === aiCenterCode) { + selectAiCenterName = aiCenterName; } - selectAiCenterCode && aiCenterSelEl.dropdown('set selected', selectAiCenterCode); - selectAiCenterName && aiCenterSelEl.dropdown('set text', selectAiCenterName); } + selectAiCenterCode && aiCenterSelEl.dropdown('set selected', selectAiCenterCode); + selectAiCenterName && aiCenterSelEl.dropdown('set text', selectAiCenterName); }, error: function (err) { console.log(err); diff --git a/templates/admin/cloudbrain/search_dashboard.tmpl b/templates/admin/cloudbrain/search_dashboard.tmpl index d6ec1d5e4..2bf738dc9 100644 --- a/templates/admin/cloudbrain/search_dashboard.tmpl +++ b/templates/admin/cloudbrain/search_dashboard.tmpl @@ -85,33 +85,36 @@ document.addEventListener('DOMContentLoaded', function() { $.ajax({ type: "GET", - url: "/admin/resources/queue/centers", + url: "/api/v1/cloudbrain/get_center_info", dataType: "json", data: {}, success: function (res) { - if (res && res.Code === 0) { - var data = res.Data; - var aiCenterSelEl = $('#aiCenter-sel'); - var itemEl = aiCenterSelEl.find('.menu .item').eq(0); - var selectAiCenterCode = aiCenterSelEl.find('.default').attr('aicenter'); - var selectAiCenterName = ''; - for (var i = 0, iLen = data.length; i < iLen; i++) { - var dataI = data[i]; - var itemClone = itemEl.clone(); - var oHref = itemClone.attr('href'); - var oId = itemClone.attr('id'); - itemClone.attr('data-value', dataI.AiCenterCode); - itemClone.removeAttr('id'); - itemClone.attr('href', oHref + dataI.AiCenterCode); - itemClone.text(dataI.AiCenterName); - aiCenterSelEl.find('.menu').append(itemClone); - if (selectAiCenterCode === dataI.AiCenterCode) { - selectAiCenterName = dataI.AiCenterName; - } + var data = res || []; + var aiCenterSelEl = $('#aiCenter-sel'); + var itemEl = aiCenterSelEl.find('.menu .item').eq(0); + var selectAiCenterCode = aiCenterSelEl.find('.default').attr('aicenter'); + var selectAiCenterName = ''; + var lang = document.querySelector('html').getAttribute('lang') || 'en-US'; + var except = ['', 'more']; + for (var i = 0, iLen = data.length; i < iLen; i++) { + var dataI = data[i]; + var aiCenterCode = dataI.name; + if (except.indexOf(aiCenterCode) >= 0) continue; + var aiCenterName = lang === 'en-US' ? dataI.content_en : dataI.content; + var itemClone = itemEl.clone(); + var oHref = itemClone.attr('href'); + var oId = itemClone.attr('id'); + itemClone.attr('data-value', aiCenterCode); + itemClone.removeAttr('id'); + itemClone.attr('href', oHref + aiCenterCode); + itemClone.text(aiCenterName); + aiCenterSelEl.find('.menu').append(itemClone); + if (selectAiCenterCode === aiCenterCode) { + selectAiCenterName = aiCenterName; } - selectAiCenterCode && aiCenterSelEl.dropdown('set selected', selectAiCenterCode); - selectAiCenterName && aiCenterSelEl.dropdown('set text', selectAiCenterName); } + selectAiCenterCode && aiCenterSelEl.dropdown('set selected', selectAiCenterCode); + selectAiCenterName && aiCenterSelEl.dropdown('set text', selectAiCenterName); }, error: function (err) { console.log(err); @@ -119,4 +122,4 @@ }); }); })(); - \ No newline at end of file +