Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.5.1^2
zouap 4 years ago
parent
commit
c1ae8275db
4 changed files with 143 additions and 0 deletions
  1. +45
    -0
      public/home/home.js
  2. +82
    -0
      routers/home.go
  3. +2
    -0
      routers/routes/routes.go
  4. +14
    -0
      templates/home.tmpl

+ 45
- 0
public/home/home.js View File

@@ -6,6 +6,7 @@ if(isEmpty(token)){
token = meta.attr("content");
}
}

var swiperNewMessage = new Swiper(".newslist", {
direction: "vertical",
slidesPerView: 10,
@@ -15,6 +16,18 @@ var swiperNewMessage = new Swiper(".newslist", {
disableOnInteraction: false,
},
});
var swiperEvent = new Swiper(".event-list", {
slidesPerView: 2,
spaceBetween: 30,
pagination: {
el: ".swiper-pagination",
clickable: true,
},
autoplay: {
delay: 2500,
disableOnInteraction: false,
},
});
var swiperRepo = new Swiper(".homepro-list", {
slidesPerView: 1,
slidesPerColumn: 2,
@@ -433,6 +446,38 @@ function queryRecommendData(){
}
});

$.ajax({
type:"GET",
url:"/recommend/imageinfo",
headers: {
authorization:token,
},
dataType:"json",
async:false,
success:function(json){
displayActivity(json);
},
error:function(response) {
}
});
}

function displayActivity(json){
var activityDiv = document.getElementById("recommendactivity");
var html = "";
if (json != null && json.length > 0){
for(var i = 0; i < json.length;i++){
var record = json[i]
html += "<div class=\"swiper-slide\">";
html += "<a href=\"" + record["image_link"] + "\" class=\"ui fluid card\">";
html += " <div class=\"image\"><img src=\"" + record["url"] + "\"></div>"
html += "</a>";
html += "</div>";
}
}
activityDiv.innerHTML = html;
swiperEvent.updateSlides();
swiperEvent.updateProgress();
}

function displayRepo(json){


+ 82
- 0
routers/home.go View File

@@ -8,6 +8,7 @@ package routers
import (
"bytes"
"net/http"
"strconv"
"strings"

"code.gitea.io/gitea/services/repository"
@@ -640,6 +641,87 @@ func GetRecommendOrg() ([]map[string]interface{}, error) {
}
return resultOrg, nil
}
func GetImageInfo() ([]map[string]interface{}, error) {
url := setting.RecommentRepoAddr + "picture_info"
result, err := repository.RecommendFromPromote(url)

if err != nil {
return nil, err
}
imageInfo := make([]map[string]interface{}, 0)
for i := 0; i < (len(result) - 1); i++ {
line := result[i]
imageMap := make(map[string]interface{})
if line[0:4] == "url=" {
url := line[4:]
imageMap["url"] = url
if result[i+1][0:11] == "image_link=" {
image_link := result[i+1][11:]
imageMap["image_link"] = image_link
}
}
imageInfo = append(imageInfo, imageMap)
i = i + 1
}
return imageInfo, nil
}

func GetRankUser(index string) ([]map[string]interface{}, error) {
url := setting.RecommentRepoAddr + "user_rank_" + index
result, err := repository.RecommendFromPromote(url)

if err != nil {
return nil, err
}
resultOrg := make([]map[string]interface{}, 0)
for _, userRank := range result {
tmpIndex := strings.Index(userRank, " ")
userName := userRank
score := 0
if tmpIndex != -1 {
userName = userRank[0:tmpIndex]
tmpScore, err := strconv.Atoi(userRank[tmpIndex+1:])
if err != nil {
log.Info("convert to int error.")
}
score = tmpScore
}
user, err := models.GetUserByName(userName)
if err == nil {
userMap := make(map[string]interface{})
userMap["Name"] = user.Name
userMap["Description"] = user.Description
userMap["FullName"] = user.FullName
userMap["HomeLink"] = user.HomeLink()
userMap["ID"] = user.ID
userMap["Avatar"] = user.RelAvatarLink()
userMap["Score"] = score
resultOrg = append(resultOrg, userMap)
} else {
log.Info("query user error," + err.Error())
}
}
return resultOrg, nil
}

func GetImageInfoFromPromote(ctx *context.Context) {
imageInfo, err := GetImageInfo()
if err != nil {
ctx.ServerError("500", err)
return
}
ctx.JSON(200, imageInfo)
}

func GetUserRankFromPromote(ctx *context.Context) {
index := ctx.Params("index")
resultUserRank, err := GetRankUser(index)
if err != nil {
ctx.ServerError("500", err)
return
}
ctx.JSON(200, resultUserRank)
}

func RecommendOrgFromPromote(ctx *context.Context) {
resultOrg, err := GetRecommendOrg()


+ 2
- 0
routers/routes/routes.go View File

@@ -325,6 +325,8 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/action/notification", routers.ActionNotification)
m.Get("/recommend/org", routers.RecommendOrgFromPromote)
m.Get("/recommend/repo", routers.RecommendRepoFromPromote)
m.Get("/recommend/userrank/:index", routers.GetUserRankFromPromote)
m.Get("/recommend/imageinfo", routers.GetImageInfoFromPromote)
m.Post("/all/search/", routers.Search)
m.Get("/all/search/", routers.EmptySearch)
m.Get("/all/dosearch/", routers.SearchApi)


+ 14
- 0
templates/home.tmpl View File

@@ -36,6 +36,20 @@
<!--组织-->
<div class="ui container homeorg">
<div class="ui stackable grid">
<div class="sixteen wide tablet four wide computer column homeorg-tit">
<h2>社区活动</h2>
<p><span class="ui text grey">社区准备了丰富的活动,等你来参加!</p>
</div>
<div class="sixteen wide tablet twelve wide computer column">
<div class="event-list">
<div class="swiper-wrapper" id="recommendactivity">
</div>
<div class="swiper-pagination"></div>
</div>
</div>

<div class="sixteen wide tablet four wide computer column homeorg-tit">
<h2>{{.page_recommend_org}}</h2>
<p><span class="ui text grey">{{.page_recommend_org_desc}}&nbsp;</span><a href="{{.RecommendURL}}">{{.page_recommend_org_commit}}</a></p>


Loading…
Cancel
Save