Browse Source

首页改版新功能。

Signed-off-by: zouap <zouap@pcl.ac.cn>
pull/3286/head
zouap 2 years ago
parent
commit
aaac5be7cb
3 changed files with 55 additions and 18 deletions
  1. +14
    -6
      models/dataset.go
  2. +34
    -11
      routers/home.go
  3. +7
    -1
      services/repository/repository.go

+ 14
- 6
models/dataset.go View File

@@ -122,22 +122,22 @@ func (datasets DatasetList) loadAttachmentAttributes(opts *SearchDatasetOptions)
for i := range datasets {
if attachment.DatasetID == datasets[i].ID {

if !attachment.IsPrivate{
if !attachment.IsPrivate {
datasets[i].Attachments = append(datasets[i].Attachments, attachment)
}else{
} else {
permission, ok := permissionMap[datasets[i].ID]
if !ok {

permission = false
datasets[i].Repo.GetOwner()
if !permission {
if datasets[i].Repo.OwnerID==opts.User.ID{
if datasets[i].Repo.OwnerID == opts.User.ID {
permission = true
}else{
} else {
isCollaborator, _ := datasets[i].Repo.IsCollaborator(opts.User.ID)
isInRepoTeam,_:=datasets[i].Repo.IsInRepoTeam(opts.User.ID)
isInRepoTeam, _ := datasets[i].Repo.IsInRepoTeam(opts.User.ID)

if isCollaborator ||isInRepoTeam {
if isCollaborator || isInRepoTeam {
permission = true
}
}
@@ -603,3 +603,11 @@ func UpdateDatasetCreateUser(ID int64, user *User) error {
}
return nil
}

func QueryDatasetGroupByTask() ([]map[string]interface{}, error) {
rows, err := x.QueryInterface("SELECT count(*) as total,task FROM public.dataset where task <>'' group by task order by total desc limit 7")
if err != nil {
return nil, err
}
return rows, nil
}

+ 34
- 11
routers/home.go View File

@@ -7,6 +7,7 @@ package routers

import (
"bytes"
"encoding/json"
"net/http"
"strconv"
"strings"
@@ -672,7 +673,7 @@ func NotFound(ctx *context.Context) {
}

func getRecommendOrg() ([]map[string]interface{}, error) {
url := setting.RecommentRepoAddr + "organizations"
url := setting.RecommentRepoAddr + "home/organizations"
result, err := repository.RecommendFromPromote(url)

if err != nil {
@@ -745,7 +746,7 @@ func GetMapInfo(ctx *context.Context) {
}

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

if err != nil {
@@ -792,25 +793,47 @@ func GetUserRankFromPromote(ctx *context.Context) {
ctx.JSON(200, resultUserRank)
}

func getMapContent(fileName string) []map[string]string {
url := setting.RecommentRepoAddr + fileName
result, err := repository.RecommendContentFromPromote(url)
remap := make([]map[string]string, 0)
if err == nil {
json.Unmarshal([]byte(result), &remap)
}
return remap
}

func RecommendHomeInfo(ctx *context.Context) {
resultOrg, err := getRecommendOrg()
if err != nil {
log.Info("error." + err.Error())
}
resultRepo, err := repository.GetRecommendRepoFromPromote("projects")
if err != nil {
log.Info("error." + err.Error())
}
resultImage, err := getImageInfo("picture_info")
resultRepo, err := repository.GetRecommendRepoFromPromote("home/projects")
if err != nil {
log.Info("error." + err.Error())
}
resultActivityInfo := getMapContent("home/activity_info")
mapInterface := make(map[string]interface{})
mapInterface["org"] = resultOrg
mapInterface["repo"] = resultRepo
mapInterface["image"] = resultImage
//mapInterface["cloudbrain"] = resultCloudBrain
mapInterface["activity"] = resultActivityInfo

user_experience := getMapContent("home/user_experience")
for _, amap := range user_experience {
userId := amap["userid"]
userIntId, _ := strconv.Atoi(userId)
user, err := models.GetUserByID(int64(userIntId))
if err == nil {
amap["name"] = user.FullName
amap["detail"] = user.Description
amap["avatar"] = user.AvatarLink()
}
}
mapInterface["user_experience"] = user_experience
dataset, err := models.QueryDatasetGroupByTask()
if err == nil {
mapInterface["dataset"] = dataset
}
ctx.JSON(http.StatusOK, mapInterface)
}

@@ -824,4 +847,4 @@ func HomePrivacy(ctx *context.Context) {

func HomeResoruceDesc(ctx *context.Context) {
ctx.HTML(200, tplResoruceDesc)
}
}

+ 7
- 1
services/repository/repository.go View File

@@ -119,6 +119,12 @@ func GetRecommendRepoFromPromote(filename string) ([]map[string]interface{}, err

//resultRepo := make([]*models.Repository, 0)
for _, repoName := range result {
tmpIndex1 := strings.Index(repoName, "##")
repoLabel := ""
if tmpIndex1 != -1 {
repoName := strings.Trim(repoName[0:tmpIndex1], " ")
repoLabel = strings.Trim(repoName[tmpIndex1+2:], " ")
}
tmpIndex := strings.Index(repoName, "/")
if tmpIndex == -1 {
log.Info("error repo name format.")
@@ -131,7 +137,7 @@ func GetRecommendRepoFromPromote(filename string) ([]map[string]interface{}, err
repoMap["ID"] = fmt.Sprint(repo.ID)
repoMap["Name"] = repo.Name
repoMap["Alias"] = repo.Alias
repoMap["Label"] = repoLabel
repoMap["OwnerName"] = repo.OwnerName
repoMap["NumStars"] = repo.NumStars
repoMap["NumForks"] = repo.NumForks


Loading…
Cancel
Save