var token; if(isEmpty(token)){ var meta = $("meta[name=_uid]"); if(!isEmpty(meta)){ token = meta.attr("content"); console.log("token is uid:" + token); } } var swiperNewMessage = new Swiper(".newslist", { direction: "vertical", slidesPerView: 10, loop: true, autoplay: { delay: 2500, disableOnInteraction: false, }, }); var swiperRepo = new Swiper(".homepro-list", { slidesPerView: 3, slidesPerColumn: 2, slidesPerColumnFill:'row', spaceBetween: 30, pagination: { el: ".swiper-pagination", clickable: true, }, autoplay: { delay: 2500, disableOnInteraction: false, }, }); var output = document.getElementById("newmessage"); var socket = new WebSocket("ws://" + document.location.host + "/action/notification"); socket.onopen = function () { console.log("message has connected."); }; var messageQueue = []; var maxSize = 20; var html =document.documentElement; var lang = html.attributes["lang"] var isZh = true; if(lang != null && lang.nodeValue =="en-US" ){ console.log("the language is " + lang.nodeValue); isZh=false; }else{ console.log("default lang=zh"); } socket.onmessage = function (e) { var data =JSON.parse(e.data) console.log("recevie data=" + e.data) var html = ""; if (data != null){ console.log("queue length=" + messageQueue.length); if(messageQueue.length > maxSize){ delete messageQueue[0]; }else{ messageQueue.push(data); } var currentTime = new Date().getTime(); for(var i = 0; i < messageQueue.length; i++){ var record = messageQueue[i]; var recordPrefix = getMsg(record); var actionName = getAction(record.OpType,isZh); if(record.OpType == "6" || record.OpType == "10" || record.OpType == "12" || record.OpType == "13"){ html += recordPrefix + actionName; html += " " + getIssueText(record) + "" } else if(record.OpType == "7" || record.OpType == "11" || record.OpType == "14" || record.OpType == "15" || record.OpType == "22" || record.OpType == "23"){ html += recordPrefix + actionName; html += " " + getPRText(record) + "" } else if(record.OpType == "1"){ html += recordPrefix + actionName; html += " " + getRepoLink(record) + "" } else if(record.OpType == "9" || record.OpType == "5"){ branch = "" + record.RefName + "" actionName = actionName.replace("{branch}",branch); html += recordPrefix + actionName; html += " " + getRepoLink(record) + "" }else if(record.OpType == "17"){ actionName = actionName.replace("{deleteBranchName}",record.RefName); var repoLink = "" + getRepoLink(record) + "" actionName = actionName.replace("{repoName}",repoLink); html += recordPrefix + actionName; } else if(record.OpType == "2"){ actionName = actionName.replace("{oldRepoName}",record.Content); html += recordPrefix + actionName; html += " " + getRepoLink(record) + "" } else{ continue; } if(record.Repo != null){ var time = getTime(record.CreatedUnix,currentTime); html += " " + time; } html += ""; html += ""; } /*
zhoupzh 合并了合并请求 OpenI/aiforge#116822 分钟前
*/ } console.log("html=" + html) output.innerHTML = html; swiperNewMessage.updateSlides(); swiperNewMessage.updateProgress(); }; function getMsg(record){ var html =""; html += "
"; html += " \"\"" html += "
" html += " " + record.ActUser.Name + "" return html; } function getRepoLink(record){ return "/" + record.Repo.OwnerName + "/" + record.Repo.Name; } function getRepoLink(record){ return record.Repo.OwnerName + "/" + record.Repo.Name; } function getTime(UpdatedUnix,currentTime){ UpdatedUnix = UpdatedUnix; currentTime = currentTime / 1000; var timeEscSecond = currentTime - UpdatedUnix; if( timeEscSecond < 0){ timeEscSecond = 1; } console.log("currentTime=" + currentTime + " updateUnix=" + UpdatedUnix); var hours= Math.floor(timeEscSecond / 3600); //计算相差分钟数 var leave2 = Math.floor(timeEscSecond % (3600)); //计算小时数后剩余的秒数 var minutes= Math.floor(leave2 / 60);//计算相差分钟数 var leave3=Math.floor(leave2 % 60); //计算分钟数后剩余的秒数 var seconds= leave3; if(hours == 0 && minutes == 0){ return seconds + getRepoOrOrg(6,isZh); }else{ if(hours > 0){ return hours + getRepoOrOrg(4,isZh); }else{ return minutes + getRepoOrOrg(5,isZh); } } } function getPRLink(record){ return "/" + record.Repo.OwnerName + "/" + record.Repo.Name + "/pulls/" + getIssueId(record); } function getPRText(record){ return record.Repo.OwnerName + "/" + record.Repo.Name + "#" + getIssueId(record); } function getIssueLink(record){ return "/" + record.Repo.OwnerName + "/" + record.Repo.Name + "/issues/" + getIssueId(record); } function getIssueId(record){ var Id = "1"; if(!isEmpty(record.Comment) && !isEmpty(record.Comment.Issue)){ Id = record.Comment.Issue.Index; }else{ if(!isEmpty(record.Content)){ var content = record.Content; var index = content.indexOf("|"); if(index != -1){ Id = content.substring(0,index); } } } return Id; } function getIssueText(record){ return record.Repo.OwnerName + "/" + record.Repo.Name + "#" + getIssueId(record); } /* ActionCreateRepo ActionType = iota + 1 // 1 ActionRenameRepo // 2 ActionStarRepo // 3 ActionWatchRepo // 4 ActionCommitRepo // 5 ActionCreateIssue // 6 ActionCreatePullRequest // 7 ActionTransferRepo // 8 ActionPushTag // 9 ActionCommentIssue // 10 ActionMergePullRequest // 11 ActionCloseIssue // 12 ActionReopenIssue // 13 ActionClosePullRequest // 14 ActionReopenPullRequest // 15 ActionDeleteTag // 16 ActionDeleteBranch // 17 ActionMirrorSyncPush // 18 ActionMirrorSyncCreate // 19 ActionMirrorSyncDelete // 20 ActionApprovePullRequest // 21 ActionRejectPullRequest // 22 ActionCommentPull // 23 */ var actionNameZH={ "1":"创建了项目", "2":"重命名项目 {oldRepoName} 为", "5":"推送了 {branch} 分支的代码到", "6":"创建了任务", "7":"创建了合并请求", "9":"推送了 {branch} 分支的代码到", "10":"评论了任务", "11":"合并了合并请求", "12":"关闭了任务", "13":"重新开启了任务", "14":"关闭了合并请求", "15":"重新开启了合并请求", "17":"从 {repoName} 删除分支 {deleteBranchName}", "22":"拒绝了合并请求", "23":"评论了合并请求" }; var actionNameEN={ "1":" created repository", "2":" renamed repository from {oldRepoName} to ", "5":" pushed to {branch} at", "6":" opened issue", "7":" created pull request", "9":" pushed to {branch} at", "10":" commented on issue", "11":" merged pull request", "12":" closed issue", "13":" reopened issue", "14":" closed pull request", "15":" reopened pull request", "17":" deleted branch {deleteBranchName} from {repoName}", "22":" rejected pull request", "23":" commented on pull request" }; var repoAndOrgZH={ "1":"项目", "2":"成员", "3":"团队", "4":"小时前", "5":"分钟前", "6":"秒前" }; var repoAndOrgEN={ "1":"repository", "2":"Members ", "3":"Teams", "4":" hours ago", "5":" minutes ago", "6":" seconds ago" }; function getAction(opType,isZh){ if(isZh){ return actionNameZH[opType] }else{ return actionNameEN[opType] } } queryRecommendData(); function queryRecommendData(){ $.ajax({ type:"GET", url:"/recommend/org", headers: { authorization:token, }, dataType:"json", async:false, success:function(json){ console.log(json); displayOrg(json); }, error:function(response) { console.log(response); } }); $.ajax({ type:"GET", url:"/recommend/repo", headers: { authorization:token, }, dataType:"json", async:false, success:function(json){ console.log(json); displayRepo(json); }, error:function(response) { console.log(response); } }); } /*
276 32 aiforge
本项目是群体化方法与技术的开源实现案例,在基于Gitea的基础上,进一步支持社交化的协同开发、协同学习、协同研究等群体创新实践服务,特别是针对新一代人工智能技术特点,重点支持项目管理、git代码管理、大数据集存储管理与智能计算平台接入。
*/ function displayRepo(json){ var orgRepo = document.getElementById("recommendrepo"); var html = ""; if (json != null && json.length > 0){ for(var i = 0; i < json.length;i++){ var record = json[i] html += "
"; html += "
"; html += "
"; html += " "; html += " " + record["NumStars"] + "" + record["NumForks"]; html += " "; html += " "; html += " " + record["Name"] +""; html += "
" + record["Description"] + "
"; html += "
" if(record["Topics"] != null){ for(var j = 0; j < record["Topics"].length; j++){ topic = record["Topics"][j]; url = "/explore/repos?q=" + (topic) + "&topic=" html += "" + topic + ""; } } html += "
"; html += "
"; html += "
"; html += "
"; } } orgRepo.innerHTML = html; swiperRepo.updateSlides(); swiperRepo.updateProgress(); } /** * *
OpenI 启智社区
39 项目 ・ 60 成员 ・ 23 团队
*/ //var repoAndOrgZH = new Map([['1', "项目"], ['2', "成员"], ['3', "团队"]]); //var repoAndOrgEN = new Map([['1', "Repository"], ['2', "Members"], ['3', "Teams"]]); function getRepoOrOrg(key,isZhLang){ if(isZhLang){ return repoAndOrgZH[key]; }else{ return repoAndOrgEN[key]; } } function displayOrg(json){ var orgDiv = document.getElementById("recommendorg"); var html = ""; if (json != null && json.length > 0){ for(var i = 0; i < json.length;i++){ var record = json[i] html += ""; } } orgDiv.innerHTML = html; }