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

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