var token; if(isEmpty(token)){ var meta = $("meta[name=_uid]"); if(!isEmpty(meta)){ token = meta.attr("content"); console.log("token is uid:" + token); } } 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 = 10; var html =document.documentElement; var lang = html.attributes["lang"] var isZh = true; if(lang != null && lang =="en-US" ){ isZh=false; } console.log("the language is " + lang); socket.onmessage = function (e) { var data =JSON.parse(e.data) console.log("recevie data=" + 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]; html += "
"; html += " \"\"" html += "
" html += " " + record.ActUser.Name + "" var actionName = getAction(record.OpType,isZh); if(record.OpType == "6" || record.OpType == "10" || record.OpType == "12" || record.OpType == "13"){ html += actionName; html += " " + getIssueText(record) + "" } if(record.OpType == "7" || record.OpType == "11" || record.OpType == "14" || record.OpType == "15"){ html += actionName; html += " " + getPRText(record) + "" } if(record.OpType == "1"){ html += actionName; html += " " + getRepoLink(record) + "" } if(record.OpType == "9"){ } if(record.Repo != null){ var time = getTime(record.Repo.UpdatedUnix,currentTime); html += time; } html += "
"; html += "
"; } /*
zhoupzh 合并了合并请求 OpenI/aiforge#116822 分钟前
*/ } console.log("html=" + html) output.innerHTML = 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){ currentTime = currentTime/1000; var timeEsc = currentTime - UpdatedUnix; console.log("currentTime=" + currentTime + " updateUnix=" + UpdatedUnix); var dayDiff = Math.floor(timeEsc / (24 * 3600 * 1000));//计算出相差天数 var leave1= timeEsc%(24*3600*1000) //计算天数后剩余的毫秒数 var hours=Math.floor(leave1/(3600*1000))//计算出小时数 //计算相差分钟数 var leave2=leave1%(3600*1000) //计算小时数后剩余的毫秒数 var minutes=Math.floor(leave2/(60*1000))//计算相差分钟数 var re = ""; if(hours > 0){ re += hours + "小时"; } if(minutes > 1){ re += hours + "分钟前"; }else{ if(hours == 0){ re = "刚刚" } } return re; } function getPRLink(record){ return "/" + record.Repo.OwnerName + "/" + record.Repo.Name + "/pulls/" + record.ID } function getPRText(record){ return record.Repo.OwnerName + "/" + record.Repo.Name + "#" + record.ID } function getIssueLink(record){ return "/" + record.Repo.OwnerName + "/" + record.Repo.Name + "/issues/" + record.ID } function getIssueText(record){ return record.Repo.OwnerName + "/" + record.Repo.Name + "#" + record.ID } /* 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} 为", "6":"创建了任务", "7":"创建了合并请求", "9":"推送了 {branch} 分支的代码到", "10":"评论了任务", "11":"合并了合并请求", "12":"关闭了任务", "13":"重新开启了任务", "14":"关闭了合并请求", "15":"重新开启了合并请求", "17":"从 {repoName} 删除分支 {deleteBranchName}", "22":"拒绝了合并请求" }; var actionNameEN={ "1":"created repository", "2":"renamed repository from {oldRepoName} to ", "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" }; var repoAndOrgZH={ "1":"项目", "2":"成员", "3":"团队" }; var repoAndOrgEN={ "1":"repository", "2":"Members ", "3":"Teams" }; 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"]; 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=" url = escape(url); html += "" + topic + ""; } } html += "
"; html += "
"; html += "
"; html += "
"; } } orgRepo.innerHTML = html; } /** * *
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 += "
"; html += "
"; html += "
"; html += "
"; html += " "; html += "
"; html += " " + record["Name"] + " " + record["FullName"]; html += "
" + record["NumRepos"] +" " + getRepoOrOrg(1,isZh) + " ・ " + record["NumMembers"] +" " + getRepoOrOrg(2,isZh) + " ・ " + record["NumTeams"] + " " + getRepoOrOrg(3,isZh) + "
"; html += "
"; html += "
"; html += "
"; html += "
"; html += "
"; } } orgDiv.innerHTML = html; }