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.

select_pro.tmpl 12 kB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <style>
  2. .text-right{
  3. float:right !important;
  4. }
  5. .header{
  6. font-weight:bold;
  7. font-size: 18px;
  8. font-family: SourceHanSansSC-medium;
  9. }
  10. .cor{
  11. color:#0366D6 !important;
  12. }
  13. .header_card{
  14. /* color:#003A8C !important; */
  15. color:#0366D6 !important;
  16. margin: 10px 0 0px 0;
  17. height: 25px;
  18. }
  19. .marg{
  20. margin: 0 5px !important;
  21. }
  22. .content_list{
  23. max-height: 130px;
  24. overflow: auto;
  25. }
  26. .Relist{
  27. color:#0366D6 !important;
  28. }
  29. .descript_height{
  30. color: #101010 !important;
  31. margin: 10px 0;
  32. height: 40px !important;
  33. word-break:break-all;
  34. line-height: 20px;
  35. overflow: hidden;
  36. /* overflow: hidden!important;
  37. word-wrap:break-word!important; */
  38. }
  39. .tags_height{
  40. height: 30px !important;
  41. }
  42. .full_height{
  43. height: 100%;
  44. }
  45. .omit{
  46. overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  47. }
  48. /deep/ ui.checkbox input[type=checkbox]::after{
  49. border: 1px solid #0366D6 !important;
  50. }
  51. .nowrap-2 {
  52. /* height: 2.837em; */
  53. /* line-height: 1.4285em; */
  54. overflow: hidden;
  55. overflow: hidden;
  56. display: -webkit-box;
  57. -webkit-line-clamp: 2;
  58. -webkit-box-orient: vertical;
  59. }
  60. </style>
  61. <div class="ui stackable grid">
  62. <div style="width: 100%;margin:15px 0;">
  63. {{if .tags}}
  64. <span class="header">
  65. 精选项目
  66. </span>
  67. <!-- {{.IsOrganizationOwner}} -->
  68. {{if .IsOrganizationOwner}}
  69. <a class="text-right" id="model" onclick="showcreate()" >{{svg "octicon-gear" 16}}自定义</a>
  70. {{end}}
  71. {{end}}
  72. </div>
  73. <div style="width: 100%;">
  74. {{ range .tags}}
  75. {{if eq .TagName "精选项目"}}
  76. <div class="ui three cards" style="margin-bottom: 10px;">
  77. {{ range .RepoList}}
  78. <div class="card" >
  79. <div class="extra full_height cor" >
  80. <div class=" header header_card omit" >
  81. <a class="header_card image poping up " href="{{.Link}}" data-content="{{.Name}}" data-position="top left" data-variation="tiny inverted"> {{.Name}}</a>
  82. </div>
  83. <div class='content descript_height nowrap-2'>
  84. {{.Description}}
  85. </div>
  86. <div class="content " >
  87. {{if .Topics }}
  88. <div class=" tags " style="position: relative;">
  89. {{range .Topics}}
  90. {{if ne . "" }}<a style="max-width:100%;margin: 5px 0;display:inline-flex;" href="{{AppSubUrl}}/explore/repos?q={{.}}&topic={{$.Topic}}" ><span class="ui small label topic omit" >{{.}}</span></a>{{end}}
  91. {{end}}
  92. </div>
  93. {{end}}
  94. </div>
  95. </div>
  96. <div class=" extra " style="color:#888888;border-top: none !important">
  97. <div class="ui mini right compact marg" >
  98. <a class="item marg ">
  99. {{svg "octicon-eye" 16}} {{.NumWatches}}
  100. </a>
  101. <a class="item marg">
  102. {{svg "octicon-star" 16}} {{.NumStars}}
  103. </a>
  104. <a class="item marg">
  105. {{svg "octicon-git-branch" 16}} {{.NumForks}}
  106. </a>
  107. </div>
  108. </div>
  109. </div>
  110. {{end}}
  111. </div>
  112. {{end}}
  113. {{end}}
  114. </div>
  115. </div>
  116. <div class="ui modal">
  117. <div class="header" style="padding: 1rem;background-color: rgba(240, 240, 240, 100);">
  118. <h4 id="model_header">自定义精选项目</h4>
  119. </div>
  120. <div class="content content-padding" style="color: black;">
  121. <p>最多可选9个公开项目</p>
  122. <div class="ui search" >
  123. <div class="ui input" style="width: 100%;">
  124. <input type="text" id = 'search_selectPro' placeholder="Search ..." value = '' oninput="search()">
  125. </div>
  126. </div>
  127. <div style="margin: 10px ;">
  128. <div id ='org_list' style="margin-bottom: 20px;"class="content_list" >
  129. </div>
  130. </div>
  131. <p id='recommend'></p>
  132. <div class="inline field" style="margin-left: 37%;">
  133. <div class="actions">
  134. <button id="submitId" type="button" class="ui create_train_job green deny button" onclick="saveSeletedPro(1)">
  135. {{.i18n.Tr "explore.save"}}
  136. </button>
  137. <button class="ui button cancel" >{{.i18n.Tr "explore.cancel"}}</button>
  138. </div>
  139. </div>
  140. </div>
  141. </div>
  142. <script>
  143. var data;
  144. var filterData=[];
  145. var num=0;
  146. function showcreate(obj){
  147. document.getElementById("search_selectPro").value=''
  148. $('.ui.modal')
  149. .modal({
  150. centered: false,
  151. onShow:function(){
  152. $("#org_list").empty()
  153. getPro(1)
  154. },
  155. onHide:function(){
  156. }
  157. })
  158. .modal('show')
  159. }
  160. function getPro(typeTag){
  161. $.ajax({
  162. type:"GET",
  163. url:"/org/{{.Org.Name}}/org_tag/repo_list?tagId="+typeTag,
  164. dataType:"json",
  165. async:false,
  166. success:function(json){
  167. data = json.data;
  168. var n_length = data.length
  169. pro_html = getHTML(data)
  170. $("#org_list").append(pro_html)
  171. // console.log('原始',data)
  172. checkedNum(0)
  173. }
  174. });
  175. }
  176. function getHTML(data){
  177. let pro_html=''
  178. for (let i=0;i<data.length;i++){
  179. if (data[i].Selected==true){
  180. console.log("data[i]:",data[i])
  181. pro_html += `<div class="ui checkbox" style="width: 33%;margin-bottom:10px" > <input type="checkbox" id = " ${i}" checked="" onclick="checkedNum(${i})" class="Relist" name ='select_pro_name' data-repoid="${data[i].RepoID}" data-reponame="${data[i].RepoName}" data-selected=${data[i].Selected} > <label class='omit image poping up' data-content=${data[i].RepoName}  data-position="top left " data-variation="mini"> ${data[i].RepoName}</label></div>`
  182. pro_html += '</div>'
  183. }
  184. else{
  185. pro_html += `<div class="ui checkbox" style="width: 33%;margin-bottom:10px" > <input type="checkbox" id = "${i}" onclick="checkedNum(${i})" class="Relist" name ='select_pro_name' data-repoid="${data[i].RepoID}" data-reponame="${data[i].RepoName}" data-selected= ${data[i].Selected}> <label class='omit image poping up' data-content=${data[i].RepoName}  data-position="top left " data-variation="mini"> ${data[i].RepoName} </label></div>`
  186. pro_html += '</div>'
  187. }
  188. }
  189. return pro_html
  190. }
  191. function saveSeletedPro(typeTag){
  192. var saveData=[];
  193. $('input[name="select_pro_name"]:checked').each(function(){
  194. console.log('值',this.dataset.repoid)
  195. saveData.push(parseInt(this.dataset.repoid));
  196. })
  197. if(saveData.length>9){
  198. alert("最多可选9个,保存失败")
  199. return
  200. }
  201. // saveData = getSelecteDataID();
  202. // console.log("数据:",saveData)
  203. $.ajax({
  204. type:"POST",
  205. url:"/org/{{.Org.Name}}/org_tag/repo_submit?tagId="+typeTag,
  206. contentType:'application/json',
  207. dataType:"json",
  208. async:false,
  209. data:JSON.stringify({'repoList':saveData
  210. }),
  211. success:function(res){
  212. console.log('保存成功');
  213. location.reload()
  214. }
  215. });
  216. }
  217. function getSelecteData(){
  218. var selectedData=[];
  219. $('input[name="select_pro_name"]:checked').each(function(){
  220. // console.log(this)
  221. // console.log('值',this.dataset.selected)
  222. selectedData.push({"RepoID":parseInt(this.dataset.repoid),"RepoName":this.dataset.reponame,"Selected":JSON.parse(this.dataset.selected)});
  223. })
  224. return selectedData
  225. }
  226. function search(){
  227. var selectedData = getSelecteData();
  228. var searchValue = document.getElementById("search_selectPro").value;
  229. filterData=[];
  230. console.log("searchValue:",searchValue)
  231. for (let i=0;i<data.length;i++){
  232. var isInclude=false;
  233. if(data[i].RepoName.toLowerCase().includes(searchValue.toLowerCase())){
  234. filterData.push(data[i])
  235. }
  236. }
  237. console.log("选中的值:",selectedData)
  238. console.log("筛选包括选中的值:",filterData)
  239. var showData=[];
  240. for(i=0;i<selectedData.length;i++){
  241. filterData =filterData.filter((item)=>{
  242. return item.RepoID!=selectedData[i].RepoID
  243. });
  244. }
  245. console.log("筛选后不包括选中的值:",filterData)
  246. $("#org_list").empty()
  247. if(searchValue!=""){
  248. if (filterData.length!=0){
  249. var pro_html = getHTML(selectedData);
  250. console.log("selectedData_pro_html:",pro_html)
  251. $("#org_list").append(pro_html)
  252. pro_html= getHTML(filterData);
  253. $("#org_list").append(pro_html)
  254. }else{
  255. var pro_html = getHTML(selectedData);
  256. $("#org_list").append(pro_html)
  257. }
  258. }else{
  259. var pro_html = getHTML(data);
  260. $("#org_list").append(pro_html)
  261. }
  262. }
  263. function checkedNum(id){
  264. num=0;
  265. var inputs = document.getElementsByName("select_pro_name")
  266. for (var i=0;i<inputs.length;i++){
  267. if(inputs[i].checked){
  268. num++
  269. if(num>9){
  270. document.getElementById(id).checked=false
  271. alert("选择超过9个,请重新选择!")
  272. return
  273. }
  274. }
  275. }
  276. var show_num = 9-num;
  277. document.getElementById("recommend").innerHTML="还能推荐"+show_num+"个"
  278. }
  279. </script>