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