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