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 12 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. var token;
  2. if(isEmpty(token)){
  3. var meta = $("meta[name=_uid]");
  4. if(!isEmpty(meta)){
  5. token = meta.attr("content");
  6. console.log("token is uid:" + token);
  7. }
  8. }
  9. var output = document.getElementById("newmessage");
  10. var socket = new WebSocket("ws://" + document.location.host + "/action/notification");
  11. socket.onopen = function () {
  12. console.log("message has connected.");
  13. };
  14. var messageQueue = [];
  15. var maxSize = 10;
  16. var html =document.documentElement;
  17. var lang = html.attributes["lang"]
  18. var isZh = true;
  19. if(lang != null && lang =="en-US" ){
  20. isZh=false;
  21. }
  22. console.log("the language is " + lang);
  23. socket.onmessage = function (e) {
  24. console.log("content=" + e.data)
  25. var data =JSON.parse(e.data)
  26. console.log("data=" + data)
  27. var html = "";
  28. if (data != null){
  29. if(messageQueue.length > maxSize){
  30. delete messageQueue[0];
  31. }else{
  32. messageQueue.push(data);
  33. }
  34. for(var i = 0; i < messageQueue.length;i++){
  35. var record = messageQueue[i];
  36. html += "<div class=\"swiper-slide item\">";
  37. html += " <img class=\"ui avatar image\" src=\"/user/avatar/" + record.ActUser.lowerName + "/-1\" alt=\"\">"
  38. html += " <div class=\"middle aligned content\">"
  39. html += " <a href=\"/" + record.ActUser.Name + "\" title=\"\">" + record.ActUser.Name + "</a>"
  40. var actionName = getAction(record.OpType,isZh);
  41. html += actionName;
  42. if(record.OpType == "6" || record.OpType == "10" || record.OpType == "12" || record.OpType == "13"){
  43. html += " <a href=\"" + getIssueLink(record) + "\" rel=\"nofollow\">" + getIssueText(record) + "</a>"
  44. }
  45. if(record.OpType == "7" || record.OpType == "11" || record.OpType == "14" || record.OpType == "15"){
  46. html += " <a href=\"" + getPRLink(record) + "\" rel=\"nofollow\">" + getPRText(record) + "</a>"
  47. }
  48. if(record.Repo != null){
  49. var time = getTime(record.Repo.UpdatedUnix);
  50. html += time;
  51. }
  52. html += "</div>";
  53. html += "</div>";
  54. }
  55. /*
  56. <div class="swiper-slide item">
  57. <img class="ui avatar image" src="/user/avatar/zhoupzh/-1" alt="">
  58. <div class="middle aligned content">
  59. <a href="/zhoupzh" title="">zhoupzh</a> 合并了合并请求 <a href="/OpenI/aiforge/pulls/1168" rel="nofollow">OpenI/aiforge#1168</a><span class="time-since">22 分钟前</span>
  60. </div>
  61. </div>
  62. */
  63. }
  64. output.innerHTML = html;
  65. };
  66. function getTime(UpdatedUnix){
  67. return "10分钟前";
  68. }
  69. function getPRLink(record){
  70. return "/" + record.Repo.OwnerName + "/" + record.Repo.Name + "/pulls/" + record.ID
  71. }
  72. function getPRText(record){
  73. return record.Repo.OwnerName + "/" + record.Repo.Name + "#" + record.ID
  74. }
  75. function getIssueLink(record){
  76. return "/" + record.Repo.OwnerName + "/" + record.Repo.Name + "/issues/" + record.ID
  77. }
  78. function getIssueText(record){
  79. return record.Repo.OwnerName + "/" + record.Repo.Name + "#" + record.ID
  80. }
  81. /*
  82. ActionCreateRepo ActionType = iota + 1 // 1
  83. ActionRenameRepo // 2
  84. ActionStarRepo // 3
  85. ActionWatchRepo // 4
  86. ActionCommitRepo // 5
  87. ActionCreateIssue // 6
  88. ActionCreatePullRequest // 7
  89. ActionTransferRepo // 8
  90. ActionPushTag // 9
  91. ActionCommentIssue // 10
  92. ActionMergePullRequest // 11
  93. ActionCloseIssue // 12
  94. ActionReopenIssue // 13
  95. ActionClosePullRequest // 14
  96. ActionReopenPullRequest // 15
  97. ActionDeleteTag // 16
  98. ActionDeleteBranch // 17
  99. ActionMirrorSyncPush // 18
  100. ActionMirrorSyncCreate // 19
  101. ActionMirrorSyncDelete // 20
  102. ActionApprovePullRequest // 21
  103. ActionRejectPullRequest // 22
  104. ActionCommentPull // 23
  105. */
  106. var actionNameZH={
  107. "1":"创建了项目",
  108. "2":"重命名项目 {oldRepoName} 为",
  109. "6":"创建了任务",
  110. "7":"创建了合并请求",
  111. "9":"推送了 {branch} 分支的代码到",
  112. "10":"评论了任务",
  113. "11":"合并了合并请求",
  114. "12":"关闭了任务",
  115. "13":"重新开启了任务",
  116. "14":"关闭了合并请求",
  117. "15":"重新开启了合并请求",
  118. "17":"从 {repoName} 删除分支 {deleteBranchName}",
  119. "22":"拒绝了合并请求"
  120. };
  121. var actionNameEN={
  122. "1":"created repository",
  123. "2":"renamed repository from {oldRepoName} to ",
  124. "6":"opened issue",
  125. "7":"created pull request",
  126. "9":"pushed to {branch} at",
  127. "10":"commented on issue",
  128. "11":"merged pull request",
  129. "12":"closed issue",
  130. "13":"reopened issue",
  131. "14":"closed pull request",
  132. "15":"reopened pull request",
  133. "17":"deleted branch {deleteBranchName} from {repoName}",
  134. "22":"rejected pull request"
  135. };
  136. var repoAndOrgZH={
  137. "1":"项目",
  138. "2":"成员",
  139. "3":"团队"
  140. };
  141. var repoAndOrgEN={
  142. "1":"repository",
  143. "2":"Members ",
  144. "3":"Teams"
  145. };
  146. function getAction(opType,isZh){
  147. if(isZh){
  148. return actionNameZH[opType]
  149. }else{
  150. return actionNameEN[opType]
  151. }
  152. }
  153. queryRecommendData();
  154. function queryRecommendData(){
  155. $.ajax({
  156. type:"GET",
  157. url:"/recommend/org",
  158. headers: {
  159. authorization:token,
  160. },
  161. dataType:"json",
  162. async:false,
  163. success:function(json){
  164. console.log(json);
  165. displayOrg(json);
  166. },
  167. error:function(response) {
  168. console.log(response);
  169. }
  170. });
  171. $.ajax({
  172. type:"GET",
  173. url:"/recommend/repo",
  174. headers: {
  175. authorization:token,
  176. },
  177. dataType:"json",
  178. async:false,
  179. success:function(json){
  180. console.log(json);
  181. displayRepo(json);
  182. },
  183. error:function(response) {
  184. console.log(response);
  185. }
  186. });
  187. }
  188. /*
  189. <div class="swiper-slide">
  190. <div class="ui fluid card">
  191. <div class="content">
  192. <span class="right floated meta">
  193. <i class="star icon"></i>276 <i class="star icon"></i>32
  194. </span>
  195. <img class="left floated mini ui image" src="/repo-avatars/278-a9f45e21b92b86dbf969c9f70dff1efc">
  196. <a class="header nowrap" href="/OpenI/aiforge">aiforge </a>
  197. <div class="description nowrap-2">
  198. 本项目是群体化方法与技术的开源实现案例,在基于Gitea的基础上,进一步支持社交化的协同开发、协同学习、协同研究等群体创新实践服务,特别是针对新一代人工智能技术特点,重点支持项目管理、git代码管理、大数据集存储管理与智能计算平台接入。
  199. </div>
  200. <div class="ui tags nowrap am-mt-10">
  201. <a class="ui small label topic" href="/explore/repos?q=ai%e5%bc%80%e5%8f%91%e5%b7%a5%e5%85%b7&amp;topic=">ai开发工具</a>
  202. <a class="ui small label topic" href="/explore/repos?q=openi&amp;topic=">openi</a>
  203. <a class="ui small label topic" href="/explore/repos?q=golang&amp;topic=">golang</a>
  204. <a class="ui small label topic" href="/explore/repos?q=git&amp;topic=">git</a>
  205. <a class="ui small label topic" href="/explore/repos?q=pcl&amp;topic=">pcl</a>
  206. </div>
  207. </div>
  208. </div>
  209. </div>
  210. */
  211. function displayRepo(json){
  212. var orgRepo = document.getElementById("recommendrepo");
  213. var html = "";
  214. if (json != null && json.length > 0){
  215. for(var i = 0; i < json.length;i++){
  216. var record = json[i]
  217. html += "<div class=\"swiper-slide\">";
  218. html += " <div class=\"ui fluid card\">";
  219. html += " <div class=\"content\">";
  220. html += " <span class=\"right floated meta\">";
  221. html += " <i class=\"star icon\"></i>" + record["NumStars"];
  222. html += " </span>";
  223. html += " <img class=\"left floated mini ui image\" src=\"" + record["Avatar"] + "\">";
  224. html += " <a class=\"header nowrap\" href=\"/" + record["OwnerName"] + "/" + record["Name"] + "\">" + record["Name"] +"</a>";
  225. html += " <div class=\"description nowrap-2\">" + record["Description"] + " <div>";
  226. html += " <div class=\"ui tags nowrap am-mt-10\">"
  227. if(record["Topics"] != null){
  228. for(var j = 0; j < record["Topics"].length; j++){
  229. topic = record["Topics"][j];
  230. url = "/explore/repos?q=" + topic + "&amp;topic="
  231. url = escape(url);
  232. html += "<a class=\"ui small label topic\" href=\"" + url + "\">" + topic + "</a>";
  233. }
  234. }
  235. html += " <div>";
  236. html += " <div>";
  237. html += " <div>";
  238. html += "<div>";
  239. }
  240. }
  241. orgRepo.innerHTML = html;
  242. }
  243. /**
  244. *
  245. * <div class="column">
  246. <div class="ui fluid card">
  247. <div class="content">
  248. <div class="ui small header">
  249. <img class="ui image" src="/user/avatar/OpenI/-1">
  250. <div class="content nowrap">
  251. <a href="/OpenI">OpenI</a> 启智社区
  252. <div class="sub header">39 项目 ・ 60 成员 ・ 23 团队</div>
  253. </div>
  254. </div>
  255. </div>
  256. </div>
  257. </div>
  258. */
  259. //var repoAndOrgZH = new Map([['1', "项目"], ['2', "成员"], ['3', "团队"]]);
  260. //var repoAndOrgEN = new Map([['1', "Repository"], ['2', "Members"], ['3', "Teams"]]);
  261. function getRepoOrOrg(key,isZhLang){
  262. if(isZhLang){
  263. return repoAndOrgZH[key];
  264. }else{
  265. return repoAndOrgEN[key];
  266. }
  267. }
  268. function displayOrg(json){
  269. var orgDiv = document.getElementById("recommendorg");
  270. var html = "";
  271. if (json != null && json.length > 0){
  272. for(var i = 0; i < json.length;i++){
  273. var record = json[i]
  274. html += "<div class=\"column\">";
  275. html += " <div class=\"ui fluid card\">";
  276. html += " <div class=\"content\">";
  277. html += " <div class=\"ui small header\">";
  278. html += " <img class=\"ui image\" src=\"" + record["Avatar"] + "\">";
  279. html += " <div class=\"content nowrap\">";
  280. html += " <a href=\"/" + record["Name"] + "\">" + record["Name"] + "</a> " + record["FullName"];
  281. html += " <div class=\"sub header\">" + record["NumRepos"] +" " + getRepoOrOrg(1,isZh) + " ・ " + record["NumMembers"] +" " + getRepoOrOrg(2,isZh) + " ・ " + record["NumTeams"] + " " + getRepoOrOrg(3,isZh) + "</div>";
  282. html += " <div>";
  283. html += " <div>";
  284. html += " <div>";
  285. html += " <div>";
  286. html += "<div>";
  287. }
  288. }
  289. orgDiv.innerHTML = html;
  290. }