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

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