var token; if(isEmpty(token)){ var meta = $("meta[name=_uid]"); if(!isEmpty(meta)){ token = meta.attr("content"); console.log("token is uid:" + token); } } var html =document.documentElement; var lang = html.attributes["lang"] var isZh = true; if(lang != null && lang.nodeValue =="en-US" ){ console.log("the language is " + lang.nodeValue); isZh=false; }else{ console.log("default lang=zh"); } function isEmpty(str){ if(typeof str == "undefined" || str == null || str == ""){ return true; } return false; } var itemType={ "1":"repository", "2":"issue", "3":"user", "4":"org", "5":"dataset", "6":"pr" }; var sortBy={ "11":"updated_unix.keyword", "12":"num_watches.keyword", "13":"num_stars.keyword", "14":"num_forks.keyword", "21":"updated_unix.keyword", "31":"created_unix.keyword", "32":"name", "41":"created_unix.keyword", "42":"name", "51":"download_times.keyword", "61":"updated_unix.keyword" }; 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]); } } function search(){ console.log("enter here."); var keyword = document.getElementById("keyword_input").value; var page =1; 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); } } function doSearch(tableName,keyword,page,pageSize=15,onlyReturnNum=true,sortBy){ $.ajax({ type:"GET", url:"/all/dosearch/", headers: { authorization:token, }, dataType:"json", dataType:"json", data:{ 'TableName': tableName, 'Key': keyword, 'Page': page, 'PageSize': pageSize, 'OnlyReturnNum':onlyReturnNum, 'SortBy':sortBy }, async:true, success:function(json){ console.log(json); displayResult(tableName,page,json,onlyReturnNum,keyword); }, error:function(response) { console.log(response); } }); } function displayResult(tableName,page,jsonResult,onlyReturnNum,keyword){ if(tableName == "repository") { displayRepoResult(page,jsonResult,onlyReturnNum,keyword); } else if (tableName == "issue") { displayIssueResult(page,jsonResult,onlyReturnNum,keyword); } else if (tableName == "user") { displayUserResult(page,jsonResult,onlyReturnNum,keyword); } else if (tableName == "org") { displayOrgResult(page,jsonResult,onlyReturnNum,keyword); } else if (tableName == "dataset") { displayDataSetResult(page,jsonResult,onlyReturnNum,keyword); } else if (tableName == "pr") { displayPrResult(page,jsonResult,onlyReturnNum,keyword); } } function displayPrResult(page,jsonResult,onlyReturnNum,keyword){ var data = jsonResult.Result; var total = jsonResult.Total; $('#pr_total').text(total); if(!onlyReturnNum){ $('#keyword_desc').text(keyword); $('#obj_desc').text("合并请求"); $('#child_total').text(total); } } function displayDataSetResult(page,jsonResult,onlyReturnNum,keyword){ var data = jsonResult.Result; var total = jsonResult.Total; $('#dataset_total').text(total); if(!onlyReturnNum){ $('#keyword_desc').text(keyword); $('#obj_desc').text("数据集"); $('#child_total').text(total); } } function displayOrgResult(page,jsonResult,onlyReturnNum,keyword){ var data = jsonResult.Result; var total = jsonResult.Total; $('#org_total').text(total); if(!onlyReturnNum){ $('#keyword_desc').text(keyword); $('#obj_desc').text("组织"); $('#child_total').text(total); } } function displayUserResult(page,jsonResult,onlyReturnNum,keyword){ var data = jsonResult.Result; var total = jsonResult.Total; $('#user_total').text(total); if(!onlyReturnNum){ $('#keyword_desc').text(keyword); $('#obj_desc').text("用户"); $('#child_total').text(total); } } function displayIssueResult(page,jsonResult,onlyReturnNum,keyword){ var data = jsonResult.Result; var total = jsonResult.Total; $('#issue_total').text(total); if(!onlyReturnNum){ setActivate("issue_item"); $('#keyword_desc').text(keyword); $('#obj_desc').text("任务"); $('#child_total').text(total); var sortHtml = ""; sortHtml +="最近更新" var html = ""; var currentTime = new Date().getTime(); for(var i = 0; i < data.length;i++){ var recordMap = data[i]; html += "
" + recordMap["description"] + "
"; html +=""; html +=" "; html +=" " + record["repoUrl"] +"#" + record["id"] + ""; html +=" "; if(isEmpty(record["is_closed"]) || record["is_closed"]=="false"){ html += "关闭"; }else{ html += "开启中"; } html +=" 最后更新于 " + getTime(recordMap["updated_unix"],currentTime) +""; html +="
"; html +="" + recordMap["description"] + "
"; html += ""; html +=" " + recordMap["num_stars"] + "" + recordMap["num_forks"]; html +=" 最后更新于 " + getTime(recordMap["updated_unix"],currentTime) +""; if(!isEmpty(recordMap["lang"])){ html +=" " + recordMap["lang"] + ""; } html +="
"; html +="