|
- 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 +="<a class=\"item\" href=\"javascript:searchItem(2,21);\" tabindex=\"-1\" role=\"menuitem\" id=\"menuitem_1\">最近更新</a>"
- var html = "";
- var currentTime = new Date().getTime();
- for(var i = 0; i < data.length;i++){
- var recordMap = data[i];
- html += "<div class=\"item\">";
- html += " <div class=\"content\">";
- html += " <div class=\"ui header\">";
- html += " <a class=\"name\" href=\"/" + record["repoUrl"] +"\">" + record["name"] + "</a>";
- html +=" </div>";
- html += " <div class=\"description\">";
- html += " <p class=\"has-emoji\"> " + recordMap["description"] + "</p>";
- html +=" <p class=\"time\">";
- html +=" <i class=\"ri-code-box-line\"></i>";
- html +=" <a class=\"am-text grey\" href=\"/" + record["repoUrl"] +"/" + record["id"] + "\"> " + record["repoUrl"] +"#" + record["id"] + "</a>";
- html +=" <i class=\"ri-information-line am-ml-10\"></i> ";
- if(isEmpty(record["is_closed"]) || record["is_closed"]=="false"){
- html += "关闭";
- }else{
- html += "开启中";
- }
- html +=" <span class=\"am-ml-10\"></span> 最后更新于 <span class=\"time-since poping up\" title=\"\" data-content=\"\" data-variation=\"inverted tiny\">" + getTime(recordMap["updated_unix"],currentTime) +"</span>";
-
- html +=" </p>";
- html +=" </div>";
- html +=" </div>";
- html +="</div>";
- }
-
- }
- }
-
- function setActivate(name){
- $('#repo_item').removeClass("active");
- $('#user_item').removeClass("active");
- $('#issue_item').removeClass("active");
- $('#dataset_item').removeClass("active");
- $('#org_item').removeClass("active");
- $('#pr_item').removeClass("active");
- var tmp = "#" + name;
- $(tmp).addClass("active");
- }
-
- function displayRepoResult(page,jsonResult,onlyReturnNum,keyword){
- var data = jsonResult.Result;
- var total = jsonResult.Total;
- $('#repo_total').text(total);
-
- if(!onlyReturnNum){
- setActivate("repo_item");
- $('#keyword_desc').text(keyword);
- $('#obj_desc').text("项目");
- $('#child_total').text(total);
-
- var sortHtml = "";
- sortHtml +="<a class=\"item\" href=\"javascript:searchItem(1,11);\" tabindex=\"-1\" role=\"menuitem\" id=\"menuitem_1\">最近更新</a>"
- sortHtml +="<a class=\"item\" href=\"javascript:searchItem(1,12);\" tabindex=\"-1\" role=\"menuitem\" id=\"menuitem_1\">关注数</a>"
- sortHtml +="<a class=\"item\" href=\"javascript:searchItem(1,13);\" tabindex=\"-1\" role=\"menuitem\" id=\"menuitem_1\">点赞数</a>"
- sortHtml +="<a class=\"item\" href=\"javascript:searchItem(1,14);\" tabindex=\"-1\" role=\"menuitem\" id=\"menuitem_1\">Fork数</a>"
-
- document.getElementById("sort_type").innerHTML=sortHtml;
-
- var html = "";
- var currentTime = new Date().getTime();
- for(var i = 0; i < data.length;i++){
- var recordMap = data[i];
- html += "<div class=\"item\">";
- if(!isEmpty(recordMap['avatar'])){
- html += "<img class=\"ui avatar image\" src=\"" + recordMap['avatar'] + "\">";
- }
- html += " <div class=\"content\">";
- html += " <div class=\"ui header\">";
- html += " <a class=\"name\" href=\"/" + recordMap["owner_name"] + "/" + recordMap["real_name"] +"\"> <span class=\"highlight\">" + recordMap["owner_name"] +"</span> <span>/</span> <strong>" + recordMap["name"] + "</strong></a>";
- html +=" <span class=\"middle\"><svg class=\"svg octicon-repo-clone\" width=\"16\" height=\"16\" aria-hidden=\"true\"><use xlink:href=\"#octicon-repo-clone\"></use></svg></span>";
- html +=" </div>";
- html += " <div class=\"description\">";
- html += " <p class=\"has-emoji\"> " + recordMap["description"] + "</p>";
- html += " <div class=\"ui tags\">";
- if(!isEmpty(recordMap["topics"]) && recordMap["topics"] !="null"){
- for(var j = 0; j < recordMap["topics"].length;j++){
- html +=" <a href=\"/explore/repos?q=" + recordMap["topics"][j] + "&topic=\"><div class=\"ui small label topic\">"+ recordMap["topics"][j] + "</div></a>";
- }
- }
- html +=" </div>";
- html +=" <p class=\"time\">";
- html +=" <i class=\"ri-star-line\"></i>" + recordMap["num_stars"] + "<i class=\"ri-git-branch-line am-ml-10\"></i>" + recordMap["num_forks"];
- html +=" 最后更新于 <span class=\"time-since poping up\" title=\"\" data-content=\"\" data-variation=\"inverted tiny\">" + getTime(recordMap["updated_unix"],currentTime) +"</span>";
- if(!isEmpty(recordMap["lang"])){
- html +=" <span class=\"text grey am-ml-10\"><i class=\"color-icon\" style=\"background-color: #3572A5\"></i>" + recordMap["lang"] + "</span>";
- }
- html +=" </p>";
- html +=" </div>";
- html +=" </div>";
- html +="</div>";
- }
-
- document.getElementById("child_search_item").innerHTML=html;
- }
- }
-
- function getTime(UpdatedUnix,currentTime){
- UpdatedUnix = UpdatedUnix;
- currentTime = currentTime / 1000;
- var timeEscSecond = currentTime - UpdatedUnix;
- if( timeEscSecond < 0){
- timeEscSecond = 1;
- }
- console.log("currentTime=" + currentTime + " updateUnix=" + UpdatedUnix);
-
- var hours= Math.floor(timeEscSecond / 3600);
- //计算相差分钟数
- var leave2 = Math.floor(timeEscSecond % (3600)); //计算小时数后剩余的秒数
- var minutes= Math.floor(leave2 / 60);//计算相差分钟数
-
- var leave3=Math.floor(leave2 % 60); //计算分钟数后剩余的秒数
- var seconds= leave3;
-
- if(hours == 0 && minutes == 0){
- return seconds + getRepoOrOrg(6,isZh);
- }else{
- if(hours > 0){
- if(hours >= 24){
- return Math.ceil(hours/24) + getRepoOrOrg(7,isZh);
- }else{
- return hours + getRepoOrOrg(4,isZh);
- }
- }else{
- return minutes + getRepoOrOrg(5,isZh);
- }
- }
- }
-
- function getRepoOrOrg(key,isZhLang){
- if(isZhLang){
- return repoAndOrgZH[key];
- }else{
- return repoAndOrgEN[key];
- }
- }
-
- var repoAndOrgZH={
- "1":"项目",
- "2":"成员",
- "3":"团队",
- "4":"小时前",
- "5":"分钟前",
- "6":"秒前",
- "7":"天前"
- };
-
- var repoAndOrgEN={
- "1":"repository",
- "2":"Members ",
- "3":"Teams",
- "4":" hours ago",
- "5":" minutes ago",
- "6":" seconds ago",
- "7":" days ago"
- };
|