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 += "
"; } /* */ } 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); } }); } /* */ 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 += "