|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501 |
-
- var token;
- if(isEmpty(token)){
- var meta = $("meta[name=_uid]");
- if(!isEmpty(meta)){
- token = meta.attr("content");
- }
- }
- var swiperNewMessage = new Swiper(".newslist", {
- direction: "vertical",
- slidesPerView: 10,
- loop: true,
- autoplay: {
- delay: 2500,
- disableOnInteraction: false,
- },
- });
- var swiperRepo = new Swiper(".homepro-list", {
- slidesPerView: 1,
- slidesPerColumn: 2,
- slidesPerColumnFill:'row',
- spaceBetween: 30,
- pagination: {
- el: ".swiper-pagination",
- clickable: true,
- },
- autoplay: {
- delay: 2500,
- disableOnInteraction: false,
- },
- breakpoints: {
- 768: {
- slidesPerView: 2,
- },
- 1024: {
- slidesPerView: 3,
- },
- },
- });
-
- var swiperOrg = new Swiper(".homeorg-list", {
- slidesPerView: 1,
- slidesPerColumn: 4,
- slidesPerColumnFill:'row',
- spaceBetween: 15,
- pagination: {
- el: ".swiper-pagination",
- clickable: true,
- },
- autoplay: {
- delay: 4500,
- disableOnInteraction: false,
- },
- breakpoints: {
- 768: {
- slidesPerView: 2,
- },
- 1024: {
- slidesPerView: 3,
- },
- },
- });
-
- var output = document.getElementById("newmessage");
- var url = "ws://" + document.location.host + "/action/notification";
- if(document.location.host == "git.openi.org.cn" || document.URL.startsWith("https")){
- url = "wss://" + document.location.host + "/action/notification"
- }
- var socket = new WebSocket(url);
-
- socket.onopen = function () {
- messageQueue = [];
- console.log("message has connected.");
- };
-
- var maxSize = 20;
- var html =document.documentElement;
- var lang = html.attributes["lang"]
- var isZh = true;
- if(lang != null && lang.nodeValue =="en-US" ){
- isZh=false;
- }else{
- }
-
- socket.onmessage = function (e) {
- var data =JSON.parse(e.data)
- var html = "";
- if (data != null){
- 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 actionName = getAction(record.OpType,isZh);
- if(record.ActUser == null){
- console.log("receive action type=" + record.OpType + " name=" + actionName + " but user is null.");
- continue;
- }
- var recordPrefix = getMsg(record);
- if(record.OpType == "6" || record.OpType == "10" || record.OpType == "12" || record.OpType == "13"){
- html += recordPrefix + actionName;
- html += " <a href=\"" + getIssueLink(record) + "\" rel=\"nofollow\">" + getIssueText(record) + "</a>"
- }
- else if(record.OpType == "7" || record.OpType == "11" || record.OpType == "14" || record.OpType == "15" || record.OpType == "22"
- || record.OpType == "23"){
- html += recordPrefix + actionName;
- html += " <a href=\"" + getPRLink(record) + "\" rel=\"nofollow\">" + getPRText(record) + "</a>"
- }
- else if(record.OpType == "1"){
- html += recordPrefix + actionName;
- html += " <a href=\"" + getRepoLink(record) + "\" rel=\"nofollow\">" +getRepotext(record) + "</a>"
- }
- else if(record.OpType == "5"){
- branch = "<a href=\"" + getRepoLink(record) + "/src/branch/" + encodeURI(record.RefName) + "\" rel=\"nofollow\">" + record.RefName + "</a>"
- actionName = actionName.replace("{branch}",branch);
- html += recordPrefix + actionName;
- html += " <a href=\"" + getRepoLink(record) + "\" rel=\"nofollow\">" + getRepotext(record) + "</a>"
- }else if(record.OpType == "9"){
- branch = "<a href=\"" + getRepoLink(record) + "/src/tag/" + encodeURI(record.RefName) + "\" rel=\"nofollow\">" + record.RefName + "</a>"
- actionName = actionName.replace("{branch}",branch);
- html += recordPrefix + actionName;
- html += " <a href=\"" + getRepoLink(record) + "\" rel=\"nofollow\">" + getRepotext(record) + "</a>"
- }
- else if(record.OpType == "17"){
- actionName = actionName.replace("{deleteBranchName}",record.RefName);
- var repoLink = "<a href=\"" + getRepoLink(record) + "\" rel=\"nofollow\">" + getRepotext(record) + "</a>"
- actionName = actionName.replace("{repoName}",repoLink);
- html += recordPrefix + actionName;
- }
- else if(record.OpType == "2"){
- actionName = actionName.replace("{oldRepoName}",record.Content);
- html += recordPrefix + actionName;
- html += " <a href=\"" + getRepoLink(record) + "\" rel=\"nofollow\">" + getRepotext(record) + "</a>"
- }
- else if(record.OpType == "24" || record.OpType == "26" || record.OpType == "27" || record.OpType == "28" || record.OpType == "30" || record.OpType == "31"){
- html += recordPrefix + actionName;
- html += " <a href=\"" + getTaskLink(record) + "\" rel=\"nofollow\">" + record.RefName + "</a>"
- }
- else if(record.OpType == "25" || record.OpType == "29"){
- html += recordPrefix + actionName;
- html += " <a href=\"" + getTaskLink(record) + "\" rel=\"nofollow\">" + record.RefName + "</a>"
- }
- else{
- continue;
- }
- if(record.Repo != null){
- var time = getTime(record.CreatedUnix,currentTime);
- html += " " + time;
- }
- html += "</div>";
- html += "</div>";
- }
- }
- output.innerHTML = html;
- swiperNewMessage.updateSlides();
- swiperNewMessage.updateProgress();
- };
-
- function getTaskLink(record){
- var re = getRepoLink(record);
- if(record.OpType == 24){
- re = re + "/datasets?type=" + record.Content;
- }else if(record.OpType == 25){
- re = re + "/cloudbrain/" + record.Content;
- }else if(record.OpType == 26){
- re = re + "/modelarts/notebook/" + record.Content;
- }else if(record.OpType == 27){
- re = re + "/modelarts/train-job/" + record.Content;
- }else if(record.OpType == 28){
- re = re + "/modelarts/inference-job/" + record.Content;
- }else if(record.OpType == 29){
- re = re + "/cloudbrain/benchmark/" + record.Content;
- }else if(record.OpType == 30){
- re = re + "/modelmanage/show_model_info?name=" + record.RefName;
- }else if(record.OpType == 31){
- re = re + "/cloudbrain/train-job/" + record.Content;
- }
- re = encodeURI(re);
- return re;
- }
-
- function getMsg(record){
- var html ="";
- html += "<div class=\"swiper-slide item\">";
- var name = "";
- if(record.ActUser != null){
- name = record.ActUser.Name;
- }else{
- console.log("act user is null.");
- }
- html += " <img class=\"ui avatar image\" src=\"/user/avatar/" + name + "/-1\" alt=\"\">"
- html += " <div class=\"middle aligned content nowrap\">"
- html += " <a href=\"/" + encodeURI(name) + "\" title=\"\">" + name + "</a>"
- return html;
- }
-
- function getRepotext(record){
- if(record.Repo.Alias){
- return record.Repo.OwnerName + "/" + record.Repo.Alias;
- }else{
- return record.Repo.OwnerName + "/" + record.Repo.Name;
- }
- }
- function getRepoLink(record){
- return encodeURI(record.Repo.OwnerName + "/" + record.Repo.Name);
-
- }
-
- function getTime(UpdatedUnix,currentTime){
- UpdatedUnix = UpdatedUnix;
- currentTime = currentTime / 1000;
- var timeEscSecond = currentTime - UpdatedUnix;
- if( timeEscSecond < 0){
- timeEscSecond = 1;
- }
-
- 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,seconds);
- }else{
- if(hours > 0){
- return hours + getRepoOrOrg(4,isZh,hours);
- }else{
- return minutes + getRepoOrOrg(5,isZh,minutes);
- }
- }
- }
-
- function getPRLink(record){
- return encodeURI("/" + record.Repo.OwnerName + "/" + record.Repo.Name + "/pulls/" + getIssueId(record));
- }
- function getPRText(record){
- if(record.Repo.Alias){
- return record.Repo.OwnerName + "/" + record.Repo.Alias + "#" + getIssueId(record);
- }else{
- return record.Repo.OwnerName + "/" + record.Repo.Name + "#" + getIssueId(record);
- }
-
- }
-
- function getIssueLink(record){
-
- return encodeURI("/" + 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){
- if(record.Repo.Alias){
- return record.Repo.OwnerName + "/" + record.Repo.Alias + "#" + getIssueId(record);
- }else{
- 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":"评论了合并请求",
- "24":"上传了数据集文件",
- "25":"创建了CPU/GPU类型调试任务",
- "26":"创建了NPU类型调试任务",
- "27":"创建了NPU类型训练任务",
- "28":"创建了推理任务",
- "29":"创建了评测任务",
- "30":"导入了新模型",
- "31":"创建了CPU/GPU类型训练任务"
- };
-
- 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 tag {branch} to ",
- "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":" proposed changes",
- "23":" commented on pull request",
- "24":" upload dataset ",
- "25":" created CPU/GPU type debugging task ",
- "26":" created NPU type debugging task ",
- "27":" created NPU type training task",
- "28":" created reasoning task",
- "29":" created profiling task",
- "30":" created new model",
- "31":" created CPU/GPU type training task",
- };
-
- var repoAndOrgZH={
- "1":"项目",
- "2":"成员",
- "3":"团队",
- "11":"项目",
- "21":"成员",
- "31":"团队",
- "4":"小时前",
- "5":"分钟前",
- "6":"秒前",
- "41":"小时前",
- "51":"分钟前",
- "61":"秒前"
- };
-
- var repoAndOrgEN={
- "1":"Repository",
- "2":"Member ",
- "3":"Team",
- "11":"Repositories",
- "21":"Members ",
- "31":"Teams",
- "4":" hour ago",
- "5":" minute ago",
- "6":" second ago",
- "41":" hours ago",
- "51":" minutes ago",
- "61":" 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){
- displayOrg(json);
- },
- error:function(response) {
- }
- });
-
- $.ajax({
- type:"GET",
- url:"/recommend/repo",
- headers: {
- authorization:token,
- },
- dataType:"json",
- async:false,
- success:function(json){
- displayRepo(json);
- },
- error:function(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 += "<div class=\"swiper-slide\">";
- html += " <div class=\"ui fluid card\">";
- html += " <div class=\"content\">";
- html += " <span class=\"right floated meta\">";
- html += " <i class=\"ri-star-line\"></i>" + record["NumStars"] + "<i class=\"ri-git-branch-line am-ml-10\"></i>" + record["NumForks"];
- html += " </span>";
- html += " <img class=\"left floated mini ui image\" src=\"" + record["Avatar"] + "\">";
- html += " <a class=\"header nowrap\" href=\"/" + record["OwnerName"] + "/" + record["Name"] + "\">" + record["Alias"] +"</a>";
- html += " <div class=\"description nowrap-2\">" + record["Description"] + " </div>";
- html += " <div class=\"ui tags nowrap am-mt-10\">"
- if(record["Topics"] != null){
- for(var j = 0; j < record["Topics"].length; j++){
- topic = record["Topics"][j];
- url = "/explore/repos?q=" + (topic) + "&topic="
- html += "<a class=\"ui small label topic\" href=\"" + url + "\">" + topic + "</a>";
- }
- }
- html += " </div>";
- html += " </div>";
- html += " </div>";
- html += "</div>";
- }
- }
- orgRepo.innerHTML = html;
- swiperRepo.updateSlides();
- swiperRepo.updateProgress();
- }
-
-
- function getRepoOrOrg(key,isZhLang,numbers=1){
- if(numbers > 1){
- key+="1";
- }
- 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 += "<div class=\"swiper-slide\">";
- html += " <a href=\"/" + record["Name"] + "\" class=\"ui fluid card\">";
- html += " <div class=\"content\">";
- html += " <div class=\"ui small header\">";
- html += " <img class=\"ui image\" src=\"" + record["Avatar"] + "\">";
- html += " <div class=\"content nowrap\">";
- html += " <span class=\"ui blue\">" + record["Name"] + "</span> " + record["FullName"];
- html += " <div class=\"sub header\">" + record["NumRepos"] +" " + getRepoOrOrg(1,isZh,record["NumRepos"]) + " ・ " + record["NumMembers"] +" " + getRepoOrOrg(2,isZh,record["NumMembers"]) + " ・ " + record["NumTeams"] + " " + getRepoOrOrg(3,isZh,record["NumTeams"]) + "</div>";
- html += " </div>";
- html += " </div>";
- html += " </div>";
- html += " </a>";
- html += "</div>";
- }
- }
- orgDiv.innerHTML = html;
- swiperOrg.updateSlides();
- }
|