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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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. span.innerText =record.RefName;
  206. //$('.rotation3D__line').find("span").eq(0).text(record.RefName)
  207. //console.log("cloudbrain one line length=" + lines.length);
  208. //lines[0].find("span").text(record.RefName);
  209. }else if(record.OpType == "26" || record.OpType == "27" || record.OpType == "28"){
  210. //cloudbrain two
  211. var lines = $('.rotation3D__line');
  212. //console.log("cloudbrain two line length=" + lines.length);
  213. var span = $('.rotation3D__line').find("span")[1];
  214. //console.log(span);
  215. if(span != null){
  216. span.innerText =record.RefName;
  217. }
  218. }
  219. }
  220. function getMsg(record){
  221. var html ="";
  222. html += "<div class=\"swiper-slide item\">";
  223. var name = "";
  224. if(record.ActUser != null){
  225. name = record.ActUser.Name;
  226. }else{
  227. console.log("act user is null.");
  228. }
  229. html += " <img class=\"ui avatar image\" src=\"/user/avatar/" + name + "/-1\" alt=\"\">"
  230. html += " <div class=\"middle aligned content nowrap\">"
  231. html += " <a href=\"/" + encodeURI(name) + "\" title=\"\">" + name + "</a>"
  232. return html;
  233. }
  234. function getRepotext(record){
  235. if(record.Repo.Alias){
  236. return record.Repo.OwnerName + "/" + record.Repo.Alias;
  237. }else{
  238. return record.Repo.OwnerName + "/" + record.Repo.Name;
  239. }
  240. }
  241. function getRepoLink(record){
  242. return encodeURI(record.Repo.OwnerName + "/" + record.Repo.Name);
  243. }
  244. function getTime(UpdatedUnix,currentTime){
  245. UpdatedUnix = UpdatedUnix;
  246. currentTime = currentTime / 1000;
  247. var timeEscSecond = currentTime - UpdatedUnix;
  248. if( timeEscSecond < 0){
  249. timeEscSecond = 1;
  250. }
  251. var hours= Math.floor(timeEscSecond / 3600);
  252. //计算相差分钟数
  253. var leave2 = Math.floor(timeEscSecond % (3600)); //计算小时数后剩余的秒数
  254. var minutes= Math.floor(leave2 / 60);//计算相差分钟数
  255. var leave3=Math.floor(leave2 % 60); //计算分钟数后剩余的秒数
  256. var seconds= leave3;
  257. if(hours == 0 && minutes == 0){
  258. return seconds + getRepoOrOrg(6,isZh,seconds);
  259. }else{
  260. if(hours > 0){
  261. return hours + getRepoOrOrg(4,isZh,hours);
  262. }else{
  263. return minutes + getRepoOrOrg(5,isZh,minutes);
  264. }
  265. }
  266. }
  267. function getPRLink(record){
  268. return encodeURI("/" + record.Repo.OwnerName + "/" + record.Repo.Name + "/pulls/" + getIssueId(record));
  269. }
  270. function getPRText(record){
  271. if(record.Repo.Alias){
  272. return record.Repo.OwnerName + "/" + record.Repo.Alias + "#" + getIssueId(record);
  273. }else{
  274. return record.Repo.OwnerName + "/" + record.Repo.Name + "#" + getIssueId(record);
  275. }
  276. }
  277. function getIssueLink(record){
  278. return encodeURI("/" + record.Repo.OwnerName + "/" + record.Repo.Name + "/issues/" + getIssueId(record));
  279. }
  280. function getIssueId(record){
  281. var Id = "1";
  282. if(!isEmpty(record.Comment) && !isEmpty(record.Comment.Issue)){
  283. Id = record.Comment.Issue.Index;
  284. }else{
  285. if(!isEmpty(record.Content)){
  286. var content = record.Content;
  287. var index = content.indexOf("|");
  288. if(index != -1){
  289. Id = content.substring(0,index);
  290. }
  291. }
  292. }
  293. return Id;
  294. }
  295. function getIssueText(record){
  296. if(record.Repo.Alias){
  297. return record.Repo.OwnerName + "/" + record.Repo.Alias + "#" + getIssueId(record);
  298. }else{
  299. return record.Repo.OwnerName + "/" + record.Repo.Name + "#" + getIssueId(record);
  300. }
  301. }
  302. /*
  303. ActionCreateRepo ActionType = iota + 1 // 1
  304. ActionRenameRepo // 2
  305. ActionStarRepo // 3
  306. ActionWatchRepo // 4
  307. ActionCommitRepo // 5
  308. ActionCreateIssue // 6
  309. ActionCreatePullRequest // 7
  310. ActionTransferRepo // 8
  311. ActionPushTag // 9
  312. ActionCommentIssue // 10
  313. ActionMergePullRequest // 11
  314. ActionCloseIssue // 12
  315. ActionReopenIssue // 13
  316. ActionClosePullRequest // 14
  317. ActionReopenPullRequest // 15
  318. ActionDeleteTag // 16
  319. ActionDeleteBranch // 17
  320. ActionMirrorSyncPush // 18
  321. ActionMirrorSyncCreate // 19
  322. ActionMirrorSyncDelete // 20
  323. ActionApprovePullRequest // 21
  324. ActionRejectPullRequest // 22
  325. ActionCommentPull // 23
  326. */
  327. var actionNameZH={
  328. "1":"创建了项目",
  329. "2":"重命名项目 {oldRepoName} 为",
  330. "5":"推送了 {branch} 分支的代码到",
  331. "6":"创建了任务",
  332. "7":"创建了合并请求",
  333. "9":"推送了标签 {branch} 到",
  334. "10":"评论了任务",
  335. "11":"合并了合并请求",
  336. "12":"关闭了任务",
  337. "13":"重新开启了任务",
  338. "14":"关闭了合并请求",
  339. "15":"重新开启了合并请求",
  340. "17":"从 {repoName} 删除分支 {deleteBranchName}",
  341. "22":"建议变更",
  342. "23":"评论了合并请求",
  343. "24":"上传了数据集文件",
  344. "25":"创建了CPU/GPU类型调试任务",
  345. "26":"创建了NPU类型调试任务",
  346. "27":"创建了NPU类型训练任务",
  347. "28":"创建了推理任务",
  348. "29":"创建了评测任务",
  349. "30":"导入了新模型",
  350. "31":"创建了CPU/GPU类型训练任务",
  351. "32":"创建了NPU类型训练任务",
  352. "33":"创建了CPU/GPU类型训练任务"
  353. };
  354. var actionNameEN={
  355. "1":" created repository",
  356. "2":" renamed repository from {oldRepoName} to ",
  357. "5":" pushed to {branch} at",
  358. "6":" opened issue",
  359. "7":" created pull request",
  360. "9":" pushed tag {branch} to ",
  361. "10":" commented on issue",
  362. "11":" merged pull request",
  363. "12":" closed issue",
  364. "13":" reopened issue",
  365. "14":" closed pull request",
  366. "15":" reopened pull request",
  367. "17":" deleted branch {deleteBranchName} from {repoName}",
  368. "22":" proposed changes",
  369. "23":" commented on pull request",
  370. "24":" upload dataset ",
  371. "25":" created CPU/GPU type debugging task ",
  372. "26":" created NPU type debugging task ",
  373. "27":" created NPU type training task",
  374. "28":" created reasoning task",
  375. "29":" created profiling task",
  376. "30":" created new model",
  377. "31":" created CPU/GPU type training task",
  378. "32":" created NPU type training task",
  379. "33":" created CPU/GPU type training task"
  380. };
  381. var repoAndOrgZH={
  382. "1":"项目",
  383. "2":"成员",
  384. "3":"团队",
  385. "11":"项目",
  386. "21":"成员",
  387. "31":"团队",
  388. "4":"小时前",
  389. "5":"分钟前",
  390. "6":"秒前",
  391. "41":"小时前",
  392. "51":"分钟前",
  393. "61":"秒前"
  394. };
  395. var repoAndOrgEN={
  396. "1":"Repository",
  397. "2":"Member ",
  398. "3":"Team",
  399. "11":"Repositories",
  400. "21":"Members ",
  401. "31":"Teams",
  402. "4":" hour ago",
  403. "5":" minute ago",
  404. "6":" second ago",
  405. "41":" hours ago",
  406. "51":" minutes ago",
  407. "61":" seconds ago"
  408. };
  409. function getAction(opType,isZh){
  410. if(isZh){
  411. return actionNameZH[opType]
  412. }else{
  413. return actionNameEN[opType]
  414. }
  415. }
  416. function queryRecommendData(){
  417. $.ajax({
  418. type:"GET",
  419. url:"/recommend/home",
  420. headers: {
  421. authorization:token,
  422. },
  423. dataType:"json",
  424. async:false,
  425. success:function(json){
  426. displayOrg(json.org);
  427. displayRepo(json.repo);
  428. displayActivity(json.image);
  429. },
  430. error:function(response) {
  431. }
  432. });
  433. }
  434. function displayActivity(json){
  435. var activityDiv = document.getElementById("recommendactivity");
  436. var html = "";
  437. if (json != null && json.length > 0){
  438. for(var i = 0; i < json.length;i++){
  439. var record = json[i]
  440. html += "<div class=\"swiper-slide\">";
  441. html += "<a href=\"" + record["image_link"] + "\" class=\"ui fluid card\">";
  442. html += " <div class=\"image\"><img src=\"" + record["url"] + "\"></div>"
  443. html += "</a>";
  444. html += "</div>";
  445. }
  446. }
  447. activityDiv.innerHTML = html;
  448. swiperEvent.updateSlides();
  449. swiperEvent.updateProgress();
  450. }
  451. function displayRepo(json){
  452. var orgRepo = document.getElementById("recommendrepo");
  453. var html = "";
  454. if (json != null && json.length > 0){
  455. for(var i = 0; i < json.length;i++){
  456. var record = json[i]
  457. html += "<div class=\"swiper-slide\">";
  458. html += " <div class=\"ui fluid card\">";
  459. html += " <div class=\"content\">";
  460. html += " <span class=\"right floated meta\">";
  461. html += " <i class=\"ri-star-line\"></i>" + record["NumStars"] + "<i class=\"ri-git-branch-line am-ml-10\"></i>" + record["NumForks"];
  462. html += " </span>";
  463. html += " <img class=\"left floated mini ui image\" src=\"" + record["Avatar"] + "\">";
  464. html += " <a class=\"header nowrap\" href=\"/" + record["OwnerName"] + "/" + record["Name"] + "\">" + record["Alias"] +"</a>";
  465. html += " <div class=\"description nowrap-2\">" + record["Description"] + " </div>";
  466. html += " <div class=\"ui tags nowrap am-mt-10\">"
  467. if(record["Topics"] != null){
  468. for(var j = 0; j < record["Topics"].length; j++){
  469. topic = record["Topics"][j];
  470. url = "/explore/repos?q=" + (topic) + "&amp;topic="
  471. html += "<a class=\"ui small label topic\" href=\"" + url + "\">" + topic + "</a>";
  472. }
  473. }
  474. html += " </div>";
  475. html += " </div>";
  476. html += " </div>";
  477. html += "</div>";
  478. }
  479. }
  480. orgRepo.innerHTML = html;
  481. swiperRepo.updateSlides();
  482. swiperRepo.updateProgress();
  483. }
  484. function getRepoOrOrg(key,isZhLang,numbers=1){
  485. if(numbers > 1){
  486. key+="1";
  487. }
  488. if(isZhLang){
  489. return repoAndOrgZH[key];
  490. }else{
  491. return repoAndOrgEN[key];
  492. }
  493. }
  494. function displayOrg(json){
  495. var orgDiv = document.getElementById("recommendorg");
  496. var html = "";
  497. if (json != null && json.length > 0){
  498. for(var i = 0; i < json.length;i++){
  499. var record = json[i]
  500. html += "<div class=\"swiper-slide\">";
  501. html += " <a href=\"/" + record["Name"] + "\" class=\"ui fluid card\">";
  502. html += " <div class=\"content\">";
  503. html += " <div class=\"ui small header\">";
  504. html += " <img class=\"ui image\" src=\"" + record["Avatar"] + "\">";
  505. html += " <div class=\"content nowrap\">";
  506. html += " <span class=\"ui blue\">" + record["Name"] + "</span> " + record["FullName"];
  507. 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>";
  508. html += " </div>";
  509. html += " </div>";
  510. html += " </div>";
  511. html += " </a>";
  512. html += "</div>";
  513. }
  514. }
  515. orgDiv.innerHTML = html;
  516. swiperOrg.updateSlides();
  517. }