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

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