Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
pull/1788/head
zouap 3 years ago
parent
commit
9975c414cf
2 changed files with 134 additions and 14 deletions
  1. +110
    -12
      public/home/search.js
  2. +24
    -2
      templates/explore/search_new.tmpl

+ 110
- 12
public/home/search.js View File

@@ -46,17 +46,24 @@ var sortBy={
"61":"updated_unix.keyword"
};

var currentPage = 1;
var pageSize = 15;
var currentSearchTableName ="";
var currentSearchKeyword="";
var currentSearchSortBy="";
var OnlySearchLabel=false;

function searchItem(type,sortType){
console.log("enter here.");
var keyword = document.getElementById("keyword_input").value;
var page =1;
var pageSize=15;
if(!isEmpty(keyword)){
doSearch(itemType[type],keyword,page,pageSize,false,sortBy[sortType]);
currentSearchKeyword = document.getElementById("keyword_input").value;
if(!isEmpty(currentSearchKeyword)){
currentSearchTableName = itemType[type];
doSearch(itemType[type],currentSearchKeyword,page,pageSize,false,sortBy[sortType]);
}
}



function search(){
console.log("enter here.");
var keyword = document.getElementById("keyword_input").value;
@@ -64,15 +71,15 @@ function search(){
var pageSize=15;
if(!isEmpty(keyword)){
doSearch("repository",keyword,page,pageSize,false,sortBy[11]);
doSearch("issue",keyword,page,pageSize,true);
doSearch("user",keyword,page,pageSize,true);
doSearch("org",keyword,page,pageSize,true);
doSearch("dataset",keyword,page,pageSize,true);
doSearch("pr",keyword,page,pageSize,true);
doSearch("issue",keyword,page,pageSize,true,"");
doSearch("user",keyword,page,pageSize,true,"");
doSearch("org",keyword,page,pageSize,true,"");
doSearch("dataset",keyword,page,pageSize,true,"");
doSearch("pr",keyword,page,pageSize,true,"");
}
}

function doSearch(tableName,keyword,page,pageSize=15,onlyReturnNum=true,sortBy,OnlySearchLabel=false){
function doSearch(tableName,keyword,page,pageSize=15,onlyReturnNum=true,sortBy="",OnlySearchLabel=false){
$.ajax({
type:"GET",
url:"/all/dosearch/",
@@ -114,6 +121,7 @@ function displayResult(tableName,page,jsonResult,onlyReturnNum,keyword){
} else if (tableName == "pr") {
displayPrResult(page,jsonResult,onlyReturnNum,keyword);
}
setPage(jsonResult,pageSize);
}

function displayPrResult(page,jsonResult,onlyReturnNum,keyword){
@@ -484,4 +492,94 @@ var repoAndOrgEN={
"5":" minutes ago",
"6":" seconds ago",
"7":" days ago"
};
};




function page(current){
//function doSearch(tableName,keyword,page,pageSize=15,onlyReturnNum=true,sortBy="",OnlySearchLabel=false){
doSearch(currentSearchTableName,currentSearchKeyword,current,pageSize,false,currentSearchSortBy,OnlySearchLabel);
}
function nextPage(){
var current = $('#currentPage').text();
console.log("current=" + current);
page(current,pageSize);
}
function prePage(){
var current =$('#currentPage').text();
console.log("current=" + current);
if(current > 1){
console.log("current=" + (current - 2));
page(current - 2,pageSize);
}
}
function goPage(){
var goNum = $('#goNum').val();
var pageTotal = $("#totalNum").text();
var pageNum = parseInt(pageTotal/pageSize);
if(pageTotal%pageSize!=0){
pageNum += 1;
}else {
pageNum = pageNum;
}
if (goNum<=0){
alert("请输入大于0的数值");
}
else if(goNum<=pageNum){
page(goNum - 1,pageSize);
}
else{
alert("不能超出总页码!");
}
}


function setPage(pageData,pageSize,currentPage){
if (isEmpty(pageData)){
return;
}
var startIndex = currentPage * pageSize;
if(pageData.Total > 0){
startIndex = startIndex + 1;
}
$('#startIndex').text(startIndex);
$('#endIndex').text(pageData.current * pageSize + pageData.data.length);
$('#totalNum').text(pageData.total);
$('#displayPage1').text(pageData.current + 1);
console.log("set prePage status, pageData.current=" + pageData.current);
if(pageData.current == 0){
console.log("set prePage disabled.");
$('#prePage').removeAttr("href");
}
else{
$('#prePage').attr("href","javascript:prePage()");
}
if((pageData.current + 1) * pageSize >= pageData.total){
console.log("set nextPage disabled.");
$('#nextPage').removeAttr("href");
}
else{
$('#nextPage').attr("href","javascript:nextPage()");
}
var pageTotal = pageData.total;
var pageNum = parseInt(pageTotal/pageSize);
if(pageTotal%pageSize!=0){
pageNum += 1;
}else {
pageNum = pageNum;
}
$("#totalPageNum").text(pageNum);
}

+ 24
- 2
templates/explore/search_new.tmpl View File

@@ -17,6 +17,8 @@
</div>
</div>
</div>

<div class="ui container seachnav">
<div class="ui secondary pointing menu">
@@ -72,8 +74,28 @@
</div><!--seach list end-->
<!--pages-->
{{template "base/paginate" .}}
<div class="center page buttons" style="margin: 0px auto 15px">
<div class="ui borderless pagination menu">
<span class="text" id="page_total"></span>
<a class="disabled item navigation" href="" id="startPage"><i class="angle double left icon"></i><span class="navigation_label">&nbsp;首页</span></a>
<a class="disabled item navigation" id="lastPage">
<i class="left arrow icon"></i><span class="navigation_label">&nbsp;</span>
</a>
<span id="pages">
<a class="active item">1</a>
<a class=" item" href="/explore/repos?page=2&amp;sort=active&amp;q=">2</a>
<a class=" item" href="/explore/repos?page=3&amp;sort=active&amp;q=">3</a>
<a class=" item" href="/explore/repos?page=4&amp;sort=active&amp;q=">4</a>
<a class=" item" href="/explore/repos?page=5&amp;sort=active&amp;q=">5</a>
<a class="disabled item">...</a>
</span>
<a class="item navigation" href="" id="nextPage">
<span class="navigation_label">&nbsp;</span><i class="icon right arrow"></i>
</a>
<a class=" item navigation" href="" id="endPage"><span class="navigation_label">末页&nbsp;</span><i class="angle double right icon"></i></a>
</div>
</div>
</div>

</div>


Loading…
Cancel
Save