You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

home.js 20 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. var token;
  2. if(isEmpty(token)){
  3. var meta = $("meta[name=_uid]");
  4. if(!isEmpty(meta)){
  5. token = meta.attr("content");
  6. }
  7. }
  8. var swiperNewMessage = new Swiper(".newslist", {
  9. direction: "vertical",
  10. slidesPerView: 9,
  11. loop: true,
  12. autoplay: {
  13. delay: 2500,
  14. disableOnInteraction: false,
  15. },
  16. });
  17. var swiperEvent = new Swiper(".event-list", {
  18. slidesPerView: 3,
  19. spaceBetween: 30,
  20. pagination: {
  21. el: ".swiper-pagination",
  22. clickable: true,
  23. },
  24. autoplay: {
  25. delay: 2500,
  26. disableOnInteraction: false,
  27. },
  28. });
  29. var swiperRepo = new Swiper(".homepro-list", {
  30. slidesPerView: 1,
  31. slidesPerColumn: 2,
  32. slidesPerColumnFill:'row',
  33. spaceBetween: 30,
  34. pagination: {
  35. el: ".swiper-pagination",
  36. clickable: true,
  37. },
  38. autoplay: {
  39. delay: 2500,
  40. disableOnInteraction: false,
  41. },
  42. breakpoints: {
  43. 768: {
  44. slidesPerView: 2,
  45. },
  46. 1024: {
  47. slidesPerView: 3,
  48. },
  49. },
  50. });
  51. var swiperOrg = new Swiper(".homeorg-list", {
  52. slidesPerView: 1,
  53. slidesPerColumn: 4,
  54. slidesPerColumnFill:'row',
  55. spaceBetween: 15,
  56. pagination: {
  57. el: ".swiper-pagination",
  58. clickable: true,
  59. },
  60. autoplay: {
  61. delay: 4500,
  62. disableOnInteraction: false,
  63. },
  64. breakpoints: {
  65. 768: {
  66. slidesPerView: 2,
  67. },
  68. 1024: {
  69. slidesPerView: 3,
  70. },
  71. },
  72. });
  73. var maxSize = 20;
  74. var html =document.documentElement;
  75. var lang = html.attributes["lang"]
  76. var isZh = true;
  77. if(lang != null && lang.nodeValue =="en-US" ){
  78. isZh=false;
  79. }
  80. document.onreadystatechange = function () {
  81. queryRecommendData();
  82. var output = document.getElementById("newmessage");
  83. var url = "ws://" + document.location.host + "/action/notification";
  84. if(document.location.host == "git.openi.org.cn" || document.URL.startsWith("https")){
  85. url = "wss://" + document.location.host + "/action/notification"
  86. }
  87. var socket = new WebSocket(url);
  88. socket.onopen = function () {
  89. messageQueue = [];
  90. console.log("message has connected.");
  91. };
  92. socket.onmessage = function (e) {
  93. var data =JSON.parse(e.data)
  94. var html = "";
  95. if (data != null){
  96. if(messageQueue.length > maxSize){
  97. delete messageQueue[0];
  98. }else{
  99. messageQueue.push(data);
  100. }
  101. var currentTime = new Date().getTime();
  102. for(var i = 0; i < messageQueue.length; i++){
  103. var record = messageQueue[i];
  104. var actionName = getAction(record.OpType,isZh);
  105. if(record.ActUser == null){
  106. console.log("receive action type=" + record.OpType + " name=" + actionName + " but user is null.");
  107. continue;
  108. }
  109. if(record.OpType == "24"){
  110. if(record.Content.indexOf("true") != -1){
  111. continue;
  112. }
  113. }
  114. //refresh3DInfo(record);
  115. var recordPrefix = getMsg(record);
  116. if(record.OpType == "6" || record.OpType == "10" || record.OpType == "12" || record.OpType == "13"){
  117. html += recordPrefix + actionName;
  118. html += " <a href=\"" + getIssueLink(record) + "\" rel=\"nofollow\">" + getIssueText(record) + "</a>"
  119. }
  120. else if(record.OpType == "7" || record.OpType == "11" || record.OpType == "14" || record.OpType == "15" || record.OpType == "22"
  121. || record.OpType == "23"){
  122. html += recordPrefix + actionName;
  123. html += " <a href=\"" + getPRLink(record) + "\" rel=\"nofollow\">" + getPRText(record) + "</a>"
  124. }
  125. else if(record.OpType == "1"){
  126. html += recordPrefix + actionName;
  127. html += " <a href=\"" + getRepoLink(record) + "\" rel=\"nofollow\">" +getRepotext(record) + "</a>"
  128. }
  129. else if(record.OpType == "5"){
  130. branch = "<a href=\"" + getRepoLink(record) + "/src/branch/" + encodeURI(record.RefName) + "\" rel=\"nofollow\">" + record.RefName + "</a>"
  131. actionName = actionName.replace("{branch}",branch);
  132. html += recordPrefix + actionName;
  133. html += " <a href=\"" + getRepoLink(record) + "\" rel=\"nofollow\">" + getRepotext(record) + "</a>"
  134. }else if(record.OpType == "9"){
  135. branch = "<a href=\"" + getRepoLink(record) + "/src/tag/" + encodeURI(record.RefName) + "\" rel=\"nofollow\">" + record.RefName + "</a>"
  136. actionName = actionName.replace("{branch}",branch);
  137. html += recordPrefix + actionName;
  138. html += " <a href=\"" + getRepoLink(record) + "\" rel=\"nofollow\">" + getRepotext(record) + "</a>"
  139. }
  140. else if(record.OpType == "17"){
  141. actionName = actionName.replace("{deleteBranchName}",record.RefName);
  142. var repoLink = "<a href=\"" + getRepoLink(record) + "\" rel=\"nofollow\">" + getRepotext(record) + "</a>"
  143. actionName = actionName.replace("{repoName}",repoLink);
  144. html += recordPrefix + actionName;
  145. }
  146. else if(record.OpType == "2"){
  147. actionName = actionName.replace("{oldRepoName}",record.Content);
  148. html += recordPrefix + actionName;
  149. html += " <a href=\"" + getRepoLink(record) + "\" rel=\"nofollow\">" + getRepotext(record) + "</a>"
  150. }
  151. else if(record.OpType == "24" || record.OpType == "26" || record.OpType == "27" || record.OpType == "28" || record.OpType == "30" || record.OpType == "31" || record.OpType == "32" || record.OpType == "33"){
  152. html += recordPrefix + actionName;
  153. html += " <a href=\"" + getTaskLink(record) + "\" rel=\"nofollow\">" + record.RefName + "</a>"
  154. }
  155. else if(record.OpType == "25" || record.OpType == "29"){
  156. html += recordPrefix + actionName;
  157. html += " <a href=\"" + getTaskLink(record) + "\" rel=\"nofollow\">" + record.RefName + "</a>"
  158. }
  159. else{
  160. continue;
  161. }
  162. if(record.Repo != null){
  163. var time = getTime(record.CreatedUnix,currentTime);
  164. html += " " + time;
  165. }
  166. html += "</div>";
  167. html += "</div>";
  168. }
  169. }
  170. output.innerHTML = html;
  171. swiperNewMessage.updateSlides();
  172. swiperNewMessage.updateProgress();
  173. };
  174. }
  175. function getTaskLink(record){
  176. var re = getRepoLink(record);
  177. if(record.OpType == 24){
  178. re = re + "/datasets";
  179. }else if(record.OpType == 25){
  180. re = re + "/cloudbrain/" + record.Content;
  181. }else if(record.OpType == 26){
  182. re = re + "/modelarts/notebook/" + record.Content;
  183. }else if(record.OpType == 27){
  184. re = re + "/modelarts/train-job/" + record.Content;
  185. }else if(record.OpType == 28){
  186. re = re + "/modelarts/inference-job/" + record.Content;
  187. }else if(record.OpType == 29){
  188. re = re + "/cloudbrain/benchmark/" + record.Content;
  189. }else if(record.OpType == 30){
  190. re = re + "/modelmanage/show_model_info?name=" + record.RefName;
  191. }else if(record.OpType == 31){
  192. re = re + "/cloudbrain/train-job/" + record.Content;
  193. }else if(record.OpType == 32 || record.OpType == 33){
  194. re = re + "/grampus/train-job/" + record.Content;
  195. }
  196. re = encodeURI(re);
  197. return re;
  198. }
  199. function refresh3DInfo(record){
  200. if(record.OpType == "25" || record.OpType == "29" || record.OpType == "31"){
  201. //cloudbrain one
  202. //var lines = $('.rotation3D__line');
  203. var span = $('.rotation3D__line').find("span")[0];
  204. //console.log(span);
  205. if(span != null){
  206. span.innerText =record.RefName;
  207. }
  208. //$('.rotation3D__line').find("span").eq(0).text(record.RefName)
  209. //console.log("cloudbrain one line length=" + lines.length);
  210. //lines[0].find("span").text(record.RefName);
  211. }else if(record.OpType == "26" || record.OpType == "27" || record.OpType == "28"){
  212. //cloudbrain two
  213. //var lines = $('.rotation3D__line');
  214. //console.log("cloudbrain two line length=" + lines.length);
  215. var span = $('.rotation3D__line').find("span")[1];
  216. //console.log(span);
  217. if(span != null){
  218. span.innerText =record.RefName;
  219. }
  220. }
  221. }
  222. function getMsg(record){
  223. var html ="";
  224. html += "<div class=\"swiper-slide item\">";
  225. var name = "";
  226. if(record.ActUser != null){
  227. name = record.ActUser.Name;
  228. }else{
  229. console.log("act user is null.");
  230. }
  231. html += " <img class=\"ui avatar image\" src=\"/user/avatar/" + name + "/-1\" alt=\"\">"
  232. html += " <div class=\"middle aligned content nowrap\">"
  233. html += " <a href=\"/" + encodeURI(name) + "\" title=\"\">" + name + "</a>"
  234. return html;
  235. }
  236. function getRepotext(record){
  237. if(record.Repo.Alias){
  238. return record.Repo.OwnerName + "/" + record.Repo.Alias;
  239. }else{
  240. return record.Repo.OwnerName + "/" + record.Repo.Name;
  241. }
  242. }
  243. function getRepoLink(record){
  244. return encodeURI(record.Repo.OwnerName + "/" + record.Repo.Name);
  245. }
  246. function getTime(UpdatedUnix,currentTime){
  247. UpdatedUnix = UpdatedUnix;
  248. currentTime = currentTime / 1000;
  249. var timeEscSecond = currentTime - UpdatedUnix;
  250. if( timeEscSecond < 0){
  251. timeEscSecond = 1;
  252. }
  253. var hours= Math.floor(timeEscSecond / 3600);
  254. //计算相差分钟数
  255. var leave2 = Math.floor(timeEscSecond % (3600)); //计算小时数后剩余的秒数
  256. var minutes= Math.floor(leave2 / 60);//计算相差分钟数
  257. var leave3=Math.floor(leave2 % 60); //计算分钟数后剩余的秒数
  258. var seconds= leave3;
  259. if(hours == 0 && minutes == 0){
  260. return seconds + getRepoOrOrg(6,isZh,seconds);
  261. }else{
  262. if(hours > 0){
  263. return hours + getRepoOrOrg(4,isZh,hours);
  264. }else{
  265. return minutes + getRepoOrOrg(5,isZh,minutes);
  266. }
  267. }
  268. }
  269. function getPRLink(record){
  270. return encodeURI("/" + record.Repo.OwnerName + "/" + record.Repo.Name + "/pulls/" + getIssueId(record));
  271. }
  272. function getPRText(record){
  273. if(record.Repo.Alias){
  274. return record.Repo.OwnerName + "/" + record.Repo.Alias + "#" + getIssueId(record);
  275. }else{
  276. return record.Repo.OwnerName + "/" + record.Repo.Name + "#" + getIssueId(record);
  277. }
  278. }
  279. function getIssueLink(record){
  280. return encodeURI("/" + record.Repo.OwnerName + "/" + record.Repo.Name + "/issues/" + getIssueId(record));
  281. }
  282. function getIssueId(record){
  283. var Id = "1";
  284. if(!isEmpty(record.Comment) && !isEmpty(record.Comment.Issue)){
  285. Id = record.Comment.Issue.Index;
  286. }else{
  287. if(!isEmpty(record.Content)){
  288. var content = record.Content;
  289. var index = content.indexOf("|");
  290. if(index != -1){
  291. Id = content.substring(0,index);
  292. }
  293. }
  294. }
  295. return Id;
  296. }
  297. function getIssueText(record){
  298. if(record.Repo.Alias){
  299. return record.Repo.OwnerName + "/" + record.Repo.Alias + "#" + getIssueId(record);
  300. }else{
  301. return record.Repo.OwnerName + "/" + record.Repo.Name + "#" + getIssueId(record);
  302. }
  303. }
  304. /*
  305. ActionCreateRepo ActionType = iota + 1 // 1
  306. ActionRenameRepo // 2
  307. ActionStarRepo // 3
  308. ActionWatchRepo // 4
  309. ActionCommitRepo // 5
  310. ActionCreateIssue // 6
  311. ActionCreatePullRequest // 7
  312. ActionTransferRepo // 8
  313. ActionPushTag // 9
  314. ActionCommentIssue // 10
  315. ActionMergePullRequest // 11
  316. ActionCloseIssue // 12
  317. ActionReopenIssue // 13
  318. ActionClosePullRequest // 14
  319. ActionReopenPullRequest // 15
  320. ActionDeleteTag // 16
  321. ActionDeleteBranch // 17
  322. ActionMirrorSyncPush // 18
  323. ActionMirrorSyncCreate // 19
  324. ActionMirrorSyncDelete // 20
  325. ActionApprovePullRequest // 21
  326. ActionRejectPullRequest // 22
  327. ActionCommentPull // 23
  328. */
  329. var actionNameZH={
  330. "1":"创建了项目",
  331. "2":"重命名项目 {oldRepoName} 为",
  332. "5":"推送了 {branch} 分支的代码到",
  333. "6":"创建了任务",
  334. "7":"创建了合并请求",
  335. "9":"推送了标签 {branch} 到",
  336. "10":"评论了任务",
  337. "11":"合并了合并请求",
  338. "12":"关闭了任务",
  339. "13":"重新开启了任务",
  340. "14":"关闭了合并请求",
  341. "15":"重新开启了合并请求",
  342. "17":"从 {repoName} 删除分支 {deleteBranchName}",
  343. "22":"建议变更",
  344. "23":"评论了合并请求",
  345. "24":"上传了数据集文件",
  346. "25":"创建了CPU/GPU类型调试任务",
  347. "26":"创建了NPU类型调试任务",
  348. "27":"创建了NPU类型训练任务",
  349. "28":"创建了推理任务",
  350. "29":"创建了评测任务",
  351. "30":"导入了新模型",
  352. "31":"创建了CPU/GPU类型训练任务",
  353. "32":"创建了NPU类型训练任务",
  354. "33":"创建了CPU/GPU类型训练任务"
  355. };
  356. var actionNameEN={
  357. "1":" created repository",
  358. "2":" renamed repository from {oldRepoName} to ",
  359. "5":" pushed to {branch} at",
  360. "6":" opened issue",
  361. "7":" created pull request",
  362. "9":" pushed tag {branch} to ",
  363. "10":" commented on issue",
  364. "11":" merged pull request",
  365. "12":" closed issue",
  366. "13":" reopened issue",
  367. "14":" closed pull request",
  368. "15":" reopened pull request",
  369. "17":" deleted branch {deleteBranchName} from {repoName}",
  370. "22":" proposed changes",
  371. "23":" commented on pull request",
  372. "24":" upload dataset ",
  373. "25":" created CPU/GPU type debugging task ",
  374. "26":" created NPU type debugging task ",
  375. "27":" created NPU type training task",
  376. "28":" created reasoning task",
  377. "29":" created profiling task",
  378. "30":" created new model",
  379. "31":" created CPU/GPU type training task",
  380. "32":" created NPU type training task",
  381. "33":" created CPU/GPU type training task"
  382. };
  383. var repoAndOrgZH={
  384. "1":"项目",
  385. "2":"成员",
  386. "3":"团队",
  387. "11":"项目",
  388. "21":"成员",
  389. "31":"团队",
  390. "4":"小时前",
  391. "5":"分钟前",
  392. "6":"秒前",
  393. "41":"小时前",
  394. "51":"分钟前",
  395. "61":"秒前"
  396. };
  397. var repoAndOrgEN={
  398. "1":"Repository",
  399. "2":"Member ",
  400. "3":"Team",
  401. "11":"Repositories",
  402. "21":"Members ",
  403. "31":"Teams",
  404. "4":" hour ago",
  405. "5":" minute ago",
  406. "6":" second ago",
  407. "41":" hours ago",
  408. "51":" minutes ago",
  409. "61":" seconds ago"
  410. };
  411. function getAction(opType,isZh){
  412. if(isZh){
  413. return actionNameZH[opType]
  414. }else{
  415. return actionNameEN[opType]
  416. }
  417. }
  418. function queryRecommendData(){
  419. $.ajax({
  420. type:"GET",
  421. url:"/recommend/home",
  422. headers: {
  423. authorization:token,
  424. },
  425. dataType:"json",
  426. async:false,
  427. success:function(json){
  428. displayOrg(json.org);
  429. displayRepo(json.repo);
  430. displayActivity(json.image);
  431. },
  432. error:function(response) {
  433. }
  434. });
  435. }
  436. function displayActivity(json){
  437. var activityDiv = document.getElementById("recommendactivity");
  438. var html = "";
  439. if (json != null && json.length > 0){
  440. for(var i = 0; i < json.length;i++){
  441. var record = json[i]
  442. html += "<div class=\"swiper-slide\">";
  443. html += "<a href=\"" + record["image_link"] + "\" class=\"ui fluid card\">";
  444. html += " <div class=\"image\"><img src=\"" + record["url"] + "\"></div>"
  445. html += "</a>";
  446. html += "</div>";
  447. }
  448. }
  449. activityDiv.innerHTML = html;
  450. swiperEvent.updateSlides();
  451. swiperEvent.updateProgress();
  452. }
  453. function displayRepo(json){
  454. var orgRepo = document.getElementById("recommendrepo");
  455. var html = "";
  456. if (json != null && json.length > 0){
  457. for(var i = 0; i < json.length;i++){
  458. var record = json[i]
  459. html += "<div class=\"swiper-slide\">";
  460. html += " <div class=\"ui fluid card\">";
  461. html += " <div class=\"content\">";
  462. html += " <span class=\"right floated meta\">";
  463. html += " <i class=\"ri-star-line\"></i>" + record["NumStars"] + "<i class=\"ri-git-branch-line am-ml-10\"></i>" + record["NumForks"];
  464. html += " </span>";
  465. html += " <img class=\"left floated mini ui image\" src=\"" + record["Avatar"] + "\">";
  466. html += " <a class=\"header nowrap\" href=\"/" + record["OwnerName"] + "/" + record["Name"] + "\">" + record["Alias"] +"</a>";
  467. html += " <div class=\"description nowrap-2\">" + record["Description"] + " </div>";
  468. html += " <div class=\"ui tags nowrap am-mt-10\">"
  469. if(record["Topics"] != null){
  470. for(var j = 0; j < record["Topics"].length; j++){
  471. topic = record["Topics"][j];
  472. url = "/explore/repos?q=" + (topic) + "&amp;topic="
  473. html += "<a class=\"ui small label topic\" href=\"" + url + "\">" + topic + "</a>";
  474. }
  475. }
  476. html += " </div>";
  477. html += " </div>";
  478. html += " </div>";
  479. html += "</div>";
  480. }
  481. }
  482. orgRepo.innerHTML = html;
  483. swiperRepo.updateSlides();
  484. swiperRepo.updateProgress();
  485. }
  486. function getRepoOrOrg(key,isZhLang,numbers=1){
  487. if(numbers > 1){
  488. key+="1";
  489. }
  490. if(isZhLang){
  491. return repoAndOrgZH[key];
  492. }else{
  493. return repoAndOrgEN[key];
  494. }
  495. }
  496. function displayOrg(json){
  497. var orgDiv = document.getElementById("recommendorg");
  498. var html = "";
  499. if (json != null && json.length > 0){
  500. for(var i = 0; i < json.length;i++){
  501. var record = json[i]
  502. html += "<div class=\"swiper-slide\">";
  503. html += " <a href=\"/" + record["Name"] + "\" class=\"ui fluid card\">";
  504. html += " <div class=\"content\">";
  505. html += " <div class=\"ui small header\">";
  506. html += " <img class=\"ui image\" src=\"" + record["Avatar"] + "\">";
  507. html += " <div class=\"content nowrap\">";
  508. html += " <span class=\"ui blue\">" + record["Name"] + "</span> " + record["FullName"];
  509. 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>";
  510. html += " </div>";
  511. html += " </div>";
  512. html += " </div>";
  513. html += " </a>";
  514. html += "</div>";
  515. }
  516. }
  517. orgDiv.innerHTML = html;
  518. swiperOrg.updateSlides();
  519. }